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