aws_smithy_observability/
meter.rs1use crate::instruments::{
10 AsyncInstrumentBuilder, AsyncMeasure, Histogram, InstrumentBuilder, MonotonicCounter,
11 UpDownCounter,
12};
13use crate::{attributes::Attributes, instruments::ProvideInstrument};
14use std::{borrow::Cow, fmt::Debug, sync::Arc};
15
16pub trait ProvideMeter: Send + Sync + Debug + 'static {
18 fn get_meter(&self, scope: &'static str, attributes: Option<&Attributes>) -> Meter;
20
21 fn as_any(&self) -> &dyn std::any::Any;
23}
24
25#[derive(Clone)]
27pub struct Meter {
28 pub(crate) instrument_provider: Arc<dyn ProvideInstrument + Send + Sync>,
29}
30
31impl Meter {
32 pub fn new(instrument_provider: Arc<dyn ProvideInstrument + Send + Sync>) -> Self {
34 Meter {
35 instrument_provider,
36 }
37 }
38
39 #[allow(clippy::type_complexity)]
41 pub fn create_gauge<F>(
42 &self,
43 name: impl Into<Cow<'static, str>>,
44 callback: F,
45 ) -> AsyncInstrumentBuilder<'_, Arc<dyn AsyncMeasure<Value = f64>>, f64>
46 where
47 F: Fn(&dyn AsyncMeasure<Value = f64>) + Send + Sync + 'static,
48 {
49 AsyncInstrumentBuilder::new(self, name.into(), Arc::new(callback))
50 }
51
52 pub fn create_up_down_counter(
54 &self,
55 name: impl Into<Cow<'static, str>>,
56 ) -> InstrumentBuilder<'_, Arc<dyn UpDownCounter>> {
57 InstrumentBuilder::new(self, name.into())
58 }
59
60 #[allow(clippy::type_complexity)]
62 pub fn create_async_up_down_counter<F>(
63 &self,
64 name: impl Into<Cow<'static, str>>,
65 callback: F,
66 ) -> AsyncInstrumentBuilder<'_, Arc<dyn AsyncMeasure<Value = i64>>, i64>
67 where
68 F: Fn(&dyn AsyncMeasure<Value = i64>) + Send + Sync + 'static,
69 {
70 AsyncInstrumentBuilder::new(self, name.into(), Arc::new(callback))
71 }
72
73 pub fn create_monotonic_counter(
75 &self,
76 name: impl Into<Cow<'static, str>>,
77 ) -> InstrumentBuilder<'_, Arc<dyn MonotonicCounter>> {
78 InstrumentBuilder::new(self, name.into())
79 }
80
81 #[allow(clippy::type_complexity)]
83 pub fn create_async_monotonic_counter<F>(
84 &self,
85 name: impl Into<Cow<'static, str>>,
86 callback: F,
87 ) -> AsyncInstrumentBuilder<'_, Arc<dyn AsyncMeasure<Value = u64>>, u64>
88 where
89 F: Fn(&dyn AsyncMeasure<Value = u64>) + Send + Sync + 'static,
90 {
91 AsyncInstrumentBuilder::new(self, name.into(), Arc::new(callback))
92 }
93
94 pub fn create_histogram(
96 &self,
97 name: impl Into<Cow<'static, str>>,
98 ) -> InstrumentBuilder<'_, Arc<dyn Histogram>> {
99 InstrumentBuilder::new(self, name.into())
100 }
101}