@@ -35,12 +35,11 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
3535 const AggregationConfig *aggregation_config)
3636 : instrument_descriptor_(instrument_descriptor),
3737 attributes_hashmap_ (new AttributesHashMap()),
38- attributes_processor_{ attributes_processor} ,
38+ attributes_processor_( attributes_processor) ,
3939#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
4040 exemplar_reservoir_ (exemplar_reservoir),
4141#endif
4242 temporal_metric_storage_ (instrument_descriptor, aggregation_type, aggregation_config)
43-
4443 {
4544 create_default_aggregation_ = [&, aggregation_type,
4645 aggregation_config]() -> std::unique_ptr<Aggregation> {
@@ -60,8 +59,9 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
6059#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
6160 exemplar_reservoir_->OfferMeasurement (value, {}, context, std::chrono::system_clock::now ());
6261#endif
62+ static size_t hash = opentelemetry::sdk::common::GetHash (" " );
6363 std::lock_guard<opentelemetry::common::SpinLockMutex> guard (attribute_hashmap_lock_);
64- attributes_hashmap_->GetOrSetDefault ({}, create_default_aggregation_ )->Aggregate (value);
64+ attributes_hashmap_->GetOrSetDefault (create_default_aggregation_, hash )->Aggregate (value);
6565 }
6666
6767 void RecordLong (int64_t value,
@@ -77,9 +77,21 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
7777 exemplar_reservoir_->OfferMeasurement (value, attributes, context,
7878 std::chrono::system_clock::now ());
7979#endif
80- auto attr = attributes_processor_->process (attributes);
80+ auto hash = opentelemetry::sdk::common::GetHashForAttributeMap (
81+ attributes, [this ](nostd::string_view key) {
82+ if (attributes_processor_)
83+ {
84+ return attributes_processor_->isPresent (key);
85+ }
86+ else
87+ {
88+ return true ;
89+ }
90+ });
91+
8192 std::lock_guard<opentelemetry::common::SpinLockMutex> guard (attribute_hashmap_lock_);
82- attributes_hashmap_->GetOrSetDefault (attr, create_default_aggregation_)->Aggregate (value);
93+ attributes_hashmap_->GetOrSetDefault (attributes, create_default_aggregation_, hash)
94+ ->Aggregate (value);
8395 }
8496
8597 void RecordDouble (double value,
@@ -93,8 +105,9 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
93105#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
94106 exemplar_reservoir_->OfferMeasurement (value, {}, context, std::chrono::system_clock::now ());
95107#endif
108+ static size_t hash = opentelemetry::sdk::common::GetHash (" " );
96109 std::lock_guard<opentelemetry::common::SpinLockMutex> guard (attribute_hashmap_lock_);
97- attributes_hashmap_->GetOrSetDefault ({}, create_default_aggregation_ )->Aggregate (value);
110+ attributes_hashmap_->GetOrSetDefault (create_default_aggregation_, hash )->Aggregate (value);
98111 }
99112
100113 void RecordDouble (double value,
@@ -114,9 +127,20 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
114127 exemplar_reservoir_->OfferMeasurement (value, attributes, context,
115128 std::chrono::system_clock::now ());
116129#endif
117- auto attr = attributes_processor_->process (attributes);
130+ auto hash = opentelemetry::sdk::common::GetHashForAttributeMap (
131+ attributes, [this ](nostd::string_view key) {
132+ if (attributes_processor_)
133+ {
134+ return attributes_processor_->isPresent (key);
135+ }
136+ else
137+ {
138+ return true ;
139+ }
140+ });
118141 std::lock_guard<opentelemetry::common::SpinLockMutex> guard (attribute_hashmap_lock_);
119- attributes_hashmap_->GetOrSetDefault (attr, create_default_aggregation_)->Aggregate (value);
142+ attributes_hashmap_->GetOrSetDefault (attributes, create_default_aggregation_, hash)
143+ ->Aggregate (value);
120144 }
121145
122146 bool Collect (CollectorHandle *collector,
@@ -127,16 +151,15 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage
127151
128152private:
129153 InstrumentDescriptor instrument_descriptor_;
130-
131154 // hashmap to maintain the metrics for delta collection (i.e, collection since last Collect call)
132155 std::unique_ptr<AttributesHashMap> attributes_hashmap_;
133156 // unreported metrics stash for all the collectors
134157 std::unordered_map<CollectorHandle *, std::list<std::shared_ptr<AttributesHashMap>>>
135158 unreported_metrics_;
136159 // last reported metrics stash for all the collectors.
137160 std::unordered_map<CollectorHandle *, LastReportedMetrics> last_reported_metrics_;
138- const AttributesProcessor *attributes_processor_;
139161 std::function<std::unique_ptr<Aggregation>()> create_default_aggregation_;
162+ const AttributesProcessor *attributes_processor_;
140163#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW
141164 nostd::shared_ptr<ExemplarReservoir> exemplar_reservoir_;
142165#endif
0 commit comments