meter.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "opentelemetry/nostd/shared_ptr.h"
  5. #include "opentelemetry/nostd/string_view.h"
  6. #include "opentelemetry/nostd/unique_ptr.h"
  7. #include "opentelemetry/version.h"
  8. OPENTELEMETRY_BEGIN_NAMESPACE
  9. namespace metrics
  10. {
  11. template <typename T>
  12. class Counter;
  13. template <typename T>
  14. class Histogram;
  15. template <typename T>
  16. class UpDownCounter;
  17. template <typename T>
  18. class Gauge;
  19. class ObservableInstrument;
  20. /**
  21. * Handles instrument creation and provides a facility for batch recording.
  22. *
  23. * This class provides methods to create new metric instruments, record a
  24. * batch of values to a specified set of instruments, and collect
  25. * measurements from all instruments.
  26. *
  27. */
  28. class Meter
  29. {
  30. public:
  31. virtual ~Meter() = default;
  32. /**
  33. * Creates a Counter with the passed characteristics and returns a unique_ptr to that Counter.
  34. *
  35. * @param name the name of the new Counter.
  36. * @param description a brief description of what the Counter is used for.
  37. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
  38. * @return a shared pointer to the created Counter.
  39. */
  40. virtual nostd::unique_ptr<Counter<uint64_t>> CreateUInt64Counter(
  41. nostd::string_view name,
  42. nostd::string_view description = "",
  43. nostd::string_view unit = "") noexcept = 0;
  44. virtual nostd::unique_ptr<Counter<double>> CreateDoubleCounter(
  45. nostd::string_view name,
  46. nostd::string_view description = "",
  47. nostd::string_view unit = "") noexcept = 0;
  48. /**
  49. * Creates a Asynchronous (Observable) counter with the passed characteristics and returns a
  50. * shared_ptr to that Observable Counter
  51. *
  52. * @param name the name of the new Observable Counter.
  53. * @param description a brief description of what the Observable Counter is used for.
  54. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
  55. */
  56. virtual nostd::shared_ptr<ObservableInstrument> CreateInt64ObservableCounter(
  57. nostd::string_view name,
  58. nostd::string_view description = "",
  59. nostd::string_view unit = "") noexcept = 0;
  60. virtual nostd::shared_ptr<ObservableInstrument> CreateDoubleObservableCounter(
  61. nostd::string_view name,
  62. nostd::string_view description = "",
  63. nostd::string_view unit = "") noexcept = 0;
  64. /**
  65. * Creates a Histogram with the passed characteristics and returns a unique_ptr to that Histogram.
  66. *
  67. * @param name the name of the new Histogram.
  68. * @param description a brief description of what the Histogram is used for.
  69. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
  70. * @return a shared pointer to the created Histogram.
  71. */
  72. virtual nostd::unique_ptr<Histogram<uint64_t>> CreateUInt64Histogram(
  73. nostd::string_view name,
  74. nostd::string_view description = "",
  75. nostd::string_view unit = "") noexcept = 0;
  76. virtual nostd::unique_ptr<Histogram<double>> CreateDoubleHistogram(
  77. nostd::string_view name,
  78. nostd::string_view description = "",
  79. nostd::string_view unit = "") noexcept = 0;
  80. #if OPENTELEMETRY_ABI_VERSION_NO >= 2
  81. /**
  82. * Creates a Gauge with the passed characteristics and returns a unique_ptr to that Gauge.
  83. *
  84. * @param name the name of the new Gauge.
  85. * @param description a brief description of what the Gauge is used for.
  86. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
  87. * @return a unique pointer to the created Gauge.
  88. */
  89. virtual nostd::unique_ptr<Gauge<int64_t>> CreateInt64Gauge(
  90. nostd::string_view name,
  91. nostd::string_view description = "",
  92. nostd::string_view unit = "") noexcept = 0;
  93. virtual nostd::unique_ptr<Gauge<double>> CreateDoubleGauge(
  94. nostd::string_view name,
  95. nostd::string_view description = "",
  96. nostd::string_view unit = "") noexcept = 0;
  97. #endif
  98. /**
  99. * Creates a Asynchronous (Observable) Gauge with the passed characteristics and returns a
  100. * shared_ptr to that Observable Gauge
  101. *
  102. * @param name the name of the new Observable Gauge.
  103. * @param description a brief description of what the Observable Gauge is used for.
  104. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
  105. */
  106. virtual nostd::shared_ptr<ObservableInstrument> CreateInt64ObservableGauge(
  107. nostd::string_view name,
  108. nostd::string_view description = "",
  109. nostd::string_view unit = "") noexcept = 0;
  110. virtual nostd::shared_ptr<ObservableInstrument> CreateDoubleObservableGauge(
  111. nostd::string_view name,
  112. nostd::string_view description = "",
  113. nostd::string_view unit = "") noexcept = 0;
  114. /**
  115. * Creates an UpDownCounter with the passed characteristics and returns a unique_ptr to that
  116. * UpDownCounter.
  117. *
  118. * @param name the name of the new UpDownCounter.
  119. * @param description a brief description of what the UpDownCounter is used for.
  120. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
  121. * @return a shared pointer to the created UpDownCounter.
  122. */
  123. virtual nostd::unique_ptr<UpDownCounter<int64_t>> CreateInt64UpDownCounter(
  124. nostd::string_view name,
  125. nostd::string_view description = "",
  126. nostd::string_view unit = "") noexcept = 0;
  127. virtual nostd::unique_ptr<UpDownCounter<double>> CreateDoubleUpDownCounter(
  128. nostd::string_view name,
  129. nostd::string_view description = "",
  130. nostd::string_view unit = "") noexcept = 0;
  131. /**
  132. * Creates a Asynchronous (Observable) UpDownCounter with the passed characteristics and returns
  133. * a shared_ptr to that Observable UpDownCounter
  134. *
  135. * @param name the name of the new Observable UpDownCounter.
  136. * @param description a brief description of what the Observable UpDownCounter is used for.
  137. * @param unit the unit of metric values following https://unitsofmeasure.org/ucum.html.
  138. */
  139. virtual nostd::shared_ptr<ObservableInstrument> CreateInt64ObservableUpDownCounter(
  140. nostd::string_view name,
  141. nostd::string_view description = "",
  142. nostd::string_view unit = "") noexcept = 0;
  143. virtual nostd::shared_ptr<ObservableInstrument> CreateDoubleObservableUpDownCounter(
  144. nostd::string_view name,
  145. nostd::string_view description = "",
  146. nostd::string_view unit = "") noexcept = 0;
  147. };
  148. } // namespace metrics
  149. OPENTELEMETRY_END_NAMESPACE