title: App Insights GetMetric("name").TrackValue doesn't aggregate when viewing in App Insights portal
body: <p>I am sending a custom metric to Application Insights (Azure Monitor?) using the following C# code in an Azure Function.</p>
  
  <p>(it measures the elapsed time between Service Bus message enqueued and Function code execution)</p>
  
  <pre class="lang-cs prettyprint-override"><code>this.TelemetryClient.GetMetric("QueueTriggerLagMs").TrackValue((now - serviceBusMessage.SystemProperties.EnqueuedTimeUtc).TotalMilliseconds);
  </code></pre>
  
  <p>I'd expect this to be aggregated by the SDK and shown as an aggregate in the portal but its summing it, I think.</p>
  
  <blockquote>
    <p>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).</p>
  </blockquote>
  
  <p>Source <a href="https://docs.microsoft.com/en-gb/azure/azure-monitor/app/api-custom-events-metrics" rel="nofollow noreferrer">https://docs.microsoft.com/en-gb/azure/azure-monitor/app/api-custom-events-metrics</a></p>
  
  <p>It's funny, while typing this question out I re-read and noticed that the wording in that pullquote is confusing and that <strong>I need to do my own aggregation</strong>.</p>
  
  <blockquote>
    <p>Use one of the GetMetric(..) overloads to get a metric object for accessing SDK pre-aggregation capabilities.</p>
  </blockquote>
  
  <p>Makes it sound like by using that method instead of <code>TrackMetric</code> then it'll pre-aggregate but I don't think that's what they're saying.</p>
  
  <p>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.</p>
  
  <p>I'm completely lost.</p>
  
  <p>Does anyone know what I'm supposed to do to track that lag time?</p>
  
  <hr>
  
  <p>Relates to question.</p>
  
  <p><a href="https://stackoverflow.com/questions/57810950/azure-function-is-not-logging-logmetric-telemetry-to-application-insights">Azure Function is not logging LogMetric telemetry to Application Insights</a></p>