Skip to content

Commit 832fad4

Browse files
cijothomaslalitb
andauthored
Minor cleanups to Metrics API docs (#1695)
Co-authored-by: Lalit Kumar Bhasin <lalit_fin@yahoo.com>
1 parent 943bb7a commit 832fad4

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

opentelemetry/src/global/metrics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
sync::{Arc, RwLock},
88
};
99

10-
/// The global `Meter` provider singleton.
10+
/// The global `MeterProvider` singleton.
1111
static GLOBAL_METER_PROVIDER: Lazy<RwLock<GlobalMeterProvider>> = Lazy::new(|| {
1212
RwLock::new(GlobalMeterProvider::new(
1313
metrics::noop::NoopMeterProvider::new(),
@@ -111,7 +111,7 @@ pub fn meter_provider() -> GlobalMeterProvider {
111111
///
112112
/// If the name is an empty string, the provider will use a default name.
113113
///
114-
/// This is a more convenient way of expressing `global::meter_provider().versioned_meter(name, None, None, None)`.
114+
/// This is a more convenient way of expressing `global::meter_provider().meter(name)`.
115115
pub fn meter(name: impl Into<Cow<'static, str>>) -> Meter {
116116
meter_provider().meter(name.into())
117117
}

opentelemetry/src/global/mod.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
//!
8484
//! ### Usage in Applications
8585
//!
86-
//! Applications configure their meter either by installing a metrics pipeline,
87-
//! or calling [`set_meter_provider`].
86+
//! Applications configure their meter by configuring a meter provider,
87+
//! and calling [`set_meter_provider`] to set it as global meter provider.
8888
//!
8989
//! ```
9090
//! # #[cfg(feature="metrics")]
@@ -93,6 +93,8 @@
9393
//! use opentelemetry::{global, KeyValue};
9494
//!
9595
//! fn init_meter() {
96+
//! // Swap this no-op provider with an actual meter provider,
97+
//! // exporting to stdout, otlp, prometheus, etc.
9698
//! let provider = NoopMeterProvider::new();
9799
//!
98100
//! // Configure the global `MeterProvider` singleton when your app starts
@@ -101,17 +103,22 @@
101103
//! }
102104
//!
103105
//! fn do_something_instrumented() {
104-
//! // Then you can get a named tracer instance anywhere in your codebase.
106+
//! // You can get a named meter instance anywhere in your codebase.
105107
//! let meter = global::meter("my-component");
108+
//! // It is recommended to reuse the same counter instance for the
109+
//! // lifetime of the application
106110
//! let counter = meter.u64_counter("my_counter").init();
107111
//!
108-
//! // record metrics
112+
//! // record measurements
109113
//! counter.add(1, &[KeyValue::new("mykey", "myvalue")]);
110114
//! }
111115
//!
112116
//! // in main or other app start
113117
//! init_meter();
114118
//! do_something_instrumented();
119+
//! // Shutdown ensures any metrics still in memory are given to exporters
120+
//! // before the program exits.
121+
//! global::shutdown_meter_provider();
115122
//! # }
116123
//! ```
117124
//!
@@ -122,13 +129,15 @@
122129
//! # {
123130
//! use opentelemetry::{global, KeyValue};
124131
//!
125-
//! pub fn my_traced_library_function() {
132+
//! pub fn my_instrumented_library_function() {
126133
//! // End users of your library will configure their global meter provider
127134
//! // so you can use the global meter without any setup
128135
//! let meter = global::meter("my-library-name");
136+
//! // It is recommended to reuse the same counter instance for the
137+
//! // lifetime of the application
129138
//! let counter = meter.u64_counter("my_counter").init();
130139
//!
131-
//! // record metrics
140+
//! // record measurements
132141
//! counter.add(1, &[KeyValue::new("mykey", "myvalue")]);
133142
//! }
134143
//! # }

0 commit comments

Comments
 (0)