Member-only story

Custom Metrics in .NET Using the New IMeterFactory

William Rees
6 min readJan 22, 2024

--

.NET 8 introduced a powerful API in system diagnostics, making it seamless for developers to add custom application metrics adhering to the open telemetry standard. In this post, we’ll explore this new feature, demonstrating how it can be leveraged to publish metrics from a minimal API. Additionally, we’ll cover various approaches to test metrics and export them to Application Insights for creating insightful dashboards.

IMeterFactory was added to the system diagnostics namespace to help developers easily publish metrics from their application. Metrics can be used to capture valuable insights about your application such as:

  1. Business metrics like number of order, number of products sold, etc…
  2. Performance metrics such as API request duration
  3. Low level system metrics such as number of times a cache was refreshed, number of times a database connection is established, etc…

The IMeterFactory supports various instruments to cater to different situations. In .NET 8, these instruments include:

  • Counter
  • UpDownCounter

--

--

William Rees
William Rees

Written by William Rees

Software engineer with 10+ years of experience. I primarily work on the Microsoft and .NET ecosystem and have extensive experience with Microsoft Azure

No responses yet