-
Notifications
You must be signed in to change notification settings - Fork 438
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
Fix observable attributes drop #2557
Changes from all commits
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 |
---|---|---|
|
@@ -26,11 +26,15 @@ class ObserverResultT final : public opentelemetry::metrics::ObserverResultT<T> | |
|
||
~ObserverResultT() override = default; | ||
|
||
void Observe(T value) noexcept override { data_.insert({{}, value}); } | ||
void Observe(T value) noexcept override | ||
{ | ||
data_[MetricAttributes{{}, attributes_processor_}] = value; | ||
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. This change is unrelated to the bug. Ideally, observing a value with an identical set of attributes should lead to it being overwritten. However, at present, using std::unordered_map::insert() leads to the value being disregarded rather than replaced. The observable callback shouldn't be reporting multiple values for the same attribute-set in single invoke, but fixing it just in case they do so. |
||
} | ||
|
||
void Observe(T value, const opentelemetry::common::KeyValueIterable &attributes) noexcept override | ||
{ | ||
data_.insert({MetricAttributes{attributes, attributes_processor_}, value}); | ||
data_[MetricAttributes{attributes, attributes_processor_}] = | ||
value; // overwrites the previous value if present | ||
} | ||
|
||
const std::unordered_map<MetricAttributes, T, AttributeHashGenerator> &GetMeasurements() | ||
|
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.
Tested the changes by the modified metrics example. More exhaustive tests need to be added for observable instruments, will add them along with the filtering issue fix.