diff --git a/CHANGELOG.md b/CHANGELOG.md index 20faa52975..6249c8dbca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ Increment the: ## [Unreleased] +* [Metrics] Switch to explicit 64 bit integers [#1686](https://github.com/open-telemetry/opentelemetry-cpp/pull/1686) + which includes breaking change in the Metrics api and sdk. * [Metrics SDK] Add support for Pull Metric Exporter [#1701](https://github.com/open-telemetry/opentelemetry-cpp/pull/1701) which includes breaking change in the Metrics api. * [BUILD] Add CMake OTELCPP_MAINTAINER_MODE [#1650](https://github.com/open-telemetry/opentelemetry-cpp/pull/1650) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 0bc9b7116c..b9830ed2d3 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -36,7 +36,7 @@ class Meter * @return a shared pointer to the created Counter. */ - virtual nostd::shared_ptr> CreateLongCounter( + virtual nostd::shared_ptr> CreateUInt64Counter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; @@ -54,7 +54,7 @@ class Meter * @param description a brief description of what the Observable Counter is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. */ - virtual nostd::shared_ptr CreateLongObservableCounter( + virtual nostd::shared_ptr CreateInt64ObservableCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; @@ -72,7 +72,7 @@ class Meter * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @return a shared pointer to the created Histogram. */ - virtual nostd::shared_ptr> CreateLongHistogram( + virtual nostd::shared_ptr> CreateUInt64Histogram( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; @@ -90,7 +90,7 @@ class Meter * @param description a brief description of what the Observable Gauge is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. */ - virtual nostd::shared_ptr CreateLongObservableGauge( + virtual nostd::shared_ptr CreateInt64ObservableGauge( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; @@ -109,7 +109,7 @@ class Meter * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @return a shared pointer to the created UpDownCounter. */ - virtual nostd::shared_ptr> CreateLongUpDownCounter( + virtual nostd::shared_ptr> CreateInt64UpDownCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; @@ -127,7 +127,7 @@ class Meter * @param description a brief description of what the Observable UpDownCounter is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. */ - virtual nostd::shared_ptr CreateLongObservableUpDownCounter( + virtual nostd::shared_ptr CreateInt64ObservableUpDownCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index ce2d8e0cfd..abe841db95 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -87,11 +87,12 @@ class NoopObservableInstrument : public ObservableInstrument class NoopMeter final : public Meter { public: - nostd::shared_ptr> CreateLongCounter(nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override + nostd::shared_ptr> CreateUInt64Counter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override { - return nostd::shared_ptr>{new NoopCounter(name, description, unit)}; + return nostd::shared_ptr>{new NoopCounter(name, description, unit)}; } nostd::shared_ptr> CreateDoubleCounter( @@ -102,7 +103,7 @@ class NoopMeter final : public Meter return nostd::shared_ptr>{new NoopCounter(name, description, unit)}; } - nostd::shared_ptr CreateLongObservableCounter( + nostd::shared_ptr CreateInt64ObservableCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override @@ -120,12 +121,13 @@ class NoopMeter final : public Meter new NoopObservableInstrument(name, description, unit)); } - nostd::shared_ptr> CreateLongHistogram( + nostd::shared_ptr> CreateUInt64Histogram( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override { - return nostd::shared_ptr>{new NoopHistogram(name, description, unit)}; + return nostd::shared_ptr>{ + new NoopHistogram(name, description, unit)}; } nostd::shared_ptr> CreateDoubleHistogram( @@ -136,7 +138,7 @@ class NoopMeter final : public Meter return nostd::shared_ptr>{new NoopHistogram(name, description, unit)}; } - nostd::shared_ptr CreateLongObservableGauge( + nostd::shared_ptr CreateInt64ObservableGauge( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override @@ -154,13 +156,13 @@ class NoopMeter final : public Meter new NoopObservableInstrument(name, description, unit)); } - nostd::shared_ptr> CreateLongUpDownCounter( + nostd::shared_ptr> CreateInt64UpDownCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override { - return nostd::shared_ptr>{ - new NoopUpDownCounter(name, description, unit)}; + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit)}; } nostd::shared_ptr> CreateDoubleUpDownCounter( @@ -172,7 +174,7 @@ class NoopMeter final : public Meter new NoopUpDownCounter(name, description, unit)}; } - nostd::shared_ptr CreateLongObservableUpDownCounter( + nostd::shared_ptr CreateInt64ObservableUpDownCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override diff --git a/api/include/opentelemetry/metrics/observer_result.h b/api/include/opentelemetry/metrics/observer_result.h index 39cf3baf7e..ab41bbf025 100644 --- a/api/include/opentelemetry/metrics/observer_result.h +++ b/api/include/opentelemetry/metrics/observer_result.h @@ -46,7 +46,7 @@ class ObserverResultT } }; -using ObserverResult = nostd::variant>, +using ObserverResult = nostd::variant>, nostd::shared_ptr>>; } // namespace metrics diff --git a/api/test/metrics/noop_sync_instrument_test.cc b/api/test/metrics/noop_sync_instrument_test.cc index 05e6006854..3cd5d408e6 100644 --- a/api/test/metrics/noop_sync_instrument_test.cc +++ b/api/test/metrics/noop_sync_instrument_test.cc @@ -9,42 +9,42 @@ TEST(Counter, Add) { - std::shared_ptr> counter{ - new opentelemetry::metrics::NoopCounter("test", "none", "unitless")}; + std::shared_ptr> counter{ + new opentelemetry::metrics::NoopCounter("test", "none", "unitless")}; std::map labels = {{"k1", "v1"}}; - counter->Add(10l, labels); - counter->Add(10l, labels, opentelemetry::context::Context{}); - counter->Add(2l); - counter->Add(2l, opentelemetry::context::Context{}); - counter->Add(10l, {{"k1", "1"}, {"k2", 2}}); - counter->Add(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); + counter->Add(10, labels); + counter->Add(10, labels, opentelemetry::context::Context{}); + counter->Add(2); + counter->Add(2, opentelemetry::context::Context{}); + counter->Add(10, {{"k1", "1"}, {"k2", 2}}); + counter->Add(10, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); } TEST(histogram, Record) { - std::shared_ptr> counter{ - new opentelemetry::metrics::NoopHistogram("test", "none", "unitless")}; + std::shared_ptr> histogram{ + new opentelemetry::metrics::NoopHistogram("test", "none", "unitless")}; std::map labels = {{"k1", "v1"}}; - counter->Record(10l, labels, opentelemetry::context::Context{}); - counter->Record(2l, opentelemetry::context::Context{}); + histogram->Record(10, labels, opentelemetry::context::Context{}); + histogram->Record(2, opentelemetry::context::Context{}); - counter->Record(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); + histogram->Record(10, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); } TEST(UpDownCountr, Record) { - std::shared_ptr> counter{ - new opentelemetry::metrics::NoopUpDownCounter("test", "none", "unitless")}; + std::shared_ptr> counter{ + new opentelemetry::metrics::NoopUpDownCounter("test", "none", "unitless")}; std::map labels = {{"k1", "v1"}}; - counter->Add(10l, labels); - counter->Add(10l, labels, opentelemetry::context::Context{}); - counter->Add(2l); - counter->Add(2l, opentelemetry::context::Context{}); - counter->Add(10l, {{"k1", "1"}, {"k2", 2}}); - counter->Add(10l, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); + counter->Add(10, labels); + counter->Add(10, labels, opentelemetry::context::Context{}); + counter->Add(2); + counter->Add(2, opentelemetry::context::Context{}); + counter->Add(10, {{"k1", "1"}, {"k2", 2}}); + counter->Add(10, {{"k1", "1"}, {"k2", 2}}, opentelemetry::context::Context{}); } #endif diff --git a/exporters/ostream/src/metric_exporter.cc b/exporters/ostream/src/metric_exporter.cc index 24d799c034..c75a177036 100644 --- a/exporters/ostream/src/metric_exporter.cc +++ b/exporters/ostream/src/metric_exporter.cc @@ -164,9 +164,9 @@ void OStreamMetricExporter::printPointData(const opentelemetry::sdk::metrics::Po { sout_ << nostd::get(sum_point_data.value_); } - else if (nostd::holds_alternative(sum_point_data.value_)) + else if (nostd::holds_alternative(sum_point_data.value_)) { - sout_ << nostd::get(sum_point_data.value_); + sout_ << nostd::get(sum_point_data.value_); } } else if (nostd::holds_alternative(point_data)) @@ -179,24 +179,24 @@ void OStreamMetricExporter::printPointData(const opentelemetry::sdk::metrics::Po { sout_ << nostd::get(histogram_point_data.sum_); } - else if (nostd::holds_alternative(histogram_point_data.sum_)) + else if (nostd::holds_alternative(histogram_point_data.sum_)) { - sout_ << nostd::get(histogram_point_data.sum_); + sout_ << nostd::get(histogram_point_data.sum_); } if (histogram_point_data.record_min_max_) { - if (nostd::holds_alternative(histogram_point_data.min_)) + if (nostd::holds_alternative(histogram_point_data.min_)) { - sout_ << "\n min : " << nostd::get(histogram_point_data.min_); + sout_ << "\n min : " << nostd::get(histogram_point_data.min_); } else if (nostd::holds_alternative(histogram_point_data.min_)) { sout_ << "\n min : " << nostd::get(histogram_point_data.min_); } - if (nostd::holds_alternative(histogram_point_data.max_)) + if (nostd::holds_alternative(histogram_point_data.max_)) { - sout_ << "\n max : " << nostd::get(histogram_point_data.max_); + sout_ << "\n max : " << nostd::get(histogram_point_data.max_); } if (nostd::holds_alternative(histogram_point_data.max_)) { @@ -222,9 +222,9 @@ void OStreamMetricExporter::printPointData(const opentelemetry::sdk::metrics::Po { sout_ << nostd::get(last_point_data.value_); } - else if (nostd::holds_alternative(last_point_data.value_)) + else if (nostd::holds_alternative(last_point_data.value_)) { - sout_ << nostd::get(last_point_data.value_); + sout_ << nostd::get(last_point_data.value_); } } } diff --git a/exporters/ostream/test/ostream_metric_test.cc b/exporters/ostream/test/ostream_metric_test.cc index e98e639dca..c7ecba6659 100644 --- a/exporters/ostream/test/ostream_metric_test.cc +++ b/exporters/ostream/test/ostream_metric_test.cc @@ -108,7 +108,7 @@ TEST(OStreamMetricsExporter, ExportHistogramPointData) histogram_point_data2.boundaries_ = std::list{10.0, 20.0, 30.0}; histogram_point_data2.count_ = 3; histogram_point_data2.counts_ = {200, 300, 400, 500}; - histogram_point_data2.sum_ = 900l; + histogram_point_data2.sum_ = (int64_t)900; metric_sdk::ResourceMetrics data; auto resource = opentelemetry::sdk::resource::Resource::Create( opentelemetry::sdk::resource::ResourceAttributes{}); @@ -190,7 +190,7 @@ TEST(OStreamMetricsExporter, ExportLastValuePointData) last_value_point_data.is_lastvalue_valid_ = true; last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; metric_sdk::LastValuePointData last_value_point_data2{}; - last_value_point_data2.value_ = 20l; + last_value_point_data2.value_ = (int64_t)20; last_value_point_data2.is_lastvalue_valid_ = true; last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{}; metric_sdk::MetricData metric_data{ diff --git a/exporters/otlp/src/otlp_metric_utils.cc b/exporters/otlp/src/otlp_metric_utils.cc index 67686a93ad..39d133f4cf 100644 --- a/exporters/otlp/src/otlp_metric_utils.cc +++ b/exporters/otlp/src/otlp_metric_utils.cc @@ -62,9 +62,9 @@ void OtlpMetricUtils::ConvertSumMetric(const metric_sdk::MetricData &metric_data proto_sum_point_data->set_time_unix_nano(ts); auto sum_data = nostd::get(point_data_with_attributes.point_data); - if ((nostd::holds_alternative(sum_data.value_))) + if ((nostd::holds_alternative(sum_data.value_))) { - proto_sum_point_data->set_as_int(nostd::get(sum_data.value_)); + proto_sum_point_data->set_as_int(nostd::get(sum_data.value_)); } else { @@ -96,9 +96,9 @@ void OtlpMetricUtils::ConvertHistogramMetric( auto histogram_data = nostd::get(point_data_with_attributes.point_data); // sum - if ((nostd::holds_alternative(histogram_data.sum_))) + if ((nostd::holds_alternative(histogram_data.sum_))) { - proto_histogram_point_data->set_sum(nostd::get(histogram_data.sum_)); + proto_histogram_point_data->set_sum(nostd::get(histogram_data.sum_)); } else { @@ -108,17 +108,17 @@ void OtlpMetricUtils::ConvertHistogramMetric( proto_histogram_point_data->set_count(histogram_data.count_); if (histogram_data.record_min_max_) { - if (nostd::holds_alternative(histogram_data.min_)) + if (nostd::holds_alternative(histogram_data.min_)) { - proto_histogram_point_data->set_min(nostd::get(histogram_data.min_)); + proto_histogram_point_data->set_min(nostd::get(histogram_data.min_)); } else { proto_histogram_point_data->set_min(nostd::get(histogram_data.min_)); } - if (nostd::holds_alternative(histogram_data.max_)) + if (nostd::holds_alternative(histogram_data.max_)) { - proto_histogram_point_data->set_min(nostd::get(histogram_data.max_)); + proto_histogram_point_data->set_min(nostd::get(histogram_data.max_)); } else { @@ -158,9 +158,9 @@ void OtlpMetricUtils::ConvertGaugeMetric(const opentelemetry::sdk::metrics::Metr auto gauge_data = nostd::get(point_data_with_attributes.point_data); - if ((nostd::holds_alternative(gauge_data.value_))) + if ((nostd::holds_alternative(gauge_data.value_))) { - proto_gauge_point_data->set_as_int(nostd::get(gauge_data.value_)); + proto_gauge_point_data->set_as_int(nostd::get(gauge_data.value_)); } else { diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index 804e1f9efb..1029df6145 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -296,7 +296,7 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test last_value_point_data.is_lastvalue_valid_ = true; last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; opentelemetry::sdk::metrics::LastValuePointData last_value_point_data2{}; - last_value_point_data2.value_ = 20l; + last_value_point_data2.value_ = (int64_t)20; last_value_point_data2.is_lastvalue_valid_ = true; last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{}; opentelemetry::sdk::metrics::MetricData metric_data{ @@ -392,7 +392,7 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test last_value_point_data.is_lastvalue_valid_ = true; last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; opentelemetry::sdk::metrics::LastValuePointData last_value_point_data2{}; - last_value_point_data2.value_ = 20l; + last_value_point_data2.value_ = (int64_t)20; last_value_point_data2.is_lastvalue_valid_ = true; last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{}; opentelemetry::sdk::metrics::MetricData metric_data{ @@ -492,7 +492,7 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test histogram_point_data2.boundaries_ = {10.0, 20.0, 30.0}; histogram_point_data2.count_ = 3; histogram_point_data2.counts_ = {200, 300, 400, 500}; - histogram_point_data2.sum_ = 900l; + histogram_point_data2.sum_ = (int64_t)900; opentelemetry::sdk::metrics::MetricData metric_data{ opentelemetry::sdk::metrics::InstrumentDescriptor{ @@ -627,7 +627,7 @@ class OtlpHttpMetricExporterTestPeer : public ::testing::Test histogram_point_data2.boundaries_ = {10.0, 20.0, 30.0}; histogram_point_data2.count_ = 3; histogram_point_data2.counts_ = {200, 300, 400, 500}; - histogram_point_data2.sum_ = 900l; + histogram_point_data2.sum_ = (int64_t)900; opentelemetry::sdk::metrics::MetricData metric_data{ opentelemetry::sdk::metrics::InstrumentDescriptor{ diff --git a/exporters/prometheus/src/exporter_utils.cc b/exporters/prometheus/src/exporter_utils.cc index f1a27b35c5..e705cd9f17 100644 --- a/exporters/prometheus/src/exporter_utils.cc +++ b/exporters/prometheus/src/exporter_utils.cc @@ -70,7 +70,7 @@ std::vector PrometheusExporterUtils::TranslateT } else { - sum = nostd::get(histogram_point_data.sum_); + sum = nostd::get(histogram_point_data.sum_); } SetData(std::vector{sum, (double)histogram_point_data.count_}, boundaries, counts, point_data_attr.attributes, time, &metric_family); @@ -283,9 +283,9 @@ void PrometheusExporterUtils::SetValue(std::vector values, { double value = 0.0; const auto &value_var = values[0]; - if (nostd::holds_alternative(value_var)) + if (nostd::holds_alternative(value_var)) { - value = nostd::get(value_var); + value = nostd::get(value_var); } else { diff --git a/exporters/prometheus/test/prometheus_test_helper.h b/exporters/prometheus/test/prometheus_test_helper.h index f4db88d2fc..1042804d00 100644 --- a/exporters/prometheus/test/prometheus_test_helper.h +++ b/exporters/prometheus/test/prometheus_test_helper.h @@ -54,7 +54,7 @@ inline metric_sdk::ResourceMetrics CreateHistogramPointData() histogram_point_data2.boundaries_ = {10.0, 20.0, 30.0}; histogram_point_data2.count_ = 3; histogram_point_data2.counts_ = {200, 300, 400, 500}; - histogram_point_data2.sum_ = 900l; + histogram_point_data2.sum_ = (int64_t)900; metric_sdk::ResourceMetrics data; auto resource = opentelemetry::sdk::resource::Resource::Create( opentelemetry::sdk::resource::ResourceAttributes{}); @@ -90,7 +90,7 @@ inline metric_sdk::ResourceMetrics CreateLastValuePointData() last_value_point_data.is_lastvalue_valid_ = true; last_value_point_data.sample_ts_ = opentelemetry::common::SystemTimestamp{}; metric_sdk::LastValuePointData last_value_point_data2{}; - last_value_point_data2.value_ = 20l; + last_value_point_data2.value_ = (int64_t)20; last_value_point_data2.is_lastvalue_valid_ = true; last_value_point_data2.sample_ts_ = opentelemetry::common::SystemTimestamp{}; metric_sdk::MetricData metric_data{ diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation.h index 7ec9a6ea2b..786466fd12 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/aggregation.h @@ -14,7 +14,7 @@ namespace metrics class Aggregation { public: - virtual void Aggregate(long value, const PointAttributes &attributes = {}) noexcept = 0; + virtual void Aggregate(int64_t value, const PointAttributes &attributes = {}) noexcept = 0; virtual void Aggregate(double value, const PointAttributes &attributes = {}) noexcept = 0; diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/drop_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/drop_aggregation.h index c919c3a8e1..f32ffcd1d3 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/drop_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/drop_aggregation.h @@ -25,7 +25,7 @@ class DropAggregation : public Aggregation DropAggregation(const DropPointData &) {} - void Aggregate(long /* value */, const PointAttributes & /* attributes */) noexcept override {} + void Aggregate(int64_t /* value */, const PointAttributes & /* attributes */) noexcept override {} void Aggregate(double /* value */, const PointAttributes & /* attributes */) noexcept override {} diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h index bc5c76ae67..0efe0c9a5b 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/histogram_aggregation.h @@ -23,7 +23,7 @@ class LongHistogramAggregation : public Aggregation LongHistogramAggregation(HistogramPointData &&); LongHistogramAggregation(const HistogramPointData &); - void Aggregate(long value, const PointAttributes &attributes = {}) noexcept override; + void Aggregate(int64_t value, const PointAttributes &attributes = {}) noexcept override; void Aggregate(double /* value */, const PointAttributes & /* attributes */) noexcept override {} @@ -53,7 +53,7 @@ class DoubleHistogramAggregation : public Aggregation DoubleHistogramAggregation(HistogramPointData &&); DoubleHistogramAggregation(const HistogramPointData &); - void Aggregate(long /* value */, const PointAttributes & /* attributes */) noexcept override {} + void Aggregate(int64_t /* value */, const PointAttributes & /* attributes */) noexcept override {} void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override; diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h index 47eabdf2f8..e4580e5e3a 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/lastvalue_aggregation.h @@ -20,7 +20,7 @@ class LongLastValueAggregation : public Aggregation LongLastValueAggregation(LastValuePointData &&); LongLastValueAggregation(const LastValuePointData &); - void Aggregate(long value, const PointAttributes &attributes = {}) noexcept override; + void Aggregate(int64_t value, const PointAttributes &attributes = {}) noexcept override; void Aggregate(double /* value */, const PointAttributes & /* attributes */) noexcept override {} @@ -42,7 +42,7 @@ class DoubleLastValueAggregation : public Aggregation DoubleLastValueAggregation(LastValuePointData &&); DoubleLastValueAggregation(const LastValuePointData &); - void Aggregate(long /* value */, const PointAttributes & /* attributes */) noexcept override {} + void Aggregate(int64_t /* value */, const PointAttributes & /* attributes */) noexcept override {} void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override; diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h index 414f0e1c28..8f156e1cc1 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/sum_aggregation.h @@ -21,7 +21,7 @@ class LongSumAggregation : public Aggregation LongSumAggregation(SumPointData &&); LongSumAggregation(const SumPointData &); - void Aggregate(long value, const PointAttributes &attributes = {}) noexcept override; + void Aggregate(int64_t value, const PointAttributes &attributes = {}) noexcept override; void Aggregate(double /* value */, const PointAttributes & /* attributes */) noexcept override {} @@ -43,7 +43,7 @@ class DoubleSumAggregation : public Aggregation DoubleSumAggregation(SumPointData &&); DoubleSumAggregation(const SumPointData &); - void Aggregate(long /* value */, const PointAttributes & /* attributes */) noexcept override {} + void Aggregate(int64_t /* value */, const PointAttributes & /* attributes */) noexcept override {} void Aggregate(double value, const PointAttributes &attributes = {}) noexcept override; diff --git a/sdk/include/opentelemetry/sdk/metrics/data/point_data.h b/sdk/include/opentelemetry/sdk/metrics/data/point_data.h index dfeda3d33d..5ee69ffba8 100644 --- a/sdk/include/opentelemetry/sdk/metrics/data/point_data.h +++ b/sdk/include/opentelemetry/sdk/metrics/data/point_data.h @@ -16,7 +16,7 @@ namespace sdk namespace metrics { -using ValueType = nostd::variant; +using ValueType = nostd::variant; // TODO: remove ctors and initializers from below classes when GCC<5 stops shipping on Ubuntu diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/always_sample_filter.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/always_sample_filter.h index 366488b2b6..8bcb974993 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/always_sample_filter.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/always_sample_filter.h @@ -15,7 +15,7 @@ class AlwaysSampleFilter final : public ExemplarFilter { public: bool ShouldSampleMeasurement( - long /* value */, + int64_t /* value */, const MetricAttributes & /* attributes */, const opentelemetry::context::Context & /* context */) noexcept override { diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h index 87e27b81c2..3c8c43fb58 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h @@ -21,7 +21,7 @@ class ExemplarFilter { public: // Returns whether or not a reservoir should attempt to filter a measurement. - virtual bool ShouldSampleMeasurement(long value, + virtual bool ShouldSampleMeasurement(int64_t value, const MetricAttributes &attributes, const opentelemetry::context::Context &context) noexcept = 0; diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h index 2db5532883..f410bef6d0 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/filtered_exemplar_reservoir.h @@ -25,7 +25,7 @@ class FilteredExemplarReservoir final : public ExemplarReservoir : filter_(filter), reservoir_(reservoir) {} - void OfferMeasurement(long value, + void OfferMeasurement(int64_t value, const MetricAttributes &attributes, const opentelemetry::context::Context &context, const opentelemetry::common::SystemTimestamp ×tamp) noexcept override diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h index a809f026b0..e8564f4285 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h @@ -33,7 +33,7 @@ class FixedSizeExemplarReservoir : public ExemplarReservoir {} void OfferMeasurement( - long value, + int64_t value, const MetricAttributes &attributes, const opentelemetry::context::Context &context, const opentelemetry::common::SystemTimestamp & /* timestamp */) noexcept override @@ -46,7 +46,7 @@ class FixedSizeExemplarReservoir : public ExemplarReservoir reservoir_cell_selector_->ReservoirCellIndexFor(storage_, value, attributes, context); if (idx != -1) { - storage_[idx].RecordDoubleMeasurement(value, attributes, context); + storage_[idx].RecordLongMeasurement(value, attributes, context); } } diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h index 5469bee8da..ad7f163860 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/histogram_exemplar_reservoir.h @@ -43,7 +43,7 @@ class HistogramExemplarReservoir : public FixedSizeExemplarReservoir HistogramCellSelector(const std::vector &boundaries) : boundaries_(boundaries) {} int ReservoirCellIndexFor(const std::vector &cells, - long value, + int64_t value, const MetricAttributes &attributes, const opentelemetry::context::Context &context) override { diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/never_sample_filter.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/never_sample_filter.h index 844bf72e10..e5015c9b9f 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/never_sample_filter.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/never_sample_filter.h @@ -15,7 +15,7 @@ class NeverSampleFilter final : public ExemplarFilter { public: bool ShouldSampleMeasurement( - long /* value */, + int64_t /* value */, const MetricAttributes & /* attributes */, const opentelemetry::context::Context & /* context */) noexcept override { diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h index 38c6c74c60..481690a0c3 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/no_exemplar_reservoir.h @@ -19,7 +19,7 @@ class NoExemplarReservoir final : public ExemplarReservoir public: void OfferMeasurement( - long /* value */, + int64_t /* value */, const MetricAttributes & /* attributes */, const opentelemetry::context::Context & /* context */, const opentelemetry::common::SystemTimestamp & /* timestamp */) noexcept override diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h index db8a37c260..5fcb90d6b4 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir.h @@ -25,7 +25,7 @@ class ExemplarReservoir /** Offers a long measurement to be sampled. */ virtual void OfferMeasurement( - long value, + int64_t value, const MetricAttributes &attributes, const opentelemetry::context::Context &context, const opentelemetry::common::SystemTimestamp ×tamp) noexcept = 0; diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h index 9a84155f2a..324fbe1993 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell.h @@ -30,7 +30,7 @@ class ReservoirCell /** * Record the long measurement to the cell. */ - void RecordLongMeasurement(long value, + void RecordLongMeasurement(int64_t value, const MetricAttributes &attributes, const opentelemetry::context::Context &context) { @@ -52,7 +52,7 @@ class ReservoirCell /** * Retrieve the cell's {@link ExemplarData}. * - *

