-
Notifications
You must be signed in to change notification settings - Fork 440
/
sync_instruments.h
134 lines (113 loc) · 3.88 KB
/
sync_instruments.h
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#ifndef ENABLE_METRICS_PREVIEW
# include "opentelemetry/common/attribute_value.h"
# include "opentelemetry/common/key_value_iterable_view.h"
# include "opentelemetry/nostd/span.h"
# include "opentelemetry/nostd/string_view.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics
{
class SynchronousInstrument
{};
template <class T>
class Counter : public SynchronousInstrument
{
public:
/**
* Add adds the value to the counter's sum
*
* @param value The increment amount. MUST be non-negative.
*/
virtual void Add(T value) noexcept = 0;
/**
* Add adds the value to the counter's sum. The attributes should contain
* the keys and values to be associated with this value. Counters only
* accept positive valued updates.
*
* @param value The increment amount. MUST be non-negative.
* @param attributes the set of attributes, as key-value pairs
*/
virtual void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0;
template <class U,
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
void Add(T value, const U &attributes) noexcept
{
this->Add(value, common::KeyValueIterableView<U>{attributes});
}
void Add(T value,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
attributes) noexcept
{
this->Add(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()});
}
};
/** A histogram instrument that records values. */
template <class T>
class Histogram : public SynchronousInstrument
{
public:
/**
* Records a value.
*
* @param value The increment amount. May be positive, negative or zero.
*/
virtual void Record(T value) noexcept = 0;
/**
* Records a value with a set of attributes.
*
* @param value The increment amount. May be positive, negative or zero.
* @param attributes A set of attributes to associate with the count.
*/
virtual void Record(T value, const common::KeyValueIterable &attributes) noexcept = 0;
template <class U,
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
void Record(T value, const U &attributes) noexcept
{
this->Record(value, common::KeyValueIterableView<U>{attributes});
}
void Record(T value,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
attributes) noexcept
{
this->Record(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()});
}
};
/** An up-down-counter instrument that adds or reduce values. */
template <class T>
class UpDownCounter : public SynchronousInstrument
{
public:
/**
* Adds a value.
*
* @param value The amount of the measurement.
*/
virtual void Add(T value) noexcept = 0;
/**
* Add a value with a set of attributes.
*
* @param value The increment amount. May be positive, negative or zero.
* @param attributes A set of attributes to associate with the count.
*/
virtual void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0;
template <class U,
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
void Add(T value, const U &attributes) noexcept
{
this->Add(value, common::KeyValueIterableView<U>{attributes});
}
void Add(T value,
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
attributes) noexcept
{
this->Add(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
attributes.begin(), attributes.end()});
}
};
} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#endif