Exploring the (underwhelming) System.Diagnostics.Metrics source generators: System.Diagnostics.Metrics APIs - Part 2 The article explains how to use the `Microsoft.Extensions.Telemetry.Abstractions` source generator to simplify metric creation in .NET, replacing manual boilerplate code from the `System.Diagnostics.Metrics` APIs introduced in .NET 6. It demonstrates updating a sample app that tracks product page views by using the source generator to automatically generate meter and instrument definitions, and also shows how to implement strongly-typed tag objects for improved type-safety. The post includes a refresher on core concepts like `Instrument` and `Meter`, and explores the generated code to highlight the reduction in manual coding required. In my previous post /creating-and-consuming-metrics-with-system-diagnostics-metrics-apis/ I provided an introduction to the System.Diagnostics.Metrics APIs introduced in .NET 6. In this post I show how to use the Microsoft.Extensions.Telemetry.Abstractions https://www.nuget.org/packages/Microsoft.Extensions.Telemetry.Abstractions source generator, explore how it changes the code you need to write, and explore the generated code. I start the post with a quick refresher on the basics of the System.Diagnostics.Metrics APIs and the sample app we wrote last time /creating-and-consuming-metrics-with-system-diagnostics-metrics-apis/ . I then show how we can update this code to use the Microsoft.Extensions.Telemetry.Abstractions source generator instead. Finally, I show how we can also update our metric definitions to use strongly-typed tag objects for additional type-safety. In both cases, we'll update our sample app to use the new approach, and explore the generated code. You can read about the source generators I discuss in this post in the Microsoft documentation here and here . Background: System.Diagnostics.Metrics APIs background-system-diagnostics-metrics-apis The System.Diagnostics.Metrics APIs were introduced in .NET 6 but are available in earlier runtimes including .NET Framework by using the System.Diagnostics.DiagnosticSource https://www.nuget.org/packages/System.Diagnostics.DiagnosticSource/ NuGet package. There are two primary concepts exposed by these APIs; Instrument and Meter : Instrument : An instrument records the values for a single metric of interest. You might have separate Instrument s for "products sold", "invoices created", "invoice total", or "GC heap size". Meter : A Meter is a logical grouping of multiple instruments. For example, thecontains multiple System.Runtime Meter Instrument s about the workings of the runtime, while the https://learn.microsoft.com/en-us/aspnet/core/log-mon/metrics/built-in?view=aspnetcore-10.0 microsoftaspnetcorehosting contains Microsoft.AspNetCore.Hosting Meter Instrument s about the HTTP requests received by ASP.NET Core. There are also multiple types of Instrument : Counter