|
7 | 7 |
|
8 | 8 | #include "opentelemetry/common/attribute_value.h" |
9 | 9 | #include "opentelemetry/common/key_value_iterable.h" |
| 10 | +#include "opentelemetry/common/macros.h" |
10 | 11 | #include "opentelemetry/metrics/observer_result.h" |
11 | 12 | #include "opentelemetry/nostd/string_view.h" |
12 | 13 | #include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" |
@@ -34,15 +35,37 @@ class ObserverResultT final : public opentelemetry::metrics::ObserverResultT<T> |
34 | 35 | ~ObserverResultT() override = default; |
35 | 36 |
|
36 | 37 | void Observe(T value) noexcept override |
| 38 | +#if OPENTELEMETRY_HAVE_EXCEPTIONS |
| 39 | + try |
| 40 | +#endif |
37 | 41 | { |
38 | 42 | data_[MetricAttributes{{}, attributes_processor_}] = value; |
39 | 43 | } |
| 44 | +#if OPENTELEMETRY_HAVE_EXCEPTIONS |
| 45 | + catch (...) |
| 46 | + { |
| 47 | + // Silently drop the measurement; per opentelemetry-cpp guidance (PR #3964), |
| 48 | + // exceptions in noexcept API/SDK code must not log or abort. |
| 49 | + return; |
| 50 | + } |
| 51 | +#endif |
40 | 52 |
|
41 | 53 | void Observe(T value, const opentelemetry::common::KeyValueIterable &attributes) noexcept override |
| 54 | +#if OPENTELEMETRY_HAVE_EXCEPTIONS |
| 55 | + try |
| 56 | +#endif |
42 | 57 | { |
43 | 58 | data_[MetricAttributes{attributes, attributes_processor_}] = |
44 | 59 | value; // overwrites the previous value if present |
45 | 60 | } |
| 61 | +#if OPENTELEMETRY_HAVE_EXCEPTIONS |
| 62 | + catch (...) |
| 63 | + { |
| 64 | + // Silently drop the measurement; per opentelemetry-cpp guidance (PR #3964), |
| 65 | + // exceptions in noexcept API/SDK code must not log or abort. |
| 66 | + return; |
| 67 | + } |
| 68 | +#endif |
46 | 69 |
|
47 | 70 | const std::unordered_map<MetricAttributes, T, AttributeHashGenerator> &GetMeasurements() |
48 | 71 | { |
|
0 commit comments