diff --git a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h index f38ad6a3b4..8b1f76377b 100644 --- a/sdk/include/opentelemetry/sdk/metrics/async_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/async_instruments.h @@ -6,7 +6,6 @@ # include "opentelemetry/metrics/async_instruments.h" # include "opentelemetry/metrics/observer_result.h" # include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" # include "opentelemetry/sdk/metrics/instruments.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -19,22 +18,14 @@ class Asynchronous { public: Asynchronous(nostd::string_view name, - const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary - *instrumentation_library, void (*callback)(opentelemetry::metrics::ObserverResult &), nostd::string_view description = "", nostd::string_view unit = "") - : name_(name), - instrumentation_library_{instrumentation_library}, - callback_(callback), - description_(description), - unit_(unit) + : name_(name), callback_(callback), description_(description), unit_(unit) {} protected: std::string name_; - const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary - *instrumentation_library_; void (*callback_)(opentelemetry::metrics::ObserverResult &); std::string description_; std::string unit_; @@ -45,12 +36,10 @@ class LongObservableCounter : public opentelemetry::metrics::ObservableCounter &), nostd::string_view description = "", nostd::string_view unit = "") - : Asynchronous(name, instrumentation_library, callback, description, unit) + : Asynchronous(name, callback, description, unit) {} }; @@ -60,12 +49,10 @@ class DoubleObservableCounter : public opentelemetry::metrics::ObservableCounter { public: DoubleObservableCounter(nostd::string_view name, - const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary - *instrumentation_library, void (*callback)(opentelemetry::metrics::ObserverResult &), nostd::string_view description = "", nostd::string_view unit = "") - : Asynchronous(name, instrumentation_library, callback, description, unit) + : Asynchronous(name, callback, description, unit) {} }; @@ -75,12 +62,10 @@ class LongObservableGauge : public opentelemetry::metrics::ObservableGauge { public: LongObservableGauge(nostd::string_view name, - const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary - *instrumentation_library, void (*callback)(opentelemetry::metrics::ObserverResult &), nostd::string_view description = "", nostd::string_view unit = "") - : Asynchronous(name, instrumentation_library, callback, description, unit) + : Asynchronous(name, callback, description, unit) {} }; @@ -90,12 +75,10 @@ class DoubleObservableGauge : public opentelemetry::metrics::ObservableGauge &), nostd::string_view description = "", nostd::string_view unit = "") - : Asynchronous(name, instrumentation_library, callback, description, unit) + : Asynchronous(name, callback, description, unit) {} }; @@ -104,14 +87,11 @@ class LongObservableUpDownCounter : public opentelemetry::metrics::ObservableUpD public Asynchronous { public: - LongObservableUpDownCounter( - nostd::string_view name, - const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary - *instrumentation_library, - void (*callback)(opentelemetry::metrics::ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") - : Asynchronous(name, instrumentation_library, callback, description, unit) + LongObservableUpDownCounter(nostd::string_view name, + void (*callback)(opentelemetry::metrics::ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") + : Asynchronous(name, callback, description, unit) {} }; @@ -121,14 +101,11 @@ class DoubleObservableUpDownCounter public Asynchronous { public: - DoubleObservableUpDownCounter( - nostd::string_view name, - const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary - *instrumentation_library, - void (*callback)(opentelemetry::metrics::ObserverResult &), - nostd::string_view description = "", - nostd::string_view unit = "") - : Asynchronous(name, instrumentation_library, callback, description, unit) + DoubleObservableUpDownCounter(nostd::string_view name, + void (*callback)(opentelemetry::metrics::ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") + : Asynchronous(name, callback, description, unit) {} }; diff --git a/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h b/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h index 7c9ee57755..d3b38759ad 100644 --- a/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h +++ b/sdk/include/opentelemetry/sdk/metrics/export/metric_producer.h @@ -3,13 +3,33 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" # include "opentelemetry/sdk/metrics/data/metric_data.h" +# include "opentelemetry/sdk/resource/resource.h" + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace metrics { +/** + * Metric Data to be exported along with resources and + * Instrumentation library. + */ +struct InstrumentationInfoMetrics +{ + const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary + *instrumentation_library_; + std::vector metric_data_; +}; + +struct ResourceMetrics +{ + const opentelemetry::sdk::resource::Resource *resource_; + std::vector instrumentation_info_metric_data_; +}; + /** * MetricProducer is the interface that is used to make metric data available to the * OpenTelemetry exporters. Implementations should be stateful, in that each call to @@ -27,7 +47,8 @@ class MetricProducer * * @return a status of completion of method. */ - virtual bool Collect(nostd::function_ref callback) noexcept = 0; + virtual bool Collect( + nostd::function_ref callback) noexcept = 0; }; } // namespace metrics diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index c9e02918a0..4a6ea26aeb 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -102,10 +102,9 @@ class Meter final : public opentelemetry::metrics::Meter const sdk::instrumentationlibrary::InstrumentationLibrary *GetInstrumentationLibrary() const noexcept; - /** collect metrics across all the meters **/ - bool Collect(CollectorHandle *collector, - opentelemetry::common::SystemTimestamp collect_ts, - nostd::function_ref callback) noexcept; + /** collect metrics across all the instruments configured for the meter **/ + std::vector Collect(CollectorHandle *collector, + opentelemetry::common::SystemTimestamp collect_ts) noexcept; private: // order of declaration is important here - instrumentation library should destroy after diff --git a/sdk/include/opentelemetry/sdk/metrics/metric_exporter.h b/sdk/include/opentelemetry/sdk/metrics/metric_exporter.h index 2488edd7ed..b6b5acf3a9 100644 --- a/sdk/include/opentelemetry/sdk/metrics/metric_exporter.h +++ b/sdk/include/opentelemetry/sdk/metrics/metric_exporter.h @@ -32,7 +32,7 @@ class MetricExporter * concurrently for the same exporter instance. * @param data metrics data */ - virtual opentelemetry::sdk::common::ExportResult Export(const MetricData &data) noexcept = 0; + virtual opentelemetry::sdk::common::ExportResult Export(const ResourceMetrics &data) noexcept = 0; /** * Force flush the exporter. diff --git a/sdk/include/opentelemetry/sdk/metrics/metric_reader.h b/sdk/include/opentelemetry/sdk/metrics/metric_reader.h index 7cf449e1e3..94924315f8 100644 --- a/sdk/include/opentelemetry/sdk/metrics/metric_reader.h +++ b/sdk/include/opentelemetry/sdk/metrics/metric_reader.h @@ -6,6 +6,7 @@ # include "opentelemetry/common/spin_lock_mutex.h" # include "opentelemetry/sdk/common/global_log_handler.h" # include "opentelemetry/sdk/metrics/data/metric_data.h" +# include "opentelemetry/sdk/metrics/export/metric_producer.h" # include "opentelemetry/sdk/metrics/instruments.h" # include "opentelemetry/version.h" @@ -18,7 +19,6 @@ namespace sdk namespace metrics { -class MetricProducer; /** * MetricReader defines the interface to collect metrics from SDK */ @@ -34,7 +34,7 @@ class MetricReader * Collect the metrics from SDK. * @return return the status of the operation. */ - bool Collect(nostd::function_ref callback) noexcept; + bool Collect(nostd::function_ref callback) noexcept; AggregationTemporality GetAggregationTemporality() const noexcept; 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 31ab70c5b8..cfbf521538 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h @@ -4,16 +4,15 @@ #pragma once #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/sdk/common/attributemap_hash.h" -# include "opentelemetry/sdk/metrics/instruments.h" - # include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" +# include "opentelemetry/sdk/metrics/instruments.h" +# include "opentelemetry/sdk/metrics/observer_result.h" # include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" # include "opentelemetry/sdk/metrics/state/metric_collector.h" # include "opentelemetry/sdk/metrics/state/metric_storage.h" # include "opentelemetry/sdk/metrics/view/attributes_processor.h" # include -# include "opentelemetry/sdk/metrics/observer_result.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -40,7 +39,7 @@ class AsyncMetricStorage : public MetricStorage nostd::span> collectors, opentelemetry::common::SystemTimestamp sdk_start_ts, opentelemetry::common::SystemTimestamp collection_ts, - nostd::function_ref metric_collection_callback) noexcept override + nostd::function_ref metric_collection_callback) noexcept override { opentelemetry::sdk::metrics::ObserverResult ob_res(attributes_processor_); @@ -57,7 +56,7 @@ class AsyncMetricStorage : public MetricStorage // TBD -> read aggregation from hashmap, and perform metric collection MetricData metric_data; - if (metric_collection_callback(metric_data)) + if (metric_collection_callback(std::move(metric_data))) { return true; } diff --git a/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h b/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h index 51c9cf6eff..20372f5209 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/metric_collector.h @@ -41,7 +41,7 @@ class MetricCollector : public MetricProducer, public CollectorHandle * * @return a status of completion of method. */ - bool Collect(nostd::function_ref callback) noexcept override; + bool Collect(nostd::function_ref callback) noexcept override; bool ForceFlush(std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept; diff --git a/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h index 20f7d56140..e0ba55cbfe 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h @@ -25,7 +25,7 @@ class MetricStorage nostd::span> collectors, opentelemetry::common::SystemTimestamp sdk_start_ts, opentelemetry::common::SystemTimestamp collection_ts, - nostd::function_ref callback) noexcept = 0; + nostd::function_ref callback) noexcept = 0; }; class WritableMetricStorage @@ -54,14 +54,10 @@ class NoopMetricStorage : public MetricStorage nostd::span> collectors, opentelemetry::common::SystemTimestamp sdk_start_ts, opentelemetry::common::SystemTimestamp collection_ts, - nostd::function_ref callback) noexcept override + nostd::function_ref callback) noexcept override { MetricData metric_data; - if (callback(metric_data)) - { - return true; - } - return false; + return callback(std::move(metric_data)); } }; 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 8269d2fd3c..c16f33ede2 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h @@ -106,7 +106,7 @@ class SyncMetricStorage : public MetricStorage, public WritableMetricStorage nostd::span> collectors, opentelemetry::common::SystemTimestamp sdk_start_ts, opentelemetry::common::SystemTimestamp collection_ts, - nostd::function_ref callback) noexcept override; + nostd::function_ref callback) noexcept override; private: InstrumentDescriptor instrument_descriptor_; diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc index e9a91a9e06..f11f84544f 100644 --- a/sdk/src/metrics/export/periodic_exporting_metric_reader.cc +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader.cc @@ -51,7 +51,7 @@ void PeriodicExportingMetricReader::DoBackgroundWork() std::atomic cancel_export_for_timeout{false}; auto start = std::chrono::steady_clock::now(); auto future_receive = std::async(std::launch::async, [this, &cancel_export_for_timeout] { - Collect([this, &cancel_export_for_timeout](MetricData data) { + Collect([this, &cancel_export_for_timeout](ResourceMetrics &metric_data) { if (cancel_export_for_timeout) { OTEL_INTERNAL_LOG_ERROR( @@ -59,7 +59,7 @@ void PeriodicExportingMetricReader::DoBackgroundWork() << export_timeout_millis_.count() << " ms, and timed out"); return false; } - this->exporter_->Export(data); + this->exporter_->Export(metric_data); return true; }); }); diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index fb74d55eb4..e7ca822b6d 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -64,7 +64,7 @@ nostd::shared_ptr> Meter::CreateLongObservableC nostd::string_view unit) noexcept { return nostd::shared_ptr>{ - new LongObservableCounter(name, GetInstrumentationLibrary(), callback, description, unit)}; + new LongObservableCounter(name, callback, description, unit)}; } nostd::shared_ptr> Meter::CreateDoubleObservableCounter( @@ -74,7 +74,7 @@ nostd::shared_ptr> Meter::CreateDoubleObserva nostd::string_view unit) noexcept { return nostd::shared_ptr>{ - new DoubleObservableCounter(name, GetInstrumentationLibrary(), callback, description, unit)}; + new DoubleObservableCounter(name, callback, description, unit)}; } nostd::shared_ptr> Meter::CreateLongHistogram( @@ -112,7 +112,7 @@ nostd::shared_ptr> Meter::CreateLongObservableGau nostd::string_view unit) noexcept { return nostd::shared_ptr>{ - new LongObservableGauge(name, GetInstrumentationLibrary(), callback, description, unit)}; + new LongObservableGauge(name, callback, description, unit)}; } nostd::shared_ptr> Meter::CreateDoubleObservableGauge( @@ -122,7 +122,7 @@ nostd::shared_ptr> Meter::CreateDoubleObservabl nostd::string_view unit) noexcept { return nostd::shared_ptr>{ - new DoubleObservableGauge(name, GetInstrumentationLibrary(), callback, description, unit)}; + new DoubleObservableGauge(name, callback, description, unit)}; } nostd::shared_ptr> Meter::CreateLongUpDownCounter( @@ -159,8 +159,8 @@ nostd::shared_ptr> Meter::CreateLongObser nostd::string_view description, nostd::string_view unit) noexcept { - return nostd::shared_ptr>{new LongObservableUpDownCounter( - name, GetInstrumentationLibrary(), callback, description, unit)}; + return nostd::shared_ptr>{ + new LongObservableUpDownCounter(name, callback, description, unit)}; } nostd::shared_ptr> @@ -170,8 +170,7 @@ Meter::CreateDoubleObservableUpDownCounter(nostd::string_view name, nostd::string_view unit) noexcept { return nostd::shared_ptr>{ - new DoubleObservableUpDownCounter(name, GetInstrumentationLibrary(), callback, description, - unit)}; + new DoubleObservableUpDownCounter(name, callback, description, unit)}; } const sdk::instrumentationlibrary::InstrumentationLibrary *Meter::GetInstrumentationLibrary() @@ -211,22 +210,20 @@ std::unique_ptr Meter::RegisterMetricStorage( } /** collect metrics across all the meters **/ -bool Meter::Collect(CollectorHandle *collector, - opentelemetry::common::SystemTimestamp collect_ts, - nostd::function_ref callback) noexcept +std::vector Meter::Collect(CollectorHandle *collector, + opentelemetry::common::SystemTimestamp collect_ts) noexcept { - std::vector data; + std::vector metric_data_list; for (auto &metric_storage : storage_registry_) { - // TBD - this needs to be asynchronous metric_storage.second->Collect(collector, meter_context_->GetCollectors(), meter_context_->GetSDKStartTime(), collect_ts, - [&callback](MetricData &metric_data) { - callback(metric_data); + [&metric_data_list](MetricData metric_data) { + metric_data_list.push_back(metric_data); return true; }); } - return true; + return metric_data_list; } } // namespace metrics diff --git a/sdk/src/metrics/metric_reader.cc b/sdk/src/metrics/metric_reader.cc index abf73d766a..eafcc60e7e 100644 --- a/sdk/src/metrics/metric_reader.cc +++ b/sdk/src/metrics/metric_reader.cc @@ -28,7 +28,8 @@ AggregationTemporality MetricReader::GetAggregationTemporality() const noexcept return aggregation_temporality_; } -bool MetricReader::Collect(nostd::function_ref callback) noexcept +bool MetricReader::Collect( + nostd::function_ref callback) noexcept { if (!metric_producer_) { diff --git a/sdk/src/metrics/state/metric_collector.cc b/sdk/src/metrics/state/metric_collector.cc index cd3b8eb6ca..6cae7bf12c 100644 --- a/sdk/src/metrics/state/metric_collector.cc +++ b/sdk/src/metrics/state/metric_collector.cc @@ -29,13 +29,20 @@ AggregationTemporality MetricCollector::GetAggregationTemporality() noexcept return metric_reader_->GetAggregationTemporality(); } -bool MetricCollector::Collect(nostd::function_ref callback) noexcept +bool MetricCollector::Collect( + nostd::function_ref callback) noexcept { + ResourceMetrics resource_metrics; for (auto &meter : meter_context_->GetMeters()) { auto collection_ts = std::chrono::system_clock::now(); - meter->Collect(this, collection_ts, callback); + InstrumentationInfoMetrics instrumentation_info_metrics; + instrumentation_info_metrics.metric_data_ = meter->Collect(this, collection_ts); + instrumentation_info_metrics.instrumentation_library_ = meter->GetInstrumentationLibrary(); + resource_metrics.instrumentation_info_metric_data_.push_back(instrumentation_info_metrics); } + resource_metrics.resource_ = &meter_context_->GetResource(); + callback(resource_metrics); return true; } diff --git a/sdk/src/metrics/state/sync_metric_storage.cc b/sdk/src/metrics/state/sync_metric_storage.cc index 5c14f8bbc3..f42de82b4b 100644 --- a/sdk/src/metrics/state/sync_metric_storage.cc +++ b/sdk/src/metrics/state/sync_metric_storage.cc @@ -15,7 +15,7 @@ bool SyncMetricStorage::Collect(CollectorHandle *collector, nostd::span> collectors, opentelemetry::common::SystemTimestamp sdk_start_ts, opentelemetry::common::SystemTimestamp collection_ts, - nostd::function_ref callback) noexcept + nostd::function_ref callback) noexcept { opentelemetry::common::SystemTimestamp last_collection_ts = sdk_start_ts; auto aggregation_temporarily = collector->GetAggregationTemporality(); diff --git a/sdk/test/metrics/async_instruments_test.cc b/sdk/test/metrics/async_instruments_test.cc index ad3a81b031..ff9504f78c 100644 --- a/sdk/test/metrics/async_instruments_test.cc +++ b/sdk/test/metrics/async_instruments_test.cc @@ -3,16 +3,12 @@ #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/sdk/metrics/async_instruments.h" -# include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h" # include using namespace opentelemetry; -using namespace opentelemetry::sdk::instrumentationlibrary; using namespace opentelemetry::sdk::metrics; -auto instrumentation_library = InstrumentationLibrary::Create("opentelemetry-cpp", "0.1.0"); - using M = std::map; void asyc_generate_measurements_long(opentelemetry::metrics::ObserverResult &observer) {} @@ -22,44 +18,43 @@ void asyc_generate_measurements_double(opentelemetry::metrics::ObserverResult &observer) {}; - EXPECT_NO_THROW(LongObservableCounter counter("long_counter", instrumentation_library.get(), - asyc_generate_meas_long, "description", "1")); + EXPECT_NO_THROW( + LongObservableCounter counter("long_counter", asyc_generate_meas_long, "description", "1")); } TEST(AsyncInstruments, DoubleObservableCounter) { auto asyc_generate_meas_double = [](opentelemetry::metrics::ObserverResult &observer) {}; - EXPECT_NO_THROW(DoubleObservableCounter counter("long_counter", instrumentation_library.get(), - asyc_generate_meas_double, "description", "1")); + EXPECT_NO_THROW(DoubleObservableCounter counter("long_counter", asyc_generate_meas_double, + "description", "1")); } TEST(AsyncInstruments, LongObservableGauge) { auto asyc_generate_meas_long = [](opentelemetry::metrics::ObserverResult &observer) {}; - EXPECT_NO_THROW(LongObservableGauge counter("long_counter", instrumentation_library.get(), - asyc_generate_meas_long, "description", "1")); + EXPECT_NO_THROW( + LongObservableGauge counter("long_counter", asyc_generate_meas_long, "description", "1")); } TEST(AsyncInstruments, DoubleObservableGauge) { auto asyc_generate_meas_double = [](opentelemetry::metrics::ObserverResult &observer) {}; - EXPECT_NO_THROW(DoubleObservableGauge counter("long_counter", instrumentation_library.get(), - asyc_generate_meas_double, "description", "1")); + EXPECT_NO_THROW( + DoubleObservableGauge counter("long_counter", asyc_generate_meas_double, "description", "1")); } TEST(AsyncInstruments, LongObservableUpDownCounter) { auto asyc_generate_meas_long = [](opentelemetry::metrics::ObserverResult &observer) {}; - EXPECT_NO_THROW(LongObservableUpDownCounter counter("long_counter", instrumentation_library.get(), - asyc_generate_meas_long, "description", "1")); + EXPECT_NO_THROW(LongObservableUpDownCounter counter("long_counter", asyc_generate_meas_long, + "description", "1")); } TEST(AsyncInstruments, DoubleObservableUpDownCounter) { auto asyc_generate_meas_double = [](opentelemetry::metrics::ObserverResult &observer) {}; - EXPECT_NO_THROW( - DoubleObservableUpDownCounter counter("long_counter", instrumentation_library.get(), - asyc_generate_meas_double, "description", "1")); + EXPECT_NO_THROW(DoubleObservableUpDownCounter counter("long_counter", asyc_generate_meas_double, + "description", "1")); } #endif diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index f7c9914e3c..512e24472c 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -38,7 +38,7 @@ void measurement_fetch(opentelemetry::metrics::ObserverResult &observer_re TEST(AsyncMetricStorageTest, BasicTests) { - auto metric_callback = [](MetricData &metric_data) { return true; }; + auto metric_callback = [](MetricData &&metric_data) { return true; }; InstrumentDescriptor instr_desc = {"name", "desc", "1unit", InstrumentType::kCounter, InstrumentValueType::kLong}; diff --git a/sdk/test/metrics/meter_provider_sdk_test.cc b/sdk/test/metrics/meter_provider_sdk_test.cc index ec0a39b523..3c059cc44c 100644 --- a/sdk/test/metrics/meter_provider_sdk_test.cc +++ b/sdk/test/metrics/meter_provider_sdk_test.cc @@ -18,7 +18,7 @@ class MockMetricExporter : public MetricExporter public: MockMetricExporter() = default; - opentelemetry::sdk::common::ExportResult Export(const MetricData &records) noexcept override + opentelemetry::sdk::common::ExportResult Export(const ResourceMetrics &records) noexcept override { return opentelemetry::sdk::common::ExportResult::kSuccess; } diff --git a/sdk/test/metrics/metric_reader_test.cc b/sdk/test/metrics/metric_reader_test.cc index 68a3fcc5f5..61a4364934 100644 --- a/sdk/test/metrics/metric_reader_test.cc +++ b/sdk/test/metrics/metric_reader_test.cc @@ -35,6 +35,6 @@ TEST(MetricReaderTest, BasicTests) std::shared_ptr meter_context2(new MeterContext(std::move(exporters))); MetricProducer *metric_producer = new MetricCollector(std::move(meter_context2), std::move(metric_reader2)); - EXPECT_NO_THROW(metric_producer->Collect([](MetricData data) { return true; })); + EXPECT_NO_THROW(metric_producer->Collect([](ResourceMetrics &metric_data) { return true; })); } #endif diff --git a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc index f13fbb0e04..5219f31100 100644 --- a/sdk/test/metrics/periodic_exporting_metric_reader_test.cc +++ b/sdk/test/metrics/periodic_exporting_metric_reader_test.cc @@ -16,7 +16,7 @@ using namespace opentelemetry::sdk::metrics; class MockPushMetricExporter : public MetricExporter { public: - opentelemetry::sdk::common::ExportResult Export(const MetricData &record) noexcept override + opentelemetry::sdk::common::ExportResult Export(const ResourceMetrics &record) noexcept override { records_.push_back(record); return opentelemetry::sdk::common::ExportResult::kSuccess; @@ -36,7 +36,7 @@ class MockPushMetricExporter : public MetricExporter size_t GetDataCount() { return records_.size(); } private: - std::vector records_; + std::vector records_; }; class MockMetricProducer : public MetricProducer @@ -46,11 +46,11 @@ class MockMetricProducer : public MetricProducer : sleep_ms_{sleep_ms}, data_sent_size_(0) {} - bool Collect(nostd::function_ref callback) noexcept override + bool Collect(nostd::function_ref callback) noexcept override { std::this_thread::sleep_for(sleep_ms_); data_sent_size_++; - MetricData data; + ResourceMetrics data; callback(data); return true; }