use std::sync::Arc;
use crate::{meter::ProvideMeter, noop::NoopMeterProvider};
#[non_exhaustive]
pub struct TelemetryProvider {
meter_provider: Box<dyn ProvideMeter + Send + Sync>,
}
impl TelemetryProvider {
pub fn builder() -> TelemetryProviderBuilder {
TelemetryProviderBuilder {
meter_provider: Box::new(NoopMeterProvider),
}
}
pub fn noop() -> TelemetryProvider {
Self {
meter_provider: Box::new(NoopMeterProvider),
}
}
pub fn meter_provider(&self) -> &(dyn ProvideMeter + Send + Sync) {
self.meter_provider.as_ref()
}
}
impl Default for TelemetryProvider {
fn default() -> Self {
Self {
meter_provider: Box::new(NoopMeterProvider),
}
}
}
#[non_exhaustive]
pub struct TelemetryProviderBuilder {
meter_provider: Box<dyn ProvideMeter + Send + Sync>,
}
impl TelemetryProviderBuilder {
pub fn meter_provider(mut self, meter_provider: impl ProvideMeter + 'static) -> Self {
self.meter_provider = Box::new(meter_provider);
self
}
pub fn build(self) -> TelemetryProvider {
TelemetryProvider {
meter_provider: self.meter_provider,
}
}
}
#[non_exhaustive]
pub(crate) struct GlobalTelemetryProvider {
pub(crate) telemetry_provider: Arc<TelemetryProvider>,
}
impl GlobalTelemetryProvider {
pub(crate) fn new(telemetry_provider: TelemetryProvider) -> Self {
Self {
telemetry_provider: Arc::new(telemetry_provider),
}
}
pub(crate) fn telemetry_provider(&self) -> &Arc<TelemetryProvider> {
&self.telemetry_provider
}
}