QuickDevGuide

Home › OpenTelemetry (Observability)

Custom Metrics in .NET (Meter) — OpenTelemetry (Observability)

.NET metrics use System.Diagnostics.Metrics. Create a Meter (ideally through IMeterFactory for DI and testability) and instruments from it. Instrument Use for Example Counter<T> monotonically increasing totals orders placed, bytes sent UpDownCounter<T> values that go up and down active connections, queue length Histogram<T> distributions request duration, payload size ObservableGauge<T> sampled current value via callback memory used, cache size Attribute (tag) cardinality Each unique combination of tags is a separate time series. Never tag with user IDs, order IDs, URLs with IDs, or timestamps — use bounded values like status, region, payment.method. Inspect locally with dotnet-counters monitor -n Orders.Api --counters Orders.Checkout.

Key Takeaways