Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions sdk/include/opentelemetry/sdk/metrics/observer_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/key_value_iterable.h"
#include "opentelemetry/common/macros.h"
#include "opentelemetry/metrics/observer_result.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/metrics/state/attributes_hashmap.h"
Expand Down Expand Up @@ -34,15 +35,37 @@ class ObserverResultT final : public opentelemetry::metrics::ObserverResultT<T>
~ObserverResultT() override = default;

void Observe(T value) noexcept override
#if OPENTELEMETRY_HAVE_EXCEPTIONS
try
#endif
{
data_[MetricAttributes{{}, attributes_processor_}] = value;
}
#if OPENTELEMETRY_HAVE_EXCEPTIONS
catch (...)
{
// Silently drop the measurement; per opentelemetry-cpp guidance (PR #3964),
// exceptions in noexcept API/SDK code must not log or abort.
return;
}
#endif

void Observe(T value, const opentelemetry::common::KeyValueIterable &attributes) noexcept override
#if OPENTELEMETRY_HAVE_EXCEPTIONS
try
#endif
{
data_[MetricAttributes{attributes, attributes_processor_}] =
value; // overwrites the previous value if present
}
#if OPENTELEMETRY_HAVE_EXCEPTIONS
catch (...)
{
// Silently drop the measurement; per opentelemetry-cpp guidance (PR #3964),
// exceptions in noexcept API/SDK code must not log or abort.
return;
}
#endif

const std::unordered_map<MetricAttributes, T, AttributeHashGenerator> &GetMeasurements()
{
Expand Down
Loading