-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Synchronous Gauge #2341
[WIP] Synchronous Gauge #2341
Changes from 8 commits
2e1e696
f5c3c80
6ac46fb
b6909af
c511147
b9f538b
06cd640
9e34355
4134c00
e0bdccc
127b107
e6abe54
a3c0101
03c3cab
1248928
272f30f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,31 +22,44 @@ class SynchronousInstrument | |
virtual ~SynchronousInstrument() = default; | ||
}; | ||
|
||
/* A Counter instrument that adds values. */ | ||
|
||
template <class T> | ||
class Counter : public SynchronousInstrument | ||
{ | ||
|
||
public: | ||
/** | ||
* Add adds the value to the counter's sum | ||
* Record a value | ||
* | ||
* @param value The increment amount. MUST be non-negative. | ||
*/ | ||
virtual void Add(T value) noexcept = 0; | ||
|
||
/** | ||
* Record a value | ||
* | ||
* @param value The increment amount. MUST be non-negative. | ||
* @param context The explicit context to associate with this measurement. | ||
*/ | ||
virtual void Add(T value, const context::Context &context) 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. | ||
* Record a value with a set of attributes. | ||
* | ||
* @param value The increment amount. MUST be non-negative. | ||
* @param attributes the set of attributes, as key-value pairs | ||
* @param attributes A set of attributes to associate with the value. | ||
*/ | ||
|
||
virtual void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0; | ||
|
||
/** | ||
* Record a value with a set of attributes. | ||
* | ||
* @param value The increment amount. MUST be non-negative. | ||
* @param attributes A set of attributes to associate with the value. | ||
* @param context The explicit context to associate with this measurement. | ||
*/ | ||
virtual void Add(T value, | ||
const common::KeyValueIterable &attributes, | ||
const context::Context &context) noexcept = 0; | ||
|
@@ -55,8 +68,7 @@ class Counter : public SynchronousInstrument | |
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr> | ||
void Add(T value, const U &attributes) noexcept | ||
{ | ||
auto context = context::Context{}; | ||
this->Add(value, common::KeyValueIterableView<U>{attributes}, context); | ||
this->Add(value, common::KeyValueIterableView<U>{attributes}); | ||
} | ||
|
||
template <class U, | ||
|
@@ -70,11 +82,8 @@ class Counter : public SynchronousInstrument | |
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> | ||
attributes) noexcept | ||
{ | ||
auto context = context::Context{}; | ||
this->Add(value, | ||
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{ | ||
attributes.begin(), attributes.end()}, | ||
context); | ||
this->Add(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{ | ||
attributes.begin(), attributes.end()}); | ||
} | ||
|
||
void Add(T value, | ||
|
@@ -94,18 +103,54 @@ template <class T> | |
class Histogram : public SynchronousInstrument | ||
{ | ||
public: | ||
#if OPENTELEMETRY_ABI_VERSION_NO >= 2 | ||
/** | ||
* @since ABI_VERSION 2 | ||
* Records a value. | ||
* | ||
* @param value The measurement value. MUST be non-negative. | ||
*/ | ||
virtual void Record(T value) noexcept = 0; | ||
|
||
/** | ||
* @since ABI_VERSION 2 | ||
* Records a value with a set of attributes. | ||
* | ||
* @param value The measurement value. MUST be non-negative. | ||
* @param attribute A set of attributes to associate with the value. | ||
*/ | ||
virtual void Record(T value, const common::KeyValueIterable &attribute) 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()}); | ||
} | ||
#endif | ||
|
||
/** | ||
* Records a value. | ||
* | ||
* @param value The measurement value. MUST be non-negative. | ||
* @param context The explicit context to associate with this measurement. | ||
*/ | ||
virtual void Record(T value, const context::Context &context) noexcept = 0; | ||
|
||
/** | ||
* Records a value with a set of attributes. | ||
* | ||
* @param value The measurement value. MUST be non-negative. | ||
* @param attributes A set of attributes to associate with the count. | ||
* @param attributes A set of attributes to associate with the value.. | ||
* @param context The explicit context to associate with this measurement. | ||
*/ | ||
virtual void Record(T value, | ||
const common::KeyValueIterable &attributes, | ||
|
@@ -137,22 +182,35 @@ class UpDownCounter : public SynchronousInstrument | |
{ | ||
public: | ||
/** | ||
* Adds a value. | ||
* Record a value. | ||
* | ||
* @param value The amount of the measurement. | ||
* @param value The increment amount. May be positive, negative or zero. | ||
*/ | ||
virtual void Add(T value) noexcept = 0; | ||
|
||
/** | ||
* Record a value. | ||
* | ||
* @param value The increment amount. May be positive, negative or zero. | ||
* @param context The explicit context to associate with this measurement. | ||
*/ | ||
virtual void Add(T value, const context::Context &context) noexcept = 0; | ||
|
||
/** | ||
* Add a value with a set of attributes. | ||
* Record 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; | ||
|
||
/** | ||
* Record 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. | ||
* @param context The explicit context to associate with this measurement. | ||
*/ | ||
virtual void Add(T value, | ||
const common::KeyValueIterable &attributes, | ||
const context::Context &context) noexcept = 0; | ||
|
@@ -161,8 +219,7 @@ class UpDownCounter : public SynchronousInstrument | |
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr> | ||
void Add(T value, const U &attributes) noexcept | ||
{ | ||
auto context = context::Context{}; | ||
this->Add(value, common::KeyValueIterableView<U>{attributes}, context); | ||
this->Add(value, common::KeyValueIterableView<U>{attributes}); | ||
} | ||
|
||
template <class U, | ||
|
@@ -176,11 +233,8 @@ class UpDownCounter : public SynchronousInstrument | |
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> | ||
attributes) noexcept | ||
{ | ||
auto context = context::Context{}; | ||
this->Add(value, | ||
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{ | ||
attributes.begin(), attributes.end()}, | ||
context); | ||
this->Add(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{ | ||
attributes.begin(), attributes.end()}); | ||
} | ||
|
||
void Add(T value, | ||
|
@@ -194,5 +248,85 @@ class UpDownCounter : public SynchronousInstrument | |
} | ||
}; | ||
|
||
#if OPENTELEMETRY_ABI_VERSION_NO >= 2 | ||
|
||
/** An Gauge instrument that records value. | ||
* @since ABI_VERSION 2 | ||
*/ | ||
|
||
template <class T> | ||
class Gauge : public SynchronousInstrument | ||
{ | ||
public: | ||
/** | ||
* Record a value | ||
* | ||
* @param value The increment amount. MUST be non-negative. | ||
*/ | ||
virtual void Record(T value) noexcept = 0; | ||
|
||
/** | ||
* Record a value | ||
* | ||
* @param value The increment amount. MUST be non-negative. | ||
* @param context The explicit context to associate with this measurement. | ||
*/ | ||
virtual void Record(T value, const context::Context &context) noexcept = 0; | ||
|
||
/** | ||
* Record a value with a set of attributes. | ||
* | ||
* @param value The increment amount. MUST be non-negative. | ||
* @param attributes A set of attributes to associate with the value. | ||
*/ | ||
|
||
virtual void Record(T value, const common::KeyValueIterable &attributes) noexcept = 0; | ||
|
||
/** | ||
* Record a value with a set of attributes. | ||
* | ||
* @param value The increment amount. MUST be non-negative. | ||
* @param attributes A set of attributes to associate with the value. | ||
* @param context The explicit context to associate with this measurement. | ||
*/ | ||
virtual void Record(T value, | ||
const common::KeyValueIterable &attributes, | ||
const context::Context &context) noexcept = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here there are 4 virtual methods for the ABI, with different parameters combinations. An alternative is to define only one virtual method for the ABI, accepting pointers instead of references:
and then have all the API helpers invoke this unique entry point, passing We can still have a helper like:
so that user code pass references as usual. Making a clear distinction between the ABI (the virtual method) and the API helpers (non virtual) will help, Changes to the unique ABI virtual method is a breaking change. Changes to the plenty of API helpers accepting combinations of parameters is not breaking the ABI, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A much cleaner method! Thanks for suggesting. I saw this approach in the GetMeter() PR but overlooked adding it here. Done now :) |
||
|
||
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}); | ||
} | ||
|
||
template <class U, | ||
nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr> | ||
void Record(T value, const U &attributes, const context::Context &context) noexcept | ||
{ | ||
this->Record(value, common::KeyValueIterableView<U>{attributes}, context); | ||
} | ||
|
||
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()}); | ||
} | ||
|
||
void Record( | ||
T value, | ||
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes, | ||
const context::Context &context) noexcept | ||
{ | ||
this->Record(value, | ||
nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{ | ||
attributes.begin(), attributes.end()}, | ||
context); | ||
} | ||
}; | ||
#endif | ||
|
||
} // namespace metrics | ||
OPENTELEMETRY_END_NAMESPACE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align with below
@param
?