diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index 2a7d56411f..25f350e5fb 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -80,13 +80,9 @@ class NoopGauge : public Gauge nostd::string_view /* description */, nostd::string_view /* unit */) noexcept {} - void Record(T /* value */, const context::Context & /* context */) noexcept override {} void Record(T /* value */, - const common::KeyValueIterable & /* attributes */, - const context::Context & /* context */) noexcept override - {} - void Record(T value) noexcept override {} - void Record(T value, const opentelemetry::common::KeyValueIterable &attributes) noexcept override + const common::KeyValueIterable * /* attributes */, + const context::Context * /* context */) noexcept override {} }; #endif diff --git a/api/include/opentelemetry/metrics/sync_instruments.h b/api/include/opentelemetry/metrics/sync_instruments.h index 811e2b2d5a..4950c2c13d 100644 --- a/api/include/opentelemetry/metrics/sync_instruments.h +++ b/api/include/opentelemetry/metrics/sync_instruments.h @@ -259,39 +259,59 @@ class Gauge : public SynchronousInstrument { public: /** - * Record a value + * Record a value with a set of attributes. * * @param value The increment amount. MUST be non-negative. + * @param attributes A set of attributes to associate with the value. + * @param context The explicit context to associate with this measurement. */ - virtual void Record(T value) noexcept = 0; + virtual void Record(T value, + const common::KeyValueIterable *attributes, + const context::Context *context) noexcept = 0; /** - * Record a value + * Record a value with a set of attributes. * * @param value The increment amount. MUST be non-negative. + * @param attributes A set of attributes to associate with the value. * @param context The explicit context to associate with this measurement. */ - virtual void Record(T value, const context::Context &context) noexcept = 0; + void Record(T value, + const common::KeyValueIterable &attributes, + const context::Context &context) noexcept + { + this->Record(value, &attributes, &context); + } /** - * Record a value with a set of attributes. + * Record a value * * @param value The increment amount. MUST be non-negative. - * @param attributes A set of attributes to associate with the value. */ + virtual void Record(T value) noexcept { this->Record(value, nullptr, nullptr); } - virtual void Record(T value, const common::KeyValueIterable &attributes) noexcept = 0; + /** + * Record a value + * + * @param value The increment amount. MUST be non-negative. + * @param context The explicit context to associate with this measurement. + */ + void Record(T value, const context::Context &context) noexcept + { + this->Record(value, nullptr, &context); + } /** * Record a value with a set of attributes. * * @param value The increment amount. MUST be non-negative. * @param attributes A set of attributes to associate with the value. - * @param context The explicit context to associate with this measurement. */ - virtual void Record(T value, - const common::KeyValueIterable &attributes, - const context::Context &context) noexcept = 0; + + void Record(T value, const common::KeyValueIterable &attributes) noexcept + { + this->Record(value, &attributes, nullptr); + } template ::value> * = nullptr> diff --git a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h index 8f5905e3a5..ee5661046a 100644 --- a/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h +++ b/sdk/include/opentelemetry/sdk/metrics/aggregation/default_aggregation.h @@ -179,9 +179,7 @@ class DefaultAggregation return AggregationType::kSum; case InstrumentType::kHistogram: return AggregationType::kHistogram; -#if OPENTELEMETRY_ABI_VERSION_NO >= 2 case InstrumentType::kGauge: -#endif case InstrumentType::kObservableGauge: return AggregationType::kLastValue; default: diff --git a/sdk/include/opentelemetry/sdk/metrics/instruments.h b/sdk/include/opentelemetry/sdk/metrics/instruments.h index 6d6375f644..375c4d70e8 100644 --- a/sdk/include/opentelemetry/sdk/metrics/instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/instruments.h @@ -19,9 +19,7 @@ enum class InstrumentType kCounter, kHistogram, kUpDownCounter, -#if OPENTELEMETRY_ABI_VERSION_NO >= 2 kGauge, -#endif kObservableCounter, kObservableGauge, kObservableUpDownCounter diff --git a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h index 210ed805b0..9f7485b970 100644 --- a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h @@ -144,19 +144,13 @@ class DoubleHistogram : public Synchronous, public opentelemetry::metrics::Histo class LongGauge : public Synchronous, public opentelemetry::metrics::Gauge { - public: LongGauge(InstrumentDescriptor instrument_descriptor, std::unique_ptr storage); void Record(uint64_t value, - const opentelemetry::common::KeyValueIterable &attributes) noexcept override; - void Record(uint64_t value, - const opentelemetry::common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept override; - - void Record(uint64_t value) noexcept override; - void Record(uint64_t value, const opentelemetry::context::Context &context) noexcept override; + const opentelemetry::common::KeyValueIterable *attributes, + const opentelemetry::context::Context *context) noexcept override; }; class DoubleGauge : public Synchronous, public opentelemetry::metrics::Gauge @@ -166,13 +160,8 @@ class DoubleGauge : public Synchronous, public opentelemetry::metrics::Gauge storage); void Record(double value, - const opentelemetry::common::KeyValueIterable &attributes) noexcept override; - void Record(double value, - const opentelemetry::common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept override; - - void Record(double value) noexcept override; - void Record(double value, const opentelemetry::context::Context &context) noexcept override; + const opentelemetry::common::KeyValueIterable *attributes, + const opentelemetry::context::Context *context) noexcept override; }; #endif diff --git a/sdk/src/metrics/sync_instruments.cc b/sdk/src/metrics/sync_instruments.cc index a3096e053b..511976ba80 100644 --- a/sdk/src/metrics/sync_instruments.cc +++ b/sdk/src/metrics/sync_instruments.cc @@ -453,8 +453,8 @@ LongGauge::LongGauge(InstrumentDescriptor instrument_descriptor, } void LongGauge::Record(uint64_t value, - const opentelemetry::common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept + const opentelemetry::common::KeyValueIterable *attributes, + const opentelemetry::context::Context *context) noexcept { if (!storage_) { @@ -462,43 +462,7 @@ void LongGauge::Record(uint64_t value, << instrument_descriptor_.name_); return; } - return storage_->RecordLong(value, attributes, context); -} - -void LongGauge::Record(uint64_t value, const opentelemetry::context::Context &context) noexcept -{ - if (!storage_) - { - OTEL_INTERNAL_LOG_WARN("[LongGauge::Record(V,C)] Value not recorded - invalid storage for: " - << instrument_descriptor_.name_); - return; - } - return storage_->RecordLong(value, context); -} - -void LongGauge::Record(uint64_t value, - const opentelemetry::common::KeyValueIterable &attributes) noexcept -{ - if (!storage_) - { - OTEL_INTERNAL_LOG_WARN("[LongGauge::Record(V,A)] Value not recorded - invalid storage for: " - << instrument_descriptor_.name_); - return; - } - auto context = opentelemetry::context::Context{}; - return storage_->RecordLong(value, attributes, context); -} - -void LongGauge::Record(uint64_t value) noexcept -{ - if (!storage_) - { - OTEL_INTERNAL_LOG_WARN("[LongGauge::Record(V)] Value not recorded - invalid storage for: " - << instrument_descriptor_.name_); - return; - } - auto context = opentelemetry::context::Context{}; - return storage_->RecordLong(value, context); + return storage_->RecordLong(value, *attributes, *context); } DoubleGauge::DoubleGauge(InstrumentDescriptor instrument_descriptor, @@ -514,8 +478,8 @@ DoubleGauge::DoubleGauge(InstrumentDescriptor instrument_descriptor, } void DoubleGauge::Record(double value, - const opentelemetry::common::KeyValueIterable &attributes, - const opentelemetry::context::Context &context) noexcept + const opentelemetry::common::KeyValueIterable *attributes, + const opentelemetry::context::Context *context) noexcept { if (value < 0) { @@ -529,62 +493,9 @@ void DoubleGauge::Record(double value, << instrument_descriptor_.name_); return; } - return storage_->RecordDouble(value, attributes, context); -} - -void DoubleGauge::Record(double value, const opentelemetry::context::Context &context) noexcept -{ - if (value < 0) - { - OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V,C)] Value not recorded - negative value for: " - << instrument_descriptor_.name_); - return; - } - if (!storage_) - { - OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V,C)] Value not recorded - invalid storage for: " - << instrument_descriptor_.name_); - return; - } - return storage_->RecordDouble(value, context); -} - -void DoubleGauge::Record(double value, - const opentelemetry::common::KeyValueIterable &attributes) noexcept -{ - if (value < 0) - { - OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V,A)] Value not recorded - negative value for: " - << instrument_descriptor_.name_); - return; - } - if (!storage_) - { - OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V,A)] Value not recorded - invalid storage for: " - << instrument_descriptor_.name_); - return; - } - auto context = opentelemetry::context::Context{}; - return storage_->RecordDouble(value, attributes, context); + return storage_->RecordDouble(value, *attributes, *context); } -void DoubleGauge::Record(double value) noexcept -{ - if (value < 0) - { - OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V)] Value not recorded - negative value for: " - << instrument_descriptor_.name_); - return; - } - if (!storage_) - { - OTEL_INTERNAL_LOG_WARN("[DoubleGauge::Record(V)] Value not recorded - invalid storage for: " - << instrument_descriptor_.name_); - return; - } - auto context = opentelemetry::context::Context{}; - return storage_->RecordDouble(value, context); -} #endif } // namespace metrics