NVIDIA DeepStream SDK API Reference

9.2 Release
9.2/includes/opentelemetry/metrics/sync_instruments.h
Go to the documentation of this file.
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include "opentelemetry/common/attribute_value.h"
7 #include "opentelemetry/common/key_value_iterable_view.h"
8 #include "opentelemetry/context/context.h"
9 #include "opentelemetry/nostd/span.h"
10 #include "opentelemetry/nostd/string_view.h"
11 #include "opentelemetry/nostd/type_traits.h"
12 #include "opentelemetry/version.h"
13 
15 namespace metrics
16 {
17 
18 class SynchronousInstrument
19 {
20 public:
21  SynchronousInstrument() = default;
22  virtual ~SynchronousInstrument() = default;
23 };
24 
25 /* A Counter instrument that adds values. */
26 template <class T>
27 class Counter : public SynchronousInstrument
28 {
29 
30 public:
36  virtual void Add(T value) noexcept = 0;
37 
44  virtual void Add(T value, const context::Context &context) noexcept = 0;
45 
53  virtual void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0;
54 
62  virtual void Add(T value,
63  const common::KeyValueIterable &attributes,
64  const context::Context &context) noexcept = 0;
65 
66  template <class U,
68  void Add(T value, const U &attributes) noexcept
69  {
70  this->Add(value, common::KeyValueIterableView<U>{attributes});
71  }
72 
73  template <class U,
75  void Add(T value, const U &attributes, const context::Context &context) noexcept
76  {
77  this->Add(value, common::KeyValueIterableView<U>{attributes}, context);
78  }
79 
80  void Add(T value,
81  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
82  attributes) noexcept
83  {
84  this->Add(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
85  attributes.begin(), attributes.end()});
86  }
87 
88  void Add(T value,
89  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
90  const context::Context &context) noexcept
91  {
92  this->Add(value,
93  nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
94  attributes.begin(), attributes.end()},
95  context);
96  }
97 };
98 
101 template <class T>
102 class Histogram : public SynchronousInstrument
103 {
104 public:
105 #if OPENTELEMETRY_ABI_VERSION_NO >= 2
106 
112  virtual void Record(T value) noexcept = 0;
113 
121  virtual void Record(T value, const common::KeyValueIterable &attribute) noexcept = 0;
122 
123  template <class U,
125  void Record(T value, const U &attributes) noexcept
126  {
127  this->Record(value, common::KeyValueIterableView<U>{attributes});
128  }
129 
130  void Record(T value,
131  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
132  attributes) noexcept
133  {
134  this->Record(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
135  attributes.begin(), attributes.end()});
136  }
137 #endif
138 
145  virtual void Record(T value, const context::Context &context) noexcept = 0;
146 
154  virtual void Record(T value,
155  const common::KeyValueIterable &attributes,
156  const context::Context &context) noexcept = 0;
157 
158  template <class U,
160  void Record(T value, const U &attributes, const context::Context &context) noexcept
161  {
162  this->Record(value, common::KeyValueIterableView<U>{attributes}, context);
163  }
164 
165  void Record(
166  T value,
167  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
168  const context::Context &context) noexcept
169  {
170  this->Record(value,
171  nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
172  attributes.begin(), attributes.end()},
173  context);
174  }
175 };
176 
179 template <class T>
180 class UpDownCounter : public SynchronousInstrument
181 {
182 public:
188  virtual void Add(T value) noexcept = 0;
189 
196  virtual void Add(T value, const context::Context &context) noexcept = 0;
197 
204  virtual void Add(T value, const common::KeyValueIterable &attributes) noexcept = 0;
205 
213  virtual void Add(T value,
214  const common::KeyValueIterable &attributes,
215  const context::Context &context) noexcept = 0;
216 
217  template <class U,
219  void Add(T value, const U &attributes) noexcept
220  {
221  this->Add(value, common::KeyValueIterableView<U>{attributes});
222  }
223 
224  template <class U,
226  void Add(T value, const U &attributes, const context::Context &context) noexcept
227  {
228  this->Add(value, common::KeyValueIterableView<U>{attributes}, context);
229  }
230 
231  void Add(T value,
232  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
233  attributes) noexcept
234  {
235  this->Add(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
236  attributes.begin(), attributes.end()});
237  }
238 
239  void Add(T value,
240  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
241  const context::Context &context) noexcept
242  {
243  this->Add(value,
244  nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
245  attributes.begin(), attributes.end()},
246  context);
247  }
248 };
249 
250 #if OPENTELEMETRY_ABI_VERSION_NO >= 2
251 /* A Gauge instrument that records values. */
252 template <class T>
253 class Gauge : public SynchronousInstrument
254 {
255 
256 public:
262  virtual void Record(T value) noexcept = 0;
263 
270  virtual void Record(T value, const context::Context &context) noexcept = 0;
271 
279  virtual void Record(T value, const common::KeyValueIterable &attributes) noexcept = 0;
280 
288  virtual void Record(T value,
289  const common::KeyValueIterable &attributes,
290  const context::Context &context) noexcept = 0;
291 
292  template <class U,
294  void Record(T value, const U &attributes) noexcept
295  {
296  this->Record(value, common::KeyValueIterableView<U>{attributes});
297  }
298 
299  template <class U,
301  void Record(T value, const U &attributes, const context::Context &context) noexcept
302  {
303  this->Record(value, common::KeyValueIterableView<U>{attributes}, context);
304  }
305 
306  void Record(T value,
307  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
308  attributes) noexcept
309  {
310  this->Record(value, nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
311  attributes.begin(), attributes.end()});
312  }
313 
314  void Record(
315  T value,
316  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
317  const context::Context &context) noexcept
318  {
319  this->Record(value,
320  nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
321  attributes.begin(), attributes.end()},
322  context);
323  }
324 };
325 #endif
326 
327 } // namespace metrics
metrics::Counter::Add
void Add(T value, const U &attributes) noexcept
Definition: 9.2/includes/opentelemetry/metrics/sync_instruments.h:68
metrics::Counter::Add
void Add(T value, const U &attributes, const context::Context &context) noexcept
Definition: 9.2/includes/opentelemetry/metrics/sync_instruments.h:75
metrics::UpDownCounter::Add
void Add(T value, std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >> attributes) noexcept
Definition: 9.2/includes/opentelemetry/metrics/sync_instruments.h:231
metrics::Histogram::Record
void Record(T value, std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >> attributes, const context::Context &context) noexcept
Definition: 9.2/includes/opentelemetry/metrics/sync_instruments.h:165
nostd::span::begin
T * begin() const noexcept
Definition: includes/opentelemetry/nostd/span.h:182
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
nostd::span
Back port of std::span.
Definition: includes/opentelemetry/nostd/span.h:51
context
Definition: includes/opentelemetry/context/context.h:16
metrics::Histogram::Record
void Record(T value, const U &attributes, const context::Context &context) noexcept
Definition: 9.2/includes/opentelemetry/metrics/sync_instruments.h:160
metrics::UpDownCounter::Add
void Add(T value, std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >> attributes, const context::Context &context) noexcept
Definition: 9.2/includes/opentelemetry/metrics/sync_instruments.h:239
metrics::UpDownCounter::Add
void Add(T value, const U &attributes) noexcept
Definition: 9.2/includes/opentelemetry/metrics/sync_instruments.h:219
metrics::Counter::Add
void Add(T value, std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >> attributes) noexcept
Definition: 9.2/includes/opentelemetry/metrics/sync_instruments.h:80
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
metrics::SynchronousInstrument::~SynchronousInstrument
virtual ~SynchronousInstrument()=default
common::KeyValueIterable
Supports internal iteration over a collection of key-value pairs.
Definition: includes/opentelemetry/common/key_value_iterable.h:17
metrics::UpDownCounter::Add
void Add(T value, const U &attributes, const context::Context &context) noexcept
Definition: 9.2/includes/opentelemetry/metrics/sync_instruments.h:226
metrics::Histogram::Record
virtual void Record(T value, const context::Context &context) noexcept=0
Records a value.
nostd::enable_if_t
typename std::enable_if< B, T >::type enable_if_t
Back port of std::enable_if_t.
Definition: includes/opentelemetry/nostd/type_traits.h:40
metrics::Counter::Add
virtual void Add(T value) noexcept=0
Record a value.
common::KeyValueIterableView
Container for key-value pairs that can transform every value in it to one of types listed in common::...
Definition: includes/opentelemetry/common/key_value_iterable_view.h:57
metrics::UpDownCounter::Add
virtual void Add(T value) noexcept=0
Record a value.
context::Context
Definition: includes/opentelemetry/context/context.h:23
metrics
Definition: includes/opentelemetry/metrics/async_instruments.h:10
metrics::SynchronousInstrument::SynchronousInstrument
SynchronousInstrument()=default
prometheus::MetricType::Counter
@ Counter
metrics::Counter::Add
void Add(T value, std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >> attributes, const context::Context &context) noexcept
Definition: 9.2/includes/opentelemetry/metrics/sync_instruments.h:88