Skip to content

Named meter registration

Use named registration when you want multiple logical meter sources in the same application and resolve them explicitly with keyed services.

var services = new ServiceCollection();
services.AddNamedMeter("orders");

This registers:

  • keyed System.Diagnostics.Metrics.Meter with the name orders
  • keyed IMeter<T> that resolves to that same named Meter
public class OrderService([FromKeyedServices("orders")] IMeter<OrderService> meter)
{
}

IMeter<T> remains available as a non-keyed service as well, where the underlying meter name defaults to the type name.