I'm trying to send custom metrics to an App Service in Azure Portal given an instrumentation key. I have the following code running in .NET Core as part of a Background service:
public override async Task StartAsync(CancellationToken stoppingToken)
{
try
{
TelemetryClient telemetry = new TelemetryClient();
telemetry.TrackEvent("new event");
var sample = new MetricTelemetry();
sample.Name = "metric name";
sample.Value = 42.3;
telemetry.TrackMetric(sample);
telemetry.Flush();
}
catch (Exception e)
{
_logger.LogError($"{e.Message} {e.StackTrace}");
}
}
This sample code comes from: https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics
However I'm not sure if these metrics are even reaching the Azure instance or where to look for them. I went to Application Insights > MyInstance > Logs and found a table there named 'customEvents'. However I can't query over it. On the Metrics tabs I only get the default metrics namespace which shows the default metrics available in Azure, but not any new custom metrics.
telemetry.Flush()
aftertelemetry.TrackMetric(sample);
(sample is here). And if you run the project in visual studio, you can also check in thevisual studio output window
to see if the metric is sent or not. – Ivan Yang