-
Type:
New Feature
-
Resolution: Duplicate
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
DB Integration & Observability
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Overview
Build the registration codegen for the unified metrics framework (epic SPM-4962). Design revised 2026-11-11: registration is a per-file MONGO_INITIALIZER with no aggregate anchor.
Scope of Work
- Emit one MONGO_INITIALIZER per *metrics.idl file into the generated _gen.cpp, named RegisterMetrics<file_path_underscores>, whose body calls addMetricsRegistration(MetricsRegistrationSpec
{parent, name, resolve, leaves, appender, otel}
) directly. No wrapper registration function, no aggregate anchor file.
- Bound registrations with the BeginMetricsRegistration / EndMetricsRegistration initializer groups (the MONGO_SERVER_PARAMETER_REGISTER pattern); materialize() runs after EndMetricsRegistration.
- Support cpp_accessor: to override the default state binding with a callable returning T&.
- Add replaceMetricsRegistration(rootPath, spec): a framework-owned override point that replaces an auto-binding before materialize(). It validates the spec's paths against the IDL catalog and fatals if called after materialization. The deterministic generated initializer names double as initializer-graph dependencies, which is the ordering hook for the override.
- Non-declarable metrics (tcmalloc, WiredTiger) register via hand-written addMetricsRegistration calls inside the Begin/End window.
- Wire observability::initialize(ServiceContext*, std::string_view serviceName) into mongod_main/mongos_main: initialize the OTel provider (otel::metrics::initialize() and traces::initialize()), materialize the registry, and install per-binary metric configurations (installMongodOtelMetrics / installMongosOtelMetrics).
Background: no anchor is needed
A registration-only TU cannot be dropped by the linker in any mongo build configuration. Default builds pass object files directly to the binary link, and skip_archive=False variants (dbg_tsan, windows, etc.) re-inject every mongo library with alwayslink=True in extract_debuginfo (bazel/separate_debug.bzl). Verified empirically on 2026-11-11 with a registration-only TU linked through mongo rules in both configurations; MONGO_INITIALIZER and command registration rely on the same mechanism. The earlier plan for an aggregate anchor file (metrics_registrations_gen.cpp) to defeat archive-member extraction is dropped as unnecessary.
Design source
[Technical Design: Unified Metrics Framework]($GDOC), Registration and Process Lifecycle tab: "Registration", "Ordering", "Naming", "Overriding a registration from C++", "Startup Ordering".
- blocks
-
SERVER-138334 Rendering: OTel bindings and serverStatus BSON export
-
- Needs Scheduling
-
-
SERVER-138335 Golden shape test harness for serverStatus backwards compatibility
-
- Needs Scheduling
-
-
SERVER-138450 Generate attribute support for metrics IDL (set_once and allowed_values)
-
- Needs Scheduling
-
- duplicates
-
SERVER-138332 Build the MetricsRegistry for materialization, validation, and unmaterialize()
-
- Needs Scheduling
-
- is blocked by
-
SERVER-138331 Codegen to create metrics structs (<file>_metrics_gen.h/cpp and metrics_sections.idl)
-
- In Code Review
-