Search code examples
asp.net-coreopen-telemetry

How to stop reporting a metric with the OpenTelemetry .NET client


I am using OpenTelementry to capture metrics in my application.

I am wishing to capture execution timings for components of batch operations. Being batch, the activity is bursty.

I am using an observable gauge, however the .NET client is repeating the last value being captured. I can understand why, but it makes my visualisations look remarkably odd and gives the impression that the application is actively processing things that it isn't.

Disposing the Meter does stop measurements, but this is a fairly brutal approach - particularly if the Meter contains other measurements.

What is the standard approach for this? If it's of any relevance, my full stack is using Telegraf, InfluxDb2 and Grafana.


Solution

  • Resorting to searching through the Microsoft OTEL code unearthed the TemporalityPreference option on MetricReaderOptions. When set to MetricReaderTemporalityPreference.Delta, the data capture is sane (for my use-case) - i.e., if no metrics are being captured then no metrics are reported.