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

Minor cleanups to Metrics API docs #1695

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions opentelemetry/src/global/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
sync::{Arc, RwLock},
};

/// The global `Meter` provider singleton.
/// The global `MeterProvider` singleton.
static GLOBAL_METER_PROVIDER: Lazy<RwLock<GlobalMeterProvider>> = Lazy::new(|| {
RwLock::new(GlobalMeterProvider::new(
metrics::noop::NoopMeterProvider::new(),
Expand Down Expand Up @@ -111,7 +111,7 @@ 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().versioned_meter(name, None, None, None)`.
/// This is a more convenient way of expressing `global::meter_provider().meter(name)`.
pub fn meter(name: impl Into<Cow<'static, str>>) -> Meter {
meter_provider().meter(name.into())
}
Expand Down
21 changes: 15 additions & 6 deletions opentelemetry/src/global/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
//!
//! ### Usage in Applications
//!
//! Applications configure their meter either by installing a metrics pipeline,
//! or calling [`set_meter_provider`].
//! Applications configure their meter by configuring a meter provider,
//! and calling [`set_meter_provider`] to set it as global meter provider.
//!
//! ```
//! # #[cfg(feature="metrics")]
Expand All @@ -93,6 +93,8 @@
//! use opentelemetry::{global, KeyValue};
//!
//! fn init_meter() {
//! // Swap this no-op provider with an actual metrics provider,
//! // exporting to stdout, otlp, prometheus, etc.
//! let provider = NoopMeterProvider::new();
//!
//! // Configure the global `MeterProvider` singleton when your app starts
Expand All @@ -101,17 +103,22 @@
//! }
//!
//! fn do_something_instrumented() {
//! // Then you can get a named tracer instance anywhere in your codebase.
//! // You can get a named meter instance anywhere in your codebase.
//! let meter = global::meter("my-component");
//! // It is recommended to reuse the same counter instance for the
//! // lifetime of the application
//! let counter = meter.u64_counter("my_counter").init();
//!
//! // record metrics
//! // record measurements
//! counter.add(1, &[KeyValue::new("mykey", "myvalue")]);
//! }
//!
//! // in main or other app start
//! init_meter();
//! do_something_instrumented();
//! // Shutdown ensures any metrics still in memory are given to exporters
//! // before the program exits.
//! global::shutdown_meter_provider();
//! # }
//! ```
//!
Expand All @@ -122,13 +129,15 @@
//! # {
//! use opentelemetry::{global, KeyValue};
//!
//! pub fn my_traced_library_function() {
//! pub fn my_instrumented_library_function() {
//! // End users of your library will configure their global meter provider
//! // so you can use the global meter without any setup
//! let meter = global::meter("my-library-name");
//! // It is recommended to reuse the same counter instance for the
//! // lifetime of the application
//! let counter = meter.u64_counter("my_counter").init();
//!
//! // record metrics
//! // record measurements
//! counter.add(1, &[KeyValue::new("mykey", "myvalue")]);
//! }
//! # }
Expand Down
Loading