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 {
18 fn get_meter(&self, scope: &'static str, attributes: Option<&Attributes>) -> Meter;
20
21 fn provider_name(&self) -> &'static str {
24 "unknown"
25 }
26}
27
28#[derive(Clone)]
30pub struct Meter {
31 pub(crate) instrument_provider: Arc<dyn ProvideInstrument + Send + Sync>,
32}
33
34impl Meter {
35 pub fn new(instrument_provider: Arc<dyn ProvideInstrument + Send + Sync>) -> Self {
37 Meter {
38 instrument_provider,
39 }
40 }
41
42 #[allow(clippy::type_complexity)]
44 pub fn create_gauge<F>(
45 &self,
46 name: impl Into<Cow<'static, str>>,
47 callback: F,
48 ) -> AsyncInstrumentBuilder<'_, Arc<dyn AsyncMeasure<Value = f64>>, f64>
49 where
50 F: Fn(&dyn AsyncMeasure<Value = f64>) + Send + Sync + 'static,
51 {
52 AsyncInstrumentBuilder::new(self, name.into(), Arc::new(callback))
53 }
54
55 pub fn create_up_down_counter(
57 &self,
58 name: impl Into<Cow<'static, str>>,
59 ) -> InstrumentBuilder<'_, Arc<dyn UpDownCounter>> {
60 InstrumentBuilder::new(self, name.into())
61 }
62
63 #[allow(clippy::type_complexity)]
65 pub fn create_async_up_down_counter<F>(
66 &self,
67 name: impl Into<Cow<'static, str>>,
68 callback: F,
69 ) -> AsyncInstrumentBuilder<'_, Arc<dyn AsyncMeasure<Value = i64>>, i64>
70 where
71 F: Fn(&dyn AsyncMeasure<Value = i64>) + Send + Sync + 'static,
72 {
73 AsyncInstrumentBuilder::new(self, name.into(), Arc::new(callback))
74 }
75
76 pub fn create_monotonic_counter(
78 &self,
79 name: impl Into<Cow<'static, str>>,
80 ) -> InstrumentBuilder<'_, Arc<dyn MonotonicCounter>> {
81 InstrumentBuilder::new(self, name.into())
82 }
83
84 #[allow(clippy::type_complexity)]
86 pub fn create_async_monotonic_counter<F>(
87 &self,
88 name: impl Into<Cow<'static, str>>,
89 callback: F,
90 ) -> AsyncInstrumentBuilder<'_, Arc<dyn AsyncMeasure<Value = u64>>, u64>
91 where
92 F: Fn(&dyn AsyncMeasure<Value = u64>) + Send + Sync + 'static,
93 {
94 AsyncInstrumentBuilder::new(self, name.into(), Arc::new(callback))
95 }
96
97 pub fn create_histogram(
99 &self,
100 name: impl Into<Cow<'static, str>>,
101 ) -> InstrumentBuilder<'_, Arc<dyn Histogram>> {
102 InstrumentBuilder::new(self, name.into())
103 }
104}