diff --git a/CHANGELOG.md b/CHANGELOG.md index 64b2213c58..644edfe2c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ Increment the: ## [Unreleased] +* [Metrics SDK] Use nostd::function_ref in AttributesHashMap + [#3393](https://github.com/open-telemetry/opentelemetry-cpp/pull/3393) + * [SDK] Base2 exponential histogram aggregation [#3175](https://github.com/open-telemetry/opentelemetry-cpp/pull/3346) diff --git a/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h b/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h index bcc7610aae..f1ab55ed61 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h @@ -74,9 +74,10 @@ class AttributesHashMapWithCustomHash * If not present, it uses the provided callback to generate * value and store in the hash */ - Aggregation *GetOrSetDefault(const opentelemetry::common::KeyValueIterable &attributes, - const AttributesProcessor *attributes_processor, - std::function()> aggregation_callback) + Aggregation *GetOrSetDefault( + const opentelemetry::common::KeyValueIterable &attributes, + const AttributesProcessor *attributes_processor, + nostd::function_ref()> aggregation_callback) { // TODO: avoid constructing MetricAttributes from KeyValueIterable for // hash_map_.find which is a heavy operation @@ -97,8 +98,9 @@ class AttributesHashMapWithCustomHash return result.first->second.get(); } - Aggregation *GetOrSetDefault(const MetricAttributes &attributes, - std::function()> aggregation_callback) + Aggregation *GetOrSetDefault( + const MetricAttributes &attributes, + nostd::function_ref()> aggregation_callback) { auto it = hash_map_.find(attributes); if (it != hash_map_.end()) @@ -115,8 +117,9 @@ class AttributesHashMapWithCustomHash return hash_map_[attributes].get(); } - Aggregation *GetOrSetDefault(MetricAttributes &&attributes, - std::function()> aggregation_callback) + Aggregation *GetOrSetDefault( + MetricAttributes &&attributes, + nostd::function_ref()> aggregation_callback) { auto it = hash_map_.find(attributes); if (it != hash_map_.end()) @@ -207,7 +210,7 @@ class AttributesHashMapWithCustomHash size_t attributes_limit_; Aggregation *GetOrSetOveflowAttributes( - std::function()> aggregation_callback) + nostd::function_ref()> aggregation_callback) { auto agg = aggregation_callback(); return GetOrSetOveflowAttributes(std::move(agg)); diff --git a/sdk/test/metrics/attributes_hashmap_benchmark.cc b/sdk/test/metrics/attributes_hashmap_benchmark.cc index 8225f8ba12..a44199878e 100644 --- a/sdk/test/metrics/attributes_hashmap_benchmark.cc +++ b/sdk/test/metrics/attributes_hashmap_benchmark.cc @@ -11,6 +11,7 @@ #include #include +#include "opentelemetry/nostd/function_ref.h" #include "opentelemetry/sdk/metrics/aggregation/aggregation.h" #include "opentelemetry/sdk/metrics/aggregation/drop_aggregation.h" #include "opentelemetry/sdk/metrics/state/attributes_hashmap.h"