logo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/// Kinds of OpenTelemetry metric instruments
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum InstrumentKind {
    /// A histogram instrument
    Histogram,
    /// A gauge observer instrument
    GaugeObserver,
    /// A synchronous per-request part of a monotonic sum.
    Counter,
    /// A synchronous per-request part of a non-monotonic sum.
    UpDownCounter,
    /// An asynchronous per-interval recorder of a monotonic sum.
    CounterObserver,
    /// An asynchronous per-interval recorder of a non-monotonic sum.
    UpDownCounterObserver,
}

impl InstrumentKind {
    /// Whether this is a synchronous kind of instrument.
    pub fn synchronous(&self) -> bool {
        matches!(
            self,
            InstrumentKind::Counter | InstrumentKind::UpDownCounter | InstrumentKind::Histogram
        )
    }

    /// Whether this is a synchronous kind of instrument.
    pub fn asynchronous(&self) -> bool {
        !self.synchronous()
    }

    /// Whether this kind of instrument adds its inputs (as opposed to grouping).
    pub fn adding(&self) -> bool {
        matches!(
            self,
            InstrumentKind::Counter
                | InstrumentKind::UpDownCounter
                | InstrumentKind::CounterObserver
                | InstrumentKind::UpDownCounterObserver
        )
    }

    /// Whether this kind of instrument groups its inputs (as opposed to adding).
    pub fn grouping(&self) -> bool {
        !self.adding()
    }

    /// Whether this kind of instrument exposes a non-decreasing sum.
    pub fn monotonic(&self) -> bool {
        matches!(
            self,
            InstrumentKind::Counter | InstrumentKind::CounterObserver
        )
    }

    /// Whether this kind of instrument receives precomputed sums.
    pub fn precomputed_sum(&self) -> bool {
        self.adding() && self.asynchronous()
    }
}