1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
5 #ifdef ENABLE_METRICS_PREVIEW
7 # include "opentelemetry/_metrics/instrument.h"
9 OPENTELEMETRY_BEGIN_NAMESPACE
14 class BoundCounter
: virtual public BoundSynchronousInstrument
<T
>
18 BoundCounter() = default;
20 BoundCounter(nostd::string_view name
,
21 nostd::string_view description
,
22 nostd::string_view unit
,
26 * Add adds the value to the counter's sum. The labels are already linked * to the instrument
27 * and are not specified.
29 * @param value the numerical representation of the metric being captured
30 * @param labels the set of labels, as key-value pairs
32 virtual void add(T value
) = 0;
36 class Counter
: virtual public SynchronousInstrument
<T
>
42 Counter(nostd::string_view name
,
43 nostd::string_view description
,
44 nostd::string_view unit
,
49 * Bind creates a bound instrument for this counter. The labels are
50 * associated with values recorded via subsequent calls to Record.
52 * @param labels the set of labels, as key-value pairs.
53 * @return a BoundIntCounter tied to the specified labels
55 virtual nostd::shared_ptr
<BoundCounter
<T
>> bindCounter(const common::KeyValueIterable
&labels
)
57 return nostd::shared_ptr
<BoundCounter
<T
>>();
61 * Add adds the value to the counter's sum. The labels should contain
62 * the keys and values to be associated with this value. Counters only * accept positive
65 * @param value the numerical representation of the metric being captured
66 * @param labels the set of labels, as key-value pairs
68 virtual void add(T value
, const common::KeyValueIterable
&labels
) = 0;
70 virtual void update(T value
, const common::KeyValueIterable
&labels
) override
= 0;
74 class BoundUpDownCounter
: virtual public BoundSynchronousInstrument
<T
>
78 BoundUpDownCounter() = default;
80 BoundUpDownCounter(nostd::string_view name
,
81 nostd::string_view description
,
82 nostd::string_view unit
,
86 * Add adds the value to the counter's sum. The labels are already linked to * the instrument and
87 * do not need to specified again. UpDownCounters can accept positive and negative values.
89 * @param value the numerical representation of the metric being captured
90 * @param labels the set of labels, as key-value pairs
92 virtual void add(T value
) = 0;
96 class UpDownCounter
: virtual public SynchronousInstrument
<T
>
100 UpDownCounter() = default;
102 UpDownCounter(nostd::string_view name
,
103 nostd::string_view description
,
104 nostd::string_view unit
,
107 virtual nostd::shared_ptr
<BoundUpDownCounter
<T
>> bindUpDownCounter(
108 const common::KeyValueIterable
&labels
)
110 return nostd::shared_ptr
<BoundUpDownCounter
<T
>>();
114 * Add adds the value to the counter's sum. The labels should contain
115 * the keys and values to be associated with this value. UpDownCounters can
116 * accept positive and negative values.
118 * @param value the numerical representation of the metric being captured
119 * @param labels the set of labels, as key-value pairs
121 virtual void add(T value
, const common::KeyValueIterable
&labels
) = 0;
123 virtual void update(T value
, const common::KeyValueIterable
&labels
) override
= 0;
127 class BoundValueRecorder
: virtual public BoundSynchronousInstrument
<T
>
131 BoundValueRecorder() = default;
133 BoundValueRecorder(nostd::string_view name
,
134 nostd::string_view description
,
135 nostd::string_view unit
,
139 * Records the value by summing it with previous measurements and checking * previously stored
140 * minimum and maximum values. The labels associated with * new values are already linked to the
141 * instrument as it is bound. * ValueRecorders can accept positive and negative values.
143 * @param value the numerical representation of the metric being captured
145 virtual void record(T value
) = 0;
149 class ValueRecorder
: virtual public SynchronousInstrument
<T
>
153 ValueRecorder() = default;
155 ValueRecorder(nostd::string_view name
,
156 nostd::string_view description
,
157 nostd::string_view unit
,
160 virtual nostd::shared_ptr
<BoundValueRecorder
<T
>> bindValueRecorder(
161 const common::KeyValueIterable
&labels
)
163 return nostd::shared_ptr
<BoundValueRecorder
<T
>>();
167 * Records the value by summing it with previous measurements and checking * previously stored
168 * minimum and maximum values. The labels should contain the keys and values to be associated with
169 * this value. ValueRecorders can accept positive and negative values.
171 * @param value the numerical representation of the metric being captured
172 * @param labels the set of labels, as key-value pairs
174 virtual void record(T value
, const common::KeyValueIterable
&labels
) = 0;
176 virtual void update(T value
, const common::KeyValueIterable
&labels
) override
= 0;
179 } // namespace metrics
180 OPENTELEMETRY_END_NAMESPACE