From a0e50615cda523fd2d1542a43ec5a3eaeb792568 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Thu, 23 Jan 2025 11:24:42 -0800 Subject: [PATCH] Update documentation for Metrics API (#2280) Co-authored-by: Cijo Thomas Co-authored-by: Zhongyang Wu --- opentelemetry/src/global/metrics.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/opentelemetry/src/global/metrics.rs b/opentelemetry/src/global/metrics.rs index 457bc662a6..19ead8ac40 100644 --- a/opentelemetry/src/global/metrics.rs +++ b/opentelemetry/src/global/metrics.rs @@ -15,6 +15,8 @@ fn global_meter_provider() -> &'static RwLock { /// Sets the given [`MeterProvider`] instance as the current global meter /// provider. +/// +/// **NOTE:** This function should be called before getting [`Meter`] instances via [`meter()`] or [`meter_with_scope()`]. Otherwise, you could get no-op [`Meter`] instances. pub fn set_meter_provider

(new_provider: P) where P: metrics::MeterProvider + Send + Sync + 'static, @@ -44,6 +46,9 @@ pub fn meter_provider() -> GlobalMeterProvider { /// Creates a named [`Meter`] via the currently configured global [`MeterProvider`]. /// /// This is a more convenient way of expressing `global::meter_provider().meter(name)`. +/// +/// **NOTE:** Calls to [`meter()`] return a [`Meter`] backed by the global [`MeterProvider`] configured during the method invocation. +/// If the global [`MeterProvider`] is changed after getting [`Meter`] instances from these calls, the [`Meter`] instances returned will not reflect the change. pub fn meter(name: &'static str) -> Meter { meter_provider().meter(name) } @@ -52,6 +57,9 @@ pub fn meter(name: &'static str) -> Meter { /// /// This is a simpler alternative to `global::meter_provider().meter_with_scope(...)` /// +/// **NOTE:** Calls to [`meter_with_scope()`] return a [`Meter`] backed by the global [`MeterProvider`] configured during the method invocation. +/// If the global [`MeterProvider`] is changed after getting [`Meter`] instances from these calls, the [`Meter`] instances returned will not reflect the change. +/// /// # Example /// /// ```