pub struct SdkMeterProvider { /* private fields */ }
Expand description
Handles the creation and coordination of Meters.
All Meter
s created by a MeterProvider
will be associated with the same
Resource, have the same [View]s applied to them, and have their produced
metric telemetry passed to the configured MetricReaders. This is a
clonable handle to the MeterProvider implementation itself, and cloning it
will create a new reference, not a new instance of a MeterProvider. Dropping
the last reference to it will trigger shutdown of the provider. Shutdown can
also be triggered manually by calling the shutdown
method.
Meter: opentelemetry::metrics::Meter
Implementations§
Source§impl SdkMeterProvider
impl SdkMeterProvider
Sourcepub fn builder() -> MeterProviderBuilder
pub fn builder() -> MeterProviderBuilder
Return default MeterProviderBuilder
Sourcepub fn force_flush(&self) -> MetricResult<()>
pub fn force_flush(&self) -> MetricResult<()>
Flushes all pending telemetry.
There is no guaranteed that all telemetry be flushed or all resources have been released on error.
§Examples
use opentelemetry::{global, Context};
use opentelemetry_sdk::metrics::SdkMeterProvider;
fn init_metrics() -> SdkMeterProvider {
// Setup metric pipelines with readers + views, default has no
// readers so nothing is exported.
let provider = SdkMeterProvider::default();
// Set provider to be used as global meter provider
let _ = global::set_meter_provider(provider.clone());
provider
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let provider = init_metrics();
// create instruments + record measurements
// force all instruments to flush
provider.force_flush()?;
// record more measurements..
// shutdown ensures any cleanup required by the provider is done,
// and also invokes shutdown on the readers.
provider.shutdown()?;
Ok(())
}
Sourcepub fn shutdown(&self) -> MetricResult<()>
pub fn shutdown(&self) -> MetricResult<()>
Shuts down the meter provider flushing all pending telemetry and releasing any held computational resources.
This call is idempotent. The first call will perform all flush and releasing operations. Subsequent calls will perform no action and will return an error stating this.
Measurements made by instruments from meters this MeterProvider created will not be exported after Shutdown is called.
There is no guaranteed that all telemetry be flushed or all resources have been released on error.
Trait Implementations§
Source§impl Clone for SdkMeterProvider
impl Clone for SdkMeterProvider
Source§fn clone(&self) -> SdkMeterProvider
fn clone(&self) -> SdkMeterProvider
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more