1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
5 #ifdef ENABLE_METRICS_PREVIEW
7 # include "opentelemetry/_metrics/instrument.h"
8 # include "opentelemetry/_metrics/observer_result.h"
10 OPENTELEMETRY_BEGIN_NAMESPACE
15 class ValueObserver
: virtual public AsynchronousInstrument
<T
>
19 ValueObserver() = default;
21 ValueObserver(nostd::string_view name
,
22 nostd::string_view description
,
23 nostd::string_view unit
,
25 void (*callback
)(ObserverResult
<T
>))
29 * Updates the instruments aggregator with the new value. The labels should
30 * contain the keys and values to be associated with this value.
32 * @param value is the numerical representation of the metric being captured
33 * @param labels the set of labels, as key-value pairs
35 virtual void observe(T value
, const common::KeyValueIterable
&labels
) override
= 0;
38 * Captures data by activating the callback function associated with the
39 * instrument and storing its return value. Callbacks for asynchronous
40 * instruments are defined during construction.
45 virtual void run() override
= 0;
49 class SumObserver
: virtual public AsynchronousInstrument
<T
>
53 SumObserver() = default;
55 SumObserver(nostd::string_view name
,
56 nostd::string_view description
,
57 nostd::string_view unit
,
59 void (*callback
)(ObserverResult
<T
>))
62 virtual void observe(T value
, const common::KeyValueIterable
&labels
) override
= 0;
64 virtual void run() override
= 0;
68 class UpDownSumObserver
: virtual public AsynchronousInstrument
<T
>
72 UpDownSumObserver() = default;
74 UpDownSumObserver(nostd::string_view name
,
75 nostd::string_view description
,
76 nostd::string_view unit
,
78 void (*callback
)(ObserverResult
<T
>))
81 virtual void observe(T value
, const common::KeyValueIterable
&labels
) override
= 0;
83 virtual void run() override
= 0;
86 } // namespace metrics
87 OPENTELEMETRY_END_NAMESPACE