opentelemetry_spanprocessor_any/metrics/
kind.rs

1/// Kinds of OpenTelemetry metric instruments
2///
3/// | **Name** | Instrument kind | Function(argument) | Default aggregation | Notes |
4/// | ----------------------- | ----- | --------- | ------------- | --- |
5/// | **ValueRecorder**       | Synchronous  | Record(value) | MinMaxSumCount  | Per-request, any non-additive measurement |
6/// | **ValueObserver**       | Asynchronous | Observe(value) | MinMaxSumCount  | Per-interval, any non-additive measurement |
7/// | **Counter**             | Synchronous additive monotonic | Add(increment) | Sum | Per-request, part of a monotonic sum |
8/// | **UpDownCounter**       | Synchronous additive | Add(increment) | Sum | Per-request, part of a non-monotonic sum |
9/// | **SumObserver**         | Asynchronous additive monotonic | Observe(sum) | Sum | Per-interval, reporting a monotonic sum |
10/// | **UpDownSumObserver**   | Asynchronous additive | Observe(sum) | Sum | Per-interval, reporting a non-monotonic sum |
11#[derive(Clone, Debug, PartialEq, Hash)]
12pub enum InstrumentKind {
13    /// A synchronous per-request recorder of non-additive measurements.
14    ValueRecorder,
15    /// An asynchronous per-interval recorder of non-additive measurements.
16    ValueObserver,
17    /// A synchronous per-request part of a monotonic sum.
18    Counter,
19    /// A synchronous per-request part of a non-monotonic sum.
20    UpDownCounter,
21    /// An asynchronous per-interval recorder of a monotonic sum.
22    SumObserver,
23    /// An asynchronous per-interval recorder of a non-monotonic sum.
24    UpDownSumObserver,
25}
26
27impl InstrumentKind {
28    /// Whether this is a synchronous kind of instrument.
29    pub fn synchronous(&self) -> bool {
30        matches!(
31            self,
32            InstrumentKind::Counter | InstrumentKind::UpDownCounter | InstrumentKind::ValueRecorder
33        )
34    }
35
36    /// Whether this is a synchronous kind of instrument.
37    pub fn asynchronous(&self) -> bool {
38        !self.synchronous()
39    }
40
41    /// Whether this kind of instrument adds its inputs (as opposed to grouping).
42    pub fn adding(&self) -> bool {
43        matches!(
44            self,
45            InstrumentKind::Counter
46                | InstrumentKind::UpDownCounter
47                | InstrumentKind::SumObserver
48                | InstrumentKind::UpDownSumObserver
49        )
50    }
51
52    /// Whether this kind of instrument groups its inputs (as opposed to adding).
53    pub fn grouping(&self) -> bool {
54        !self.adding()
55    }
56
57    /// Whether this kind of instrument exposes a non-decreasing sum.
58    pub fn monotonic(&self) -> bool {
59        matches!(self, InstrumentKind::Counter | InstrumentKind::SumObserver)
60    }
61
62    /// Whether this kind of instrument receives precomputed sums.
63    pub fn precomputed_sum(&self) -> bool {
64        self.adding() && self.asynchronous()
65    }
66}