Struct opentelemetry_sdk::metrics::SdkMeterProvider
source · 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 Views applied to them, and have their produced
metric telemetry passed to the configured MetricReaders.
Implementations§
source§impl SdkMeterProvider
impl SdkMeterProvider
sourcepub fn builder() -> MeterProviderBuilder
pub fn builder() -> MeterProviderBuilder
Return default MeterProviderBuilder
sourcepub fn force_flush(&self) -> Result<()>
pub fn force_flush(&self) -> Result<()>
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) -> Result<()>
pub fn shutdown(&self) -> Result<()>
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 moresource§impl Debug for SdkMeterProvider
impl Debug for SdkMeterProvider
source§impl Default for SdkMeterProvider
impl Default for SdkMeterProvider
source§impl MeterProvider for SdkMeterProvider
impl MeterProvider for SdkMeterProvider
Auto Trait Implementations§
impl Freeze for SdkMeterProvider
impl !RefUnwindSafe for SdkMeterProvider
impl Send for SdkMeterProvider
impl Sync for SdkMeterProvider
impl Unpin for SdkMeterProvider
impl !UnwindSafe for SdkMeterProvider
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)