The Microsoft.Extensions.Telemetry.Abstractions source generator for System.Diagnostics.Metrics APIs generates boilerplate code for creating strongly-typed metrics and tag objects. However, the generated code offers minimal advantages over manual implementation—it doesn't improve performance, limits API flexibility (missing Description support, experimental Unit parameter), and supports niche scenarios like registering instruments with multiple meters. The strongly-typed tags feature helps prevent parameter-ordering bugs but can be implemented manually with better optimization opportunities. The underlying System.Diagnostics.Metrics APIs are already well-designed with minimal boilerplate, making the source generator's value proposition questionable for most use cases.

15m read timeFrom andrewlock.net
Post cover image
Table of contents
Background: System.Diagnostics.Metrics APIsBackground: sample app with manual boilerplateReplacing boiler plate with a source generatorUsing strongly-typed tag objectsAre the source generators worth using?Summary

Sort: