blob: 9d4b453f3e5654122d33808c7ab6fa9c822420ff [file] [log] [blame]
Joey Armstrong903c69d2024-02-01 19:46:39 -05001// Copyright The OpenTelemetry Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//go:generate stringer -type=Kind
16
17package metric
18
19// Kind describes the kind of instrument.
20type Kind int8
21
22const (
23 // ValueRecorderKind indicates a ValueRecorder instrument.
24 ValueRecorderKind Kind = iota
25 // ValueObserverKind indicates an ValueObserver instrument.
26 ValueObserverKind
27
28 // CounterKind indicates a Counter instrument.
29 CounterKind
30 // UpDownCounterKind indicates a UpDownCounter instrument.
31 UpDownCounterKind
32
33 // SumObserverKind indicates a SumObserver instrument.
34 SumObserverKind
35 // UpDownSumObserverKind indicates a UpDownSumObserver instrument.
36 UpDownSumObserverKind
37)
38
39// Synchronous returns whether this is a synchronous kind of instrument.
40func (k Kind) Synchronous() bool {
41 switch k {
42 case CounterKind, UpDownCounterKind, ValueRecorderKind:
43 return true
44 }
45 return false
46}
47
48// Asynchronous returns whether this is an asynchronous kind of instrument.
49func (k Kind) Asynchronous() bool {
50 return !k.Synchronous()
51}
52
53// Adding returns whether this kind of instrument adds its inputs (as opposed to Grouping).
54func (k Kind) Adding() bool {
55 switch k {
56 case CounterKind, UpDownCounterKind, SumObserverKind, UpDownSumObserverKind:
57 return true
58 }
59 return false
60}
61
62// Adding returns whether this kind of instrument groups its inputs (as opposed to Adding).
63func (k Kind) Grouping() bool {
64 return !k.Adding()
65}
66
67// Monotonic returns whether this kind of instrument exposes a non-decreasing sum.
68func (k Kind) Monotonic() bool {
69 switch k {
70 case CounterKind, SumObserverKind:
71 return true
72 }
73 return false
74}
75
76// Cumulative returns whether this kind of instrument receives precomputed sums.
77func (k Kind) PrecomputedSum() bool {
78 return k.Adding() && k.Asynchronous()
79}