telemetry: expose MetricsRegistry::meter() for call-site metric macros

This commit is contained in:
Pratik Mankawde
2026-07-21 16:08:10 +01:00
parent eceed19f2b
commit 364cf36c36

View File

@@ -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<opentelemetry::metrics::Meter>
meter() const noexcept
{
return meter_;
}
#endif
private:
/**
* Master enable flag; when false all methods are no-ops.