diff --git a/examples/common/metrics_foo_library/foo_library.cc b/examples/common/metrics_foo_library/foo_library.cc index 2fcbd660e0..c46276833c 100644 --- a/examples/common/metrics_foo_library/foo_library.cc +++ b/examples/common/metrics_foo_library/foo_library.cc @@ -5,10 +5,12 @@ # include "foo_library.h" # include # include +# include # include # include # include "opentelemetry/context/context.h" # include "opentelemetry/metrics/provider.h" +# include "opentelemetry/nostd/shared_ptr.h" namespace nostd = opentelemetry::nostd; namespace metrics_api = opentelemetry::metrics; @@ -72,8 +74,8 @@ void foo_library::histogram_example(const std::string &name) std::string histogram_name = name + "_histogram"; auto provider = metrics_api::Provider::GetMeterProvider(); nostd::shared_ptr meter = provider->GetMeter(name, "1.2.0"); - auto histogram_counter = meter->CreateDoubleHistogram(histogram_name); - auto context = opentelemetry::context::Context{}; + auto histogram_counter = meter->CreateDoubleHistogram(histogram_name, "des", "unit"); + auto context = opentelemetry::context::Context{}; while (true) { double val = (rand() % 700) + 1.1; diff --git a/examples/metrics_simple/metrics_ostream.cc b/examples/metrics_simple/metrics_ostream.cc index 585856f91f..669362830b 100644 --- a/examples/metrics_simple/metrics_ostream.cc +++ b/examples/metrics_simple/metrics_ostream.cc @@ -72,8 +72,14 @@ void initMetrics(const std::string &name) new metric_sdk::InstrumentSelector(metric_sdk::InstrumentType::kHistogram, histogram_name)}; std::unique_ptr histogram_meter_selector{ new metric_sdk::MeterSelector(name, version, schema)}; - std::unique_ptr histogram_view{ - new metric_sdk::View{name, "description", metric_sdk::AggregationType::kHistogram}}; + std::shared_ptr aggregation_config{ + new opentelemetry::sdk::metrics::HistogramAggregationConfig}; + static_cast *>( + aggregation_config.get()) + ->boundaries_ = + std::list{0.0, 50.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 10000.0}; + std::unique_ptr histogram_view{new metric_sdk::View{ + name, "description", metric_sdk::AggregationType::kHistogram, aggregation_config}}; p->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_selector), std::move(histogram_view)); metrics_api::Provider::SetMeterProvider(provider); diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h new file mode 100644 index 0000000000..bd2fe55c5a --- /dev/null +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation_config.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef ENABLE_METRICS_PREVIEW +# include +# include "opentelemetry/version.h" +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace metrics +{ +class AggregationConfig +{ +public: + virtual ~AggregationConfig() = default; +}; + +template +class HistogramAggregationConfig : public AggregationConfig +{ +public: + std::list boundaries_; +}; +} // namespace metrics +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE + +#endif // ENABLE_METRICS_PREVIEW \ No newline at end of file diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h index 887e1beb92..98221d9b46 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h @@ -3,12 +3,15 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW +# include # include "opentelemetry/common/spin_lock_mutex.h" # include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +# include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" # include "opentelemetry/sdk/metrics/aggregation/drop_aggregation.h" # include "opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h" # include "opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h" # include "opentelemetry/sdk/metrics/aggregation/sum_aggregation.h" +# include "opentelemetry/sdk/metrics/data/point_data.h" # include "opentelemetry/sdk/metrics/instruments.h" # include @@ -18,11 +21,13 @@ namespace sdk { namespace metrics { + class DefaultAggregation { public: static std::unique_ptr CreateAggregation( - const opentelemetry::sdk::metrics::InstrumentDescriptor &instrument_descriptor) + const opentelemetry::sdk::metrics::InstrumentDescriptor &instrument_descriptor, + const opentelemetry::sdk::metrics::AggregationConfig *aggregation_config) { switch (instrument_descriptor.type_) { @@ -34,11 +39,17 @@ class DefaultAggregation ? std::move(std::unique_ptr(new LongSumAggregation())) : std::move(std::unique_ptr(new DoubleSumAggregation())); break; - case InstrumentType::kHistogram: + case InstrumentType::kHistogram: { return (instrument_descriptor.value_type_ == InstrumentValueType::kLong) - ? std::move(std::unique_ptr(new LongHistogramAggregation())) - : std::move(std::unique_ptr(new DoubleHistogramAggregation())); + ? std::move(std::unique_ptr(new LongHistogramAggregation( + static_cast< + const opentelemetry::sdk::metrics::HistogramAggregationConfig *>( + aggregation_config)))) + : std::move(std::unique_ptr(new DoubleHistogramAggregation( + static_cast *>(aggregation_config)))); break; + } case InstrumentType::kObservableGauge: return (instrument_descriptor.value_type_ == InstrumentValueType::kLong) ? std::move(std::unique_ptr(new LongLastValueAggregation())) @@ -88,7 +99,7 @@ class DefaultAggregation } break; default: - return DefaultAggregation::CreateAggregation(instrument_descriptor); + return DefaultAggregation::CreateAggregation(instrument_descriptor, nullptr); } } @@ -135,7 +146,7 @@ class DefaultAggregation new DoubleSumAggregation(nostd::get(point_data))); } default: - return DefaultAggregation::CreateAggregation(instrument_descriptor); + return DefaultAggregation::CreateAggregation(instrument_descriptor, nullptr); } } }; diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h index e2a55fba58..e648a6a4bc 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h @@ -5,6 +5,7 @@ #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/common/spin_lock_mutex.h" # include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +# include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" # include @@ -17,7 +18,7 @@ namespace metrics class LongHistogramAggregation : public Aggregation { public: - LongHistogramAggregation(); + LongHistogramAggregation(const HistogramAggregationConfig *aggregation_config = nullptr); LongHistogramAggregation(HistogramPointData &&); LongHistogramAggregation(const HistogramPointData &); @@ -46,7 +47,8 @@ class LongHistogramAggregation : public Aggregation class DoubleHistogramAggregation : public Aggregation { public: - DoubleHistogramAggregation(); + DoubleHistogramAggregation( + const HistogramAggregationConfig *aggregation_config = nullptr); DoubleHistogramAggregation(HistogramPointData &&); DoubleHistogramAggregation(const HistogramPointData &); diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 22608e2b05..d3df60ced0 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -148,9 +148,9 @@ class Meter final : public opentelemetry::metrics::Meter { view_instr_desc.description_ = view.GetDescription(); } - auto storage = std::shared_ptr>( - new AsyncMetricStorage(view_instr_desc, view.GetAggregationType(), callback, - &view.GetAttributesProcessor(), state)); + auto storage = std::shared_ptr>(new AsyncMetricStorage( + view_instr_desc, view.GetAggregationType(), callback, &view.GetAttributesProcessor(), + view.GetAggregationConfig(), state)); storage_registry_[instrument_descriptor.name_] = storage; return true; }); diff --git a/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h index e5dcbc2738..11e7d83c14 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h @@ -3,6 +3,7 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/sdk/common/attributemap_hash.h" # include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" # include "opentelemetry/sdk/metrics/instruments.h" @@ -30,6 +31,7 @@ class AsyncMetricStorage : public MetricStorage void (*measurement_callback)(opentelemetry::metrics::ObserverResult &, void *), const AttributesProcessor *attributes_processor, + nostd::shared_ptr aggregation_config, void *state = nullptr) : instrument_descriptor_(instrument_descriptor), aggregation_type_{aggregation_type}, @@ -37,7 +39,7 @@ class AsyncMetricStorage : public MetricStorage attributes_processor_{attributes_processor}, state_{state}, cumulative_hash_map_(new AttributesHashMap()), - temporal_metric_storage_(instrument_descriptor) + temporal_metric_storage_(instrument_descriptor, aggregation_config) {} bool Collect(CollectorHandle *collector, diff --git a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h index 37f485997c..d547f3699f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h @@ -3,6 +3,7 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW +# include # include "opentelemetry/common/key_value_iterable_view.h" # include "opentelemetry/sdk/common/attributemap_hash.h" # include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" @@ -29,13 +30,14 @@ class SyncMetricStorage : public MetricStorage, public WritableMetricStorage SyncMetricStorage(InstrumentDescriptor instrument_descriptor, const AggregationType aggregation_type, const AttributesProcessor *attributes_processor, - nostd::shared_ptr &&exemplar_reservoir) + nostd::shared_ptr &&exemplar_reservoir, + nostd::shared_ptr aggregation_config) : instrument_descriptor_(instrument_descriptor), aggregation_type_{aggregation_type}, attributes_hashmap_(new AttributesHashMap()), attributes_processor_{attributes_processor}, exemplar_reservoir_(exemplar_reservoir), - temporal_metric_storage_(instrument_descriptor) + temporal_metric_storage_(instrument_descriptor, aggregation_config) { create_default_aggregation_ = [&]() -> std::unique_ptr { diff --git a/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h index 16659c14f5..f8a0c36b0f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/temporal_metric_storage.h @@ -3,6 +3,8 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" # include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" # include "opentelemetry/sdk/metrics/state/metric_collector.h" @@ -23,7 +25,8 @@ struct LastReportedMetrics class TemporalMetricStorage { public: - TemporalMetricStorage(InstrumentDescriptor instrument_descriptor); + TemporalMetricStorage(InstrumentDescriptor instrument_descriptor, + nostd::shared_ptr aggregation_config); bool buildMetrics(CollectorHandle *collector, nostd::span> collectors, @@ -43,6 +46,7 @@ class TemporalMetricStorage // Lock while building metrics mutable opentelemetry::common::SpinLockMutex lock_; + const nostd::shared_ptr aggregation_config_; }; } // namespace metrics } // namespace sdk diff --git a/sdk/include/opentelemetry/sdk/metrics/view/view.h b/sdk/include/opentelemetry/sdk/metrics/view/view.h index 3cd9f850e1..a7f8edb8fc 100644 --- a/sdk/include/opentelemetry/sdk/metrics/view/view.h +++ b/sdk/include/opentelemetry/sdk/metrics/view/view.h @@ -3,7 +3,9 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" # include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" # include "opentelemetry/sdk/metrics/instruments.h" # include "opentelemetry/sdk/metrics/view/attributes_processor.h" @@ -22,14 +24,16 @@ class View { public: View(const std::string &name, - const std::string &description = "", - AggregationType aggregation_type = AggregationType::kDefault, + const std::string &description = "", + AggregationType aggregation_type = AggregationType::kDefault, + std::shared_ptr aggregation_config = std::shared_ptr{}, std::unique_ptr attributes_processor = std::unique_ptr( new opentelemetry::sdk::metrics::DefaultAttributesProcessor())) : name_(name), description_(description), aggregation_type_{aggregation_type}, + aggregation_config_{aggregation_config}, attributes_processor_{std::move(attributes_processor)} {} @@ -39,6 +43,11 @@ class View virtual AggregationType GetAggregationType() const noexcept { return aggregation_type_; } + virtual nostd::shared_ptr GetAggregationConfig() const noexcept + { + return aggregation_config_; + } + virtual const opentelemetry::sdk::metrics::AttributesProcessor &GetAttributesProcessor() const noexcept { @@ -49,6 +58,7 @@ class View std::string name_; std::string description_; AggregationType aggregation_type_; + nostd::shared_ptr aggregation_config_; std::unique_ptr attributes_processor_; }; } // namespace metrics diff --git a/sdk/src/metrics/aggregation/histogram_aggregation.cc b/sdk/src/metrics/aggregation/histogram_aggregation.cc index aa2be74713..79f0714b54 100644 --- a/sdk/src/metrics/aggregation/histogram_aggregation.cc +++ b/sdk/src/metrics/aggregation/histogram_aggregation.cc @@ -12,9 +12,17 @@ namespace sdk namespace metrics { -LongHistogramAggregation::LongHistogramAggregation() +LongHistogramAggregation::LongHistogramAggregation( + const HistogramAggregationConfig *aggregation_config) { - point_data_.boundaries_ = std::list{0l, 5l, 10l, 25l, 50l, 75l, 100l, 250l, 500l, 1000l}; + if (aggregation_config && aggregation_config->boundaries_.size()) + { + point_data_.boundaries_ = aggregation_config->boundaries_; + } + else + { + point_data_.boundaries_ = std::list{0l, 5l, 10l, 25l, 50l, 75l, 100l, 250l, 500l, 1000l}; + } point_data_.counts_ = std::vector(nostd::get>(point_data_.boundaries_).size() + 1, 0); point_data_.sum_ = 0l; @@ -73,10 +81,18 @@ PointType LongHistogramAggregation::ToPoint() const noexcept return point_data_; } -DoubleHistogramAggregation::DoubleHistogramAggregation() +DoubleHistogramAggregation::DoubleHistogramAggregation( + const HistogramAggregationConfig *aggregation_config) { - point_data_.boundaries_ = - std::list{0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 1000.0}; + if (aggregation_config && aggregation_config->boundaries_.size()) + { + point_data_.boundaries_ = aggregation_config->boundaries_; + } + else + { + point_data_.boundaries_ = + std::list{0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 1000.0}; + } point_data_.counts_ = std::vector(nostd::get>(point_data_.boundaries_).size() + 1, 0); point_data_.sum_ = 0.0; diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index d17b61f120..551d87b2bc 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -217,7 +217,7 @@ std::unique_ptr Meter::RegisterMetricStorage( } auto storage = std::shared_ptr(new SyncMetricStorage( view_instr_desc, view.GetAggregationType(), &view.GetAttributesProcessor(), - NoExemplarReservoir::GetNoExemplarReservoir())); + NoExemplarReservoir::GetNoExemplarReservoir(), view.GetAggregationConfig())); storage_registry_[instrument_descriptor.name_] = storage; auto multi_storage = static_cast(storages.get()); multi_storage->AddStorage(storage); diff --git a/sdk/src/metrics/state/temporal_metric_storage.cc b/sdk/src/metrics/state/temporal_metric_storage.cc index b208695b8a..bee2986f09 100644 --- a/sdk/src/metrics/state/temporal_metric_storage.cc +++ b/sdk/src/metrics/state/temporal_metric_storage.cc @@ -2,9 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 #ifndef ENABLE_METRICS_PREVIEW +# include +# include +# include +# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/sdk/metrics/state/temporal_metric_storage.h" +# include "opentelemetry/metrics/meter.h" # include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" +# include "opentelemetry/sdk/metrics/state/temporal_metric_storage.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -12,8 +17,10 @@ namespace sdk namespace metrics { -TemporalMetricStorage::TemporalMetricStorage(InstrumentDescriptor instrument_descriptor) - : instrument_descriptor_(instrument_descriptor) +TemporalMetricStorage::TemporalMetricStorage( + InstrumentDescriptor instrument_descriptor, + nostd::shared_ptr aggregation_config) + : instrument_descriptor_(instrument_descriptor), aggregation_config_(aggregation_config) {} bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, @@ -54,9 +61,9 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, } else { - merged_metrics->Set( - attributes, - DefaultAggregation::CreateAggregation(instrument_descriptor_)->Merge(aggregation)); + merged_metrics->Set(attributes, DefaultAggregation::CreateAggregation( + instrument_descriptor_, aggregation_config_.get()) + ->Merge(aggregation)); merged_metrics->GetAllEnteries( [](const MetricAttributes &attr, Aggregation &aggr) { return true; }); } @@ -80,20 +87,20 @@ bool TemporalMetricStorage::buildMetrics(CollectorHandle *collector, if (aggregation_temporarily == AggregationTemporality::kCumulative) { // merge current delta to previous cumulative - last_aggr_hashmap->GetAllEnteries( - [&merged_metrics, this](const MetricAttributes &attributes, Aggregation &aggregation) { - auto agg = merged_metrics->Get(attributes); - if (agg) - { - merged_metrics->Set(attributes, agg->Merge(aggregation)); - } - else - { - merged_metrics->Set(attributes, - DefaultAggregation::CreateAggregation(instrument_descriptor_)); - } - return true; - }); + last_aggr_hashmap->GetAllEnteries([&merged_metrics, this](const MetricAttributes &attributes, + Aggregation &aggregation) { + auto agg = merged_metrics->Get(attributes); + if (agg) + { + merged_metrics->Set(attributes, agg->Merge(aggregation)); + } + else + { + merged_metrics->Set( + attributes, DefaultAggregation::CreateAggregation(instrument_descriptor_, nullptr)); + } + return true; + }); } last_reported_metrics_[collector] = LastReportedMetrics{std::move(merged_metrics), collection_ts}; diff --git a/sdk/test/metrics/aggregation_test.cc b/sdk/test/metrics/aggregation_test.cc index f8051776d1..3fb9d55126 100644 --- a/sdk/test/metrics/aggregation_test.cc +++ b/sdk/test/metrics/aggregation_test.cc @@ -7,6 +7,7 @@ # include "opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h" # include "opentelemetry/sdk/metrics/aggregation/sum_aggregation.h" +# include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/nostd/variant.h" using namespace opentelemetry::sdk::metrics; @@ -123,6 +124,35 @@ TEST(Aggregation, LongHistogramAggregation) EXPECT_EQ(histogram_data.counts_[7], 1); // aggr2(105) - aggr1(0) } +TEST(Aggregation, LongHistogramAggregationBoundaries) +{ + nostd::shared_ptr> + aggregation_config{new opentelemetry::sdk::metrics::HistogramAggregationConfig}; + std::list user_boundaries = {0, 50, 100, 250, 500, 750, 1000, 2500, 5000, 10000}; + aggregation_config->boundaries_ = user_boundaries; + LongHistogramAggregation aggr{aggregation_config.get()}; + auto data = aggr.ToPoint(); + ASSERT_TRUE(nostd::holds_alternative(data)); + auto histogram_data = nostd::get(data); + ASSERT_TRUE(nostd::holds_alternative>(histogram_data.boundaries_)); + EXPECT_EQ(nostd::get>(histogram_data.boundaries_), user_boundaries); +} + +TEST(Aggregation, DoubleHistogramAggregationBoundaries) +{ + nostd::shared_ptr> + aggregation_config{new opentelemetry::sdk::metrics::HistogramAggregationConfig}; + std::list user_boundaries = {0.0, 50.0, 100.0, 250.0, 500.0, + 750.0, 1000.0, 2500.0, 5000.0, 10000.0}; + aggregation_config->boundaries_ = user_boundaries; + DoubleHistogramAggregation aggr{aggregation_config.get()}; + auto data = aggr.ToPoint(); + ASSERT_TRUE(nostd::holds_alternative(data)); + auto histogram_data = nostd::get(data); + ASSERT_TRUE(nostd::holds_alternative>(histogram_data.boundaries_)); + EXPECT_EQ(nostd::get>(histogram_data.boundaries_), user_boundaries); +} + TEST(Aggregation, DoubleHistogramAggregation) { DoubleHistogramAggregation aggr; diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index 8eb55ecd7b..6e2e399e44 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -4,6 +4,7 @@ #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/sdk/metrics/state/async_metric_storage.h" # include "opentelemetry/common/key_value_iterable_view.h" +# include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/sdk/metrics/instruments.h" # include "opentelemetry/sdk/metrics/meter_context.h" # include "opentelemetry/sdk/metrics/metric_exporter.h" @@ -20,7 +21,8 @@ using namespace opentelemetry::sdk::resource; using namespace opentelemetry::sdk::metrics; using namespace opentelemetry::common; -using M = std::map; +using M = std::map; +namespace nostd = opentelemetry::nostd; class MockCollectorHandle : public CollectorHandle { @@ -96,9 +98,10 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation) std::unique_ptr default_attributes_rocessor{ new DefaultAttributesProcessor{}}; - opentelemetry::sdk::metrics::AsyncMetricStorage storage(instr_desc, AggregationType::kSum, - MeasurementFetcher::Fetcher, - default_attributes_rocessor.get()); + opentelemetry::sdk::metrics::AsyncMetricStorage storage( + instr_desc, AggregationType::kSum, MeasurementFetcher::Fetcher, + default_attributes_rocessor.get(), + std::shared_ptr{}); storage.Collect(collector.get(), collectors, sdk_start_ts, collection_ts, [&](const MetricData data) { diff --git a/sdk/test/metrics/sync_metric_storage_test.cc b/sdk/test/metrics/sync_metric_storage_test.cc index 8d4ee99262..cb24ae5178 100644 --- a/sdk/test/metrics/sync_metric_storage_test.cc +++ b/sdk/test/metrics/sync_metric_storage_test.cc @@ -4,6 +4,7 @@ #include #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/common/key_value_iterable_view.h" +# include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h" # include "opentelemetry/sdk/metrics/instruments.h" # include "opentelemetry/sdk/metrics/state/sync_metric_storage.h" @@ -14,7 +15,8 @@ using namespace opentelemetry::sdk::metrics; using namespace opentelemetry::common; -using M = std::map; +using M = std::map; +namespace nostd = opentelemetry::nostd; class MockCollectorHandle : public CollectorHandle { @@ -45,7 +47,8 @@ TEST_P(WritableMetricStorageTestFixture, LongSumAggregation) new DefaultAttributesProcessor{}}; opentelemetry::sdk::metrics::SyncMetricStorage storage( instr_desc, AggregationType::kSum, default_attributes_processor.get(), - NoExemplarReservoir::GetNoExemplarReservoir()); + NoExemplarReservoir::GetNoExemplarReservoir(), + std::shared_ptr{}); storage.RecordLong(10l, KeyValueIterableView>(attributes_get), opentelemetry::context::Context{}); @@ -153,7 +156,8 @@ TEST_P(WritableMetricStorageTestFixture, DoubleSumAggregation) new DefaultAttributesProcessor{}}; opentelemetry::sdk::metrics::SyncMetricStorage storage( instr_desc, AggregationType::kSum, default_attributes_processor.get(), - NoExemplarReservoir::GetNoExemplarReservoir()); + NoExemplarReservoir::GetNoExemplarReservoir(), + std::shared_ptr{}); storage.RecordDouble(10.0, KeyValueIterableView>(attributes_get),