in src/Relecloud.Web.CallCenter/Controllers/CartController.cs [71:104]
public IActionResult Add(int concertId, int count)
{
if (ModelState.IsValid)
{
try
{
var cartData = GetCartData();
if (!cartData.ContainsKey(concertId))
{
cartData.Add(concertId, 0);
}
cartData[concertId] = cartData[concertId] + count;
SetCartData(cartData);
// Most custom telemetry should go through OpenTelemetry APIs,
// but Azure Monitor's OpenTelemetry SDK does not support custom events yet.
// https://learn.microsoft.com/azure/azure-monitor/app/opentelemetry-add-modify#send-custom-telemetry-using-the-application-insights-classic-api
// https://learn.microsoft.com/azure/azure-monitor/app/opentelemetry-add-modify#whats-the-current-release-state-of-features-within-the-azure-monitor-opentelemetry-distro
this.telemetryClient.TrackEvent("AddToCart", new Dictionary<string, string> {
{ "ConcertId", concertId.ToString() },
{ "Count", count.ToString() }
});
// An alternative which wouldn't require AppInsights SDK usage is to log traces.
// Note that these will appear as traces in Application Insights rather than true
// separately queryable custom events. But they may work for some scenarios.
this.logger.LogInformation("Concert {ConcertId} (count {Count}) added to cart", concertId, count);
}
catch (Exception ex)
{
this.logger.LogError(ex, $"Unable to add {concertId} to cart");
}
}
return RedirectToAction(nameof(Index));
}