99
1010#include " opentelemetry/nostd/shared_ptr.h"
1111#include " opentelemetry/sdk/common/attributemap_hash.h"
12+ #include " opentelemetry/sdk/metrics/aggregation/aggregation_config.h"
1213#include " opentelemetry/sdk/metrics/aggregation/default_aggregation.h"
1314
1415#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
@@ -42,8 +43,11 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora
4243 const AggregationConfig *aggregation_config)
4344 : instrument_descriptor_(instrument_descriptor),
4445 aggregation_type_{aggregation_type},
45- cumulative_hash_map_ (new AttributesHashMap()),
46- delta_hash_map_ (new AttributesHashMap()),
46+ aggregation_config_{AggregationConfig::GetOrDefault (aggregation_config)},
47+ cumulative_hash_map_ (
48+ std::make_unique<AttributesHashMap>(aggregation_config_->cardinality_limit_)),
49+ delta_hash_map_ (
50+ std::make_unique<AttributesHashMap>(aggregation_config_->cardinality_limit_)),
4751#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
4852 exemplar_filter_type_ (exempler_filter_type),
4953 exemplar_reservoir_(exemplar_reservoir),
@@ -124,7 +128,8 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora
124128 {
125129 std::lock_guard<opentelemetry::common::SpinLockMutex> guard (hashmap_lock_);
126130 delta_metrics = std::move (delta_hash_map_);
127- delta_hash_map_.reset (new AttributesHashMap);
131+ delta_hash_map_ =
132+ std::make_unique<AttributesHashMap>(aggregation_config_->cardinality_limit_ );
128133 }
129134
130135 auto status =
@@ -136,6 +141,7 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora
136141private:
137142 InstrumentDescriptor instrument_descriptor_;
138143 AggregationType aggregation_type_;
144+ const AggregationConfig *aggregation_config_;
139145 std::unique_ptr<AttributesHashMap> cumulative_hash_map_;
140146 std::unique_ptr<AttributesHashMap> delta_hash_map_;
141147 opentelemetry::common::SpinLockMutex hashmap_lock_;
0 commit comments