diff --git a/api/include/opentelemetry/metrics/meter.h b/api/include/opentelemetry/metrics/meter.h index 19439da6df..c58c489f2a 100644 --- a/api/include/opentelemetry/metrics/meter.h +++ b/api/include/opentelemetry/metrics/meter.h @@ -1,17 +1,283 @@ #pragma once + +#include "opentelemetry/metrics/async_instruments.h" +#include "opentelemetry/metrics/instrument.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: - Meter() = default; -}; + virtual ~Meter() = default; -} // namespace metrics + /** + * 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> NewShortCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewIntCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewFloatCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 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. + * @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> NewShortUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewIntUpDownCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewFloatUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewDoubleUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + /** + * Creates a ValueRecorder with the passed characteristics and returns a shared_ptr to that + * ValueRecorder. + * + * @param name the name of the new ValueRecorder. + * @param description a brief description of what the ValueRecorder 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 DoubleValueRecorder. + * @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> NewShortValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewIntValueRecorder(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewFloatValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + virtual nostd::shared_ptr> NewDoubleValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) = 0; + + /** + * Creates a SumObserver with the passed characteristics and returns a shared_ptr to that + * SumObserver. + * + * @param name the name of the new SumObserver. + * @param description a brief description of what the SumObserver 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 SumObserver. + * @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> NewShortSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + virtual nostd::shared_ptr> NewIntSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewFloatSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewDoubleSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + /** + * Creates an UpDownSumObserver with the passed characteristics and returns a shared_ptr to + * that UpDowNSumObserver. + * + * @param name the name of the new UpDownSumObserver. + * @param description a brief description of what the UpDownSumObserver 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 UpDownSumObserver. + * @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> NewShortUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewIntUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewFloatUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewDoubleUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + /** + * Creates a ValueObserver with the passed characteristics and returns a shared_ptr to that + * ValueObserver. + * + * @param name the name of the new ValueObserver. + * @param description a brief description of what the ValueObserver 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 ValueObserver. + * @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> NewShortValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewIntValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewFloatValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) = 0; + + virtual nostd::shared_ptr> NewDoubleValueObserver( + 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 trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept = 0; + + virtual void RecordIntBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept = 0; + + virtual void RecordFloatBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept = 0; + + virtual void RecordDoubleBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept = 0; +}; +} // namespace metrics OPENTELEMETRY_END_NAMESPACE diff --git a/api/include/opentelemetry/metrics/noop.h b/api/include/opentelemetry/metrics/noop.h index b5e8988f92..c5569fd4e9 100644 --- a/api/include/opentelemetry/metrics/noop.h +++ b/api/include/opentelemetry/metrics/noop.h @@ -18,31 +18,6 @@ OPENTELEMETRY_BEGIN_NAMESPACE namespace metrics { -/** - * No-op implementation of a MeterProvider. - */ -class NoopMeter final : public Meter, public std::enable_shared_from_this -{}; - -class NoopMeterProvider final : public opentelemetry::metrics::MeterProvider -{ -public: - NoopMeterProvider() - : meter_{nostd::shared_ptr( - new opentelemetry::metrics::NoopMeter)} - {} - - nostd::shared_ptr GetMeter( - nostd::string_view library_name, - nostd::string_view library_version) override - { - return meter_; - } - -private: - nostd::shared_ptr meter_; -}; - template class NoopValueObserver : public ValueObserver { @@ -303,5 +278,376 @@ class NoopValueRecorder : public ValueRecorder virtual InstrumentKind GetKind() override { return InstrumentKind::ValueRecorder; } }; +/** + * No-op implementation of Meter. This class should not be used directly. + */ +class NoopMeter : public Meter +{ +public: + NoopMeter() = default; + + /** + * + * Creates a new NoopCounter and returns a shared ptr to that counter. + * + * @param name the name of the instrument. + * @param description a brief description of the instrument. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean that turns the metric instrument on and off. + * @return + */ + opentelemetry::nostd::shared_ptr> NewShortCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ + new NoopCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewIntCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{new NoopCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewFloatCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ + new NoopCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ + new NoopCounter(name, description, unit, enabled)}; + } + + /** + * + * Creates a new NoopCounter and returns a shared ptr to that counter. + * + * @param name the name of the instrument. + * @param description a brief description of the instrument. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean that turns the metric instrument on and off. + * @return + */ + opentelemetry::nostd::shared_ptr> NewShortUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewIntUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewFloatUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewDoubleUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ + new NoopUpDownCounter(name, description, unit, enabled)}; + } + + /** + * + * Creates a new ValueRecorder and returns a shared ptr to that counter. + * + * @param name the name of the instrument. + * @param description a brief description of the instrument. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean that turns the metric instrument on and off. + * @return + */ + opentelemetry::nostd::shared_ptr> NewShortValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewIntValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewFloatValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; + } + + opentelemetry::nostd::shared_ptr> NewDoubleValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>{ + new NoopValueRecorder(name, description, unit, enabled)}; + } + + /** + * + * Creates a new SumObserver and returns a shared ptr to that counter. + * + * @param name the name of the instrument. + * @param description a brief description of the instrument. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean that turns the metric instrument on and off. + * @return + */ + opentelemetry::nostd::shared_ptr> NewShortSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewIntSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewFloatSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewDoubleSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ + new NoopSumObserver(name, description, unit, enabled, callback)}; + } + + /** + * + * Creates a new UpDownSumObserver and returns a shared ptr to that counter. + * + * @param name the name of the instrument. + * @param description a brief description of the instrument. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean that turns the metric instrument on and off. + * @return + */ + opentelemetry::nostd::shared_ptr> NewShortUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewIntUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewFloatUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewDoubleUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ + new NoopUpDownSumObserver(name, description, unit, enabled, callback)}; + } + + /** + * + * Creates a new ValueObserverObserver and returns a shared ptr to that counter. + * + * @param name the name of the instrument. + * @param description a brief description of the instrument. + * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html. + * @param enabled a boolean that turns the metric instrument on and off. + * @return + */ + opentelemetry::nostd::shared_ptr> NewShortValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewIntValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewFloatValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; + } + + opentelemetry::nostd::shared_ptr> NewDoubleValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(ObserverResult)) override + { + return nostd::shared_ptr>{ + new NoopValueObserver(name, description, unit, enabled, callback)}; + } + + /** + * + * 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 instrs the instruments to record to. + * @param values the value to record to those instruments. + */ + void RecordShortBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override + { + // No-op + } + + void RecordIntBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override + { + // No-op + } + + void RecordFloatBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override + { + // No-op + } + + void RecordDoubleBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override + { + // No-op + } +}; + +class NoopMeterProvider final : public opentelemetry::metrics::MeterProvider +{ +public: + NoopMeterProvider() + : meter_{nostd::shared_ptr( + new opentelemetry::metrics::NoopMeter)} + {} + + nostd::shared_ptr GetMeter( + nostd::string_view library_name, + nostd::string_view library_version) override + { + return meter_; + } + +private: + nostd::shared_ptr meter_; +}; } // namespace metrics OPENTELEMETRY_END_NAMESPACE diff --git a/api/test/metrics/BUILD b/api/test/metrics/BUILD index a56dc3fcd0..09b4d8018d 100644 --- a/api/test/metrics/BUILD +++ b/api/test/metrics/BUILD @@ -11,6 +11,17 @@ cc_test( ], ) +cc_test( + name = "noop_metrics_test", + srcs = [ + "noop_metrics_test.cc", + ], + deps = [ + "//api", + "@com_google_googletest//:gtest_main", + ], +) + cc_test( name = "noop_instrument_test", srcs = [ diff --git a/api/test/metrics/CMakeLists.txt b/api/test/metrics/CMakeLists.txt index 204aa992a6..c9d2083d5a 100644 --- a/api/test/metrics/CMakeLists.txt +++ b/api/test/metrics/CMakeLists.txt @@ -1,4 +1,4 @@ -foreach(testname noop_instrument_test meter_provider_test) +foreach(testname noop_instrument_test meter_provider_test noop_metrics_test) add_executable(${testname} "${testname}.cc") target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) diff --git a/api/test/metrics/noop_metrics_test.cc b/api/test/metrics/noop_metrics_test.cc new file mode 100644 index 0000000000..85533e070e --- /dev/null +++ b/api/test/metrics/noop_metrics_test.cc @@ -0,0 +1,79 @@ +#include +#include "opentelemetry/metrics/instrument.h" +#include "opentelemetry/metrics/noop.h" +#include "opentelemetry/metrics/observer_result.h" +#include "opentelemetry/metrics/sync_instruments.h" + +#include + +OPENTELEMETRY_BEGIN_NAMESPACE + +using opentelemetry::metrics::Meter; +using opentelemetry::metrics::NoopMeter; + +namespace metrics_api = opentelemetry::metrics; + +void Callback(opentelemetry::metrics::ObserverResult result) +{ + std::map labels = {{"key", "value"}}; + auto labelkv = trace::KeyValueIterableView{labels}; + result.observe(1, labelkv); +} + +TEST(NoopTest, CreateInstruments) +{ + auto m = std::unique_ptr(new NoopMeter{}); + + // Test instrument constructors + m->NewIntCounter("Test counter", "For testing", "Unitless", true); + m->NewIntUpDownCounter("Test ud counter", "For testing", "Unitless", true); + m->NewIntValueRecorder("Test recorder", "For testing", "Unitless", true); + + m->NewIntSumObserver("Test sum obs", "For testing", "Unitless", true, &Callback); + m->NewIntUpDownSumObserver("Test udsum obs", "For testing", "Unitless", true, &Callback); + m->NewIntValueObserver("Test val obs", "For testing", "Unitless", true, &Callback); +} + +TEST(NoopMeter, RecordBatch) +{ + // Test BatchRecord with all supported types + // Create Counter and call RecordBatch for all four supported types: short, int, float, and double + + std::unique_ptr m{std::unique_ptr(new NoopMeter{})}; + + std::map labels = {{"Key", "Value"}}; + auto labelkv = opentelemetry::trace::KeyValueIterableView{labels}; + + auto s = m->NewShortCounter("Test short counter", "For testing", "Unitless", true); + + std::array *, 1> siarr{s.get()}; + std::array svarr{1}; + nostd::span *> ssp{siarr}; + nostd::span sval{svarr}; + m->RecordShortBatch(labelkv, ssp, sval); + + auto i = m->NewIntCounter("Test int counter", "For testing", "Unitless", true); + + std::array *, 1> iiarr{i.get()}; + std::array ivarr{1}; + nostd::span *> isp{iiarr}; + nostd::span ival{ivarr}; + m->RecordIntBatch(labelkv, isp, ival); + + auto f = m->NewFloatCounter("Test int counter", "For testing", "Unitless", true); + + std::array *, 1> fiarr{f.get()}; + std::array fvarr{1.0f}; + nostd::span *> fsp{fiarr}; + nostd::span fval{fvarr}; + m->RecordFloatBatch(labelkv, fsp, fval); + + auto d = m->NewDoubleCounter("Test int counter", "For testing", "Unitless", true); + + std::array *, 1> diarr{d.get()}; + std::array dvarr{1.0f}; + nostd::span *> dsp{diarr}; + nostd::span dval{dvarr}; + m->RecordDoubleBatch(labelkv, dsp, dval); +} +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/metrics/meter.h b/sdk/include/opentelemetry/sdk/metrics/meter.h index 9a66adb6d9..ccb96ea804 100644 --- a/sdk/include/opentelemetry/sdk/metrics/meter.h +++ b/sdk/include/opentelemetry/sdk/metrics/meter.h @@ -4,22 +4,266 @@ #include "opentelemetry/version.h" #include -#include OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace metrics { -class Meter final : public opentelemetry::metrics::Meter, public std::enable_shared_from_this +namespace metrics_api = opentelemetry::metrics; +class Meter final : public metrics_api::Meter, public std::enable_shared_from_this { public: - explicit Meter(std::string library_name, std::string library_version) + explicit Meter(std::string library_name, std::string library_version = "") { library_name_ = library_name; library_version_ = library_version; } + nostd::shared_ptr> NewShortCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewIntCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewFloatCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewDoubleCounter(nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewShortUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewIntUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewFloatUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewDoubleUpDownCounter( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewShortValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewIntValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewFloatValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewDoubleValueRecorder( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewShortSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewIntSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewFloatSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewDoubleSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewShortUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewIntUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewFloatUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewDoubleUpDownSumObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewShortValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewIntValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewFloatValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override + { + return nostd::shared_ptr>(nullptr); + } + + nostd::shared_ptr> NewDoubleValueObserver( + nostd::string_view name, + nostd::string_view description, + nostd::string_view unit, + const bool enabled, + void (*callback)(metrics_api::ObserverResult)) override + { + return nostd::shared_ptr>(nullptr); + } + + void RecordShortBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override + {} + + void RecordIntBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override + {} + + void RecordFloatBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override + {} + + void RecordDoubleBatch(const trace::KeyValueIterable &labels, + nostd::span *> instruments, + nostd::span values) noexcept override + {} + private: std::string library_name_; std::string library_version_;