10
10
#include " opentelemetry/nostd/shared_ptr.h"
11
11
#include " opentelemetry/sdk/common/attributemap_hash.h"
12
12
#include " opentelemetry/sdk/metrics/aggregation/default_aggregation.h"
13
+ #include " opentelemetry/sdk/metrics/exemplar/reservoir.h"
13
14
#include " opentelemetry/sdk/metrics/instruments.h"
14
15
#include " opentelemetry/sdk/metrics/observer_result.h"
15
16
#include " opentelemetry/sdk/metrics/state/attributes_hashmap.h"
@@ -29,11 +30,16 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora
29
30
public:
30
31
AsyncMetricStorage (InstrumentDescriptor instrument_descriptor,
31
32
const AggregationType aggregation_type,
33
+ nostd::shared_ptr<ExemplarReservoir> &&exemplar_reservoir
34
+ OPENTELEMETRY_MAYBE_UNUSED,
32
35
const AggregationConfig *aggregation_config)
33
36
: instrument_descriptor_(instrument_descriptor),
34
37
aggregation_type_{aggregation_type},
35
38
cumulative_hash_map_ (new AttributesHashMap()),
36
39
delta_hash_map_ (new AttributesHashMap()),
40
+ #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
41
+ exemplar_reservoir_ (exemplar_reservoir),
42
+ #endif
37
43
temporal_metric_storage_ (instrument_descriptor, aggregation_type, aggregation_config)
38
44
{}
39
45
@@ -47,6 +53,11 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora
47
53
std::lock_guard<opentelemetry::common::SpinLockMutex> guard (hashmap_lock_);
48
54
for (auto &measurement : measurements)
49
55
{
56
+ #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
57
+ exemplar_reservoir_->OfferMeasurement (measurement.second , {}, {},
58
+ std::chrono::system_clock::now ());
59
+ #endif
60
+
50
61
auto aggr = DefaultAggregation::CreateAggregation (aggregation_type_, instrument_descriptor_);
51
62
aggr->Aggregate (measurement.second );
52
63
auto hash = opentelemetry::sdk::common::GetHashForAttributeMap (measurement.first );
@@ -119,6 +130,9 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora
119
130
std::unique_ptr<AttributesHashMap> cumulative_hash_map_;
120
131
std::unique_ptr<AttributesHashMap> delta_hash_map_;
121
132
opentelemetry::common::SpinLockMutex hashmap_lock_;
133
+ #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
134
+ nostd::shared_ptr<ExemplarReservoir> exemplar_reservoir_;
135
+ #endif
122
136
TemporalMetricStorage temporal_metric_storage_;
123
137
};
124
138
0 commit comments