use crate::{
metrics::{
AsyncInstrument, InstrumentProvider, Meter, MeterProvider, SyncCounter, SyncGauge,
SyncHistogram, SyncUpDownCounter,
},
KeyValue,
};
use std::{any::Any, borrow::Cow, sync::Arc};
#[derive(Debug, Default)]
pub struct NoopMeterProvider {
_private: (),
}
impl NoopMeterProvider {
pub fn new() -> Self {
NoopMeterProvider { _private: () }
}
}
impl MeterProvider for NoopMeterProvider {
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 {
Meter::new(Arc::new(NoopMeterCore::new()))
}
}
#[derive(Debug, Default)]
pub struct NoopMeterCore {
_private: (),
}
impl NoopMeterCore {
pub fn new() -> Self {
NoopMeterCore { _private: () }
}
}
impl InstrumentProvider for NoopMeterCore {}
#[derive(Debug, Default)]
pub struct NoopSyncInstrument {
_private: (),
}
impl NoopSyncInstrument {
pub fn new() -> Self {
NoopSyncInstrument { _private: () }
}
}
impl<T> SyncCounter<T> for NoopSyncInstrument {
fn add(&self, _value: T, _attributes: &[KeyValue]) {
}
}
impl<T> SyncUpDownCounter<T> for NoopSyncInstrument {
fn add(&self, _value: T, _attributes: &[KeyValue]) {
}
}
impl<T> SyncHistogram<T> for NoopSyncInstrument {
fn record(&self, _value: T, _attributes: &[KeyValue]) {
}
}
impl<T> SyncGauge<T> for NoopSyncInstrument {
fn record(&self, _value: T, _attributes: &[KeyValue]) {
}
}
#[derive(Debug, Default)]
pub struct NoopAsyncInstrument {
_private: (),
}
impl NoopAsyncInstrument {
pub fn new() -> Self {
NoopAsyncInstrument { _private: () }
}
}
impl<T> AsyncInstrument<T> for NoopAsyncInstrument {
fn observe(&self, _value: T, _attributes: &[KeyValue]) {
}
fn as_any(&self) -> Arc<dyn Any> {
Arc::new(())
}
}