1010#include " opentelemetry/nostd/shared_ptr.h"
1111#include " opentelemetry/sdk/common/attributemap_hash.h"
1212#include " opentelemetry/sdk/metrics/aggregation/default_aggregation.h"
13+ #include " opentelemetry/sdk/metrics/exemplar/reservoir.h"
1314#include " opentelemetry/sdk/metrics/instruments.h"
1415#include " opentelemetry/sdk/metrics/observer_result.h"
1516#include " opentelemetry/sdk/metrics/state/attributes_hashmap.h"
@@ -29,11 +30,16 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora
2930public:
3031 AsyncMetricStorage (InstrumentDescriptor instrument_descriptor,
3132 const AggregationType aggregation_type,
33+ nostd::shared_ptr<ExemplarReservoir> &&exemplar_reservoir
34+ OPENTELEMETRY_MAYBE_UNUSED,
3235 const AggregationConfig *aggregation_config)
3336 : instrument_descriptor_(instrument_descriptor),
3437 aggregation_type_{aggregation_type},
3538 cumulative_hash_map_ (new AttributesHashMap()),
3639 delta_hash_map_ (new AttributesHashMap()),
40+ #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
41+ exemplar_reservoir_ (exemplar_reservoir),
42+ #endif
3743 temporal_metric_storage_ (instrument_descriptor, aggregation_type, aggregation_config)
3844 {}
3945
@@ -47,6 +53,11 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora
4753 std::lock_guard<opentelemetry::common::SpinLockMutex> guard (hashmap_lock_);
4854 for (auto &measurement : measurements)
4955 {
56+ #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
57+ exemplar_reservoir_->OfferMeasurement (measurement.second , {}, {},
58+ std::chrono::system_clock::now ());
59+ #endif
60+
5061 auto aggr = DefaultAggregation::CreateAggregation (aggregation_type_, instrument_descriptor_);
5162 aggr->Aggregate (measurement.second );
5263 auto hash = opentelemetry::sdk::common::GetHashForAttributeMap (measurement.first );
@@ -119,6 +130,9 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora
119130 std::unique_ptr<AttributesHashMap> cumulative_hash_map_;
120131 std::unique_ptr<AttributesHashMap> delta_hash_map_;
121132 opentelemetry::common::SpinLockMutex hashmap_lock_;
133+ #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
134+ nostd::shared_ptr<ExemplarReservoir> exemplar_reservoir_;
135+ #endif
122136 TemporalMetricStorage temporal_metric_storage_;
123137};
124138
0 commit comments