-
Notifications
You must be signed in to change notification settings - Fork 384
/
kind.rs
73 lines (67 loc) · 3.05 KB
/
kind.rs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
/// Kinds of OpenTelemetry metric instruments
///
/// | **Name** | Instrument kind | Function(argument) | Default aggregation | Notes |
/// | ----------------------- | ----- | --------- | ------------- | --- |
/// | **Histogram** | Synchronous | Record(value) | MinMaxSumCount | Per-request, any non-additive measurement |
/// | **ValueRecorder** | Synchronous | Record(value) | MinMaxSumCount | Depreated. Use Histogram. |
/// | **ValueObserver** | Asynchronous | Observe(value) | MinMaxSumCount | Per-interval, any non-additive measurement |
/// | **Counter** | Synchronous additive monotonic | Add(increment) | Sum | Per-request, part of a monotonic sum |
/// | **UpDownCounter** | Synchronous additive | Add(increment) | Sum | Per-request, part of a non-monotonic sum |
/// | **SumObserver** | Asynchronous additive monotonic | Observe(sum) | Sum | Per-interval, reporting a monotonic sum |
/// | **UpDownSumObserver** | Asynchronous additive | Observe(sum) | Sum | Per-interval, reporting a non-monotonic sum |
#[derive(Clone, Debug, PartialEq, Hash)]
pub enum InstrumentKind {
/// A synchronous per-request recorder of non-additive measurements.
Histogram,
/// Deprecated: Replaced by Histogram
/// A synchronous per-request recorder of non-additive measurements.
ValueRecorder,
/// An asynchronous per-interval recorder of non-additive measurements.
ValueObserver,
/// 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.
SumObserver,
/// An asynchronous per-interval recorder of a non-monotonic sum.
UpDownSumObserver,
}
impl InstrumentKind {
/// Whether this is a synchronous kind of instrument.
pub fn synchronous(&self) -> bool {
matches!(
self,
InstrumentKind::Counter
| InstrumentKind::UpDownCounter
| InstrumentKind::ValueRecorder
| 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::SumObserver
| InstrumentKind::UpDownSumObserver
)
}
/// 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::SumObserver)
}
/// Whether this kind of instrument receives precomputed sums.
pub fn precomputed_sum(&self) -> bool {
self.adding() && self.asynchronous()
}
}