From 364cf36c36c19de5b96890d6c54b1a178231ccf7 Mon Sep 17 00:00:00 2001 From: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com> Date: Tue, 21 Jul 2026 16:08:10 +0100 Subject: [PATCH] telemetry: expose MetricsRegistry::meter() for call-site metric macros --- src/xrpld/telemetry/MetricsRegistry.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/xrpld/telemetry/MetricsRegistry.h b/src/xrpld/telemetry/MetricsRegistry.h index 3658831ba5..93b55fb35e 100644 --- a/src/xrpld/telemetry/MetricsRegistry.h +++ b/src/xrpld/telemetry/MetricsRegistry.h @@ -204,8 +204,15 @@ namespace telemetry { * @note Extending: * - Adding a new CountedObject type is auto-picked up by the * object_count gauge via iteration. - * - Adding a new synchronous instrument requires a header field, - * an initializer in start(), and a record method. + * - Adding a new SYNCHRONOUS instrument (counter/histogram): prefer the + * XRPL_METRIC_* call-site macros in MetricMacros.h -- no header/cpp + * edit needed. Fall back to a dedicated member + init line + record + * method (the pattern below) only when the metric needs to be read + * back by other code (e.g. ValidationTracker-style accumulation) or + * needs a custom histogram bucket View (see MetricMacros.h Limitation + * 2 in tasks/metric-macro-plan.md). + * - Adding a new OBSERVABLE gauge still requires eager central + * registration -- pull-model instruments cannot be lazily created. */ class MetricsRegistry { @@ -410,6 +417,22 @@ public: return validationTracker_; } +#ifdef XRPL_ENABLE_TELEMETRY + /** + * Access the shared OTel Meter for call-site instrument creation. + * Used by the XRPL_METRIC_* macros (MetricMacros.h) so new synchronous + * counters/histograms can be declared at their call site instead of as + * MetricsRegistry members. Returns an empty (falsy) shared_ptr before + * start() has run or when disabled. + * @return The shared Meter, or empty if not yet started. + */ + opentelemetry::nostd::shared_ptr + meter() const noexcept + { + return meter_; + } +#endif + private: /** * Master enable flag; when false all methods are no-ops.