Trait opentelemetry::metrics::MeterProvider
source · pub trait MeterProvider {
// Required method
fn meter_with_scope(&self, scope: InstrumentationScope) -> Meter;
// Provided method
fn meter(&self, name: &'static str) -> Meter { ... }
}
Expand description
Provides access to named Meter instances, for instrumenting an application or crate.
Required Methods§
sourcefn meter_with_scope(&self, scope: InstrumentationScope) -> Meter
fn meter_with_scope(&self, scope: InstrumentationScope) -> Meter
Returns a new Meter with the given instrumentation scope.
§Examples
use std::sync::Arc;
use opentelemetry::InstrumentationScope;
use opentelemetry::metrics::MeterProvider;
use opentelemetry_sdk::metrics::SdkMeterProvider;
let provider = SdkMeterProvider::default();
// meter used in applications/binaries
let meter = provider.meter("my_app");
// meter used in libraries/crates that optionally includes version and schema url
let scope = InstrumentationScope::builder(env!("CARGO_PKG_NAME"))
.with_version(env!("CARGO_PKG_VERSION"))
.with_schema_url("https://opentelemetry.io/schema/1.0.0")
.build();
let meter = provider.meter_with_scope(scope);
Provided Methods§
sourcefn meter(&self, name: &'static str) -> Meter
fn meter(&self, name: &'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");