Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation for Metrics API #2280

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions opentelemetry/src/global/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ static GLOBAL_METER_PROVIDER: Lazy<RwLock<GlobalMeterProvider>> =

/// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we mention something like - do this at the earliest stage of your application/similar? Or is this sufficient?
I am also wondering what happens if a library statically creates Meter - is that going to be no-ops always, as we won't have an opportunity to set the global provider beforehand?

pub fn set_meter_provider<P>(new_provider: P)
where
P: metrics::MeterProvider + Send + Sync + 'static,
Expand All @@ -34,6 +36,9 @@ pub fn meter_provider() -> GlobalMeterProvider {
/// If the name is an empty string, the provider will use a default name.
///
/// 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)
}
Expand All @@ -42,6 +47,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
///
/// ```
Expand Down
Loading