From 092339ffca167518208287151616e44e27697c50 Mon Sep 17 00:00:00 2001 From: Lalit Date: Sun, 24 Oct 2021 23:57:26 -0700 Subject: [PATCH 01/14] meter changes - intial commit --- .../metrics_new/async_instruments.h | 88 ++++++ api/include/opentelemetry/metrics_new/meter.h | 276 ++++++++++++++++++ .../metrics_new/meter_provider.h | 33 +++ .../metrics_new/observer_result.h | 41 +++ .../opentelemetry/metrics_new/provider.h | 59 ++++ .../metrics_new/sync_instruments.h | 87 ++++++ 6 files changed, 584 insertions(+) create mode 100644 api/include/opentelemetry/metrics_new/async_instruments.h create mode 100644 api/include/opentelemetry/metrics_new/meter.h create mode 100644 api/include/opentelemetry/metrics_new/meter_provider.h create mode 100644 api/include/opentelemetry/metrics_new/observer_result.h create mode 100644 api/include/opentelemetry/metrics_new/provider.h create mode 100644 api/include/opentelemetry/metrics_new/sync_instruments.h diff --git a/api/include/opentelemetry/metrics_new/async_instruments.h b/api/include/opentelemetry/metrics_new/async_instruments.h new file mode 100644 index 0000000000..867382ec19 --- /dev/null +++ b/api/include/opentelemetry/metrics_new/async_instruments.h @@ -0,0 +1,88 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifdef ENABLE_METRICS_PREVIEW + +# include "instrument.h" +# include "observer_result.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace metrics +{ + +template +class ValueObserver : virtual public AsynchronousInstrument +{ + +public: + ValueObserver() = default; + + ValueObserver(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + bool enabled, + void (*callback)(ObserverResult)) + {} + + /* + * Updates the instruments aggregator with the new value. The labels should + * contain the keys and values to be associated with this value. + * + * @param value is the numerical representation of the metric being captured + * @param labels the set of labels, as key-value pairs + */ + virtual void observe(T value, const common::KeyValueIterable &labels) override = 0; + + /** + * Captures data by activating the callback function associated with the + * instrument and storing its return value. Callbacks for asynchronous + * instruments are defined during construction. + * + * @param none + * @return none + */ + virtual void run() override = 0; +}; + +template +class SumObserver : virtual public AsynchronousInstrument +{ + +public: + SumObserver() = default; + + SumObserver(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + bool enabled, + void (*callback)(ObserverResult)) + {} + + virtual void observe(T value, const common::KeyValueIterable &labels) override = 0; + + virtual void run() override = 0; +}; + +template +class UpDownSumObserver : virtual public AsynchronousInstrument +{ + +public: + UpDownSumObserver() = default; + + UpDownSumObserver(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + bool enabled, + void (*callback)(ObserverResult)) + {} + + virtual void observe(T value, const common::KeyValueIterable &labels) override = 0; + + virtual void run() override = 0; +}; + +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics_new/meter.h b/api/include/opentelemetry/metrics_new/meter.h new file mode 100644 index 0000000000..9712275de5 --- /dev/null +++ b/api/include/opentelemetry/metrics_new/meter.h @@ -0,0 +1,276 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifdef ENABLE_METRICS_PREVIEW + +# include "opentelemetry/metrics_new/async_instruments.h" +# include "opentelemetry/metrics_new/instrument.h" +# include "opentelemetry/metrics_new/sync_instruments.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/nostd/span.h" +# include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace metrics_new +{ +/** + * Handles instrument creation and provides a facility for batch recording. + * + * This class provides methods to create new metric instruments, record a + * batch of values to a specified set of instruments, and collect + * measurements from all instruments. + * + */ +class Meter +{ +public: + virtual ~Meter() = default; + + /** + * Creates a Counter with the passed characteristics and returns a shared_ptr to that Counter. + * + * @param name the name of the new Counter. + * @param description a brief description of what the Counter is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a shared pointer to the created Counter. + * @throws NullPointerException if {@code name} is null + * @throws IllegalArgumentException if a different metric by the same name exists in this meter. + * @throws IllegalArgumentException if the {@code name} does not match spec requirements. + */ + virtual nostd::shared_ptr> CreateShortCounter(nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; + + virtual nostd::shared_ptr> CreateIntCounter(nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; + + virtual nostd::shared_ptr> CreateFloatCounter(nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; + + virtual nostd::shared_ptr> CreateDoubleCounter(nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; + +/** + * Creates a Asynchronouse (Observable) counter with the passed characteristics and returns a shared_ptr to that + * Observable Counter + * + * @param name the name of the new Observable Counter. + * @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. + * @param enabled a boolean value that turns on or off the metric instrument. + * @param callback the function to be observed by the instrument. + * @return a shared pointer to the created Observable Counter. + */ + virtual nostd::shared_ptr> CreateShortObservableCounter( + nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true + ) = 0; + + virtual nostd::shared_ptr> CreateIntObservableCounter( + nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true, + ) = 0; + + virtual nostd::shared_ptr> CreateFloatObservableCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> CreateDoubleObservableCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true, + void (*callback)(ObserverResult)) = 0; + + /** + * Creates a Histogram with the passed characteristics and returns a shared_ptr to that Histogram. + * + * @param name the name of the new Histogram. + * @param description a brief description of what the Histogram is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a shared pointer to the created Histogram. + */ + virtual nostd::shared_ptr> CreateShortHistogram(nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; + + virtual nostd::shared_ptr> CreateIntHistogram(nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; + + virtual nostd::shared_ptr> CreateFloatHistogram(nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; + + virtual nostd::shared_ptr> CreateDoubleHistogram(nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; + + +/** + * Creates a Asynchronouse (Observable) Gauge with the passed characteristics and returns a shared_ptr to that + * Observable Counter + * + * @param name the name of the new Observable Gauge. + * @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. + * @param enabled a boolean value that turns on or off the metric instrument. + * @param callback the function to be observed by the instrument. + * @return a shared pointer to the created Observable Gauge. + */ + virtual nostd::shared_ptr> CreateShortObservableGauge( + nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true + ) = 0; + + virtual nostd::shared_ptr> CreateIntObservableGauge( + nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true, + ) = 0; + + virtual nostd::shared_ptr> CreateFloatObservableGauge( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> CreateDoubleObservableGauge( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + /** + * Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that + * UpDownCounter. + * + * @param name the name of the new UpDownCounter. + * @param description a brief description of what the UpDownCounter is used for. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean value that turns on or off the metric instrument. + * @return a shared pointer to the created UpDownCounter. + */ + virtual nostd::shared_ptr> CreateShortUpDownCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; + + virtual nostd::shared_ptr> CreateIntUpDownCounter(nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; + + virtual nostd::shared_ptr> CreateFloatUpDownCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; + + virtual nostd::shared_ptr> CreateDoubleUpDownCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; + +/** + * Creates a Asynchronouse (Observable) UpDownCounter with the passed characteristics and returns a shared_ptr to that + * Observable UpDownCounter + * + * @param name the name of the new Observable UpDownCounter. + * @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. + * @param enabled a boolean value that turns on or off the metric instrument. + * @param callback the function to be observed by the instrument. + * @return a shared pointer to the created Observable UpDownCounter. + */ + virtual nostd::shared_ptr> CreateShortObservableUpDownCounter( + nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true + ) = 0; + + virtual nostd::shared_ptr> CreateIntObservableUpDownCounter( + nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true, + ) = 0; + + virtual nostd::shared_ptr> CreateFloatObservableUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> CreateDoubleObservableUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + /** + * Utility method that allows users to atomically record measurements to a set of + * synchronous metric instruments with a common set of labels. + * + * @param labels the set of labels to associate with this recorder. + * @param instruments a span of pointers to the instruments to record to. + * @param values a span of values to record to the instruments in the corresponding + * position in the instruments span. + */ + virtual void RecordShortBatch(const common::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept = 0; + + virtual void RecordIntBatch(const common::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept = 0; + + virtual void RecordFloatBatch(const common::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept = 0; + + virtual void RecordDoubleBatch(const common::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept = 0; +}; +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics_new/meter_provider.h b/api/include/opentelemetry/metrics_new/meter_provider.h new file mode 100644 index 0000000000..8d57f6d201 --- /dev/null +++ b/api/include/opentelemetry/metrics_new/meter_provider.h @@ -0,0 +1,33 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifdef ENABLE_METRICS_PREVIEW + +# include "opentelemetry/metrics/meter.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/nostd/string_view.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace metrics_new +{ +/** + * Creates new Meter instances. + */ +class MeterProvider +{ +public: + virtual ~MeterProvider() = default; + /** + * Gets or creates a named Meter instance. + * + * Optionally a version can be passed to create a named and versioned Meter + * instance. + */ + virtual nostd::shared_ptr GetMeter(nostd::string_view library_name, + nostd::string_view library_version = "", + nostd::string_view schema_url = "") = 0;) = 0; +}; +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics_new/observer_result.h b/api/include/opentelemetry/metrics_new/observer_result.h new file mode 100644 index 0000000000..90ad10efc2 --- /dev/null +++ b/api/include/opentelemetry/metrics_new/observer_result.h @@ -0,0 +1,41 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifdef ENABLE_METRICS_PREVIEW + +# include "instrument.h" +# include "opentelemetry/nostd/shared_ptr.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace metrics +{ + +/** + * ObserverResult class is necessary for the callback recording asynchronous + * instrument use. Callback functions asynchronous instruments are designed to + * accept a single ObserverResult object and update using its pointer to the + * instrument itself. + */ + +template +class ObserverResult +{ + +public: + ObserverResult() = default; + + ObserverResult(AsynchronousInstrument *instrument) : instrument_(instrument) {} + + virtual void observe(T value, const common::KeyValueIterable &labels) + { + instrument_->observe(value, labels); + } + +private: + AsynchronousInstrument *instrument_; +}; + +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics_new/provider.h b/api/include/opentelemetry/metrics_new/provider.h new file mode 100644 index 0000000000..5c350c2147 --- /dev/null +++ b/api/include/opentelemetry/metrics_new/provider.h @@ -0,0 +1,59 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifdef ENABLE_METRICS_PREVIEW +# include + +# include "opentelemetry/common/spin_lock_mutex.h" +# include "opentelemetry/metrics/meter_provider.h" +# include "opentelemetry/metrics/noop.h" +# include "opentelemetry/nostd/shared_ptr.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace metrics_new +{ +/** + * Stores the singleton global MeterProvider. + */ +class Provider +{ +public: + /** + * Returns the singleton MeterProvider. + * + * By default, a no-op MeterProvider is returned. This will never return a + * nullptr MeterProvider. + */ + static nostd::shared_ptr GetMeterProvider() noexcept + { + std::lock_guard guard(GetLock()); + return nostd::shared_ptr(GetProvider()); + } + + /** + * Changes the singleton MeterProvider. + */ + static void SetMeterProvider(nostd::shared_ptr tp) noexcept + { + std::lock_guard guard(GetLock()); + GetProvider() = tp; + } + +private: + static nostd::shared_ptr &GetProvider() noexcept + { + static nostd::shared_ptr provider(new NoopMeterProvider); + return provider; + } + + static common::SpinLockMutex &GetLock() noexcept + { + static common::SpinLockMutex lock; + return lock; + } +}; + +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics_new/sync_instruments.h b/api/include/opentelemetry/metrics_new/sync_instruments.h new file mode 100644 index 0000000000..0150ece1f0 --- /dev/null +++ b/api/include/opentelemetry/metrics_new/sync_instruments.h @@ -0,0 +1,87 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifdef ENABLE_METRICS_PREVIEW + + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace metrics_new +{ + +template +class Counter +{ + +public: + + /** + * Add adds the value to the counter's sum + * + * @param value The increment amount. MUST be non-negative. + */ + virtual void add(T value ) = 0; + + /** + * Add adds the value to the counter's sum. The labels should contain + * the keys and values to be associated with this value. Counters only + * accept positive valued updates. + * + * @param value The increment amount. MUST be non-negative. + * @param labels the set of labels, as key-value pairs + */ + + virtual void add(T value, const common::KeyValueIterable &labels) = 0; + +}; + +/** A histogram instrument that records values. */ + +template +class Historgram +{ + public: + + /** + * Records a value. + * + * @param value The increment amount. May be positive, negative or zero. + */ + virtual void record(T value) = 0; + + /** + * Records a value with a set of attributes. + * + * @param value The increment amount. May be positive, negative or zero. + * @param attributes A set of attributes to associate with the count. + */ + void record(T value, const common::KeyValueIterable &labels) = 0; + +} + +/** An up-down-counter instrument that adds or reduce values. */ + +template +class UpDownCounter +{ + public: + /** + * Adds a value. + * + * @param value The amount of the measurement. + */ + virtual void add(T value) = 0; + + /** + * Add a value with a set of attributes. + * + * @param value The increment amount. May be positive, negative or zero. + * @param attributes A set of attributes to associate with the count. + */ + void add(T value, const common::KeyValueIterable &labels) = 0; + +}; + +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif From e8674e2362b5c024f0135367304c5be916d87730 Mon Sep 17 00:00:00 2001 From: Lalit Date: Mon, 25 Oct 2021 08:49:47 -0700 Subject: [PATCH 02/14] initial commit for async instruments --- .../metrics_new/async_instruments.h | 78 +++---------------- 1 file changed, 10 insertions(+), 68 deletions(-) diff --git a/api/include/opentelemetry/metrics_new/async_instruments.h b/api/include/opentelemetry/metrics_new/async_instruments.h index 867382ec19..426f109839 100644 --- a/api/include/opentelemetry/metrics_new/async_instruments.h +++ b/api/include/opentelemetry/metrics_new/async_instruments.h @@ -8,81 +8,23 @@ # include "observer_result.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics +namespace metrics_new { +class AsynchronousInstrument +{}; template -class ValueObserver : virtual public AsynchronousInstrument -{ - -public: - ValueObserver() = default; - - ValueObserver(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - bool enabled, - void (*callback)(ObserverResult)) - {} - - /* - * Updates the instruments aggregator with the new value. The labels should - * contain the keys and values to be associated with this value. - * - * @param value is the numerical representation of the metric being captured - * @param labels the set of labels, as key-value pairs - */ - virtual void observe(T value, const common::KeyValueIterable &labels) override = 0; - - /** - * Captures data by activating the callback function associated with the - * instrument and storing its return value. Callbacks for asynchronous - * instruments are defined during construction. - * - * @param none - * @return none - */ - virtual void run() override = 0; -}; +class ObservableCounter : public AsynchronousInstrument +{}; template -class SumObserver : virtual public AsynchronousInstrument -{ - -public: - SumObserver() = default; - - SumObserver(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - bool enabled, - void (*callback)(ObserverResult)) - {} - - virtual void observe(T value, const common::KeyValueIterable &labels) override = 0; - - virtual void run() override = 0; -}; +class ObservableGauge : public AsynchronousInstrument +{}; template -class UpDownSumObserver : virtual public AsynchronousInstrument -{ - -public: - UpDownSumObserver() = default; - - UpDownSumObserver(nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - bool enabled, - void (*callback)(ObserverResult)) - {} - - virtual void observe(T value, const common::KeyValueIterable &labels) override = 0; - - virtual void run() override = 0; -}; +class ObservableUpDownCounter : public AsynchronousInstrument +{}; -} // namespace metrics +} // namespace metrics_new OPENTELEMETRY_END_NAMESPACE #endif From 4a829a0b28ca18db0b73be32e9814a80e02b6a10 Mon Sep 17 00:00:00 2001 From: Lalit Date: Mon, 25 Oct 2021 08:52:00 -0700 Subject: [PATCH 03/14] format --- api/include/opentelemetry/metrics_new/meter.h | 186 ++++++++---------- .../metrics_new/meter_provider.h | 3 +- .../metrics_new/observer_result.h | 24 +-- .../opentelemetry/metrics_new/provider.h | 2 +- .../metrics_new/sync_instruments.h | 38 ++-- 5 files changed, 108 insertions(+), 145 deletions(-) diff --git a/api/include/opentelemetry/metrics_new/meter.h b/api/include/opentelemetry/metrics_new/meter.h index 9712275de5..1219a61024 100644 --- a/api/include/opentelemetry/metrics_new/meter.h +++ b/api/include/opentelemetry/metrics_new/meter.h @@ -40,29 +40,32 @@ class Meter * @throws IllegalArgumentException if a different metric by the same name exists in this meter. * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ - virtual nostd::shared_ptr> CreateShortCounter(nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; + virtual nostd::shared_ptr> CreateShortCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; virtual nostd::shared_ptr> CreateIntCounter(nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; - virtual nostd::shared_ptr> CreateFloatCounter(nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; + virtual nostd::shared_ptr> CreateFloatCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; - virtual nostd::shared_ptr> CreateDoubleCounter(nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; + virtual nostd::shared_ptr> CreateDoubleCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; -/** - * Creates a Asynchronouse (Observable) counter with the passed characteristics and returns a shared_ptr to that - * Observable Counter + /** + * Creates a Asynchronouse (Observable) counter with the passed characteristics and returns a + * shared_ptr to that Observable Counter * * @param name the name of the new Observable Counter. * @param description a brief description of what the Observable Counter is used for. @@ -75,31 +78,29 @@ class Meter nostd::string_view name, void (*callback)(ObserverResult), nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true - ) = 0; + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; virtual nostd::shared_ptr> CreateIntObservableCounter( nostd::string_view name, void (*callback)(ObserverResult), nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true, - ) = 0; + nostd::string_view unit = "", + const bool enabled = true, ) noexcept = 0; virtual nostd::shared_ptr> CreateFloatObservableCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true, - void (*callback)(ObserverResult)) = 0; + nostd::string_view unit = "", + const bool enabled = true, + void (*callback)(ObserverResult)) noexcept = 0; virtual nostd::shared_ptr> CreateDoubleObservableCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true, - void (*callback)(ObserverResult)) = 0; + nostd::string_view unit = "", + const bool enabled = true, + void (*callback)(ObserverResult)) noexcept = 0; /** * Creates a Histogram with the passed characteristics and returns a shared_ptr to that Histogram. @@ -110,30 +111,33 @@ class Meter * @param enabled a boolean value that turns on or off the metric instrument. * @return a shared pointer to the created Histogram. */ - virtual nostd::shared_ptr> CreateShortHistogram(nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; - - virtual nostd::shared_ptr> CreateIntHistogram(nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; + virtual nostd::shared_ptr> CreateShortHistogram( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; - virtual nostd::shared_ptr> CreateFloatHistogram(nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; + virtual nostd::shared_ptr> CreateIntHistogram( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; - virtual nostd::shared_ptr> CreateDoubleHistogram(nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; + virtual nostd::shared_ptr> CreateFloatHistogram( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; + virtual nostd::shared_ptr> CreateDoubleHistogram( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; -/** - * Creates a Asynchronouse (Observable) Gauge with the passed characteristics and returns a shared_ptr to that - * Observable Counter + /** + * Creates a Asynchronouse (Observable) Gauge with the passed characteristics and returns a + * shared_ptr to that Observable Counter * * @param name the name of the new Observable Gauge. * @param description a brief description of what the Observable Gauge is used for. @@ -146,31 +150,29 @@ class Meter nostd::string_view name, void (*callback)(ObserverResult), nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true - ) = 0; + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; virtual nostd::shared_ptr> CreateIntObservableGauge( nostd::string_view name, void (*callback)(ObserverResult), nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true, - ) = 0; + nostd::string_view unit = "", + const bool enabled = true, ) noexcept = 0; virtual nostd::shared_ptr> CreateFloatObservableGauge( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(ObserverResult)) = 0; + void (*callback)(ObserverResult)) noexcept = 0; virtual nostd::shared_ptr> CreateDoubleObservableGauge( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(ObserverResult)) = 0; + void (*callback)(ObserverResult)) noexcept = 0; /** * Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that @@ -185,29 +187,30 @@ class Meter virtual nostd::shared_ptr> CreateShortUpDownCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; - virtual nostd::shared_ptr> CreateIntUpDownCounter(nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; + virtual nostd::shared_ptr> CreateIntUpDownCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "", + const bool enabled = true) = 0; virtual nostd::shared_ptr> CreateFloatUpDownCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; virtual nostd::shared_ptr> CreateDoubleUpDownCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; -/** - * Creates a Asynchronouse (Observable) UpDownCounter with the passed characteristics and returns a shared_ptr to that - * Observable UpDownCounter + /** + * Creates a Asynchronouse (Observable) UpDownCounter with the passed characteristics and returns + * a shared_ptr to that Observable UpDownCounter * * @param name the name of the new Observable UpDownCounter. * @param description a brief description of what the Observable UpDownCounter is used for. @@ -220,57 +223,30 @@ class Meter nostd::string_view name, void (*callback)(ObserverResult), nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true - ) = 0; + nostd::string_view unit = "", + const bool enabled = true) noexcept = 0; virtual nostd::shared_ptr> CreateIntObservableUpDownCounter( nostd::string_view name, void (*callback)(ObserverResult), nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true, - ) = 0; + nostd::string_view unit = "", + const bool enabled = true, ) noexcept = 0; virtual nostd::shared_ptr> CreateFloatObservableUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(ObserverResult)) = 0; + void (*callback)(ObserverResult)) noexcept = 0; virtual nostd::shared_ptr> CreateDoubleObservableUpDownCounter( nostd::string_view name, nostd::string_view description, nostd::string_view unit, const bool enabled, - void (*callback)(ObserverResult)) = 0; - - /** - * Utility method that allows users to atomically record measurements to a set of - * synchronous metric instruments with a common set of labels. - * - * @param labels the set of labels to associate with this recorder. - * @param instruments a span of pointers to the instruments to record to. - * @param values a span of values to record to the instruments in the corresponding - * position in the instruments span. - */ - virtual void RecordShortBatch(const common::KeyValueIterable &labels, - nostd::span *> instruments, - nostd::span values) noexcept = 0; - - virtual void RecordIntBatch(const common::KeyValueIterable &labels, - nostd::span *> instruments, - nostd::span values) noexcept = 0; - - virtual void RecordFloatBatch(const common::KeyValueIterable &labels, - nostd::span *> instruments, - nostd::span values) noexcept = 0; - - virtual void RecordDoubleBatch(const common::KeyValueIterable &labels, - nostd::span *> instruments, - nostd::span values) noexcept = 0; + void (*callback)(ObserverResult)) noexcept = 0; }; -} // namespace metrics +} // namespace metrics_new OPENTELEMETRY_END_NAMESPACE #endif diff --git a/api/include/opentelemetry/metrics_new/meter_provider.h b/api/include/opentelemetry/metrics_new/meter_provider.h index 8d57f6d201..8bd2c590f2 100644 --- a/api/include/opentelemetry/metrics_new/meter_provider.h +++ b/api/include/opentelemetry/metrics_new/meter_provider.h @@ -26,8 +26,7 @@ class MeterProvider */ virtual nostd::shared_ptr GetMeter(nostd::string_view library_name, nostd::string_view library_version = "", - nostd::string_view schema_url = "") = 0;) = 0; -}; + nostd::string_view schema_url = "") noexcept = 0; } // namespace metrics OPENTELEMETRY_END_NAMESPACE #endif diff --git a/api/include/opentelemetry/metrics_new/observer_result.h b/api/include/opentelemetry/metrics_new/observer_result.h index 90ad10efc2..0533e21a31 100644 --- a/api/include/opentelemetry/metrics_new/observer_result.h +++ b/api/include/opentelemetry/metrics_new/observer_result.h @@ -3,19 +3,15 @@ #pragma once #ifdef ENABLE_METRICS_PREVIEW - -# include "instrument.h" -# include "opentelemetry/nostd/shared_ptr.h" +# include "c OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics +namespace metrics_new { /** * ObserverResult class is necessary for the callback recording asynchronous - * instrument use. Callback functions asynchronous instruments are designed to - * accept a single ObserverResult object and update using its pointer to the - * instrument itself. + * instrument use. */ template @@ -23,19 +19,11 @@ class ObserverResult { public: - ObserverResult() = default; - - ObserverResult(AsynchronousInstrument *instrument) : instrument_(instrument) {} - - virtual void observe(T value, const common::KeyValueIterable &labels) - { - instrument_->observe(value, labels); - } + virtual void observe(T value) noexcept = 0; -private: - AsynchronousInstrument *instrument_; + virtual void observer(T value, const common::KeyValueIterable &labels) noexcept = 0; }; -} // namespace metrics +} // namespace metrics_new OPENTELEMETRY_END_NAMESPACE #endif diff --git a/api/include/opentelemetry/metrics_new/provider.h b/api/include/opentelemetry/metrics_new/provider.h index 5c350c2147..27c14c0489 100644 --- a/api/include/opentelemetry/metrics_new/provider.h +++ b/api/include/opentelemetry/metrics_new/provider.h @@ -54,6 +54,6 @@ class Provider } }; -} // namespace metrics +} // namespace metrics_new OPENTELEMETRY_END_NAMESPACE #endif diff --git a/api/include/opentelemetry/metrics_new/sync_instruments.h b/api/include/opentelemetry/metrics_new/sync_instruments.h index 0150ece1f0..cd1a1fad87 100644 --- a/api/include/opentelemetry/metrics_new/sync_instruments.h +++ b/api/include/opentelemetry/metrics_new/sync_instruments.h @@ -4,50 +4,51 @@ #pragma once #ifdef ENABLE_METRICS_PREVIEW +# include "opentelemetry/common/key_value_iterable.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics_new { +class SynchronousInstrument +{}; + template -class Counter +class Counter : public SynchronousInstrument { public: - /** * Add adds the value to the counter's sum * * @param value The increment amount. MUST be non-negative. */ - virtual void add(T value ) = 0; + virtual void add(T value) noexcept = 0; /** * Add adds the value to the counter's sum. The labels should contain - * the keys and values to be associated with this value. Counters only + * the keys and values to be associated with this value. Counters only * accept positive valued updates. * * @param value The increment amount. MUST be non-negative. * @param labels the set of labels, as key-value pairs */ - virtual void add(T value, const common::KeyValueIterable &labels) = 0; - + virtual void add(T value, const common::KeyValueIterable &labels) noexcept = 0; }; /** A histogram instrument that records values. */ template -class Historgram +class Historgram : public SynchronousInstrument { - public: - +public: /** * Records a value. * * @param value The increment amount. May be positive, negative or zero. - */ - virtual void record(T value) = 0; + */ + virtual void record(T value) noexcept = 0; /** * Records a value with a set of attributes. @@ -55,22 +56,22 @@ class Historgram * @param value The increment amount. May be positive, negative or zero. * @param attributes A set of attributes to associate with the count. */ - void record(T value, const common::KeyValueIterable &labels) = 0; + void record(T value, const common::KeyValueIterable &labels) noexcept = 0; } /** An up-down-counter instrument that adds or reduce values. */ template -class UpDownCounter +class UpDownCounter : public SynchronousInstrument { - public: +public: /** * Adds a value. * * @param value The amount of the measurement. - */ - virtual void add(T value) = 0; + */ + virtual void add(T value) noexcept = 0; /** * Add a value with a set of attributes. @@ -78,10 +79,9 @@ class UpDownCounter * @param value The increment amount. May be positive, negative or zero. * @param attributes A set of attributes to associate with the count. */ - void add(T value, const common::KeyValueIterable &labels) = 0; - + void add(T value, const common::KeyValueIterable &labels) noexcept = 0; }; -} // namespace metrics +} // namespace metrics_new OPENTELEMETRY_END_NAMESPACE #endif From d0d6131b8f1bc5c4eed465a1f84cf9516471785e Mon Sep 17 00:00:00 2001 From: Lalit Date: Mon, 25 Oct 2021 13:21:43 -0700 Subject: [PATCH 04/14] review comments --- CMakeLists.txt | 21 +++++++++++++++++++ .../metrics_new/observer_result.h | 2 +- .../metrics_new/sync_instruments.h | 10 ++++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 272e10927b..1f2c86471d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,6 +165,8 @@ option(WITH_NO_GETENV "Whether the platform supports environment variables" OFF) option(BUILD_TESTING "Whether to enable tests" ON) +option(BUILD_PACKAGE "Whether to build rpm/deb package" OFF) + if(WITH_NO_GENENV) add_definitions(-DNO_GETENV) endif() @@ -412,3 +414,22 @@ install( EXPORT "${PROJECT_NAME}-target" NAMESPACE "${PROJECT_NAME}::" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + +if(BUILD_PACKAGE AND UNIX) + execute_process( + COMMAND lsb_release -si + OUTPUT_VARIABLE distribution + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(distribution STREQUAL "Debian" OR distribution STREQUAL "Ubuntu") + set(INSTALL_LIB_DIR + ${CMAKE_INSTALL_PREFIX}/lib/${CPACK_DEBIAN_ARCHITECTURE}-linux-gnu) + include(cmake/MakeDeb.cmake) + elseif( + distribution MATCHES "RedHat.*" + OR distribution MATCHES "openSUSE.*" + OR distribution STREQUAL "Fedora") + set(INSTALL_LIB_DIR + ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu) + include(cmake/MakeRpm.cmake) + endif() +endif() diff --git a/api/include/opentelemetry/metrics_new/observer_result.h b/api/include/opentelemetry/metrics_new/observer_result.h index 0533e21a31..f668760db8 100644 --- a/api/include/opentelemetry/metrics_new/observer_result.h +++ b/api/include/opentelemetry/metrics_new/observer_result.h @@ -21,7 +21,7 @@ class ObserverResult public: virtual void observe(T value) noexcept = 0; - virtual void observer(T value, const common::KeyValueIterable &labels) noexcept = 0; + virtual void observer(T value, const common::KeyValueIterable &attributes) noexcept = 0; }; } // namespace metrics_new diff --git a/api/include/opentelemetry/metrics_new/sync_instruments.h b/api/include/opentelemetry/metrics_new/sync_instruments.h index cd1a1fad87..a8b14394b3 100644 --- a/api/include/opentelemetry/metrics_new/sync_instruments.h +++ b/api/include/opentelemetry/metrics_new/sync_instruments.h @@ -26,15 +26,15 @@ class Counter : public SynchronousInstrument virtual void add(T value) noexcept = 0; /** - * Add adds the value to the counter's sum. The labels should contain + * Add adds the value to the counter's sum. The attributes should contain * the keys and values to be associated with this value. Counters only * accept positive valued updates. * * @param value The increment amount. MUST be non-negative. - * @param labels the set of labels, as key-value pairs + * @param attributes the set of attributes, as key-value pairs */ - virtual void add(T value, const common::KeyValueIterable &labels) noexcept = 0; + virtual void add(T value, const common::KeyValueIterable &attributes) noexcept = 0; }; /** A histogram instrument that records values. */ @@ -56,7 +56,7 @@ class Historgram : public SynchronousInstrument * @param value The increment amount. May be positive, negative or zero. * @param attributes A set of attributes to associate with the count. */ - void record(T value, const common::KeyValueIterable &labels) noexcept = 0; + void record(T value, const common::KeyValueIterable &attributes) noexcept = 0; } @@ -79,7 +79,7 @@ class UpDownCounter : public SynchronousInstrument * @param value The increment amount. May be positive, negative or zero. * @param attributes A set of attributes to associate with the count. */ - void add(T value, const common::KeyValueIterable &labels) noexcept = 0; + void add(T value, const common::KeyValueIterable &attributes) noexcept = 0; }; } // namespace metrics_new From 7f47b1e796ed1534240dc251e08ac0cadbf4a35f Mon Sep 17 00:00:00 2001 From: Lalit Date: Mon, 25 Oct 2021 14:59:53 -0700 Subject: [PATCH 05/14] overload sync instruement --- .../metrics_new/async_instruments.h | 5 +- api/include/opentelemetry/metrics_new/meter.h | 19 ++---- .../metrics_new/meter_provider.h | 8 +-- .../metrics_new/observer_result.h | 26 ++++++-- .../opentelemetry/metrics_new/provider.h | 14 ++-- .../metrics_new/sync_instruments.h | 64 ++++++++++++++++--- 6 files changed, 95 insertions(+), 41 deletions(-) diff --git a/api/include/opentelemetry/metrics_new/async_instruments.h b/api/include/opentelemetry/metrics_new/async_instruments.h index 426f109839..143206789e 100644 --- a/api/include/opentelemetry/metrics_new/async_instruments.h +++ b/api/include/opentelemetry/metrics_new/async_instruments.h @@ -2,10 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_METRICS_PREVIEW -# include "instrument.h" -# include "observer_result.h" +#include "instrument.h" +#include "observer_result.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics_new diff --git a/api/include/opentelemetry/metrics_new/meter.h b/api/include/opentelemetry/metrics_new/meter.h index 1219a61024..65b5f065db 100644 --- a/api/include/opentelemetry/metrics_new/meter.h +++ b/api/include/opentelemetry/metrics_new/meter.h @@ -2,15 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_METRICS_PREVIEW -# include "opentelemetry/metrics_new/async_instruments.h" -# include "opentelemetry/metrics_new/instrument.h" -# include "opentelemetry/metrics_new/sync_instruments.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/span.h" -# include "opentelemetry/nostd/string_view.h" -# include "opentelemetry/version.h" +#include "opentelemetry/metrics_new/async_instruments.h" +#include "opentelemetry/metrics_new/instrument.h" +#include "opentelemetry/metrics_new/sync_instruments.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics_new @@ -36,9 +35,6 @@ class Meter * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. * @param enabled a boolean value that turns on or off the metric instrument. * @return a shared pointer to the created Counter. - * @throws NullPointerException if {@code name} is null - * @throws IllegalArgumentException if a different metric by the same name exists in this meter. - * @throws IllegalArgumentException if the {@code name} does not match spec requirements. */ virtual nostd::shared_ptr> CreateShortCounter( nostd::string_view name, @@ -249,4 +245,3 @@ class Meter }; } // namespace metrics_new OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/api/include/opentelemetry/metrics_new/meter_provider.h b/api/include/opentelemetry/metrics_new/meter_provider.h index 8bd2c590f2..e5579694ce 100644 --- a/api/include/opentelemetry/metrics_new/meter_provider.h +++ b/api/include/opentelemetry/metrics_new/meter_provider.h @@ -2,11 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_METRICS_PREVIEW -# include "opentelemetry/metrics/meter.h" -# include "opentelemetry/nostd/shared_ptr.h" -# include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/nostd/string_view.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics_new @@ -29,4 +28,3 @@ class MeterProvider nostd::string_view schema_url = "") noexcept = 0; } // namespace metrics OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/api/include/opentelemetry/metrics_new/observer_result.h b/api/include/opentelemetry/metrics_new/observer_result.h index f668760db8..5d78fe2f58 100644 --- a/api/include/opentelemetry/metrics_new/observer_result.h +++ b/api/include/opentelemetry/metrics_new/observer_result.h @@ -2,8 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_METRICS_PREVIEW -# include "c +#include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/common/key_value_iterable_view.h" +#include "opentelemetry/nostd/span.h" +#include "opentelemetry/nostd/string_view.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics_new @@ -19,11 +21,25 @@ class ObserverResult { public: - virtual void observe(T value) noexcept = 0; + virtual void Observe(T value) noexcept = 0; - virtual void observer(T value, const common::KeyValueIterable &attributes) noexcept = 0; + virtual void Observer(T value, const common::KeyValueIterable &attributes) noexcept = 0; + + template ::value> * = nullptr> + void Observe(T value, const U &attributes) noexcept + { + this->Observe(value, common::KeyValueIterableView{attributes}); + } + + void Observe(T value, + std::initializer_list> + attributes) noexcept + { + this->Observe(value, nostd::span>{ + attributes.begin(), attributes.end()}); + } }; } // namespace metrics_new OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/api/include/opentelemetry/metrics_new/provider.h b/api/include/opentelemetry/metrics_new/provider.h index 27c14c0489..aebca3fa73 100644 --- a/api/include/opentelemetry/metrics_new/provider.h +++ b/api/include/opentelemetry/metrics_new/provider.h @@ -2,13 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_METRICS_PREVIEW -# include +#include -# include "opentelemetry/common/spin_lock_mutex.h" -# include "opentelemetry/metrics/meter_provider.h" -# include "opentelemetry/metrics/noop.h" -# include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/common/spin_lock_mutex.h" +#include "opentelemetry/metrics/meter_provider.h" +#include "opentelemetry/metrics/noop.h" +#include "opentelemetry/nostd/shared_ptr.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics_new @@ -55,5 +54,4 @@ class Provider }; } // namespace metrics_new -OPENTELEMETRY_END_NAMESPACE -#endif +OPENTELEMETRY_END_NAMESPACE \ No newline at end of file diff --git a/api/include/opentelemetry/metrics_new/sync_instruments.h b/api/include/opentelemetry/metrics_new/sync_instruments.h index a8b14394b3..bfeab5f95e 100644 --- a/api/include/opentelemetry/metrics_new/sync_instruments.h +++ b/api/include/opentelemetry/metrics_new/sync_instruments.h @@ -2,9 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#ifdef ENABLE_METRICS_PREVIEW +#ifndef ENABLE_METRICS_PREVIEW -# include "opentelemetry/common/key_value_iterable.h" +# include "opentelemetry/common/attribute_value.h" +# include "opentelemetry/common/key_value_iterable_view.h" +# include "opentelemetry/nostd/span.h" +# include "opentelemetry/nostd/string_view.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics_new @@ -23,7 +26,7 @@ class Counter : public SynchronousInstrument * * @param value The increment amount. MUST be non-negative. */ - virtual void add(T value) noexcept = 0; + virtual void Add(T value) noexcept = 0; /** * Add adds the value to the counter's sum. The attributes should contain @@ -34,7 +37,22 @@ class Counter : public SynchronousInstrument * @param attributes the set of attributes, as key-value pairs */ - virtual void add(T value, const common::KeyValueIterable &attributes) noexcept = 0; + virtual void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0; + + template ::value> * = nullptr> + void Add(T value, const U &attributes) noexcept + { + this->Add(value, common::KeyValueIterableView{attributes}); + } + + void Add(T value, + std::initializer_list> + attributes) noexcept + { + this->Add(value, nostd::span>{ + attributes.begin(), attributes.end()}); + } }; /** A histogram instrument that records values. */ @@ -48,7 +66,7 @@ class Historgram : public SynchronousInstrument * * @param value The increment amount. May be positive, negative or zero. */ - virtual void record(T value) noexcept = 0; + virtual void Record(T value) noexcept = 0; /** * Records a value with a set of attributes. @@ -56,7 +74,22 @@ class Historgram : public SynchronousInstrument * @param value The increment amount. May be positive, negative or zero. * @param attributes A set of attributes to associate with the count. */ - void record(T value, const common::KeyValueIterable &attributes) noexcept = 0; + virtual void Record(T value, const common::KeyValueIterable &attributes) noexcept = 0; + + template ::value> * = nullptr> + void Record(T value, const U &attributes) noexcept + { + this->Record(value, common::KeyValueIterableView{attributes}); + } + + void Record(T value, + std::initializer_list> + attributes) noexcept + { + this->Record(value, nostd::span>{ + attributes.begin(), attributes.end()}); + } } @@ -71,7 +104,7 @@ class UpDownCounter : public SynchronousInstrument * * @param value The amount of the measurement. */ - virtual void add(T value) noexcept = 0; + virtual void Add(T value) noexcept = 0; /** * Add a value with a set of attributes. @@ -79,7 +112,22 @@ class UpDownCounter : public SynchronousInstrument * @param value The increment amount. May be positive, negative or zero. * @param attributes A set of attributes to associate with the count. */ - void add(T value, const common::KeyValueIterable &attributes) noexcept = 0; + void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0; + + template ::value> * = nullptr> + void Add(T value, const U &attributes) noexcept + { + this->Add(value, common::KeyValueIterableView{attributes}); + } + + void Add(T value, + std::initializer_list> + attributes) noexcept + { + this->Add(value, nostd::span>{ + attributes.begin(), attributes.end()}); + } }; } // namespace metrics_new From 49ff6e2575995e519bd6d10d9f5251b7f1e9d302 Mon Sep 17 00:00:00 2001 From: Lalit Date: Mon, 25 Oct 2021 15:47:25 -0700 Subject: [PATCH 06/14] format --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a72275bdc..b6e2585631 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -433,4 +433,3 @@ install( EXPORT "${PROJECT_NAME}-target" NAMESPACE "${PROJECT_NAME}::" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") - \ No newline at end of file From 0fd654b89134c5f8cabe22a3c808d370bac13674 Mon Sep 17 00:00:00 2001 From: Lalit Date: Tue, 26 Oct 2021 15:03:57 -0700 Subject: [PATCH 07/14] add noop --- api/include/opentelemetry/metrics_new/meter.h | 146 ++++-------------- api/include/opentelemetry/metrics_new/noop.h | 90 +++++++++++ 2 files changed, 116 insertions(+), 120 deletions(-) create mode 100644 api/include/opentelemetry/metrics_new/noop.h diff --git a/api/include/opentelemetry/metrics_new/meter.h b/api/include/opentelemetry/metrics_new/meter.h index 65b5f065db..4844041a35 100644 --- a/api/include/opentelemetry/metrics_new/meter.h +++ b/api/include/opentelemetry/metrics_new/meter.h @@ -33,31 +33,18 @@ class Meter * @param name the name of the new Counter. * @param description a brief description of what the Counter is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. - * @param enabled a boolean value that turns on or off the metric instrument. * @return a shared pointer to the created Counter. */ - virtual nostd::shared_ptr> CreateShortCounter( - nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; - - virtual nostd::shared_ptr> CreateIntCounter(nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; - virtual nostd::shared_ptr> CreateFloatCounter( + virtual nostd::shared_ptr> CreateLongCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; + nostd::string_view unit = "") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; + nostd::string_view unit = "") noexcept = 0; /** * Creates a Asynchronouse (Observable) counter with the passed characteristics and returns a @@ -66,37 +53,20 @@ class Meter * @param name the name of the new Observable Counter. * @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. - * @param enabled a boolean value that turns on or off the metric instrument. * @param callback the function to be observed by the instrument. * @return a shared pointer to the created Observable Counter. */ - virtual nostd::shared_ptr> CreateShortObservableCounter( - nostd::string_view name, - void (*callback)(ObserverResult), - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; - - virtual nostd::shared_ptr> CreateIntObservableCounter( - nostd::string_view name, - void (*callback)(ObserverResult), - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true, ) noexcept = 0; - - virtual nostd::shared_ptr> CreateFloatObservableCounter( + virtual nostd::shared_ptr> CreateLongObservableCounter( nostd::string_view name, + void (*callback)(ObserverResult), nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true, - void (*callback)(ObserverResult)) noexcept = 0; + nostd::string_view unit = "") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleObservableCounter( nostd::string_view name, + void (*callback)(ObserverResult), nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true, - void (*callback)(ObserverResult)) noexcept = 0; + nostd::string_view unit = "") noexcept = 0; /** * Creates a Histogram with the passed characteristics and returns a shared_ptr to that Histogram. @@ -104,32 +74,17 @@ class Meter * @param name the name of the new Histogram. * @param description a brief description of what the Histogram is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. - * @param enabled a boolean value that turns on or off the metric instrument. * @return a shared pointer to the created Histogram. */ - virtual nostd::shared_ptr> CreateShortHistogram( + virtual nostd::shared_ptr> CreateLongHistogram( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; - - virtual nostd::shared_ptr> CreateIntHistogram( - nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; - - virtual nostd::shared_ptr> CreateFloatHistogram( - nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; + nostd::string_view unit = "") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleHistogram( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; + nostd::string_view unit = "") noexcept = 0; /** * Creates a Asynchronouse (Observable) Gauge with the passed characteristics and returns a @@ -138,37 +93,20 @@ class Meter * @param name the name of the new Observable Gauge. * @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. - * @param enabled a boolean value that turns on or off the metric instrument. * @param callback the function to be observed by the instrument. * @return a shared pointer to the created Observable Gauge. */ - virtual nostd::shared_ptr> CreateShortObservableGauge( + virtual nostd::shared_ptr> CreateLongObservableGauge( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult), nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; - - virtual nostd::shared_ptr> CreateIntObservableGauge( - nostd::string_view name, - void (*callback)(ObserverResult), - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true, ) noexcept = 0; - - virtual nostd::shared_ptr> CreateFloatObservableGauge( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled, - void (*callback)(ObserverResult)) noexcept = 0; + nostd::string_view unit = "") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleObservableGauge( nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled, - void (*callback)(ObserverResult)) noexcept = 0; + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; /** * Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that @@ -177,32 +115,17 @@ class Meter * @param name the name of the new UpDownCounter. * @param description a brief description of what the UpDownCounter is used for. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. - * @param enabled a boolean value that turns on or off the metric instrument. * @return a shared pointer to the created UpDownCounter. */ - virtual nostd::shared_ptr> CreateShortUpDownCounter( - nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; - - virtual nostd::shared_ptr> CreateIntUpDownCounter( - nostd::string_view name, - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) = 0; - - virtual nostd::shared_ptr> CreateFloatUpDownCounter( + virtual nostd::shared_ptr> CreateLongUpDownCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; + nostd::string_view unit = "") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleUpDownCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; + nostd::string_view unit = "") noexcept = 0; /** * Creates a Asynchronouse (Observable) UpDownCounter with the passed characteristics and returns @@ -211,37 +134,20 @@ class Meter * @param name the name of the new Observable UpDownCounter. * @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. - * @param enabled a boolean value that turns on or off the metric instrument. * @param callback the function to be observed by the instrument. * @return a shared pointer to the created Observable UpDownCounter. */ - virtual nostd::shared_ptr> CreateShortObservableUpDownCounter( - nostd::string_view name, - void (*callback)(ObserverResult), - nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true) noexcept = 0; - - virtual nostd::shared_ptr> CreateIntObservableUpDownCounter( + virtual nostd::shared_ptr> CreateLongObservableUpDownCounter( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult), nostd::string_view description = "", - nostd::string_view unit = "", - const bool enabled = true, ) noexcept = 0; - - virtual nostd::shared_ptr> CreateFloatObservableUpDownCounter( - nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled, - void (*callback)(ObserverResult)) noexcept = 0; + nostd::string_view unit = "") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleObservableUpDownCounter( nostd::string_view name, - nostd::string_view description, - nostd::string_view unit, - const bool enabled, - void (*callback)(ObserverResult)) noexcept = 0; + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; }; } // namespace metrics_new OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/metrics_new/noop.h b/api/include/opentelemetry/metrics_new/noop.h new file mode 100644 index 0000000000..f984907612 --- /dev/null +++ b/api/include/opentelemetry/metrics_new/noop.h @@ -0,0 +1,90 @@ +#include "opentelemetry/metrics_new/sync_instruments.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace metrics_new +{ + +template +class NoopCounter : public opentelemetry::metrics_new::Counter +{ +public: + void Add(T value) noexcept override {} + void Add(T value, const common::KeyValueIterable &attributes) {} +} + +template +class NoopHistorgram : public opentelemetry::metrics_new::Historgram +{ +public: + void Add(T value) noexcept override {} + void Add(T value, const common::KeyValueIterable &attributes) {} +} + +template +class NoopUpDownCounter : public opentelemetry::metrics_new::UpDownCounter +{ +public: + void Add(T value) noexcept override {} + void Add(T value, const common::KeyValueIterable &attributes) {} +} + +template +class NoopObservableCounter : public ObservableCounter +{}; + +template +class NoopObservableGauge : public ObservableGauge +{}; + +template +class NoopObservableUpDownCounter : public ObservableUpDownCounter +{}; + +/** + * No-op implementation of Meter. + */ +class NoopMeter final : public opentelemetry::Meter +{ +public: + // Tracer + nostd::shared_ptr StartSpan(nostd::string_view /*name*/, + const common::KeyValueIterable & /*attributes*/, + const SpanContextKeyValueIterable & /*links*/, + const StartSpanOptions & /*options*/) noexcept override + { + // Don't allocate a no-op span for every StartSpan call, but use a static + // singleton for this case. + static nostd::shared_ptr noop_span( + new trace_api::NoopSpan{this->shared_from_this()}); + + return noop_span; + } + + void ForceFlushWithMicroseconds(uint64_t /*timeout*/) noexcept override {} + + void CloseWithMicroseconds(uint64_t /*timeout*/) noexcept override {} +}; + +/** + * No-op implementation of a TracerProvider. + */ +class NoopMeterProvider final : public opentelemetry::trace::MeterProvider +{ +public: + NoopMeterProvider() + : tracer_{ + nostd::shared_ptr(new opentelemetry::trace::NoopMeter)} + {} + + nostd::shared_ptr GetMeter(nostd::string_view library_name, + nostd::string_view library_version, + nostd::string_view schema_url) override + { + return meter_; + } + +private: + nostd::shared_ptr meter_; +}; +} // namespace metrics_new +OPENTELEMETRY_END_NAMESPACE \ No newline at end of file From ff80cbe27e4e8065e9992a849ed8514be6da793c Mon Sep 17 00:00:00 2001 From: Lalit Date: Wed, 27 Oct 2021 23:54:10 -0700 Subject: [PATCH 08/14] add unit tests --- .../metrics_new/async_instruments.h | 2 - api/include/opentelemetry/metrics_new/meter.h | 1 - .../metrics_new/meter_provider.h | 5 +- api/include/opentelemetry/metrics_new/noop.h | 208 ++++++++++++++---- .../metrics_new/observer_result.h | 1 + .../opentelemetry/metrics_new/provider.h | 4 +- .../metrics_new/sync_instruments.h | 13 +- api/test/CMakeLists.txt | 2 + api/test/metrics_new/CMakeLists.txt | 9 + api/test/metrics_new/meter_provider_test.cc | 35 +++ .../metrics_new/noop_sync_instrument_test.cc | 39 ++++ 11 files changed, 266 insertions(+), 53 deletions(-) create mode 100644 api/test/metrics_new/CMakeLists.txt create mode 100644 api/test/metrics_new/meter_provider_test.cc create mode 100644 api/test/metrics_new/noop_sync_instrument_test.cc diff --git a/api/include/opentelemetry/metrics_new/async_instruments.h b/api/include/opentelemetry/metrics_new/async_instruments.h index 143206789e..1bd095f50c 100644 --- a/api/include/opentelemetry/metrics_new/async_instruments.h +++ b/api/include/opentelemetry/metrics_new/async_instruments.h @@ -3,7 +3,6 @@ #pragma once -#include "instrument.h" #include "observer_result.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -26,4 +25,3 @@ class ObservableUpDownCounter : public AsynchronousInstrument } // namespace metrics_new OPENTELEMETRY_END_NAMESPACE -#endif diff --git a/api/include/opentelemetry/metrics_new/meter.h b/api/include/opentelemetry/metrics_new/meter.h index 4844041a35..0a5a1611ed 100644 --- a/api/include/opentelemetry/metrics_new/meter.h +++ b/api/include/opentelemetry/metrics_new/meter.h @@ -4,7 +4,6 @@ #pragma once #include "opentelemetry/metrics_new/async_instruments.h" -#include "opentelemetry/metrics_new/instrument.h" #include "opentelemetry/metrics_new/sync_instruments.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/span.h" diff --git a/api/include/opentelemetry/metrics_new/meter_provider.h b/api/include/opentelemetry/metrics_new/meter_provider.h index e5579694ce..a010d551f6 100644 --- a/api/include/opentelemetry/metrics_new/meter_provider.h +++ b/api/include/opentelemetry/metrics_new/meter_provider.h @@ -3,7 +3,7 @@ #pragma once -#include "opentelemetry/metrics/meter.h" +#include "opentelemetry/metrics_new/meter.h" #include "opentelemetry/nostd/shared_ptr.h" #include "opentelemetry/nostd/string_view.h" @@ -26,5 +26,6 @@ class MeterProvider virtual nostd::shared_ptr GetMeter(nostd::string_view library_name, nostd::string_view library_version = "", nostd::string_view schema_url = "") noexcept = 0; -} // namespace metrics +}; +} // namespace metrics_new OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/metrics_new/noop.h b/api/include/opentelemetry/metrics_new/noop.h index f984907612..7738f488e9 100644 --- a/api/include/opentelemetry/metrics_new/noop.h +++ b/api/include/opentelemetry/metrics_new/noop.h @@ -1,90 +1,220 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#include "opentelemetry/metrics_new/async_instruments.h" +#include "opentelemetry/metrics_new/meter.h" +#include "opentelemetry/metrics_new/meter_provider.h" +#include "opentelemetry/metrics_new/observer_result.h" #include "opentelemetry/metrics_new/sync_instruments.h" +#include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics_new { template -class NoopCounter : public opentelemetry::metrics_new::Counter +class NoopCounter : public Counter { public: + NoopCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit) noexcept + {} void Add(T value) noexcept override {} - void Add(T value, const common::KeyValueIterable &attributes) {} -} + void Add(T value, const common::KeyValueIterable &attributes) noexcept override {} +}; template -class NoopHistorgram : public opentelemetry::metrics_new::Historgram +class NoopHistogram : public Histogram { public: - void Add(T value) noexcept override {} - void Add(T value, const common::KeyValueIterable &attributes) {} -} + NoopHistogram(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit) noexcept + {} + void Record(T value) noexcept override {} + void Record(T value, const common::KeyValueIterable &attributes) noexcept override {} +}; template -class NoopUpDownCounter : public opentelemetry::metrics_new::UpDownCounter +class NoopUpDownCounter : public UpDownCounter { public: + NoopUpDownCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit) noexcept + {} void Add(T value) noexcept override {} - void Add(T value, const common::KeyValueIterable &attributes) {} -} + void Add(T value, const common::KeyValueIterable &attributes) noexcept override {} +}; template -class NoopObservableCounter : public ObservableCounter -{}; +class NoopObservableCounter : public ObservableCounter +{ +public: + NoopObservableCounter(nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description, + nostd::string_view unit) noexcept + {} +}; template -class NoopObservableGauge : public ObservableGauge -{}; +class NoopObservableGauge : public ObservableGauge +{ +public: + NoopObservableGauge(nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description, + nostd::string_view unit) noexcept + {} +}; template -class NoopObservableUpDownCounter : public ObservableUpDownCounter -{}; +class NoopObservableUpDownCounter : public ObservableUpDownCounter +{ +public: + NoopObservableUpDownCounter(nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description, + nostd::string_view unit) noexcept + {} +}; /** * No-op implementation of Meter. */ -class NoopMeter final : public opentelemetry::Meter +class NoopMeter final : public Meter { public: - // Tracer - nostd::shared_ptr StartSpan(nostd::string_view /*name*/, - const common::KeyValueIterable & /*attributes*/, - const SpanContextKeyValueIterable & /*links*/, - const StartSpanOptions & /*options*/) noexcept override + nostd::shared_ptr> CreateLongCounter(nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override { - // Don't allocate a no-op span for every StartSpan call, but use a static - // singleton for this case. - static nostd::shared_ptr noop_span( - new trace_api::NoopSpan{this->shared_from_this()}); + return nostd::shared_ptr>{new NoopCounter(name, description, unit)}; + } - return noop_span; + nostd::shared_ptr> CreateDoubleCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{new NoopCounter(name, description, unit)}; } - void ForceFlushWithMicroseconds(uint64_t /*timeout*/) noexcept override {} + nostd::shared_ptr> CreateLongObservableCounter( + nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopObservableCounter(name, callback, description, unit)}; + } - void CloseWithMicroseconds(uint64_t /*timeout*/) noexcept override {} + nostd::shared_ptr> CreateDoubleObservableCounter( + nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopObservableCounter(name, callback, description, unit)}; + } + + nostd::shared_ptr> CreateLongHistogram( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{new NoopHistogram(name, description, unit)}; + } + + nostd::shared_ptr> CreateDoubleHistogram( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{new NoopHistogram(name, description, unit)}; + } + + nostd::shared_ptr> CreateLongObservableGauge( + nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopObservableGauge(name, callback, description, unit)}; + } + + nostd::shared_ptr> CreateDoubleObservableGauge( + nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopObservableGauge(name, callback, description, unit)}; + } + + nostd::shared_ptr> CreateLongUpDownCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit)}; + } + + nostd::shared_ptr> CreateDoubleUpDownCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit)}; + } + + nostd::shared_ptr> CreateLongObservableUpDownCounter( + nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopObservableUpDownCounter(name, callback, description, unit)}; + } + + nostd::shared_ptr> CreateDoubleObservableUpDownCounter( + nostd::string_view name, + void (*callback)(ObserverResult), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopObservableUpDownCounter(name, callback, description, unit)}; + } }; /** - * No-op implementation of a TracerProvider. + * No-op implementation of a MeterProvider. */ -class NoopMeterProvider final : public opentelemetry::trace::MeterProvider +class NoopMeterProvider final : public MeterProvider { public: - NoopMeterProvider() - : tracer_{ - nostd::shared_ptr(new opentelemetry::trace::NoopMeter)} - {} + NoopMeterProvider() : meter_{nostd::shared_ptr(new NoopMeter)} {} - nostd::shared_ptr GetMeter(nostd::string_view library_name, - nostd::string_view library_version, - nostd::string_view schema_url) override + nostd::shared_ptr GetMeter(nostd::string_view library_name, + nostd::string_view library_version, + nostd::string_view schema_url) noexcept override { return meter_; } private: - nostd::shared_ptr meter_; + nostd::shared_ptr meter_; }; } // namespace metrics_new OPENTELEMETRY_END_NAMESPACE \ No newline at end of file diff --git a/api/include/opentelemetry/metrics_new/observer_result.h b/api/include/opentelemetry/metrics_new/observer_result.h index 5d78fe2f58..088d4be859 100644 --- a/api/include/opentelemetry/metrics_new/observer_result.h +++ b/api/include/opentelemetry/metrics_new/observer_result.h @@ -6,6 +6,7 @@ #include "opentelemetry/common/key_value_iterable_view.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/nostd/type_traits.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics_new diff --git a/api/include/opentelemetry/metrics_new/provider.h b/api/include/opentelemetry/metrics_new/provider.h index aebca3fa73..d8feeaa1f3 100644 --- a/api/include/opentelemetry/metrics_new/provider.h +++ b/api/include/opentelemetry/metrics_new/provider.h @@ -5,8 +5,8 @@ #include #include "opentelemetry/common/spin_lock_mutex.h" -#include "opentelemetry/metrics/meter_provider.h" -#include "opentelemetry/metrics/noop.h" +#include "opentelemetry/metrics_new/meter_provider.h" +#include "opentelemetry/metrics_new/noop.h" #include "opentelemetry/nostd/shared_ptr.h" OPENTELEMETRY_BEGIN_NAMESPACE diff --git a/api/include/opentelemetry/metrics_new/sync_instruments.h b/api/include/opentelemetry/metrics_new/sync_instruments.h index bfeab5f95e..f0fcc8ab1d 100644 --- a/api/include/opentelemetry/metrics_new/sync_instruments.h +++ b/api/include/opentelemetry/metrics_new/sync_instruments.h @@ -43,7 +43,7 @@ class Counter : public SynchronousInstrument nostd::enable_if_t::value> * = nullptr> void Add(T value, const U &attributes) noexcept { - this->Add(value, common::KeyValueIterableView{attributes}); + this->Add(value, common::KeyValueIterableView{attributes}); } void Add(T value, @@ -58,7 +58,7 @@ class Counter : public SynchronousInstrument /** A histogram instrument that records values. */ template -class Historgram : public SynchronousInstrument +class Histogram : public SynchronousInstrument { public: /** @@ -80,7 +80,7 @@ class Historgram : public SynchronousInstrument nostd::enable_if_t::value> * = nullptr> void Record(T value, const U &attributes) noexcept { - this->Record(value, common::KeyValueIterableView{attributes}); + this->Record(value, common::KeyValueIterableView{attributes}); } void Record(T value, @@ -90,8 +90,7 @@ class Historgram : public SynchronousInstrument this->Record(value, nostd::span>{ attributes.begin(), attributes.end()}); } - -} +}; /** An up-down-counter instrument that adds or reduce values. */ @@ -112,13 +111,13 @@ class UpDownCounter : public SynchronousInstrument * @param value The increment amount. May be positive, negative or zero. * @param attributes A set of attributes to associate with the count. */ - void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0; + virtual void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0; template ::value> * = nullptr> void Add(T value, const U &attributes) noexcept { - this->Add(value, common::KeyValueIterableView{attributes}); + this->Add(value, common::KeyValueIterableView{attributes}); } void Add(T value, diff --git a/api/test/CMakeLists.txt b/api/test/CMakeLists.txt index 0e4c9bd0f3..2cc72d152a 100644 --- a/api/test/CMakeLists.txt +++ b/api/test/CMakeLists.txt @@ -5,6 +5,8 @@ add_subdirectory(nostd) add_subdirectory(trace) if(WITH_METRICS_PREVIEW) add_subdirectory(metrics) +else() + add_subdirectory(metrics_new) endif() if(WITH_LOGS_PREVIEW) add_subdirectory(logs) diff --git a/api/test/metrics_new/CMakeLists.txt b/api/test/metrics_new/CMakeLists.txt new file mode 100644 index 0000000000..89ce81fd01 --- /dev/null +++ b/api/test/metrics_new/CMakeLists.txt @@ -0,0 +1,9 @@ +foreach(testname meter_provider_test noop_sync_instrument_test) + add_executable(${testname} "${testname}.cc") + target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) + gtest_add_tests( + TARGET ${testname} + TEST_PREFIX metrics_new. + TEST_LIST ${testname}) +endforeach() diff --git a/api/test/metrics_new/meter_provider_test.cc b/api/test/metrics_new/meter_provider_test.cc new file mode 100644 index 0000000000..0df7cda65c --- /dev/null +++ b/api/test/metrics_new/meter_provider_test.cc @@ -0,0 +1,35 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include "opentelemetry/metrics_new/noop.h" +#include "opentelemetry/metrics_new/provider.h" +#include "opentelemetry/nostd/shared_ptr.h" + +using opentelemetry::metrics_new::Meter; +using opentelemetry::metrics_new::MeterProvider; +using opentelemetry::metrics_new::NoopMeterProvider; +using opentelemetry::metrics_new::Provider; + +TEST(Provider, GetMeterProviderDefault) +{ + auto tf = Provider::GetMeterProvider(); + EXPECT_NE(nullptr, tf); +} + +TEST(Provider, SetMeterProvider) +{ + auto tf = opentelemetry::nostd::shared_ptr(new NoopMeterProvider()); + Provider::SetMeterProvider(tf); + ASSERT_EQ(tf, Provider::GetMeterProvider()); +} + +TEST(Provider, MultipleMeterProviders) +{ + auto tf = opentelemetry::nostd::shared_ptr(new NoopMeterProvider()); + Provider::SetMeterProvider(tf); + auto tf2 = opentelemetry::nostd::shared_ptr(new NoopMeterProvider()); + Provider::SetMeterProvider(tf2); + + ASSERT_NE(Provider::GetMeterProvider(), tf); +} diff --git a/api/test/metrics_new/noop_sync_instrument_test.cc b/api/test/metrics_new/noop_sync_instrument_test.cc new file mode 100644 index 0000000000..4922d9273d --- /dev/null +++ b/api/test/metrics_new/noop_sync_instrument_test.cc @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include "opentelemetry/metrics_new/noop.h" + +TEST(Counter, Add) +{ + std::shared_ptr> counter{ + new opentelemetry::metrics_new::NoopCounter("test", "none", "unitless")}; + + std::map labels = {{"k1", "v1"}}; + EXPECT_NO_THROW(counter->Add(10l, labels)); + EXPECT_NO_THROW(counter->Add(2l)); + EXPECT_NO_THROW(counter->Add(10l, {{"k1", "1"}, {"k2", 2}})); +} + +TEST(histogram, Record) +{ + std::shared_ptr> counter{ + new opentelemetry::metrics_new::NoopHistogram("test", "none", "unitless")}; + + std::map labels = {{"k1", "v1"}}; + EXPECT_NO_THROW(counter->Record(10l, labels)); + EXPECT_NO_THROW(counter->Record(2l)); + EXPECT_NO_THROW(counter->Record(10l, {{"k1", "1"}, {"k2", 2}})); +} + +TEST(UpDownCountr, Record) +{ + std::shared_ptr> counter{ + new opentelemetry::metrics_new::NoopUpDownCounter("test", "none", "unitless")}; + + std::map labels = {{"k1", "v1"}}; + EXPECT_NO_THROW(counter->Add(10l, labels)); + EXPECT_NO_THROW(counter->Add(2l)); + EXPECT_NO_THROW(counter->Add(10l, {{"k1", "1"}, {"k2", 2}})); +} \ No newline at end of file From 67961a4e79073c5fc5308eaf97c4ae2a99764fed Mon Sep 17 00:00:00 2001 From: Lalit Date: Thu, 28 Oct 2021 13:40:28 -0700 Subject: [PATCH 09/14] add callback state --- api/include/opentelemetry/metrics_new/meter.h | 57 +++++++++-- api/include/opentelemetry/metrics_new/noop.h | 97 +++++++++++++++++-- 2 files changed, 136 insertions(+), 18 deletions(-) diff --git a/api/include/opentelemetry/metrics_new/meter.h b/api/include/opentelemetry/metrics_new/meter.h index 0a5a1611ed..368784adca 100644 --- a/api/include/opentelemetry/metrics_new/meter.h +++ b/api/include/opentelemetry/metrics_new/meter.h @@ -52,18 +52,31 @@ class Meter * @param name the name of the new Observable Counter. * @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. - * @param callback the function to be observed by the instrument. + * @param callback the function to be observed by the instrument. This can optionally take `state` + * as key-value argument. * @return a shared pointer to the created Observable Counter. */ virtual nostd::shared_ptr> CreateLongObservableCounter( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; + + virtual nostd::shared_ptr> CreateLongObservableCounter( + nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleObservableCounter( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; + + virtual nostd::shared_ptr> CreateDoubleObservableCounter( + nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; @@ -92,18 +105,31 @@ class Meter * @param name the name of the new Observable Gauge. * @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. - * @param callback the function to be observed by the instrument. + * @param callback the function to be observed by the instrument. This can optionally take `state` + * as key-value argument. * @return a shared pointer to the created Observable Gauge. */ virtual nostd::shared_ptr> CreateLongObservableGauge( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; + + virtual nostd::shared_ptr> CreateLongObservableGauge( + nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleObservableGauge( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; + + virtual nostd::shared_ptr> CreateDoubleObservableGauge( + nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; @@ -133,18 +159,31 @@ class Meter * @param name the name of the new Observable UpDownCounter. * @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. - * @param callback the function to be observed by the instrument. + * @param callback the function to be observed by the instrument. This can optionally take `state` + * as key-value argument. * @return a shared pointer to the created Observable UpDownCounter. */ virtual nostd::shared_ptr> CreateLongObservableUpDownCounter( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; + + virtual nostd::shared_ptr> CreateLongObservableUpDownCounter( + nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept = 0; + + virtual nostd::shared_ptr> CreateDoubleObservableUpDownCounter( + nostd::string_view name, + void (*callback)(ObserverResult &), nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleObservableUpDownCounter( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; }; diff --git a/api/include/opentelemetry/metrics_new/noop.h b/api/include/opentelemetry/metrics_new/noop.h index 7738f488e9..40623c7ba9 100644 --- a/api/include/opentelemetry/metrics_new/noop.h +++ b/api/include/opentelemetry/metrics_new/noop.h @@ -54,7 +54,13 @@ class NoopObservableCounter : public ObservableCounter { public: NoopObservableCounter(nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description, + nostd::string_view unit) noexcept + {} + + NoopObservableCounter(nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description, nostd::string_view unit) noexcept {} @@ -65,7 +71,13 @@ class NoopObservableGauge : public ObservableGauge { public: NoopObservableGauge(nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description, + nostd::string_view unit) noexcept + {} + + NoopObservableGauge(nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description, nostd::string_view unit) noexcept {} @@ -76,7 +88,14 @@ class NoopObservableUpDownCounter : public ObservableUpDownCounter { public: NoopObservableUpDownCounter(nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description, + nostd::string_view unit) noexcept + {} + + NoopObservableUpDownCounter(nostd::string_view name, + void (*callback)(ObserverResult &, + const common::KeyValueIterable &), nostd::string_view description, nostd::string_view unit) noexcept {} @@ -105,7 +124,17 @@ class NoopMeter final : public Meter nostd::shared_ptr> CreateLongObservableCounter( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopObservableCounter(name, callback, description, unit)}; + } + + nostd::shared_ptr> CreateLongObservableCounter( + nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description = "", nostd::string_view unit = "") noexcept override { @@ -115,7 +144,17 @@ class NoopMeter final : public Meter nostd::shared_ptr> CreateDoubleObservableCounter( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopObservableCounter(name, callback, description, unit)}; + } + + nostd::shared_ptr> CreateDoubleObservableCounter( + nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description = "", nostd::string_view unit = "") noexcept override { @@ -141,7 +180,17 @@ class NoopMeter final : public Meter nostd::shared_ptr> CreateLongObservableGauge( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopObservableGauge(name, callback, description, unit)}; + } + + nostd::shared_ptr> CreateLongObservableGauge( + nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description = "", nostd::string_view unit = "") noexcept override { @@ -151,7 +200,17 @@ class NoopMeter final : public Meter nostd::shared_ptr> CreateDoubleObservableGauge( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopObservableGauge(name, callback, description, unit)}; + } + + nostd::shared_ptr> CreateDoubleObservableGauge( + nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description = "", nostd::string_view unit = "") noexcept override { @@ -179,7 +238,17 @@ class NoopMeter final : public Meter nostd::shared_ptr> CreateLongObservableUpDownCounter( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopObservableUpDownCounter(name, callback, description, unit)}; + } + + nostd::shared_ptr> CreateLongObservableUpDownCounter( + nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description = "", nostd::string_view unit = "") noexcept override { @@ -189,7 +258,17 @@ class NoopMeter final : public Meter nostd::shared_ptr> CreateDoubleObservableUpDownCounter( nostd::string_view name, - void (*callback)(ObserverResult), + void (*callback)(ObserverResult &), + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{ + new NoopObservableUpDownCounter(name, callback, description, unit)}; + } + + nostd::shared_ptr> CreateDoubleObservableUpDownCounter( + nostd::string_view name, + void (*callback)(ObserverResult &, const common::KeyValueIterable &), nostd::string_view description = "", nostd::string_view unit = "") noexcept override { From b745284e84f02eff45f6186e63fd142fdd3112ee Mon Sep 17 00:00:00 2001 From: Lalit Date: Tue, 9 Nov 2021 20:06:00 -0800 Subject: [PATCH 10/14] rename metrics_new to metrics --- .../async_instruments.h | 8 ++++--- .../{metrics_new => metrics}/meter.h | 18 +++++++------- .../{metrics_new => metrics}/meter_provider.h | 12 ++++++---- .../{metrics_new => metrics}/noop.h | 21 +++++++++------- .../observer_result.h | 17 +++++++------ .../{metrics_new => metrics}/provider.h | 19 ++++++++------- .../sync_instruments.h | 4 ++-- .../{metrics_new => metrics}/CMakeLists.txt | 0 .../meter_provider_test.cc | 19 ++++++++------- .../noop_sync_instrument_test.cc | 24 +++++++++++-------- 10 files changed, 82 insertions(+), 60 deletions(-) rename api/include/opentelemetry/{metrics_new => metrics}/async_instruments.h (79%) rename api/include/opentelemetry/{metrics_new => metrics}/meter.h (95%) rename api/include/opentelemetry/{metrics_new => metrics}/meter_provider.h (75%) rename api/include/opentelemetry/{metrics_new => metrics}/noop.h (96%) rename api/include/opentelemetry/{metrics_new => metrics}/observer_result.h (75%) rename api/include/opentelemetry/{metrics_new => metrics}/provider.h (77%) rename api/include/opentelemetry/{metrics_new => metrics}/sync_instruments.h (98%) rename api/test/{metrics_new => metrics}/CMakeLists.txt (100%) rename api/test/{metrics_new => metrics}/meter_provider_test.cc (66%) rename api/test/{metrics_new => metrics}/noop_sync_instrument_test.cc (60%) diff --git a/api/include/opentelemetry/metrics_new/async_instruments.h b/api/include/opentelemetry/metrics/async_instruments.h similarity index 79% rename from api/include/opentelemetry/metrics_new/async_instruments.h rename to api/include/opentelemetry/metrics/async_instruments.h index 1bd095f50c..daf43a32f5 100644 --- a/api/include/opentelemetry/metrics_new/async_instruments.h +++ b/api/include/opentelemetry/metrics/async_instruments.h @@ -2,11 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once +#ifndef ENABLE_METRICS_PREVIEW -#include "observer_result.h" +# include "observer_result.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics_new +namespace metrics { class AsynchronousInstrument {}; @@ -23,5 +24,6 @@ template class ObservableUpDownCounter : public AsynchronousInstrument {}; -} // namespace metrics_new +} // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics_new/meter.h b/api/include/opentelemetry/metrics/meter.h similarity index 95% rename from api/include/opentelemetry/metrics_new/meter.h rename to api/include/opentelemetry/metrics/meter.h index 368784adca..a56e1c3417 100644 --- a/api/include/opentelemetry/metrics_new/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -2,16 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once +#ifndef ENABLE_METRICS_PREVIEW -#include "opentelemetry/metrics_new/async_instruments.h" -#include "opentelemetry/metrics_new/sync_instruments.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/span.h" -#include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/version.h" +# include "opentelemetry/metrics/async_instruments.h" +# include "opentelemetry/metrics/sync_instruments.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/nostd/span.h" +# include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics_new +namespace metrics { /** * Handles instrument creation and provides a facility for batch recording. @@ -187,5 +188,6 @@ class Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; }; -} // namespace metrics_new +} // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics_new/meter_provider.h b/api/include/opentelemetry/metrics/meter_provider.h similarity index 75% rename from api/include/opentelemetry/metrics_new/meter_provider.h rename to api/include/opentelemetry/metrics/meter_provider.h index a010d551f6..1892c7d8f9 100644 --- a/api/include/opentelemetry/metrics_new/meter_provider.h +++ b/api/include/opentelemetry/metrics/meter_provider.h @@ -2,13 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once +#ifndef ENABLE_METRICS_PREVIEW -#include "opentelemetry/metrics_new/meter.h" -#include "opentelemetry/nostd/shared_ptr.h" -#include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/metrics/meter.h" +# include "opentelemetry/nostd/shared_ptr.h" +# include "opentelemetry/nostd/string_view.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics_new +namespace metrics { /** * Creates new Meter instances. @@ -27,5 +28,6 @@ class MeterProvider nostd::string_view library_version = "", nostd::string_view schema_url = "") noexcept = 0; }; -} // namespace metrics_new +} // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics_new/noop.h b/api/include/opentelemetry/metrics/noop.h similarity index 96% rename from api/include/opentelemetry/metrics_new/noop.h rename to api/include/opentelemetry/metrics/noop.h index 40623c7ba9..f596c94f39 100644 --- a/api/include/opentelemetry/metrics_new/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -2,15 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#include "opentelemetry/metrics_new/async_instruments.h" -#include "opentelemetry/metrics_new/meter.h" -#include "opentelemetry/metrics_new/meter_provider.h" -#include "opentelemetry/metrics_new/observer_result.h" -#include "opentelemetry/metrics_new/sync_instruments.h" -#include "opentelemetry/version.h" +#ifndef ENABLE_METRICS_PREVIEW + +# include "opentelemetry/metrics/async_instruments.h" +# include "opentelemetry/metrics/meter.h" +# include "opentelemetry/metrics/meter_provider.h" +# include "opentelemetry/metrics/observer_result.h" +# include "opentelemetry/metrics/sync_instruments.h" +# include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics_new +namespace metrics { template @@ -295,5 +297,6 @@ class NoopMeterProvider final : public MeterProvider private: nostd::shared_ptr meter_; }; -} // namespace metrics_new -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif \ No newline at end of file diff --git a/api/include/opentelemetry/metrics_new/observer_result.h b/api/include/opentelemetry/metrics/observer_result.h similarity index 75% rename from api/include/opentelemetry/metrics_new/observer_result.h rename to api/include/opentelemetry/metrics/observer_result.h index 088d4be859..355b5a4a31 100644 --- a/api/include/opentelemetry/metrics_new/observer_result.h +++ b/api/include/opentelemetry/metrics/observer_result.h @@ -2,14 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#include "opentelemetry/common/attribute_value.h" -#include "opentelemetry/common/key_value_iterable_view.h" -#include "opentelemetry/nostd/span.h" -#include "opentelemetry/nostd/string_view.h" -#include "opentelemetry/nostd/type_traits.h" +#ifndef ENABLE_METRICS_PREVIEW + +# include "opentelemetry/common/attribute_value.h" +# include "opentelemetry/common/key_value_iterable_view.h" +# include "opentelemetry/nostd/span.h" +# include "opentelemetry/nostd/string_view.h" +# include "opentelemetry/nostd/type_traits.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics_new +namespace metrics { /** @@ -42,5 +44,6 @@ class ObserverResult } }; -} // namespace metrics_new +} // namespace metrics OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics_new/provider.h b/api/include/opentelemetry/metrics/provider.h similarity index 77% rename from api/include/opentelemetry/metrics_new/provider.h rename to api/include/opentelemetry/metrics/provider.h index d8feeaa1f3..3bacac9760 100644 --- a/api/include/opentelemetry/metrics_new/provider.h +++ b/api/include/opentelemetry/metrics/provider.h @@ -2,15 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#include +#ifndef ENABLE_METRICS_PREVIEW -#include "opentelemetry/common/spin_lock_mutex.h" -#include "opentelemetry/metrics_new/meter_provider.h" -#include "opentelemetry/metrics_new/noop.h" -#include "opentelemetry/nostd/shared_ptr.h" +# include + +# include "opentelemetry/common/spin_lock_mutex.h" +# include "opentelemetry/metrics/meter_provider.h" +# include "opentelemetry/metrics/noop.h" +# include "opentelemetry/nostd/shared_ptr.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics_new +namespace metrics { /** * Stores the singleton global MeterProvider. @@ -53,5 +55,6 @@ class Provider } }; -} // namespace metrics_new -OPENTELEMETRY_END_NAMESPACE \ No newline at end of file +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif \ No newline at end of file diff --git a/api/include/opentelemetry/metrics_new/sync_instruments.h b/api/include/opentelemetry/metrics/sync_instruments.h similarity index 98% rename from api/include/opentelemetry/metrics_new/sync_instruments.h rename to api/include/opentelemetry/metrics/sync_instruments.h index f0fcc8ab1d..9c8a776672 100644 --- a/api/include/opentelemetry/metrics_new/sync_instruments.h +++ b/api/include/opentelemetry/metrics/sync_instruments.h @@ -10,7 +10,7 @@ # include "opentelemetry/nostd/string_view.h" OPENTELEMETRY_BEGIN_NAMESPACE -namespace metrics_new +namespace metrics { class SynchronousInstrument @@ -129,6 +129,6 @@ class UpDownCounter : public SynchronousInstrument } }; -} // namespace metrics_new +} // namespace metrics OPENTELEMETRY_END_NAMESPACE #endif diff --git a/api/test/metrics_new/CMakeLists.txt b/api/test/metrics/CMakeLists.txt similarity index 100% rename from api/test/metrics_new/CMakeLists.txt rename to api/test/metrics/CMakeLists.txt diff --git a/api/test/metrics_new/meter_provider_test.cc b/api/test/metrics/meter_provider_test.cc similarity index 66% rename from api/test/metrics_new/meter_provider_test.cc rename to api/test/metrics/meter_provider_test.cc index 0df7cda65c..161d852f09 100644 --- a/api/test/metrics_new/meter_provider_test.cc +++ b/api/test/metrics/meter_provider_test.cc @@ -1,15 +1,17 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include -#include "opentelemetry/metrics_new/noop.h" -#include "opentelemetry/metrics_new/provider.h" -#include "opentelemetry/nostd/shared_ptr.h" +#ifndef ENABLE_METRICS_PREVIEW -using opentelemetry::metrics_new::Meter; -using opentelemetry::metrics_new::MeterProvider; -using opentelemetry::metrics_new::NoopMeterProvider; -using opentelemetry::metrics_new::Provider; +# include +# include "opentelemetry/metrics/noop.h" +# include "opentelemetry/metrics/provider.h" +# include "opentelemetry/nostd/shared_ptr.h" + +using opentelemetry::metrics::Meter; +using opentelemetry::metrics::MeterProvider; +using opentelemetry::metrics::NoopMeterProvider; +using opentelemetry::metrics::Provider; TEST(Provider, GetMeterProviderDefault) { @@ -33,3 +35,4 @@ TEST(Provider, MultipleMeterProviders) ASSERT_NE(Provider::GetMeterProvider(), tf); } +#endif diff --git a/api/test/metrics_new/noop_sync_instrument_test.cc b/api/test/metrics/noop_sync_instrument_test.cc similarity index 60% rename from api/test/metrics_new/noop_sync_instrument_test.cc rename to api/test/metrics/noop_sync_instrument_test.cc index 4922d9273d..4597e79e8b 100644 --- a/api/test/metrics_new/noop_sync_instrument_test.cc +++ b/api/test/metrics/noop_sync_instrument_test.cc @@ -1,14 +1,16 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include -#include -#include "opentelemetry/metrics_new/noop.h" +#ifndef ENABLE_METRICS_PREVIEW + +# include +# include +# include "opentelemetry/metrics/noop.h" TEST(Counter, Add) { - std::shared_ptr> counter{ - new opentelemetry::metrics_new::NoopCounter("test", "none", "unitless")}; + std::shared_ptr> counter{ + new opentelemetry::metrics::NoopCounter("test", "none", "unitless")}; std::map labels = {{"k1", "v1"}}; EXPECT_NO_THROW(counter->Add(10l, labels)); @@ -18,8 +20,8 @@ TEST(Counter, Add) TEST(histogram, Record) { - std::shared_ptr> counter{ - new opentelemetry::metrics_new::NoopHistogram("test", "none", "unitless")}; + std::shared_ptr> counter{ + new opentelemetry::metrics::NoopHistogram("test", "none", "unitless")}; std::map labels = {{"k1", "v1"}}; EXPECT_NO_THROW(counter->Record(10l, labels)); @@ -29,11 +31,13 @@ TEST(histogram, Record) TEST(UpDownCountr, Record) { - std::shared_ptr> counter{ - new opentelemetry::metrics_new::NoopUpDownCounter("test", "none", "unitless")}; + std::shared_ptr> counter{ + new opentelemetry::metrics::NoopUpDownCounter("test", "none", "unitless")}; std::map labels = {{"k1", "v1"}}; EXPECT_NO_THROW(counter->Add(10l, labels)); EXPECT_NO_THROW(counter->Add(2l)); EXPECT_NO_THROW(counter->Add(10l, {{"k1", "1"}, {"k2", 2}})); -} \ No newline at end of file +} + +#endif \ No newline at end of file From 93341e23444474435f5187e259f94de58c7708b5 Mon Sep 17 00:00:00 2001 From: Lalit Date: Tue, 9 Nov 2021 21:49:45 -0800 Subject: [PATCH 11/14] fix async meter --- api/include/opentelemetry/metrics/meter.h | 36 ----------------------- 1 file changed, 36 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index a56e1c3417..4978c834fc 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -63,24 +63,12 @@ class Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateLongObservableCounter( - nostd::string_view name, - void (*callback)(ObserverResult &, const common::KeyValueIterable &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateDoubleObservableCounter( nostd::string_view name, void (*callback)(ObserverResult &), nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateDoubleObservableCounter( - nostd::string_view name, - void (*callback)(ObserverResult &, const common::KeyValueIterable &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; - /** * Creates a Histogram with the passed characteristics and returns a shared_ptr to that Histogram. * @@ -116,24 +104,12 @@ class Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateLongObservableGauge( - nostd::string_view name, - void (*callback)(ObserverResult &, const common::KeyValueIterable &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateDoubleObservableGauge( nostd::string_view name, void (*callback)(ObserverResult &), nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateDoubleObservableGauge( - nostd::string_view name, - void (*callback)(ObserverResult &, const common::KeyValueIterable &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; - /** * Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that * UpDownCounter. @@ -170,23 +146,11 @@ class Meter nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateLongObservableUpDownCounter( - nostd::string_view name, - void (*callback)(ObserverResult &, const common::KeyValueIterable &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; - virtual nostd::shared_ptr> CreateDoubleObservableUpDownCounter( nostd::string_view name, void (*callback)(ObserverResult &), nostd::string_view description = "", nostd::string_view unit = "") noexcept = 0; - - virtual nostd::shared_ptr> CreateDoubleObservableUpDownCounter( - nostd::string_view name, - void (*callback)(ObserverResult &, const common::KeyValueIterable &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE From 96ee875c475e1f3a6013973f8b83194b261857a4 Mon Sep 17 00:00:00 2001 From: Lalit Date: Tue, 9 Nov 2021 21:51:43 -0800 Subject: [PATCH 12/14] update comment --- api/include/opentelemetry/metrics/meter.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 4978c834fc..9f7f2d2b0a 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -53,8 +53,7 @@ class Meter * @param name the name of the new Observable Counter. * @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. - * @param callback the function to be observed by the instrument. This can optionally take `state` - * as key-value argument. + * @param callback the function to be observed by the instrument. * @return a shared pointer to the created Observable Counter. */ virtual nostd::shared_ptr> CreateLongObservableCounter( @@ -94,8 +93,7 @@ class Meter * @param name the name of the new Observable Gauge. * @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. - * @param callback the function to be observed by the instrument. This can optionally take `state` - * as key-value argument. + * @param callback the function to be observed by the instrument. * @return a shared pointer to the created Observable Gauge. */ virtual nostd::shared_ptr> CreateLongObservableGauge( @@ -136,8 +134,7 @@ class Meter * @param name the name of the new Observable UpDownCounter. * @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. - * @param callback the function to be observed by the instrument. This can optionally take `state` - * as key-value argument. + * @param callback the function to be observed by the instrument. * @return a shared pointer to the created Observable UpDownCounter. */ virtual nostd::shared_ptr> CreateLongObservableUpDownCounter( From d17ea27ba6bcd9e674a0e08244e9c281c49ed71d Mon Sep 17 00:00:00 2001 From: Lalit Date: Tue, 9 Nov 2021 22:15:43 -0800 Subject: [PATCH 13/14] build failure --- api/include/opentelemetry/metrics/noop.h | 60 ------------------------ 1 file changed, 60 deletions(-) diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index f596c94f39..19b9443a7d 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -134,16 +134,6 @@ class NoopMeter final : public Meter new NoopObservableCounter(name, callback, description, unit)}; } - nostd::shared_ptr> CreateLongObservableCounter( - nostd::string_view name, - void (*callback)(ObserverResult &, const common::KeyValueIterable &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override - { - return nostd::shared_ptr>{ - new NoopObservableCounter(name, callback, description, unit)}; - } - nostd::shared_ptr> CreateDoubleObservableCounter( nostd::string_view name, void (*callback)(ObserverResult &), @@ -154,16 +144,6 @@ class NoopMeter final : public Meter new NoopObservableCounter(name, callback, description, unit)}; } - nostd::shared_ptr> CreateDoubleObservableCounter( - nostd::string_view name, - void (*callback)(ObserverResult &, const common::KeyValueIterable &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override - { - return nostd::shared_ptr>{ - new NoopObservableCounter(name, callback, description, unit)}; - } - nostd::shared_ptr> CreateLongHistogram( nostd::string_view name, nostd::string_view description = "", @@ -190,16 +170,6 @@ class NoopMeter final : public Meter new NoopObservableGauge(name, callback, description, unit)}; } - nostd::shared_ptr> CreateLongObservableGauge( - nostd::string_view name, - void (*callback)(ObserverResult &, const common::KeyValueIterable &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override - { - return nostd::shared_ptr>{ - new NoopObservableGauge(name, callback, description, unit)}; - } - nostd::shared_ptr> CreateDoubleObservableGauge( nostd::string_view name, void (*callback)(ObserverResult &), @@ -210,16 +180,6 @@ class NoopMeter final : public Meter new NoopObservableGauge(name, callback, description, unit)}; } - nostd::shared_ptr> CreateDoubleObservableGauge( - nostd::string_view name, - void (*callback)(ObserverResult &, const common::KeyValueIterable &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override - { - return nostd::shared_ptr>{ - new NoopObservableGauge(name, callback, description, unit)}; - } - nostd::shared_ptr> CreateLongUpDownCounter( nostd::string_view name, nostd::string_view description = "", @@ -248,16 +208,6 @@ class NoopMeter final : public Meter new NoopObservableUpDownCounter(name, callback, description, unit)}; } - nostd::shared_ptr> CreateLongObservableUpDownCounter( - nostd::string_view name, - void (*callback)(ObserverResult &, const common::KeyValueIterable &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override - { - return nostd::shared_ptr>{ - new NoopObservableUpDownCounter(name, callback, description, unit)}; - } - nostd::shared_ptr> CreateDoubleObservableUpDownCounter( nostd::string_view name, void (*callback)(ObserverResult &), @@ -267,16 +217,6 @@ class NoopMeter final : public Meter return nostd::shared_ptr>{ new NoopObservableUpDownCounter(name, callback, description, unit)}; } - - nostd::shared_ptr> CreateDoubleObservableUpDownCounter( - nostd::string_view name, - void (*callback)(ObserverResult &, const common::KeyValueIterable &), - nostd::string_view description = "", - nostd::string_view unit = "") noexcept override - { - return nostd::shared_ptr>{ - new NoopObservableUpDownCounter(name, callback, description, unit)}; - } }; /** From 5736834765fcdf020e761beb8b1c861d898ce4ee Mon Sep 17 00:00:00 2001 From: Lalit Date: Wed, 10 Nov 2021 15:16:54 -0800 Subject: [PATCH 14/14] make default unit to 1 --- api/include/opentelemetry/metrics/meter.h | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 9f7f2d2b0a..cd176d3157 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -39,12 +39,12 @@ class Meter virtual nostd::shared_ptr> CreateLongCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + nostd::string_view unit = "1") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + nostd::string_view unit = "1") noexcept = 0; /** * Creates a Asynchronouse (Observable) counter with the passed characteristics and returns a @@ -60,13 +60,13 @@ class Meter nostd::string_view name, void (*callback)(ObserverResult &), nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + nostd::string_view unit = "1") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleObservableCounter( nostd::string_view name, void (*callback)(ObserverResult &), nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + nostd::string_view unit = "1") noexcept = 0; /** * Creates a Histogram with the passed characteristics and returns a shared_ptr to that Histogram. @@ -79,12 +79,12 @@ class Meter virtual nostd::shared_ptr> CreateLongHistogram( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + nostd::string_view unit = "1") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleHistogram( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + nostd::string_view unit = "1") noexcept = 0; /** * Creates a Asynchronouse (Observable) Gauge with the passed characteristics and returns a @@ -100,13 +100,13 @@ class Meter nostd::string_view name, void (*callback)(ObserverResult &), nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + nostd::string_view unit = "1") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleObservableGauge( nostd::string_view name, void (*callback)(ObserverResult &), nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + nostd::string_view unit = "1") noexcept = 0; /** * Creates an UpDownCounter with the passed characteristics and returns a shared_ptr to that @@ -120,12 +120,12 @@ class Meter virtual nostd::shared_ptr> CreateLongUpDownCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + nostd::string_view unit = "1") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleUpDownCounter( nostd::string_view name, nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + nostd::string_view unit = "1") noexcept = 0; /** * Creates a Asynchronouse (Observable) UpDownCounter with the passed characteristics and returns @@ -141,13 +141,13 @@ class Meter nostd::string_view name, void (*callback)(ObserverResult &), nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + nostd::string_view unit = "1") noexcept = 0; virtual nostd::shared_ptr> CreateDoubleObservableUpDownCounter( nostd::string_view name, void (*callback)(ObserverResult &), nostd::string_view description = "", - nostd::string_view unit = "") noexcept = 0; + nostd::string_view unit = "1") noexcept = 0; }; } // namespace metrics OPENTELEMETRY_END_NAMESPACE