opentelemetry/metrics/
mod.rs

1//! # OpenTelemetry Metrics API
2
3use std::sync::Arc;
4
5mod instruments;
6mod meter;
7pub(crate) mod noop;
8pub use instruments::{
9    counter::{Counter, ObservableCounter},
10    gauge::{Gauge, ObservableGauge},
11    histogram::Histogram,
12    up_down_counter::{ObservableUpDownCounter, UpDownCounter},
13    AsyncInstrument, AsyncInstrumentBuilder, Callback, HistogramBuilder, InstrumentBuilder,
14    SyncInstrument,
15};
16pub use meter::{Meter, MeterProvider};
17
18/// SDK implemented trait for creating instruments
19pub trait InstrumentProvider {
20    /// creates an instrument for recording increasing values.
21    fn u64_counter(&self, _builder: InstrumentBuilder<'_, Counter<u64>>) -> Counter<u64> {
22        Counter::new(Arc::new(noop::NoopSyncInstrument::new()))
23    }
24
25    /// creates an instrument for recording increasing values.
26    fn f64_counter(&self, _builder: InstrumentBuilder<'_, Counter<f64>>) -> Counter<f64> {
27        Counter::new(Arc::new(noop::NoopSyncInstrument::new()))
28    }
29
30    /// creates an instrument for recording increasing values via callback.
31    fn u64_observable_counter(
32        &self,
33        _builder: AsyncInstrumentBuilder<'_, ObservableCounter<u64>, u64>,
34    ) -> ObservableCounter<u64> {
35        ObservableCounter::new()
36    }
37
38    /// creates an instrument for recording increasing values via callback.
39    fn f64_observable_counter(
40        &self,
41        _builder: AsyncInstrumentBuilder<'_, ObservableCounter<f64>, f64>,
42    ) -> ObservableCounter<f64> {
43        ObservableCounter::new()
44    }
45
46    /// creates an instrument for recording changes of a value.
47    fn i64_up_down_counter(
48        &self,
49        _builder: InstrumentBuilder<'_, UpDownCounter<i64>>,
50    ) -> UpDownCounter<i64> {
51        UpDownCounter::new(Arc::new(noop::NoopSyncInstrument::new()))
52    }
53
54    /// creates an instrument for recording changes of a value.
55    fn f64_up_down_counter(
56        &self,
57        _builder: InstrumentBuilder<'_, UpDownCounter<f64>>,
58    ) -> UpDownCounter<f64> {
59        UpDownCounter::new(Arc::new(noop::NoopSyncInstrument::new()))
60    }
61
62    /// creates an instrument for recording changes of a value.
63    fn i64_observable_up_down_counter(
64        &self,
65        _builder: AsyncInstrumentBuilder<'_, ObservableUpDownCounter<i64>, i64>,
66    ) -> ObservableUpDownCounter<i64> {
67        ObservableUpDownCounter::new()
68    }
69
70    /// creates an instrument for recording changes of a value via callback.
71    fn f64_observable_up_down_counter(
72        &self,
73        _builder: AsyncInstrumentBuilder<'_, ObservableUpDownCounter<f64>, f64>,
74    ) -> ObservableUpDownCounter<f64> {
75        ObservableUpDownCounter::new()
76    }
77
78    /// creates an instrument for recording independent values.
79    fn u64_gauge(&self, _builder: InstrumentBuilder<'_, Gauge<u64>>) -> Gauge<u64> {
80        Gauge::new(Arc::new(noop::NoopSyncInstrument::new()))
81    }
82
83    /// creates an instrument for recording independent values.
84    fn f64_gauge(&self, _builder: InstrumentBuilder<'_, Gauge<f64>>) -> Gauge<f64> {
85        Gauge::new(Arc::new(noop::NoopSyncInstrument::new()))
86    }
87
88    /// creates an instrument for recording independent values.
89    fn i64_gauge(&self, _builder: InstrumentBuilder<'_, Gauge<i64>>) -> Gauge<i64> {
90        Gauge::new(Arc::new(noop::NoopSyncInstrument::new()))
91    }
92
93    /// creates an instrument for recording the current value via callback.
94    fn u64_observable_gauge(
95        &self,
96        _builder: AsyncInstrumentBuilder<'_, ObservableGauge<u64>, u64>,
97    ) -> ObservableGauge<u64> {
98        ObservableGauge::new()
99    }
100
101    /// creates an instrument for recording the current value via callback.
102    fn i64_observable_gauge(
103        &self,
104        _builder: AsyncInstrumentBuilder<'_, ObservableGauge<i64>, i64>,
105    ) -> ObservableGauge<i64> {
106        ObservableGauge::new()
107    }
108
109    /// creates an instrument for recording the current value via callback.
110    fn f64_observable_gauge(
111        &self,
112        _builder: AsyncInstrumentBuilder<'_, ObservableGauge<f64>, f64>,
113    ) -> ObservableGauge<f64> {
114        ObservableGauge::new()
115    }
116
117    /// creates an instrument for recording a distribution of values.
118    fn f64_histogram(&self, _builder: HistogramBuilder<'_, Histogram<f64>>) -> Histogram<f64> {
119        Histogram::new(Arc::new(noop::NoopSyncInstrument::new()))
120    }
121
122    /// creates an instrument for recording a distribution of values.
123    fn u64_histogram(&self, _builder: HistogramBuilder<'_, Histogram<u64>>) -> Histogram<u64> {
124        Histogram::new(Arc::new(noop::NoopSyncInstrument::new()))
125    }
126}