How Replacing a Metrics God Class with Per-Subsystem Modules Improved an OTel Codebase
A software team refactored their OpenTelemetry metrics architecture by replacing a single monolithic god class with separate per-subsystem modules, each owning its own instruments. The original design used multiple inheritance mixins on one global Metrics object, which caused silent attribute shadowing and forced developers to call methods through explicit base classes to avoid name collisions. OpenTelemetry's core constraint — that instruments can be created only once per process and never unregistered — means every codebase must carefully manage a process-level singleton. The new pattern solves this with a frozen dataclass holding OTel handles, a memoized factory function acting as the singleton, and a lightweight wrapper class instantiated per request. This approach enforces composition over inheritance, keeping metric definitions close to the code that uses them and eliminating the risk of silently lost metrics.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in