diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 8784fe788e..f0e5d90df3 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -21,6 +21,9 @@ class Histogram; template class UpDownCounter; +template +class Gauge; + class ObservableInstrument; /** @@ -91,6 +94,24 @@ class Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; + /** + * Creates a Gauge with the passed characteristics and returns a + * unique_ptr to that Gauge + * + * @param name the name of the new Gauge. + * @param description a brief description of what the Gauge is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + */ + virtual nostd::unique_ptr> CreateInt64Gauge( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; + + virtual nostd::unique_ptr> CreateDoubleGauge( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; + /** * Creates a Asynchronouse (Observable) Gauge with the passed characteristics and returns a * shared_ptr to that Observable Gauge diff --git a/api/include/opentelemetry/metrics/sync_instruments.h b/api/include/opentelemetry/metrics/sync_instruments.h index b26e527c2c..1a299ef9a1 100644 --- a/api/include/opentelemetry/metrics/sync_instruments.h +++ b/api/include/opentelemetry/metrics/sync_instruments.h @@ -194,5 +194,47 @@ class UpDownCounter : public SynchronousInstrument } }; +/** An Gauge instrument that records value. */ + +template +class Gauge : public SynchronousInstrument +{ +public: + /** + * Records the current value. + * + * @param value The measurement value. MUST be non-negative. + */ + virtual void Record(T value, const context::Context &context) noexcept = 0; + + /** + * Records a value with a set of attributes. + * + * @param value The measurement value. MUST be non-negative. + * @param attributes A set of attributes to associate with the value. + */ + virtual void Record(T value, + const common::KeyValueIterable &attributes, + const context::Context &context) noexcept = 0; + + template ::value> * = nullptr> + void Record(T value, const U &attributes, const context::Context &context) noexcept + { + this->Record(value, common::KeyValueIterableView{attributes}, context); + } + + void Record( + T value, + std::initializer_list> attributes, + const context::Context &context) noexcept + { + this->Record(value, + nostd::span>{ + attributes.begin(), attributes.end()}, + context); + } +}; + } // namespace metrics OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 7e89d444ab..26d7e847ac 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -74,6 +74,16 @@ class Meter final : public opentelemetry::metrics::Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept override; + nostd::unique_ptr> CreateInt64Gauge( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override; + + nostd::unique_ptr> CreateDoubleGauge( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override; + nostd::shared_ptr CreateInt64ObservableGauge( nostd::string_view name, nostd::string_view description = "", diff --git a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h index 825547a846..fb54604d24 100644 --- a/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/metrics/sync_instruments.h @@ -196,6 +196,37 @@ class DoubleHistogram : public Synchronous, public opentelemetry::metrics::Histo void Record(double value, const opentelemetry::context::Context &context) noexcept override; }; +class LongGauge : public Synchronous, public opentelemetry::metrics::Gauge +{ +{ +public: + /** + * Records the current value. + * + * @param value The measurement value. MUST be non-negative. + */ + virtual void Record(int64_t value, const context::Context &context) noexcept{ + + } + +}; + +class DoubleGauge : public Synchronous, public opentelemetry::metrics::Gauge +{ +{ +public: + /** + * Records the current value. + * + * @param value The measurement value. MUST be non-negative. + */ + virtual void Record(int64_t value, const context::Context &context) noexcept{ + + } + +}; + + } // namespace metrics } // namespace sdk OPENTELEMETRY_END_NAMESPACE