|
83 | 83 | //!
|
84 | 84 | //! ### Usage in Applications
|
85 | 85 | //!
|
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. |
88 | 88 | //!
|
89 | 89 | //! ```
|
90 | 90 | //! # #[cfg(feature="metrics")]
|
|
93 | 93 | //! use opentelemetry::{global, KeyValue};
|
94 | 94 | //!
|
95 | 95 | //! fn init_meter() {
|
| 96 | +//! // Swap this no-op provider with an actual meter provider, |
| 97 | +//! // exporting to stdout, otlp, prometheus, etc. |
96 | 98 | //! let provider = NoopMeterProvider::new();
|
97 | 99 | //!
|
98 | 100 | //! // Configure the global `MeterProvider` singleton when your app starts
|
|
101 | 103 | //! }
|
102 | 104 | //!
|
103 | 105 | //! 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. |
105 | 107 | //! let meter = global::meter("my-component");
|
| 108 | +//! // It is recommended to reuse the same counter instance for the |
| 109 | +//! // lifetime of the application |
106 | 110 | //! let counter = meter.u64_counter("my_counter").init();
|
107 | 111 | //!
|
108 |
| -//! // record metrics |
| 112 | +//! // record measurements |
109 | 113 | //! counter.add(1, &[KeyValue::new("mykey", "myvalue")]);
|
110 | 114 | //! }
|
111 | 115 | //!
|
112 | 116 | //! // in main or other app start
|
113 | 117 | //! init_meter();
|
114 | 118 | //! 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(); |
115 | 122 | //! # }
|
116 | 123 | //! ```
|
117 | 124 | //!
|
|
122 | 129 | //! # {
|
123 | 130 | //! use opentelemetry::{global, KeyValue};
|
124 | 131 | //!
|
125 |
| -//! pub fn my_traced_library_function() { |
| 132 | +//! pub fn my_instrumented_library_function() { |
126 | 133 | //! // End users of your library will configure their global meter provider
|
127 | 134 | //! // so you can use the global meter without any setup
|
128 | 135 | //! let meter = global::meter("my-library-name");
|
| 136 | +//! // It is recommended to reuse the same counter instance for the |
| 137 | +//! // lifetime of the application |
129 | 138 | //! let counter = meter.u64_counter("my_counter").init();
|
130 | 139 | //!
|
131 |
| -//! // record metrics |
| 140 | +//! // record measurements |
132 | 141 | //! counter.add(1, &[KeyValue::new("mykey", "myvalue")]);
|
133 | 142 | //! }
|
134 | 143 | //! # }
|
|
0 commit comments