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 /// /// ```