123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- #pragma once
- #include "opentelemetry/common/attribute_value.h"
- #include "opentelemetry/common/key_value_iterable_view.h"
- #include "opentelemetry/context/context.h"
- #include "opentelemetry/nostd/span.h"
- #include "opentelemetry/nostd/string_view.h"
- #include "opentelemetry/nostd/type_traits.h"
- #include "opentelemetry/version.h"
- OPENTELEMETRY_BEGIN_NAMESPACE
- namespace metrics
- {
- class SynchronousInstrument
- {
- public:
- SynchronousInstrument() = default;
- virtual ~SynchronousInstrument() = default;
- };
- /* A Counter instrument that adds values. */
- template <class T>
- class Counter : public SynchronousInstrument
- {
- public:
- /**
- * Record a value
- *
- * @param value The increment amount. MUST be non-negative.
- */
- virtual void Add(T value) noexcept = 0;
- /**
- * Record a value
- *
- * @param value The increment amount. MUST be non-negative.
- * @param context The explicit context to associate with this measurement.
- */
- virtual void Add(T value, const context::Context &context) noexcept = 0;
- /**
- * Record a value with a set of attributes.
- *
- * @param value The increment amount. MUST be non-negative.
- * @param attributes A set of attributes to associate with the value.
- */
- virtual void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0;
- /**
- * Record a value with a set of attributes.
- *
- * @param value The increment amount. MUST be non-negative.
- * @param attributes A set of attributes to associate with the value.
- * @param context The explicit context to associate with this measurement.
- */
- virtual void Add(T value,
- const common::KeyValueIterable &attributes,
- const context::Context &context) noexcept = 0;
- template <class U,
- nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
- void Add(T value, const U &attributes) noexcept
- {
- this->Add(value, common::KeyValueIterableView<U>{attributes});
- }
- template <class U,
- nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
- void Add(T value, const U &attributes, const context::Context &context) noexcept
- {
- this->Add(value, common::KeyValueIterableView<U>{attributes}, context);
- }
- void Add(T value,
- std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
- attributes) noexcept
- {
- this->Add(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
- attributes.begin(), attributes.end()});
- }
- void Add(T value,
- std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
- const context::Context &context) noexcept
- {
- this->Add(value,
- nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
- attributes.begin(), attributes.end()},
- context);
- }
- };
- /** A histogram instrument that records values. */
- template <class T>
- class Histogram : public SynchronousInstrument
- {
- public:
- #if OPENTELEMETRY_ABI_VERSION_NO >= 2
- /**
- * @since ABI_VERSION 2
- * Records a value.
- *
- * @param value The measurement value. MUST be non-negative.
- */
- virtual void Record(T value) noexcept = 0;
- /**
- * @since ABI_VERSION 2
- * Records a value with a set of attributes.
- *
- * @param value The measurement value. MUST be non-negative.
- * @param attribute A set of attributes to associate with the value.
- */
- virtual void Record(T value, const common::KeyValueIterable &attribute) noexcept = 0;
- template <class U,
- nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
- void Record(T value, const U &attributes) noexcept
- {
- this->Record(value, common::KeyValueIterableView<U>{attributes});
- }
- void Record(T value,
- std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
- attributes) noexcept
- {
- this->Record(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
- attributes.begin(), attributes.end()});
- }
- #endif
- /**
- * Records a value.
- *
- * @param value The measurement value. MUST be non-negative.
- * @param context The explicit context to associate with this measurement.
- */
- virtual void Record(T value, const context::Context &context) noexcept = 0;
- /**
- * Records a value with a set of attributes.
- *
- * @param value The measurement value. MUST be non-negative.
- * @param attributes A set of attributes to associate with the value..
- * @param context The explicit context to associate with this measurement.
- */
- virtual void Record(T value,
- const common::KeyValueIterable &attributes,
- const context::Context &context) noexcept = 0;
- template <class U,
- nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
- void Record(T value, const U &attributes, const context::Context &context) noexcept
- {
- this->Record(value, common::KeyValueIterableView<U>{attributes}, context);
- }
- void Record(
- T value,
- std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
- const context::Context &context) noexcept
- {
- this->Record(value,
- nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
- attributes.begin(), attributes.end()},
- context);
- }
- };
- /** An up-down-counter instrument that adds or reduce values. */
- template <class T>
- class UpDownCounter : public SynchronousInstrument
- {
- public:
- /**
- * Record a value.
- *
- * @param value The increment amount. May be positive, negative or zero.
- */
- virtual void Add(T value) noexcept = 0;
- /**
- * Record a value.
- *
- * @param value The increment amount. May be positive, negative or zero.
- * @param context The explicit context to associate with this measurement.
- */
- virtual void Add(T value, const context::Context &context) noexcept = 0;
- /**
- * Record 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;
- /**
- * Record 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.
- * @param context The explicit context to associate with this measurement.
- */
- virtual void Add(T value,
- const common::KeyValueIterable &attributes,
- const context::Context &context) noexcept = 0;
- template <class U,
- nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
- void Add(T value, const U &attributes) noexcept
- {
- this->Add(value, common::KeyValueIterableView<U>{attributes});
- }
- template <class U,
- nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
- void Add(T value, const U &attributes, const context::Context &context) noexcept
- {
- this->Add(value, common::KeyValueIterableView<U>{attributes}, context);
- }
- void Add(T value,
- std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
- attributes) noexcept
- {
- this->Add(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
- attributes.begin(), attributes.end()});
- }
- void Add(T value,
- std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
- const context::Context &context) noexcept
- {
- this->Add(value,
- nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
- attributes.begin(), attributes.end()},
- context);
- }
- };
- #if OPENTELEMETRY_ABI_VERSION_NO >= 2
- /* A Gauge instrument that records values. */
- template <class T>
- class Gauge : public SynchronousInstrument
- {
- public:
- /**
- * Record a value
- *
- * @param value The measurement value. May be positive, negative or zero.
- */
- virtual void Record(T value) noexcept = 0;
- /**
- * Record a value
- *
- * @param value The measurement value. May be positive, negative or zero.
- * @param context The explicit context to associate with this measurement.
- */
- virtual void Record(T value, const context::Context &context) noexcept = 0;
- /**
- * Record a value with a set of attributes.
- *
- * @param value The measurement value. May be positive, negative or zero.
- * @param attributes A set of attributes to associate with the value.
- */
- virtual void Record(T value, const common::KeyValueIterable &attributes) noexcept = 0;
- /**
- * Record a value with a set of attributes.
- *
- * @param value The measurement value. May be positive, negative or zero.
- * @param attributes A set of attributes to associate with the value.
- * @param context The explicit context to associate with this measurement.
- */
- virtual void Record(T value,
- const common::KeyValueIterable &attributes,
- const context::Context &context) noexcept = 0;
- template <class U,
- nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
- void Record(T value, const U &attributes) noexcept
- {
- this->Record(value, common::KeyValueIterableView<U>{attributes});
- }
- template <class U,
- nostd::enable_if_t<common::detail::is_key_value_iterable<U>::value> * = nullptr>
- void Record(T value, const U &attributes, const context::Context &context) noexcept
- {
- this->Record(value, common::KeyValueIterableView<U>{attributes}, context);
- }
- void Record(T value,
- std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
- attributes) noexcept
- {
- this->Record(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
- attributes.begin(), attributes.end()});
- }
- void Record(
- T value,
- std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
- const context::Context &context) noexcept
- {
- this->Record(value,
- nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
- attributes.begin(), attributes.end()},
- context);
- }
- };
- #endif
- } // namespace metrics
- OPENTELEMETRY_END_NAMESPACE
|