Must be used in tandem with {@link #recordLongMeasurement(long, Attributes, Context)}. + *

Must be used in tandem with {@link #recordLongMeasurement(int64_t, Attributes, Context)}. */ std::shared_ptr GetAndResetLong(const MetricAttributes &point_attributes) { @@ -63,9 +63,10 @@ class ReservoirCell auto attributes = attributes_; PointDataAttributes point_data_attributes; point_data_attributes.attributes = filtered(attributes, point_attributes); - if (nostd::holds_alternative(value_)) + if (nostd::holds_alternative(value_)) { - point_data_attributes.point_data = ExemplarData::CreateSumPointData(nostd::get(value_)); + point_data_attributes.point_data = + ExemplarData::CreateSumPointData(nostd::get(value_)); } std::shared_ptr result{ new ExemplarData{ExemplarData::Create(context_, record_time_, point_data_attributes)}}; @@ -139,7 +140,7 @@ class ReservoirCell // Cell stores either long or double values, but must not store both std::shared_ptr context_; - nostd::variant value_; + nostd::variant value_; opentelemetry::common::SystemTimestamp record_time_; MetricAttributes attributes_; // For testing diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h index 13e149f0aa..6972bf429b 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h @@ -24,7 +24,7 @@ class ReservoirCellSelector /** Determine the index of the {@code cells} to record the measurement to. */ virtual int ReservoirCellIndexFor(const std::vector &cells, - long value, + int64_t value, const MetricAttributes &attributes, const opentelemetry::context::Context &context) = 0; diff --git a/sdk/include/opentelemetry/sdk/metrics/exemplar/with_trace_sample_filter.h b/sdk/include/opentelemetry/sdk/metrics/exemplar/with_trace_sample_filter.h index 46fceb306d..afeb179866 100644 --- a/sdk/include/opentelemetry/sdk/metrics/exemplar/with_trace_sample_filter.h +++ b/sdk/include/opentelemetry/sdk/metrics/exemplar/with_trace_sample_filter.h @@ -15,7 +15,7 @@ namespace metrics class WithTraceSampleFilter final : public ExemplarFilter { public: - bool ShouldSampleMeasurement(long /* value */, + bool ShouldSampleMeasurement(int64_t /* value */, const MetricAttributes & /* attributes */, const opentelemetry::context::Context &context) noexcept override { diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index b2c86a7e49..b2e8e49709 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -35,7 +35,7 @@ class Meter final : public opentelemetry::metrics::Meter std::unique_ptr scope = opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("")) noexcept; - nostd::shared_ptr> CreateLongCounter( + nostd::shared_ptr> CreateUInt64Counter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override; @@ -45,7 +45,7 @@ class Meter final : public opentelemetry::metrics::Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr CreateLongObservableCounter( + nostd::shared_ptr CreateInt64ObservableCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override; @@ -55,7 +55,7 @@ class Meter final : public opentelemetry::metrics::Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> CreateLongHistogram( + nostd::shared_ptr> CreateUInt64Histogram( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override; @@ -65,7 +65,7 @@ class Meter final : public opentelemetry::metrics::Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr CreateLongObservableGauge( + nostd::shared_ptr CreateInt64ObservableGauge( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override; @@ -75,7 +75,7 @@ class Meter final : public opentelemetry::metrics::Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr> CreateLongUpDownCounter( + nostd::shared_ptr> CreateInt64UpDownCounter( nostd::string_view name, nostd::string_view description = "", nostd::string_view unit = "") noexcept override; @@ -85,10 +85,10 @@ class Meter final : public opentelemetry::metrics::Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept override; - nostd::shared_ptr CreateLongObservableUpDownCounter( - nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override; + nostd::shared_ptr + CreateInt64ObservableUpDownCounter(nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override; nostd::shared_ptr CreateDoubleObservableUpDownCounter(nostd::string_view name, 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 8270a32c02..82b5d385db 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h @@ -72,14 +72,14 @@ class AsyncMetricStorage : public MetricStorage, public AsyncWritableMetricStora } void RecordLong( - const std::unordered_map &measurements, + const std::unordered_map &measurements, opentelemetry::common::SystemTimestamp observation_time) noexcept override { if (instrument_descriptor_.value_type_ != InstrumentValueType::kLong) { return; } - Record(measurements, observation_time); + Record(measurements, observation_time); } void RecordDouble( diff --git a/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h index be097a8be0..b85854358e 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h @@ -37,9 +37,10 @@ class MetricStorage class SyncWritableMetricStorage { public: - virtual void RecordLong(long value, const opentelemetry::context::Context &context) noexcept = 0; + virtual void RecordLong(int64_t value, + const opentelemetry::context::Context &context) noexcept = 0; - virtual void RecordLong(long value, + virtual void RecordLong(int64_t value, const opentelemetry::common::KeyValueIterable &attributes, const opentelemetry::context::Context &context) noexcept = 0; @@ -62,7 +63,7 @@ class AsyncWritableMetricStorage /* Records a batch of measurements */ virtual void RecordLong( - const std::unordered_map &measurements, + const std::unordered_map &measurements, opentelemetry::common::SystemTimestamp observation_time) noexcept = 0; virtual void RecordDouble( @@ -87,9 +88,10 @@ class NoopMetricStorage : public MetricStorage class NoopWritableMetricStorage : public SyncWritableMetricStorage { public: - void RecordLong(long value, const opentelemetry::context::Context &context) noexcept override = 0; + void RecordLong(int64_t value, + const opentelemetry::context::Context &context) noexcept override = 0; - void RecordLong(long /* value */, + void RecordLong(int64_t /* value */, const opentelemetry::common::KeyValueIterable & /* attributes */, const opentelemetry::context::Context & /* context */) noexcept override {} @@ -107,9 +109,9 @@ class NoopWritableMetricStorage : public SyncWritableMetricStorage class NoopAsyncWritableMetricStorage : public AsyncWritableMetricStorage { public: - void RecordLong( - const std::unordered_map & /* measurements */, - opentelemetry::common::SystemTimestamp /* observation_time */) noexcept override + void RecordLong(const std::unordered_map + & /* measurements */, + opentelemetry::common::SystemTimestamp /* observation_time */) noexcept override {} void RecordDouble(const std::unordered_map diff --git a/sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h b/sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h index b3cae8694c..740261a0c2 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h @@ -23,7 +23,7 @@ class SyncMultiMetricStorage : public SyncWritableMetricStorage storages_.push_back(storage); } - virtual void RecordLong(long value, + virtual void RecordLong(int64_t value, const opentelemetry::context::Context &context) noexcept override { for (auto &s : storages_) @@ -32,7 +32,7 @@ class SyncMultiMetricStorage : public SyncWritableMetricStorage } } - virtual void RecordLong(long value, + virtual void RecordLong(int64_t value, const opentelemetry::common::KeyValueIterable &attributes, const opentelemetry::context::Context &context) noexcept override { @@ -74,7 +74,7 @@ class AsyncMultiMetricStorage : public AsyncWritableMetricStorage } void RecordLong( - const std::unordered_map &measurements, + const std::unordered_map &measurements, opentelemetry::common::SystemTimestamp observation_time) noexcept override { for (auto &s : storages_) 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 b0c7229864..dfbc4be2ef 100644 --- a/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h +++ b/sdk/include/opentelemetry/sdk/metrics/state/sync_metric_storage.h @@ -46,7 +46,7 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage }; } - void RecordLong(long value, const opentelemetry::context::Context &context) noexcept override + void RecordLong(int64_t value, const opentelemetry::context::Context &context) noexcept override { if (instrument_descriptor_.value_type_ != InstrumentValueType::kLong) { @@ -57,7 +57,7 @@ class SyncMetricStorage : public MetricStorage, public SyncWritableMetricStorage attributes_hashmap_->GetOrSetDefault({}, create_default_aggregation_)->Aggregate(value); } - void RecordLong(long value, + void RecordLong(int64_t value, const opentelemetry::common::KeyValueIterable &attributes, const opentelemetry::context::Context &context) noexcept override { diff --git a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h index 57166ee60e..8e2f420598 100644 --- a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h @@ -7,6 +7,8 @@ # include "opentelemetry/metrics/sync_instruments.h" # include "opentelemetry/nostd/string_view.h" # include "opentelemetry/sdk/metrics/instruments.h" +# include "opentelemetry/sdk/metrics/state/metric_storage.h" +# include "opentelemetry/sdk_config.h" # include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" @@ -32,19 +34,61 @@ class Synchronous std::unique_ptr storage_; }; -class LongCounter : public Synchronous, public opentelemetry::metrics::Counter +template +class LongCounter : public Synchronous, public opentelemetry::metrics::Counter { public: LongCounter(InstrumentDescriptor instrument_descriptor, - std::unique_ptr storage); - - void Add(long value, const opentelemetry::common::KeyValueIterable &attributes) noexcept override; - void Add(long value, + std::unique_ptr storage) + : Synchronous(instrument_descriptor, std::move(storage)) + { + if (!storage_) + { + OTEL_INTERNAL_LOG_ERROR("[LongCounter::LongCounter] - Error during constructing LongCounter." + << "The metric storage is invalid" + << "No value will be added"); + } + } + + void Add(T value, const opentelemetry::common::KeyValueIterable &attributes) noexcept override + { + if (!storage_) + { + return; + } + auto context = opentelemetry::context::Context{}; + return storage_->RecordLong(value, attributes, context); + } + + void Add(T value, const opentelemetry::common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept override; - - void Add(long value) noexcept override; - void Add(long value, const opentelemetry::context::Context &context) noexcept override; + const opentelemetry::context::Context &context) noexcept override + { + if (!storage_) + { + return; + } + return storage_->RecordLong(value, attributes, context); + } + + void Add(T value) noexcept override + { + auto context = opentelemetry::context::Context{}; + if (!storage_) + { + return; + } + return storage_->RecordLong(value, context); + } + + void Add(T value, const opentelemetry::context::Context &context) noexcept override + { + if (!storage_) + { + return; + } + return storage_->RecordLong(value, context); + } }; class DoubleCounter : public Synchronous, public opentelemetry::metrics::Counter @@ -64,19 +108,20 @@ class DoubleCounter : public Synchronous, public opentelemetry::metrics::Counter void Add(double value, const opentelemetry::context::Context &context) noexcept override; }; -class LongUpDownCounter : public Synchronous, public opentelemetry::metrics::UpDownCounter +class LongUpDownCounter : public Synchronous, public opentelemetry::metrics::UpDownCounter { public: LongUpDownCounter(InstrumentDescriptor instrument_descriptor, std::unique_ptr storage); - void Add(long value, const opentelemetry::common::KeyValueIterable &attributes) noexcept override; - void Add(long value, + void Add(int64_t value, + const opentelemetry::common::KeyValueIterable &attributes) noexcept override; + void Add(int64_t value, const opentelemetry::common::KeyValueIterable &attributes, const opentelemetry::context::Context &context) noexcept override; - void Add(long value) noexcept override; - void Add(long value, const opentelemetry::context::Context &context) noexcept override; + void Add(int64_t value) noexcept override; + void Add(int64_t value, const opentelemetry::context::Context &context) noexcept override; }; class DoubleUpDownCounter : public Synchronous, public opentelemetry::metrics::UpDownCounter @@ -95,17 +140,48 @@ class DoubleUpDownCounter : public Synchronous, public opentelemetry::metrics::U void Add(double value, const opentelemetry::context::Context &context) noexcept override; }; -class LongHistogram : public Synchronous, public opentelemetry::metrics::Histogram +template +class LongHistogram : public Synchronous, public opentelemetry::metrics::Histogram { public: LongHistogram(InstrumentDescriptor instrument_descriptor, - std::unique_ptr storage); - - void Record(long value, + std::unique_ptr storage) + : Synchronous(instrument_descriptor, std::move(storage)) + { + if (!storage_) + { + OTEL_INTERNAL_LOG_ERROR( + "[LongHistogram::LongHistogram] - Error during constructing LongHistogram." + << "The metric storage is invalid" + << "No value will be added"); + } + } + + void Record(T value, const opentelemetry::common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept override; - - void Record(long value, const opentelemetry::context::Context &context) noexcept override; + const opentelemetry::context::Context &context) noexcept override + { + if (value < 0) + { + OTEL_INTERNAL_LOG_WARN( + "[LongHistogram::Record(value, attributes)] negative value provided to histogram Name:" + << instrument_descriptor_.name_ << " Value:" << value); + return; + } + return storage_->RecordLong(value, attributes, context); + } + + void Record(T value, const opentelemetry::context::Context &context) noexcept override + { + if (value < 0) + { + OTEL_INTERNAL_LOG_WARN( + "[LongHistogram::Record(value)] negative value provided to histogram Name:" + << instrument_descriptor_.name_ << " Value:" << value); + return; + } + return storage_->RecordLong(value, context); + } }; class DoubleHistogram : public Synchronous, public opentelemetry::metrics::Histogram diff --git a/sdk/src/metrics/aggregation/histogram_aggregation.cc b/sdk/src/metrics/aggregation/histogram_aggregation.cc index e9ca7d18b0..b8bbb190d3 100644 --- a/sdk/src/metrics/aggregation/histogram_aggregation.cc +++ b/sdk/src/metrics/aggregation/histogram_aggregation.cc @@ -34,11 +34,11 @@ LongHistogramAggregation::LongHistogramAggregation(const AggregationConfig *aggr record_min_max_ = ac->record_min_max_; } point_data_.counts_ = std::vector(point_data_.boundaries_.size() + 1, 0); - point_data_.sum_ = 0l; + point_data_.sum_ = (int64_t)0; point_data_.count_ = 0; point_data_.record_min_max_ = record_min_max_; - point_data_.min_ = std::numeric_limits::max(); - point_data_.max_ = std::numeric_limits::min(); + point_data_.min_ = std::numeric_limits::max(); + point_data_.max_ = std::numeric_limits::min(); } LongHistogramAggregation::LongHistogramAggregation(HistogramPointData &&data) @@ -49,16 +49,16 @@ LongHistogramAggregation::LongHistogramAggregation(const HistogramPointData &dat : point_data_{data}, record_min_max_{point_data_.record_min_max_} {} -void LongHistogramAggregation::Aggregate(long value, +void LongHistogramAggregation::Aggregate(int64_t value, const PointAttributes & /* attributes */) noexcept { const std::lock_guard locked(lock_); point_data_.count_ += 1; - point_data_.sum_ = nostd::get(point_data_.sum_) + value; + point_data_.sum_ = nostd::get(point_data_.sum_) + value; if (record_min_max_) { - point_data_.min_ = std::min(nostd::get(point_data_.min_), value); - point_data_.max_ = std::max(nostd::get(point_data_.max_), value); + point_data_.min_ = std::min(nostd::get(point_data_.min_), value); + point_data_.max_ = std::max(nostd::get(point_data_.max_), value); } size_t index = 0; for (auto it = point_data_.boundaries_.begin(); it != point_data_.boundaries_.end(); ++it) @@ -79,7 +79,7 @@ std::unique_ptr LongHistogramAggregation::Merge( auto delta_value = nostd::get( (static_cast(delta).ToPoint())); LongHistogramAggregation *aggr = new LongHistogramAggregation(); - HistogramMerge(curr_value, delta_value, aggr->point_data_); + HistogramMerge(curr_value, delta_value, aggr->point_data_); return std::unique_ptr(aggr); } @@ -89,7 +89,7 @@ std::unique_ptr LongHistogramAggregation::Diff(const Aggregation &n auto next_value = nostd::get( (static_cast(next).ToPoint())); LongHistogramAggregation *aggr = new LongHistogramAggregation(); - HistogramDiff(curr_value, next_value, aggr->point_data_); + HistogramDiff(curr_value, next_value, aggr->point_data_); return std::unique_ptr(aggr); } diff --git a/sdk/src/metrics/aggregation/lastvalue_aggregation.cc b/sdk/src/metrics/aggregation/lastvalue_aggregation.cc index d12d393831..17ccbbd726 100644 --- a/sdk/src/metrics/aggregation/lastvalue_aggregation.cc +++ b/sdk/src/metrics/aggregation/lastvalue_aggregation.cc @@ -17,7 +17,7 @@ namespace metrics LongLastValueAggregation::LongLastValueAggregation() { point_data_.is_lastvalue_valid_ = false; - point_data_.value_ = 0l; + point_data_.value_ = (int64_t)0; } LongLastValueAggregation::LongLastValueAggregation(LastValuePointData &&data) @@ -28,7 +28,7 @@ LongLastValueAggregation::LongLastValueAggregation(const LastValuePointData &dat : point_data_{data} {} -void LongLastValueAggregation::Aggregate(long value, +void LongLastValueAggregation::Aggregate(int64_t value, const PointAttributes & /* attributes */) noexcept { const std::lock_guard locked(lock_); diff --git a/sdk/src/metrics/aggregation/sum_aggregation.cc b/sdk/src/metrics/aggregation/sum_aggregation.cc index 9a5b833eb2..1c2772f540 100644 --- a/sdk/src/metrics/aggregation/sum_aggregation.cc +++ b/sdk/src/metrics/aggregation/sum_aggregation.cc @@ -17,26 +17,26 @@ namespace metrics LongSumAggregation::LongSumAggregation() { - point_data_.value_ = 0l; + point_data_.value_ = (int64_t)0; } LongSumAggregation::LongSumAggregation(SumPointData &&data) : point_data_{std::move(data)} {} LongSumAggregation::LongSumAggregation(const SumPointData &data) : point_data_{data} {} -void LongSumAggregation::Aggregate(long value, const PointAttributes & /* attributes */) noexcept +void LongSumAggregation::Aggregate(int64_t value, const PointAttributes & /* attributes */) noexcept { const std::lock_guard locked(lock_); - point_data_.value_ = nostd::get(point_data_.value_) + value; + point_data_.value_ = nostd::get(point_data_.value_) + value; } std::unique_ptr LongSumAggregation::Merge(const Aggregation &delta) const noexcept { - long merge_value = - nostd::get( + int64_t merge_value = + nostd::get( nostd::get((static_cast(delta).ToPoint())) .value_) + - nostd::get(nostd::get(ToPoint()).value_); + nostd::get(nostd::get(ToPoint()).value_); std::unique_ptr aggr(new LongSumAggregation()); static_cast(aggr.get())->point_data_.value_ = merge_value; return aggr; @@ -45,10 +45,11 @@ std::unique_ptr LongSumAggregation::Merge(const Aggregation &delta) std::unique_ptr LongSumAggregation::Diff(const Aggregation &next) const noexcept { - long diff_value = nostd::get(nostd::get( - (static_cast(next).ToPoint())) - .value_) - - nostd::get(nostd::get(ToPoint()).value_); + int64_t diff_value = + nostd::get( + nostd::get((static_cast(next).ToPoint())) + .value_) - + nostd::get(nostd::get(ToPoint()).value_); std::unique_ptr aggr(new LongSumAggregation()); static_cast(aggr.get())->point_data_.value_ = diff_value; return aggr; diff --git a/sdk/src/metrics/meter.cc b/sdk/src/metrics/meter.cc index 8d36509c34..86ba798e03 100644 --- a/sdk/src/metrics/meter.cc +++ b/sdk/src/metrics/meter.cc @@ -3,6 +3,7 @@ #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/sdk/metrics/meter.h" +# include # include "opentelemetry/metrics/noop.h" # include "opentelemetry/nostd/shared_ptr.h" # include "opentelemetry/sdk/metrics/async_instruments.h" @@ -33,16 +34,17 @@ Meter::Meter( observable_registry_(new ObservableRegistry()) {} -nostd::shared_ptr> Meter::CreateLongCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +nostd::shared_ptr> Meter::CreateUInt64Counter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit) noexcept { InstrumentDescriptor instrument_descriptor = { std::string{name.data(), name.size()}, std::string{description.data(), description.size()}, std::string{unit.data(), unit.size()}, InstrumentType::kCounter, InstrumentValueType::kLong}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr>( - new LongCounter(instrument_descriptor, std::move(storage))); + return nostd::shared_ptr>( + new LongCounter(instrument_descriptor, std::move(storage))); } nostd::shared_ptr> Meter::CreateDoubleCounter( @@ -59,7 +61,7 @@ nostd::shared_ptr> Meter::CreateDoubleCounter( new DoubleCounter(instrument_descriptor, std::move(storage))}; } -nostd::shared_ptr Meter::CreateLongObservableCounter( +nostd::shared_ptr Meter::CreateInt64ObservableCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit) noexcept @@ -87,7 +89,7 @@ Meter::CreateDoubleObservableCounter(nostd::string_view name, new ObservableInstrument(instrument_descriptor, std::move(storage), observable_registry_)}; } -nostd::shared_ptr> Meter::CreateLongHistogram( +nostd::shared_ptr> Meter::CreateUInt64Histogram( nostd::string_view name, nostd::string_view description, nostd::string_view unit) noexcept @@ -97,8 +99,8 @@ nostd::shared_ptr> Meter::CreateLongHistogram( std::string{unit.data(), unit.size()}, InstrumentType::kHistogram, InstrumentValueType::kLong}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr>{ - new LongHistogram(instrument_descriptor, std::move(storage))}; + return nostd::shared_ptr>{ + new LongHistogram(instrument_descriptor, std::move(storage))}; } nostd::shared_ptr> Meter::CreateDoubleHistogram( @@ -115,7 +117,7 @@ nostd::shared_ptr> Meter::CreateDoubleHistogram( new DoubleHistogram(instrument_descriptor, std::move(storage))}; } -nostd::shared_ptr Meter::CreateLongObservableGauge( +nostd::shared_ptr Meter::CreateInt64ObservableGauge( nostd::string_view name, nostd::string_view description, nostd::string_view unit) noexcept @@ -143,7 +145,7 @@ nostd::shared_ptr Meter::CreateDou new ObservableInstrument(instrument_descriptor, std::move(storage), observable_registry_)}; } -nostd::shared_ptr> Meter::CreateLongUpDownCounter( +nostd::shared_ptr> Meter::CreateInt64UpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit) noexcept @@ -153,7 +155,7 @@ nostd::shared_ptr> Meter::CreateLongUpDownCounter( std::string{unit.data(), unit.size()}, InstrumentType::kUpDownCounter, InstrumentValueType::kLong}; auto storage = RegisterSyncMetricStorage(instrument_descriptor); - return nostd::shared_ptr>{ + return nostd::shared_ptr>{ new LongUpDownCounter(instrument_descriptor, std::move(storage))}; } @@ -172,9 +174,9 @@ nostd::shared_ptr> Meter::CreateDoubleUpDownCount } nostd::shared_ptr -Meter::CreateLongObservableUpDownCounter(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit) noexcept +Meter::CreateInt64ObservableUpDownCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit) noexcept { InstrumentDescriptor instrument_descriptor = { std::string{name.data(), name.size()}, std::string{description.data(), description.size()}, diff --git a/sdk/src/metrics/state/observable_registry.cc b/sdk/src/metrics/state/observable_registry.cc index 0d6d770f87..215f202916 100644 --- a/sdk/src/metrics/state/observable_registry.cc +++ b/sdk/src/metrics/state/observable_registry.cc @@ -70,11 +70,11 @@ void ObservableRegistry::Observe(opentelemetry::common::SystemTimestamp collecti } else { - nostd::shared_ptr> ob_res( - new opentelemetry::sdk::metrics::ObserverResultT()); + nostd::shared_ptr> ob_res( + new opentelemetry::sdk::metrics::ObserverResultT()); callback_wrap->callback(ob_res, callback_wrap->state); storage->RecordLong( - static_cast *>(ob_res.get()) + static_cast *>(ob_res.get()) ->GetMeasurements(), collection_ts); } diff --git a/sdk/src/metrics/sync_instruments.cc b/sdk/src/metrics/sync_instruments.cc index 5db5d02251..a39e622d78 100644 --- a/sdk/src/metrics/sync_instruments.cc +++ b/sdk/src/metrics/sync_instruments.cc @@ -3,8 +3,6 @@ #ifndef ENABLE_METRICS_PREVIEW # include "opentelemetry/sdk/metrics/sync_instruments.h" -# include "opentelemetry/sdk/metrics/state/metric_storage.h" -# include "opentelemetry/sdk_config.h" # include @@ -13,59 +11,6 @@ namespace sdk { namespace metrics { -LongCounter::LongCounter(InstrumentDescriptor instrument_descriptor, - std::unique_ptr storage) - : Synchronous(instrument_descriptor, std::move(storage)) -{ - if (!storage_) - { - OTEL_INTERNAL_LOG_ERROR("[LongCounter::LongCounter] - Error during constructing LongCounter." - << "The metric storage is invalid" - << "No value will be added"); - } -} - -void LongCounter::Add(long value, - const opentelemetry::common::KeyValueIterable &attributes) noexcept -{ - if (!storage_) - { - return; - } - auto context = opentelemetry::context::Context{}; - return storage_->RecordLong(value, attributes, context); -} - -void LongCounter::Add(long value, - const opentelemetry::common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept -{ - if (!storage_) - { - return; - } - return storage_->RecordLong(value, attributes, context); -} - -void LongCounter::Add(long value) noexcept -{ - auto context = opentelemetry::context::Context{}; - if (!storage_) - { - return; - } - return storage_->RecordLong(value, context); -} - -void LongCounter::Add(long value, const opentelemetry::context::Context &context) noexcept -{ - if (!storage_) - { - return; - } - return storage_->RecordLong(value, context); -} - DoubleCounter::DoubleCounter(InstrumentDescriptor instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) @@ -133,7 +78,7 @@ LongUpDownCounter::LongUpDownCounter(InstrumentDescriptor instrument_descriptor, } } -void LongUpDownCounter::Add(long value, +void LongUpDownCounter::Add(int64_t value, const opentelemetry::common::KeyValueIterable &attributes) noexcept { auto context = opentelemetry::context::Context{}; @@ -144,7 +89,7 @@ void LongUpDownCounter::Add(long value, return storage_->RecordLong(value, attributes, context); } -void LongUpDownCounter::Add(long value, +void LongUpDownCounter::Add(int64_t value, const opentelemetry::common::KeyValueIterable &attributes, const opentelemetry::context::Context &context) noexcept { @@ -155,7 +100,7 @@ void LongUpDownCounter::Add(long value, return storage_->RecordLong(value, attributes, context); } -void LongUpDownCounter::Add(long value) noexcept +void LongUpDownCounter::Add(int64_t value) noexcept { auto context = opentelemetry::context::Context{}; if (!storage_) @@ -165,7 +110,7 @@ void LongUpDownCounter::Add(long value) noexcept return storage_->RecordLong(value, context); } -void LongUpDownCounter::Add(long value, const opentelemetry::context::Context &context) noexcept +void LongUpDownCounter::Add(int64_t value, const opentelemetry::context::Context &context) noexcept { if (!storage_) { @@ -225,45 +170,6 @@ void DoubleUpDownCounter::Add(double value, const opentelemetry::context::Contex return storage_->RecordDouble(value, context); } -LongHistogram::LongHistogram(InstrumentDescriptor instrument_descriptor, - std::unique_ptr storage) - : Synchronous(instrument_descriptor, std::move(storage)) -{ - if (!storage_) - { - OTEL_INTERNAL_LOG_ERROR( - "[LongHistogram::LongHistogram] - Error during constructing LongHistogram." - << "The metric storage is invalid" - << "No value will be added"); - } -} - -void LongHistogram::Record(long value, - const opentelemetry::common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept -{ - if (value < 0) - { - OTEL_INTERNAL_LOG_WARN( - "[LongHistogram::Record(value, attributes)] negative value provided to histogram Name:" - << instrument_descriptor_.name_ << " Value:" << value); - return; - } - return storage_->RecordLong(value, attributes, context); -} - -void LongHistogram::Record(long value, const opentelemetry::context::Context &context) noexcept -{ - if (value < 0) - { - OTEL_INTERNAL_LOG_WARN( - "[LongHistogram::Record(value)] negative value provided to histogram Name:" - << instrument_descriptor_.name_ << " Value:" << value); - return; - } - return storage_->RecordLong(value, context); -} - DoubleHistogram::DoubleHistogram(InstrumentDescriptor instrument_descriptor, std::unique_ptr storage) : Synchronous(instrument_descriptor, std::move(storage)) diff --git a/sdk/test/metrics/aggregation_test.cc b/sdk/test/metrics/aggregation_test.cc index a41fa65771..33f17871aa 100644 --- a/sdk/test/metrics/aggregation_test.cc +++ b/sdk/test/metrics/aggregation_test.cc @@ -18,12 +18,12 @@ TEST(Aggregation, LongSumAggregation) auto data = aggr.ToPoint(); ASSERT_TRUE(nostd::holds_alternative(data)); auto sum_data = nostd::get(data); - ASSERT_TRUE(nostd::holds_alternative(sum_data.value_)); - EXPECT_EQ(nostd::get(sum_data.value_), 0l); - aggr.Aggregate(12l, {}); - aggr.Aggregate(0l, {}); + ASSERT_TRUE(nostd::holds_alternative(sum_data.value_)); + EXPECT_EQ(nostd::get(sum_data.value_), 0); + aggr.Aggregate((int64_t)12, {}); + aggr.Aggregate((int64_t)0, {}); sum_data = nostd::get(aggr.ToPoint()); - EXPECT_EQ(nostd::get(sum_data.value_), 12l); + EXPECT_EQ(nostd::get(sum_data.value_), 12); } TEST(Aggregation, DoubleSumAggregation) @@ -46,12 +46,12 @@ TEST(Aggregation, LongLastValueAggregation) auto data = aggr.ToPoint(); ASSERT_TRUE(nostd::holds_alternative(data)); auto lastvalue_data = nostd::get(data); - ASSERT_TRUE(nostd::holds_alternative(lastvalue_data.value_)); + ASSERT_TRUE(nostd::holds_alternative(lastvalue_data.value_)); EXPECT_EQ(lastvalue_data.is_lastvalue_valid_, false); - aggr.Aggregate(12l, {}); - aggr.Aggregate(1l, {}); + aggr.Aggregate((int64_t)12, {}); + aggr.Aggregate((int64_t)1, {}); lastvalue_data = nostd::get(aggr.ToPoint()); - EXPECT_EQ(nostd::get(lastvalue_data.value_), 1.0); + EXPECT_EQ(nostd::get(lastvalue_data.value_), 1.0); } TEST(Aggregation, DoubleLastValueAggregation) @@ -74,39 +74,39 @@ TEST(Aggregation, LongHistogramAggregation) auto data = aggr.ToPoint(); ASSERT_TRUE(nostd::holds_alternative(data)); auto histogram_data = nostd::get(data); - ASSERT_TRUE(nostd::holds_alternative(histogram_data.sum_)); - EXPECT_EQ(nostd::get(histogram_data.sum_), 0); + ASSERT_TRUE(nostd::holds_alternative(histogram_data.sum_)); + EXPECT_EQ(nostd::get(histogram_data.sum_), 0); EXPECT_EQ(histogram_data.count_, 0); - aggr.Aggregate(12l, {}); // lies in fourth bucket - aggr.Aggregate(100l, {}); // lies in eight bucket + aggr.Aggregate((int64_t)12, {}); // lies in fourth bucket + aggr.Aggregate((int64_t)100, {}); // lies in eight bucket histogram_data = nostd::get(aggr.ToPoint()); - EXPECT_EQ(nostd::get(histogram_data.min_), 12); - EXPECT_EQ(nostd::get(histogram_data.max_), 100); - EXPECT_EQ(nostd::get(histogram_data.sum_), 112); + EXPECT_EQ(nostd::get(histogram_data.min_), 12); + EXPECT_EQ(nostd::get(histogram_data.max_), 100); + EXPECT_EQ(nostd::get(histogram_data.sum_), 112); EXPECT_EQ(histogram_data.count_, 2); EXPECT_EQ(histogram_data.counts_[3], 1); EXPECT_EQ(histogram_data.counts_[7], 1); - aggr.Aggregate(13l, {}); // lies in fourth bucket - aggr.Aggregate(252l, {}); // lies in ninth bucket + aggr.Aggregate((int64_t)13, {}); // lies in fourth bucket + aggr.Aggregate((int64_t)252, {}); // lies in ninth bucket histogram_data = nostd::get(aggr.ToPoint()); EXPECT_EQ(histogram_data.count_, 4); EXPECT_EQ(histogram_data.counts_[3], 2); EXPECT_EQ(histogram_data.counts_[8], 1); - EXPECT_EQ(nostd::get(histogram_data.min_), 12); - EXPECT_EQ(nostd::get(histogram_data.max_), 252); + EXPECT_EQ(nostd::get(histogram_data.min_), 12); + EXPECT_EQ(nostd::get(histogram_data.max_), 252); // Merge LongHistogramAggregation aggr1; - aggr1.Aggregate(1l, {}); - aggr1.Aggregate(11l, {}); - aggr1.Aggregate(26l, {}); + aggr1.Aggregate((int64_t)1, {}); + aggr1.Aggregate((int64_t)11, {}); + aggr1.Aggregate((int64_t)26, {}); LongHistogramAggregation aggr2; - aggr2.Aggregate(2l, {}); - aggr2.Aggregate(3l, {}); - aggr2.Aggregate(13l, {}); - aggr2.Aggregate(28l, {}); - aggr2.Aggregate(105l, {}); + aggr2.Aggregate((int64_t)2, {}); + aggr2.Aggregate((int64_t)3, {}); + aggr2.Aggregate((int64_t)13, {}); + aggr2.Aggregate((int64_t)28, {}); + aggr2.Aggregate((int64_t)105, {}); auto aggr3 = aggr1.Merge(aggr2); histogram_data = nostd::get(aggr3->ToPoint()); @@ -116,8 +116,8 @@ TEST(Aggregation, LongHistogramAggregation) EXPECT_EQ(histogram_data.counts_[3], 2); // 11, 13 EXPECT_EQ(histogram_data.counts_[4], 2); // 25, 28 EXPECT_EQ(histogram_data.counts_[7], 1); // 105 - EXPECT_EQ(nostd::get(histogram_data.min_), 1); - EXPECT_EQ(nostd::get(histogram_data.max_), 105); + EXPECT_EQ(nostd::get(histogram_data.min_), 1); + EXPECT_EQ(nostd::get(histogram_data.max_), 105); // Diff auto aggr4 = aggr1.Diff(aggr2); diff --git a/sdk/test/metrics/async_metric_storage_test.cc b/sdk/test/metrics/async_metric_storage_test.cc index 01c04d609e..fd4df4d7f8 100644 --- a/sdk/test/metrics/async_metric_storage_test.cc +++ b/sdk/test/metrics/async_metric_storage_test.cc @@ -1,8 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include #ifndef ENABLE_METRICS_PREVIEW -# include "opentelemetry/sdk/metrics/state/async_metric_storage.h" # include "opentelemetry/common/key_value_iterable_view.h" # include "opentelemetry/sdk/metrics/async_instruments.h" # include "opentelemetry/sdk/metrics/instruments.h" @@ -10,6 +10,7 @@ # include "opentelemetry/sdk/metrics/metric_reader.h" # include "opentelemetry/sdk/metrics/observer_result.h" # include "opentelemetry/sdk/metrics/push_metric_exporter.h" +# include "opentelemetry/sdk/metrics/state/async_metric_storage.h" # include "opentelemetry/sdk/metrics/state/metric_collector.h" # include "opentelemetry/sdk/metrics/state/observable_registry.h" @@ -69,9 +70,9 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation) new DefaultAttributesProcessor{}}; opentelemetry::sdk::metrics::AsyncMetricStorage storage( instr_desc, AggregationType::kSum, default_attributes_processor.get(), nullptr); - long get_count1 = 20l; - long put_count1 = 10l; - std::unordered_map measurements1 = { + int64_t get_count1 = 20; + int64_t put_count1 = 10; + std::unordered_map measurements1 = { {{{"RequestType", "GET"}}, get_count1}, {{{"RequestType", "PUT"}}, put_count1}}; storage.RecordLong(measurements1, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); @@ -84,22 +85,22 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation) if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count1); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count1); } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count1); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count1); } } return true; }); // subsequent recording after collection shouldn't fail // monotonic increasing values; - long get_count2 = 50l; - long put_count2 = 70l; + int64_t get_count2 = 50; + int64_t put_count2 = 70; - std::unordered_map measurements2 = { + std::unordered_map measurements2 = { {{{"RequestType", "GET"}}, get_count2}, {{{"RequestType", "PUT"}}, put_count2}}; storage.RecordLong(measurements2, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); @@ -113,11 +114,11 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation) { if (temporality == AggregationTemporality::kCumulative) { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count2); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count2); } else { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count2 - get_count1); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), get_count2 - get_count1); } } else if (opentelemetry::nostd::get( @@ -125,11 +126,11 @@ TEST_P(WritableMetricStorageTestFixture, TestAggregation) { if (temporality == AggregationTemporality::kCumulative) { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count2); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count2); } else { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count2 - put_count1); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), put_count2 - put_count1); } } } @@ -161,9 +162,9 @@ TEST_P(WritableMetricStorageTestObservableGaugeFixture, TestAggregation) new DefaultAttributesProcessor{}}; opentelemetry::sdk::metrics::AsyncMetricStorage storage( instr_desc, AggregationType::kLastValue, default_attributes_processor.get(), nullptr); - long freq_cpu0 = 3l; - long freq_cpu1 = 5l; - std::unordered_map measurements1 = { + int64_t freq_cpu0 = 3; + int64_t freq_cpu1 = 5; + std::unordered_map measurements1 = { {{{"CPU", "0"}}, freq_cpu0}, {{{"CPU", "1"}}, freq_cpu1}}; storage.RecordLong(measurements1, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); @@ -176,21 +177,21 @@ TEST_P(WritableMetricStorageTestObservableGaugeFixture, TestAggregation) if (opentelemetry::nostd::get(data_attr.attributes.find("CPU")->second) == "0") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), freq_cpu0); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), freq_cpu0); } else if (opentelemetry::nostd::get( data_attr.attributes.find("CPU")->second) == "1") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), freq_cpu1); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), freq_cpu1); } } return true; }); - freq_cpu0 = 6l; - freq_cpu1 = 8l; + freq_cpu0 = 6; + freq_cpu1 = 8; - std::unordered_map measurements2 = { + std::unordered_map measurements2 = { {{{"CPU", "0"}}, freq_cpu0}, {{{"CPU", "1"}}, freq_cpu1}}; storage.RecordLong(measurements2, opentelemetry::common::SystemTimestamp(std::chrono::system_clock::now())); @@ -202,12 +203,12 @@ TEST_P(WritableMetricStorageTestObservableGaugeFixture, TestAggregation) if (opentelemetry::nostd::get(data_attr.attributes.find("CPU")->second) == "0") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), freq_cpu0); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), freq_cpu0); } else if (opentelemetry::nostd::get( data_attr.attributes.find("CPU")->second) == "1") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), freq_cpu1); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), freq_cpu1); } } return true; diff --git a/sdk/test/metrics/attributes_hashmap_benchmark.cc b/sdk/test/metrics/attributes_hashmap_benchmark.cc index af7ead0778..2e90291e7c 100644 --- a/sdk/test/metrics/attributes_hashmap_benchmark.cc +++ b/sdk/test/metrics/attributes_hashmap_benchmark.cc @@ -33,7 +33,7 @@ void BM_AttributseHashMap(benchmark::State &state) return std::unique_ptr(new DropAggregation); }; m.lock(); - hash_map.GetOrSetDefault(attributes[i % 2], create_default_aggregation)->Aggregate(1l); + hash_map.GetOrSetDefault(attributes[i % 2], create_default_aggregation)->Aggregate((int64_t)1); benchmark::DoNotOptimize(hash_map.Has(attributes[i % 2])); m.unlock(); }; diff --git a/sdk/test/metrics/attributes_hashmap_test.cc b/sdk/test/metrics/attributes_hashmap_test.cc index 0d95fbad61..c4a58b4813 100644 --- a/sdk/test/metrics/attributes_hashmap_test.cc +++ b/sdk/test/metrics/attributes_hashmap_test.cc @@ -26,14 +26,14 @@ TEST(AttributesHashMap, BasicTests) std::unique_ptr aggregation1( new DropAggregation()); // = std::unique_ptr(new DropAggregation); hash_map.Set(m1, std::move(aggregation1)); - EXPECT_NO_THROW(hash_map.Get(m1)->Aggregate(1l)); + EXPECT_NO_THROW(hash_map.Get(m1)->Aggregate((int64_t)1)); EXPECT_EQ(hash_map.Size(), 1); EXPECT_EQ(hash_map.Has(m1), true); // Set same key again auto aggregation2 = std::unique_ptr(new DropAggregation()); hash_map.Set(m1, std::move(aggregation2)); - EXPECT_NO_THROW(hash_map.Get(m1)->Aggregate(1l)); + EXPECT_NO_THROW(hash_map.Get(m1)->Aggregate((int64_t)1)); EXPECT_EQ(hash_map.Size(), 1); EXPECT_EQ(hash_map.Has(m1), true); @@ -43,7 +43,7 @@ TEST(AttributesHashMap, BasicTests) hash_map.Set(m3, std::move(aggregation3)); EXPECT_EQ(hash_map.Has(m1), true); EXPECT_EQ(hash_map.Has(m3), true); - EXPECT_NO_THROW(hash_map.Get(m3)->Aggregate(1l)); + EXPECT_NO_THROW(hash_map.Get(m3)->Aggregate((int64_t)1)); EXPECT_EQ(hash_map.Size(), 2); // GetOrSetDefault @@ -52,7 +52,7 @@ TEST(AttributesHashMap, BasicTests) return std::unique_ptr(new DropAggregation); }; MetricAttributes m4 = {{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}; - EXPECT_NO_THROW(hash_map.GetOrSetDefault(m4, create_default_aggregation)->Aggregate(1l)); + EXPECT_NO_THROW(hash_map.GetOrSetDefault(m4, create_default_aggregation)->Aggregate((int64_t)1)); EXPECT_EQ(hash_map.Size(), 3); // Set attributes with different order - shouldn't create a new entry. diff --git a/sdk/test/metrics/exemplar/always_sample_filter_test.cc b/sdk/test/metrics/exemplar/always_sample_filter_test.cc index 5f9716f60d..a2f70c1585 100644 --- a/sdk/test/metrics/exemplar/always_sample_filter_test.cc +++ b/sdk/test/metrics/exemplar/always_sample_filter_test.cc @@ -12,8 +12,8 @@ TEST(AlwaysSampleFilter, SampleMeasurement) auto filter = opentelemetry::sdk::metrics::ExemplarFilter::GetAlwaysSampleFilter(); ASSERT_TRUE( filter->ShouldSampleMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{})); - ASSERT_TRUE( - filter->ShouldSampleMeasurement(1l, MetricAttributes{}, opentelemetry::context::Context{})); + ASSERT_TRUE(filter->ShouldSampleMeasurement((int64_t)1, MetricAttributes{}, + opentelemetry::context::Context{})); } #endif diff --git a/sdk/test/metrics/exemplar/histogram_exemplar_reservoir_test.cc b/sdk/test/metrics/exemplar/histogram_exemplar_reservoir_test.cc index 1f7b3100ea..0d180b3836 100644 --- a/sdk/test/metrics/exemplar/histogram_exemplar_reservoir_test.cc +++ b/sdk/test/metrics/exemplar/histogram_exemplar_reservoir_test.cc @@ -23,8 +23,9 @@ TEST_F(HistogramExemplarReservoirTestPeer, OfferMeasurement) boundaries.size(), HistogramExemplarReservoir::GetHistogramCellSelector(boundaries), nullptr); histogram_exemplar_reservoir->OfferMeasurement( 1.0, MetricAttributes{}, opentelemetry::context::Context{}, std::chrono::system_clock::now()); - histogram_exemplar_reservoir->OfferMeasurement( - 1l, MetricAttributes{}, opentelemetry::context::Context{}, std::chrono::system_clock::now()); + histogram_exemplar_reservoir->OfferMeasurement((int64_t)1, MetricAttributes{}, + opentelemetry::context::Context{}, + std::chrono::system_clock::now()); auto exemplar_data = histogram_exemplar_reservoir->CollectAndReset(MetricAttributes{}); ASSERT_TRUE(exemplar_data.empty()); } diff --git a/sdk/test/metrics/exemplar/never_sample_filter_test.cc b/sdk/test/metrics/exemplar/never_sample_filter_test.cc index 4e40015e8f..61d991e41e 100644 --- a/sdk/test/metrics/exemplar/never_sample_filter_test.cc +++ b/sdk/test/metrics/exemplar/never_sample_filter_test.cc @@ -13,8 +13,8 @@ TEST(NeverSampleFilter, SampleMeasurement) auto filter = opentelemetry::sdk::metrics::ExemplarFilter::GetNeverSampleFilter(); ASSERT_FALSE( filter->ShouldSampleMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{})); - ASSERT_FALSE( - filter->ShouldSampleMeasurement(1l, MetricAttributes{}, opentelemetry::context::Context{})); + ASSERT_FALSE(filter->ShouldSampleMeasurement((int64_t)1, MetricAttributes{}, + opentelemetry::context::Context{})); } #endif diff --git a/sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc b/sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc index a0f645fee1..d93ac0a018 100644 --- a/sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc +++ b/sdk/test/metrics/exemplar/no_exemplar_reservoir_test.cc @@ -12,7 +12,7 @@ TEST(NoExemplarReservoir, OfferMeasurement) auto reservoir = opentelemetry::sdk::metrics::ExemplarReservoir::GetNoExemplarReservoir(); reservoir->OfferMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{}, std::chrono::system_clock::now()); - reservoir->OfferMeasurement(1l, MetricAttributes{}, opentelemetry::context::Context{}, + reservoir->OfferMeasurement((int64_t)1, MetricAttributes{}, opentelemetry::context::Context{}, std::chrono::system_clock::now()); auto exemplar_data = reservoir->CollectAndReset(MetricAttributes{}); ASSERT_TRUE(exemplar_data.empty()); diff --git a/sdk/test/metrics/exemplar/reservoir_cell_test.cc b/sdk/test/metrics/exemplar/reservoir_cell_test.cc index a42f11151a..c73701b9af 100644 --- a/sdk/test/metrics/exemplar/reservoir_cell_test.cc +++ b/sdk/test/metrics/exemplar/reservoir_cell_test.cc @@ -13,9 +13,9 @@ namespace metrics class ReservoirCellTestPeer : public ::testing::Test { public: - long GetLongVal(const opentelemetry::sdk::metrics::ReservoirCell &reservoir_cell) + int64_t GetLongVal(const opentelemetry::sdk::metrics::ReservoirCell &reservoir_cell) { - return nostd::get(reservoir_cell.value_); + return nostd::get(reservoir_cell.value_); } double GetDoubleVal(const opentelemetry::sdk::metrics::ReservoirCell &reservoir_cell) @@ -42,7 +42,8 @@ class ReservoirCellTestPeer : public ::testing::Test TEST_F(ReservoirCellTestPeer, recordMeasurement) { opentelemetry::sdk::metrics::ReservoirCell reservoir_cell; - reservoir_cell.RecordLongMeasurement(1l, MetricAttributes{}, opentelemetry::context::Context{}); + reservoir_cell.RecordLongMeasurement((int64_t)1, MetricAttributes{}, + opentelemetry::context::Context{}); ASSERT_TRUE(GetLongVal(reservoir_cell) == 1); reservoir_cell.RecordDoubleMeasurement(1.5, MetricAttributes{}, diff --git a/sdk/test/metrics/exemplar/with_trace_sample_filter_test.cc b/sdk/test/metrics/exemplar/with_trace_sample_filter_test.cc index 1c46dcddd6..77bc534f46 100644 --- a/sdk/test/metrics/exemplar/with_trace_sample_filter_test.cc +++ b/sdk/test/metrics/exemplar/with_trace_sample_filter_test.cc @@ -13,8 +13,8 @@ TEST(WithTraceSampleFilter, SampleMeasurement) auto filter = opentelemetry::sdk::metrics::ExemplarFilter::GetWithTraceSampleFilter(); ASSERT_FALSE( filter->ShouldSampleMeasurement(1.0, MetricAttributes{}, opentelemetry::context::Context{})); - ASSERT_FALSE( - filter->ShouldSampleMeasurement(1l, MetricAttributes{}, opentelemetry::context::Context{})); + ASSERT_FALSE(filter->ShouldSampleMeasurement((int64_t)1, MetricAttributes{}, + opentelemetry::context::Context{})); } #endif diff --git a/sdk/test/metrics/meter_test.cc b/sdk/test/metrics/meter_test.cc index b4cd12416c..ec78a23707 100644 --- a/sdk/test/metrics/meter_test.cc +++ b/sdk/test/metrics/meter_test.cc @@ -46,15 +46,15 @@ nostd::shared_ptr InitMeter(MetricReader **metricReaderPtr, void asyc_generate_measurements(opentelemetry::metrics::ObserverResult observer, void * /* state */) { auto observer_long = - nostd::get>>(observer); - observer_long->Observe(10l); + nostd::get>>(observer); + observer_long->Observe(10); } TEST(MeterTest, BasicAsyncTests) { MetricReader *metric_reader_ptr = nullptr; auto meter = InitMeter(&metric_reader_ptr); - auto observable_counter = meter->CreateLongObservableCounter("observable_counter"); + auto observable_counter = meter->CreateInt64ObservableCounter("observable_counter"); observable_counter->AddCallback(asyc_generate_measurements, nullptr); size_t count = 0; @@ -99,15 +99,15 @@ TEST(MeterTest, StressMultiThread) if (do_sync_create.exchange(false)) { std::string instrument_name = "test_couter_" + std::to_string(instrument_id); - meter->CreateLongCounter(instrument_name, "", ""); + meter->CreateUInt64Counter(instrument_name, "", ""); do_async_create.store(true); instrument_id++; } if (do_async_create.exchange(false)) { std::cout << "\n creating async thread " << std::to_string(numIterations); - auto observable_instrument = - meter->CreateLongObservableGauge("test_gauge_" + std::to_string(instrument_id)); + auto observable_instrument = meter->CreateInt64ObservableUpDownCounter( + "test_gauge_" + std::to_string(instrument_id)); observable_instrument->AddCallback(asyc_generate_measurements, nullptr); observable_instruments.push_back(std::move(observable_instrument)); do_collect.store(true); diff --git a/sdk/test/metrics/multi_metric_storage_test.cc b/sdk/test/metrics/multi_metric_storage_test.cc index 66e336192d..30d2e4ccb9 100644 --- a/sdk/test/metrics/multi_metric_storage_test.cc +++ b/sdk/test/metrics/multi_metric_storage_test.cc @@ -16,13 +16,13 @@ using namespace opentelemetry::sdk::metrics; class TestMetricStorage : public SyncWritableMetricStorage { public: - void RecordLong(long /* value */, + void RecordLong(int64_t /* value */, const opentelemetry::context::Context & /* context */) noexcept override { num_calls_long++; } - void RecordLong(long /* value */, + void RecordLong(int64_t /* value */, const opentelemetry::common::KeyValueIterable & /* attributes */, const opentelemetry::context::Context & /* context */) noexcept override { @@ -52,11 +52,11 @@ TEST(MultiMetricStorageTest, BasicTests) new TestMetricStorage()); SyncMultiMetricStorage storages{}; storages.AddStorage(storage); - storages.RecordLong(10l, opentelemetry::context::Context{}); - storages.RecordLong(20l, opentelemetry::context::Context{}); + storages.RecordLong(10, opentelemetry::context::Context{}); + storages.RecordLong(20, opentelemetry::context::Context{}); storages.RecordDouble(10.0, opentelemetry::context::Context{}); - storages.RecordLong(30l, opentelemetry::context::Context{}); + storages.RecordLong(30, opentelemetry::context::Context{}); EXPECT_EQ(static_cast(storage.get())->num_calls_long, 3); EXPECT_EQ(static_cast(storage.get())->num_calls_double, 1); diff --git a/sdk/test/metrics/observable_registry_test.cc b/sdk/test/metrics/observable_registry_test.cc index bfbb83fe9d..a0ee283ef7 100644 --- a/sdk/test/metrics/observable_registry_test.cc +++ b/sdk/test/metrics/observable_registry_test.cc @@ -19,17 +19,17 @@ class MeasurementFetcher fetch_count1++; if (fetch_count1 == 1) { - std::get observer_result(attributes_processor); + ObserverResultT observer_result(attributes_processor); - observer_result.Observe(10l); - observer_result.Observe(20l); + observer_result.Observe(10); + observer_result.Observe(20); EXPECT_EQ(observer_result.GetMeasurements().size(), 1); std::map m1 = {{"k2", 12}}; observer_result.Observe( - 30l, opentelemetry::common::KeyValueIterableView>(m1)); + 30, opentelemetry::common::KeyValueIterableView>(m1)); EXPECT_EQ(observer_result.GetMeasurements().size(), 2); observer_result.Observe( - 40l, opentelemetry::common::KeyValueIterableView>(m1)); + 40, opentelemetry::common::KeyValueIterableView>(m1)); EXPECT_EQ(observer_result.GetMeasurements().size(), 2); std::map m2 = {{"k2", 12}, {"k4", 12}}; observer_result.Observe( - 40l, opentelemetry::common::KeyValueIterableView>(m2)); + 40, opentelemetry::common::KeyValueIterableView>(m2)); EXPECT_EQ(observer_result.GetMeasurements().size(), 3); delete attributes_processor; diff --git a/sdk/test/metrics/sync_instruments_test.cc b/sdk/test/metrics/sync_instruments_test.cc index 696bf7ae49..fd9240518a 100644 --- a/sdk/test/metrics/sync_instruments_test.cc +++ b/sdk/test/metrics/sync_instruments_test.cc @@ -25,16 +25,15 @@ TEST(SyncInstruments, LongCounter) InstrumentDescriptor instrument_descriptor = { "long_counter", "description", "1", InstrumentType::kCounter, InstrumentValueType::kLong}; std::unique_ptr metric_storage(new SyncMultiMetricStorage()); - LongCounter counter(instrument_descriptor, std::move(metric_storage)); - counter.Add(10l); - counter.Add(10l, opentelemetry::context::Context{}); + LongCounter counter(instrument_descriptor, std::move(metric_storage)); + counter.Add(10); + counter.Add(10, opentelemetry::context::Context{}); - counter.Add(10l, - opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}})); - counter.Add(10l, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}), + counter.Add(10, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}})); + counter.Add(10, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}), opentelemetry::context::Context{}); - counter.Add(10l, opentelemetry::common::KeyValueIterableView({})); - counter.Add(10l, opentelemetry::common::KeyValueIterableView({}), + counter.Add(10, opentelemetry::common::KeyValueIterableView({})); + counter.Add(10, opentelemetry::common::KeyValueIterableView({}), opentelemetry::context::Context{}); } @@ -64,15 +63,14 @@ TEST(SyncInstruments, LongUpDownCounter) InstrumentValueType::kLong}; std::unique_ptr metric_storage(new SyncMultiMetricStorage()); LongUpDownCounter counter(instrument_descriptor, std::move(metric_storage)); - counter.Add(10l); - counter.Add(10l, opentelemetry::context::Context{}); + counter.Add(10); + counter.Add(10, opentelemetry::context::Context{}); - counter.Add(10l, - opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}})); - counter.Add(10l, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}), + counter.Add(10, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}})); + counter.Add(10, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}), opentelemetry::context::Context{}); - counter.Add(10l, opentelemetry::common::KeyValueIterableView({})); - counter.Add(10l, opentelemetry::common::KeyValueIterableView({}), + counter.Add(10, opentelemetry::common::KeyValueIterableView({})); + counter.Add(10, opentelemetry::common::KeyValueIterableView({}), opentelemetry::context::Context{}); } @@ -101,14 +99,14 @@ TEST(SyncInstruments, LongHistogram) InstrumentDescriptor instrument_descriptor = { "long_histogram", "description", "1", InstrumentType::kHistogram, InstrumentValueType::kLong}; std::unique_ptr metric_storage(new SyncMultiMetricStorage()); - LongHistogram counter(instrument_descriptor, std::move(metric_storage)); - counter.Record(10l, opentelemetry::context::Context{}); - counter.Record(-10l, opentelemetry::context::Context{}); // This is ignored + LongHistogram counter(instrument_descriptor, std::move(metric_storage)); + counter.Record(10, opentelemetry::context::Context{}); + counter.Record(-10, opentelemetry::context::Context{}); // This is ignored - counter.Record(10l, + counter.Record(10, opentelemetry::common::KeyValueIterableView({{"abc", "123"}, {"xyz", "456"}}), opentelemetry::context::Context{}); - counter.Record(10l, opentelemetry::common::KeyValueIterableView({}), + counter.Record(10, opentelemetry::common::KeyValueIterableView({}), opentelemetry::context::Context{}); } diff --git a/sdk/test/metrics/sync_metric_storage_counter_test.cc b/sdk/test/metrics/sync_metric_storage_counter_test.cc index 5a41c0ad5e..f182d36f4f 100644 --- a/sdk/test/metrics/sync_metric_storage_counter_test.cc +++ b/sdk/test/metrics/sync_metric_storage_counter_test.cc @@ -40,11 +40,11 @@ class WritableMetricStorageTestFixture : public ::testing::TestWithParam attributes_get = {{"RequestType", "GET"}}; std::map attributes_put = {{"RequestType", "PUT"}}; @@ -55,19 +55,19 @@ TEST_P(WritableMetricStorageTestFixture, LongSumAggregation) instr_desc, AggregationType::kSum, default_attributes_processor.get(), ExemplarReservoir::GetNoExemplarReservoir(), nullptr); - storage.RecordLong(10l, KeyValueIterableView>(attributes_get), + storage.RecordLong(10, KeyValueIterableView>(attributes_get), opentelemetry::context::Context{}); expected_total_get_requests += 10; - storage.RecordLong(30l, KeyValueIterableView>(attributes_put), + storage.RecordLong(30, KeyValueIterableView>(attributes_put), opentelemetry::context::Context{}); expected_total_put_requests += 30; - storage.RecordLong(20l, KeyValueIterableView>(attributes_get), + storage.RecordLong(20, KeyValueIterableView>(attributes_get), opentelemetry::context::Context{}); expected_total_get_requests += 20; - storage.RecordLong(40l, KeyValueIterableView>(attributes_put), + storage.RecordLong(40, KeyValueIterableView>(attributes_put), opentelemetry::context::Context{}); expected_total_put_requests += 40; @@ -86,13 +86,13 @@ TEST_P(WritableMetricStorageTestFixture, LongSumAggregation) if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_get_requests); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_get_requests); count_attributes++; } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_put_requests); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_put_requests); count_attributes++; } } @@ -119,13 +119,13 @@ TEST_P(WritableMetricStorageTestFixture, LongSumAggregation) data_attr.attributes.find("RequestType")->second) == "GET") { count_attributes++; - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_get_requests); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_get_requests); } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { count_attributes++; - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_put_requests); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_put_requests); } } return true; @@ -135,10 +135,10 @@ TEST_P(WritableMetricStorageTestFixture, LongSumAggregation) EXPECT_EQ(count_attributes, 2); // GET AND PUT } - storage.RecordLong(50l, KeyValueIterableView>(attributes_get), + storage.RecordLong(50, KeyValueIterableView>(attributes_get), opentelemetry::context::Context{}); expected_total_get_requests += 50; - storage.RecordLong(40l, KeyValueIterableView>(attributes_put), + storage.RecordLong(40, KeyValueIterableView>(attributes_put), opentelemetry::context::Context{}); expected_total_put_requests += 40; @@ -152,13 +152,13 @@ TEST_P(WritableMetricStorageTestFixture, LongSumAggregation) if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_get_requests); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_get_requests); count_attributes++; } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { - EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_put_requests); + EXPECT_EQ(opentelemetry::nostd::get(data.value_), expected_total_put_requests); count_attributes++; } } diff --git a/sdk/test/metrics/sync_metric_storage_histogram_test.cc b/sdk/test/metrics/sync_metric_storage_histogram_test.cc index 21042f5460..a50848ad3d 100644 --- a/sdk/test/metrics/sync_metric_storage_histogram_test.cc +++ b/sdk/test/metrics/sync_metric_storage_histogram_test.cc @@ -41,11 +41,11 @@ class WritableMetricStorageHistogramTestFixture TEST_P(WritableMetricStorageHistogramTestFixture, LongHistogram) { - AggregationTemporality temporality = GetParam(); - auto sdk_start_ts = std::chrono::system_clock::now(); - long expected_total_get_requests = 0; - long expected_total_put_requests = 0; - InstrumentDescriptor instr_desc = {"name", "desc", "1unit", InstrumentType::kHistogram, + AggregationTemporality temporality = GetParam(); + auto sdk_start_ts = std::chrono::system_clock::now(); + int64_t expected_total_get_requests = 0; + int64_t expected_total_put_requests = 0; + InstrumentDescriptor instr_desc = {"name", "desc", "1unit", InstrumentType::kHistogram, InstrumentValueType::kLong}; std::map attributes_get = {{"RequestType", "GET"}}; std::map attributes_put = {{"RequestType", "PUT"}}; @@ -56,19 +56,19 @@ TEST_P(WritableMetricStorageHistogramTestFixture, LongHistogram) instr_desc, AggregationType::kHistogram, default_attributes_processor.get(), NoExemplarReservoir::GetNoExemplarReservoir(), nullptr); - storage.RecordLong(10l, KeyValueIterableView>(attributes_get), + storage.RecordLong(10, KeyValueIterableView>(attributes_get), opentelemetry::context::Context{}); expected_total_get_requests += 10; - storage.RecordLong(30l, KeyValueIterableView>(attributes_put), + storage.RecordLong(30, KeyValueIterableView>(attributes_put), opentelemetry::context::Context{}); expected_total_put_requests += 30; - storage.RecordLong(20l, KeyValueIterableView>(attributes_get), + storage.RecordLong(20, KeyValueIterableView>(attributes_get), opentelemetry::context::Context{}); expected_total_get_requests += 20; - storage.RecordLong(40l, KeyValueIterableView>(attributes_put), + storage.RecordLong(40, KeyValueIterableView>(attributes_put), opentelemetry::context::Context{}); expected_total_put_requests += 40; @@ -87,13 +87,13 @@ TEST_P(WritableMetricStorageHistogramTestFixture, LongHistogram) if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { - EXPECT_EQ(opentelemetry::nostd::get(data.sum_), expected_total_get_requests); + EXPECT_EQ(opentelemetry::nostd::get(data.sum_), expected_total_get_requests); count_attributes++; } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { - EXPECT_EQ(opentelemetry::nostd::get(data.sum_), expected_total_put_requests); + EXPECT_EQ(opentelemetry::nostd::get(data.sum_), expected_total_put_requests); count_attributes++; } } @@ -120,13 +120,13 @@ TEST_P(WritableMetricStorageHistogramTestFixture, LongHistogram) data_attr.attributes.find("RequestType")->second) == "GET") { count_attributes++; - EXPECT_EQ(opentelemetry::nostd::get(data.sum_), expected_total_get_requests); + EXPECT_EQ(opentelemetry::nostd::get(data.sum_), expected_total_get_requests); } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { count_attributes++; - EXPECT_EQ(opentelemetry::nostd::get(data.sum_), expected_total_put_requests); + EXPECT_EQ(opentelemetry::nostd::get(data.sum_), expected_total_put_requests); } } return true; @@ -136,10 +136,10 @@ TEST_P(WritableMetricStorageHistogramTestFixture, LongHistogram) EXPECT_EQ(count_attributes, 2); // GET AND PUT } - storage.RecordLong(50l, KeyValueIterableView>(attributes_get), + storage.RecordLong(50, KeyValueIterableView>(attributes_get), opentelemetry::context::Context{}); expected_total_get_requests += 50; - storage.RecordLong(40l, KeyValueIterableView>(attributes_put), + storage.RecordLong(40, KeyValueIterableView>(attributes_put), opentelemetry::context::Context{}); expected_total_put_requests += 40; @@ -153,13 +153,13 @@ TEST_P(WritableMetricStorageHistogramTestFixture, LongHistogram) if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "GET") { - EXPECT_EQ(opentelemetry::nostd::get(data.sum_), expected_total_get_requests); + EXPECT_EQ(opentelemetry::nostd::get(data.sum_), expected_total_get_requests); count_attributes++; } else if (opentelemetry::nostd::get( data_attr.attributes.find("RequestType")->second) == "PUT") { - EXPECT_EQ(opentelemetry::nostd::get(data.sum_), expected_total_put_requests); + EXPECT_EQ(opentelemetry::nostd::get(data.sum_), expected_total_put_requests); count_attributes++; } }