Skip to main content

opentelemetry/metrics/
mod.rs

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