aws_smithy_observability/
noop.rs1use std::marker::PhantomData;
9use std::{fmt::Debug, sync::Arc};
10
11use crate::instruments::{
12 AsyncInstrumentBuilder, AsyncMeasure, Histogram, InstrumentBuilder, MonotonicCounter,
13 ProvideInstrument, UpDownCounter,
14};
15use crate::{
16 attributes::Attributes,
17 context::Context,
18 meter::{Meter, ProvideMeter},
19};
20
21#[derive(Debug)]
22pub(crate) struct NoopMeterProvider;
23impl ProvideMeter for NoopMeterProvider {
24 fn get_meter(&self, _scope: &'static str, _attributes: Option<&Attributes>) -> Meter {
25 Meter::new(Arc::new(NoopMeter))
26 }
27}
28
29#[derive(Debug)]
30pub(crate) struct NoopMeter;
31impl ProvideInstrument for NoopMeter {
32 fn create_gauge(
33 &self,
34 _builder: AsyncInstrumentBuilder<'_, Arc<dyn AsyncMeasure<Value = f64>>, f64>,
35 ) -> Arc<dyn AsyncMeasure<Value = f64>> {
36 Arc::new(NoopAsyncMeasurement(PhantomData::<f64>))
37 }
38
39 fn create_up_down_counter(
40 &self,
41 _builder: InstrumentBuilder<'_, Arc<dyn UpDownCounter>>,
42 ) -> Arc<dyn UpDownCounter> {
43 Arc::new(NoopUpDownCounter)
44 }
45
46 fn create_async_up_down_counter(
47 &self,
48 _builder: AsyncInstrumentBuilder<'_, Arc<dyn AsyncMeasure<Value = i64>>, i64>,
49 ) -> Arc<dyn AsyncMeasure<Value = i64>> {
50 Arc::new(NoopAsyncMeasurement(PhantomData::<i64>))
51 }
52
53 fn create_monotonic_counter(
54 &self,
55 _builder: InstrumentBuilder<'_, Arc<dyn MonotonicCounter>>,
56 ) -> Arc<dyn MonotonicCounter> {
57 Arc::new(NoopMonotonicCounter)
58 }
59
60 fn create_async_monotonic_counter(
61 &self,
62 _builder: AsyncInstrumentBuilder<'_, Arc<dyn AsyncMeasure<Value = u64>>, u64>,
63 ) -> Arc<dyn AsyncMeasure<Value = u64>> {
64 Arc::new(NoopAsyncMeasurement(PhantomData::<u64>))
65 }
66
67 fn create_histogram(
68 &self,
69 _builder: InstrumentBuilder<'_, Arc<dyn Histogram>>,
70 ) -> Arc<dyn Histogram> {
71 Arc::new(NoopHistogram)
72 }
73}
74
75#[derive(Debug)]
76struct NoopAsyncMeasurement<T: Send + Sync + Debug>(PhantomData<T>);
77impl<T: Send + Sync + Debug> AsyncMeasure for NoopAsyncMeasurement<T> {
78 type Value = T;
79
80 fn record(&self, _value: T, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {}
81
82 fn stop(&self) {}
83}
84
85#[derive(Debug)]
86struct NoopUpDownCounter;
87impl UpDownCounter for NoopUpDownCounter {
88 fn add(&self, _value: i64, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {}
89}
90
91#[derive(Debug)]
92struct NoopMonotonicCounter;
93impl MonotonicCounter for NoopMonotonicCounter {
94 fn add(&self, _value: u64, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {}
95}
96
97#[derive(Debug)]
98struct NoopHistogram;
99impl Histogram for NoopHistogram {
100 fn record(
101 &self,
102 _value: f64,
103 _attributes: Option<&Attributes>,
104 _context: Option<&dyn Context>,
105 ) {
106 }
107}