aws_smithy_observability/
meter.rs
use crate::instruments::{
AsyncInstrumentBuilder, AsyncMeasure, Histogram, InstrumentBuilder, MonotonicCounter,
UpDownCounter,
};
use crate::{attributes::Attributes, instruments::ProvideInstrument};
use std::{borrow::Cow, fmt::Debug, sync::Arc};
pub trait ProvideMeter: Send + Sync + Debug {
fn get_meter(&self, scope: &'static str, attributes: Option<&Attributes>) -> Meter;
}
#[derive(Clone)]
pub struct Meter {
pub(crate) instrument_provider: Arc<dyn ProvideInstrument + Send + Sync>,
}
impl Meter {
pub fn new(instrument_provider: Arc<dyn ProvideInstrument + Send + Sync>) -> Self {
Meter {
instrument_provider,
}
}
#[allow(clippy::type_complexity)]
pub fn create_gauge<F>(
&self,
name: impl Into<Cow<'static, str>>,
callback: F,
) -> AsyncInstrumentBuilder<'_, Arc<dyn AsyncMeasure<Value = f64>>, f64>
where
F: Fn(&dyn AsyncMeasure<Value = f64>) + Send + Sync + 'static,
{
AsyncInstrumentBuilder::new(self, name.into(), Arc::new(callback))
}
pub fn create_up_down_counter(
&self,
name: impl Into<Cow<'static, str>>,
) -> InstrumentBuilder<'_, Arc<dyn UpDownCounter>> {
InstrumentBuilder::new(self, name.into())
}
#[allow(clippy::type_complexity)]
pub fn create_async_up_down_counter<F>(
&self,
name: impl Into<Cow<'static, str>>,
callback: F,
) -> AsyncInstrumentBuilder<'_, Arc<dyn AsyncMeasure<Value = i64>>, i64>
where
F: Fn(&dyn AsyncMeasure<Value = i64>) + Send + Sync + 'static,
{
AsyncInstrumentBuilder::new(self, name.into(), Arc::new(callback))
}
pub fn create_monotonic_counter(
&self,
name: impl Into<Cow<'static, str>>,
) -> InstrumentBuilder<'_, Arc<dyn MonotonicCounter>> {
InstrumentBuilder::new(self, name.into())
}
#[allow(clippy::type_complexity)]
pub fn create_async_monotonic_counter<F>(
&self,
name: impl Into<Cow<'static, str>>,
callback: F,
) -> AsyncInstrumentBuilder<'_, Arc<dyn AsyncMeasure<Value = u64>>, u64>
where
F: Fn(&dyn AsyncMeasure<Value = u64>) + Send + Sync + 'static,
{
AsyncInstrumentBuilder::new(self, name.into(), Arc::new(callback))
}
pub fn create_histogram(
&self,
name: impl Into<Cow<'static, str>>,
) -> InstrumentBuilder<'_, Arc<dyn Histogram>> {
InstrumentBuilder::new(self, name.into())
}
}