Trait opentelemetry::metrics::MeterProvider
source · pub trait MeterProvider {
// Required method
fn versioned_meter(
&self,
name: impl Into<Cow<'static, str>>,
version: Option<impl Into<Cow<'static, str>>>,
schema_url: Option<impl Into<Cow<'static, str>>>,
attributes: Option<Vec<KeyValue>>,
) -> Meter;
// Provided method
fn meter(&self, name: impl Into<Cow<'static, str>>) -> Meter { ... }
}
Expand description
Provides access to named Meter instances, for instrumenting an application or crate.
Required Methods§
sourcefn versioned_meter(
&self,
name: impl Into<Cow<'static, str>>,
version: Option<impl Into<Cow<'static, str>>>,
schema_url: Option<impl Into<Cow<'static, str>>>,
attributes: Option<Vec<KeyValue>>,
) -> Meter
fn versioned_meter( &self, name: impl Into<Cow<'static, str>>, version: Option<impl Into<Cow<'static, str>>>, schema_url: Option<impl Into<Cow<'static, str>>>, attributes: Option<Vec<KeyValue>>, ) -> Meter
Returns a new versioned meter with a given name.
The instrumentation name must be the name of the library providing instrumentation. This name may be the same as the instrumented code only if that code provides built-in instrumentation. If the instrumentation name is empty, then a implementation defined default name will be used instead.
Provided Methods§
sourcefn meter(&self, name: impl Into<Cow<'static, str>>) -> Meter
fn meter(&self, name: impl Into<Cow<'static, str>>) -> Meter
Returns a new Meter with the provided name and default configuration.
A Meter should be scoped at most to a single application or crate. The name needs to be unique so it does not collide with other names used by an application, nor other applications.
If the name is empty, then an implementation defined default name will be used instead.
§Examples
use opentelemetry::{global, metrics::MeterProvider};
use opentelemetry::KeyValue;
let provider = global::meter_provider();
// meter used in applications
let meter = provider.meter("my_app");
// meter used in libraries/crates that optionally includes version and schema url
let meter = provider.versioned_meter(
"my_library",
Some(env!("CARGO_PKG_VERSION")),
Some("https://opentelemetry.io/schema/1.0.0"),
Some(vec![KeyValue::new("key", "value")]),
);