I am sending a custom metric to Application Insights (Azure Monitor?) using the following C# code in an Azure Function.
(it measures the elapsed time between Service Bus message enqueued and Function code execution)
this.TelemetryClient.GetMetric("QueueTriggerLagMs").TrackValue((now - serviceBusMessage.SystemProperties.EnqueuedTimeUtc).TotalMilliseconds);
I'd expect this to be aggregated by the SDK and shown as an aggregate in the portal but its summing it, I think.
Microsoft.ApplicationInsights.TelemetryClient.TrackMetric is not the preferred method for sending metrics. Metrics should always be pre-aggregated across a time period before being sent. Use one of the GetMetric(..) overloads to get a metric object for accessing SDK pre-aggregation capabilities. If you are implementing your own pre-aggregation logic, you can use the TrackMetric() method to send the resulting aggregates. If your application requires sending a separate telemetry item at every occasion without aggregation across time, you likely have a use case for event telemetry; see TelemetryClient.TrackEvent (Microsoft.ApplicationInsights.DataContracts.EventTelemetry).
Source https://docs.microsoft.com/en-gb/azure/azure-monitor/app/api-custom-events-metrics
It's funny, while typing this question out I re-read and noticed that the wording in that pullquote is confusing and that I need to do my own aggregation.
Use one of the GetMetric(..) overloads to get a metric object for accessing SDK pre-aggregation capabilities.
Makes it sound like by using that method instead of TrackMetric
then it'll pre-aggregate but I don't think that's what they're saying.
I thought the built-in behaviour would be to aggregate for me, instead of forcing every developer to write the same code to aggregate over some batching time period that we don't know.
I'm completely lost.
Does anyone know what I'm supposed to do to track that lag time?
Relates to question.
Azure Function is not logging LogMetric telemetry to Application Insights
valueSum / valueCount
gives me a huge number. My code is as above. – Luke Puplett