diff --git a/api/include/opentelemetry/metrics/async_instruments.h b/api/include/opentelemetry/metrics/async_instruments.h new file mode 100644 index 0000000000..daf43a32f5 --- /dev/null +++ b/api/include/opentelemetry/metrics/async_instruments.h @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef ENABLE_METRICS_PREVIEW + +# include "observer_result.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace metrics +{ +class AsynchronousInstrument +{}; + +template +class ObservableCounter : public AsynchronousInstrument +{}; + +template +class ObservableGauge : public AsynchronousInstrument +{}; + +template +class ObservableUpDownCounter : public AsynchronousInstrument +{}; + +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h new file mode 100644 index 0000000000..cd176d3157 --- /dev/null +++ b/api/include/opentelemetry/metrics/meter.h @@ -0,0 +1,154 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef ENABLE_METRICS_PREVIEW + +# 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 +{ +/** + * 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. + * @return a shared pointer to the created Counter. + */ + + virtual nostd::shared_ptr> CreateLongCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "1") noexcept = 0; + + virtual nostd::shared_ptr> CreateDoubleCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "1") noexcept = 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 callback the function to be observed by the instrument. + * @return a shared pointer to the created Observable Counter. + */ + virtual nostd::shared_ptr> CreateLongObservableCounter( + nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + 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 = "1") noexcept = 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. + * @return a shared pointer to the created Histogram. + */ + virtual nostd::shared_ptr> CreateLongHistogram( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "1") noexcept = 0; + + virtual nostd::shared_ptr> CreateDoubleHistogram( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "1") noexcept = 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 callback the function to be observed by the instrument. + * @return a shared pointer to the created Observable Gauge. + */ + virtual nostd::shared_ptr> CreateLongObservableGauge( + nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + 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 = "1") noexcept = 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. + * @return a shared pointer to the created UpDownCounter. + */ + virtual nostd::shared_ptr> CreateLongUpDownCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "1") noexcept = 0; + + virtual nostd::shared_ptr> CreateDoubleUpDownCounter( + nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "1") noexcept = 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 callback the function to be observed by the instrument. + * @return a shared pointer to the created Observable UpDownCounter. + */ + virtual nostd::shared_ptr> CreateLongObservableUpDownCounter( + nostd::string_view name, + void (*callback)(ObserverResult &), + nostd::string_view description = "", + 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 = "1") noexcept = 0; +}; +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics/meter_provider.h b/api/include/opentelemetry/metrics/meter_provider.h new file mode 100644 index 0000000000..1892c7d8f9 --- /dev/null +++ b/api/include/opentelemetry/metrics/meter_provider.h @@ -0,0 +1,33 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef 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 +{ +/** + * 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 = "") noexcept = 0; +}; +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h new file mode 100644 index 0000000000..19b9443a7d --- /dev/null +++ b/api/include/opentelemetry/metrics/noop.h @@ -0,0 +1,242 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#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 +{ + +template +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) noexcept override {} +}; + +template +class NoopHistogram : public Histogram +{ +public: + 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 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) noexcept override {} +}; + +template +class NoopObservableCounter : public ObservableCounter +{ +public: + NoopObservableCounter(nostd::string_view name, + 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 + {} +}; + +template +class NoopObservableGauge : public ObservableGauge +{ +public: + NoopObservableGauge(nostd::string_view name, + 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 + {} +}; + +template +class NoopObservableUpDownCounter : public ObservableUpDownCounter +{ +public: + NoopObservableUpDownCounter(nostd::string_view name, + 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 + {} +}; + +/** + * No-op implementation of Meter. + */ +class NoopMeter final : public Meter +{ +public: + nostd::shared_ptr> CreateLongCounter(nostd::string_view name, + nostd::string_view description = "", + nostd::string_view unit = "") noexcept override + { + return nostd::shared_ptr>{new NoopCounter(name, description, unit)}; + } + + 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)}; + } + + 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)}; + } + + 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 MeterProvider. + */ +class NoopMeterProvider final : public MeterProvider +{ +public: + 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) noexcept override + { + return meter_; + } + +private: + nostd::shared_ptr meter_; +}; +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif \ No newline at end of file diff --git a/api/include/opentelemetry/metrics/observer_result.h b/api/include/opentelemetry/metrics/observer_result.h new file mode 100644 index 0000000000..355b5a4a31 --- /dev/null +++ b/api/include/opentelemetry/metrics/observer_result.h @@ -0,0 +1,49 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#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 +{ + +/** + * ObserverResult class is necessary for the callback recording asynchronous + * instrument use. + */ + +template +class ObserverResult +{ + +public: + virtual void Observe(T value) 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 +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/include/opentelemetry/metrics/provider.h b/api/include/opentelemetry/metrics/provider.h new file mode 100644 index 0000000000..3bacac9760 --- /dev/null +++ b/api/include/opentelemetry/metrics/provider.h @@ -0,0 +1,60 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#ifndef 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 +{ +/** + * 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 \ No newline at end of file diff --git a/api/include/opentelemetry/metrics/sync_instruments.h b/api/include/opentelemetry/metrics/sync_instruments.h new file mode 100644 index 0000000000..9c8a776672 --- /dev/null +++ b/api/include/opentelemetry/metrics/sync_instruments.h @@ -0,0 +1,134 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once +#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" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace metrics +{ + +class SynchronousInstrument +{}; + +template +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) noexcept = 0; + + /** + * 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 attributes the set of attributes, as key-value pairs + */ + + 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. */ + +template +class Histogram : public SynchronousInstrument +{ +public: + /** + * Records a value. + * + * @param value The increment amount. May be positive, negative or zero. + */ + virtual void Record(T value) noexcept = 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. + */ + 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()}); + } +}; + +/** An up-down-counter instrument that adds or reduce values. */ + +template +class UpDownCounter : public SynchronousInstrument +{ +public: + /** + * Adds a value. + * + * @param value The amount of the measurement. + */ + virtual void Add(T value) noexcept = 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. + */ + 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()}); + } +}; + +} // namespace metrics +OPENTELEMETRY_END_NAMESPACE +#endif diff --git a/api/test/CMakeLists.txt b/api/test/CMakeLists.txt index 7eb67a6b55..41125005ee 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) endif() if(WITH_LOGS_PREVIEW) add_subdirectory(logs) diff --git a/api/test/metrics/CMakeLists.txt b/api/test/metrics/CMakeLists.txt new file mode 100644 index 0000000000..89ce81fd01 --- /dev/null +++ b/api/test/metrics/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/meter_provider_test.cc b/api/test/metrics/meter_provider_test.cc new file mode 100644 index 0000000000..161d852f09 --- /dev/null +++ b/api/test/metrics/meter_provider_test.cc @@ -0,0 +1,38 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef ENABLE_METRICS_PREVIEW + +# 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) +{ + 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); +} +#endif diff --git a/api/test/metrics/noop_sync_instrument_test.cc b/api/test/metrics/noop_sync_instrument_test.cc new file mode 100644 index 0000000000..4597e79e8b --- /dev/null +++ b/api/test/metrics/noop_sync_instrument_test.cc @@ -0,0 +1,43 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#ifndef ENABLE_METRICS_PREVIEW + +# include +# include +# include "opentelemetry/metrics/noop.h" + +TEST(Counter, Add) +{ + std::shared_ptr> counter{ + new opentelemetry::metrics::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::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::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}})); +} + +#endif \ No newline at end of file