Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
19 changes: 11 additions & 8 deletions sdk/include/opentelemetry/sdk/metrics/state/attributes_hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::unique_ptr<Aggregation>()> aggregation_callback)
Aggregation *GetOrSetDefault(
const opentelemetry::common::KeyValueIterable &attributes,
const AttributesProcessor *attributes_processor,
nostd::function_ref<std::unique_ptr<Aggregation>()> aggregation_callback)
{
// TODO: avoid constructing MetricAttributes from KeyValueIterable for
// hash_map_.find which is a heavy operation
Expand All @@ -97,8 +98,9 @@ class AttributesHashMapWithCustomHash
return result.first->second.get();
}

Aggregation *GetOrSetDefault(const MetricAttributes &attributes,
std::function<std::unique_ptr<Aggregation>()> aggregation_callback)
Aggregation *GetOrSetDefault(
const MetricAttributes &attributes,
nostd::function_ref<std::unique_ptr<Aggregation>()> aggregation_callback)
{
auto it = hash_map_.find(attributes);
if (it != hash_map_.end())
Expand All @@ -115,8 +117,9 @@ class AttributesHashMapWithCustomHash
return hash_map_[attributes].get();
}

Aggregation *GetOrSetDefault(MetricAttributes &&attributes,
std::function<std::unique_ptr<Aggregation>()> aggregation_callback)
Aggregation *GetOrSetDefault(
MetricAttributes &&attributes,
nostd::function_ref<std::unique_ptr<Aggregation>()> aggregation_callback)
{
auto it = hash_map_.find(attributes);
if (it != hash_map_.end())
Expand Down Expand Up @@ -207,7 +210,7 @@ class AttributesHashMapWithCustomHash
size_t attributes_limit_;

Aggregation *GetOrSetOveflowAttributes(
std::function<std::unique_ptr<Aggregation>()> aggregation_callback)
nostd::function_ref<std::unique_ptr<Aggregation>()> aggregation_callback)
{
auto agg = aggregation_callback();
return GetOrSetOveflowAttributes(std::move(agg));
Expand Down
1 change: 1 addition & 0 deletions sdk/test/metrics/attributes_hashmap_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <thread>
#include <vector>

#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"
Expand Down
Loading