use crate::{
metrics::{
AsyncInstrument, CallbackRegistration, InstrumentProvider, Meter, MeterProvider, Observer,
Result, 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 {
fn register_callback(
&self,
_instruments: &[Arc<dyn Any>],
_callback: Box<dyn Fn(&dyn Observer) + Send + Sync>,
) -> Result<Box<dyn CallbackRegistration>> {
Ok(Box::new(NoopRegistration::new()))
}
}
#[derive(Debug, Default)]
pub struct NoopRegistration {
_private: (),
}
impl NoopRegistration {
pub fn new() -> Self {
NoopRegistration { _private: () }
}
}
impl CallbackRegistration for NoopRegistration {
fn unregister(&mut self) -> Result<()> {
Ok(())
}
}
#[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(())
}
}