NVIDIA DeepStream SDK API Reference

9.2 Release
9.2/includes/opentelemetry/trace/tracer.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 <chrono>
7 
8 #include "opentelemetry/context/context.h"
9 #include "opentelemetry/nostd/shared_ptr.h"
10 #include "opentelemetry/nostd/string_view.h"
11 #include "opentelemetry/trace/default_span.h"
12 #include "opentelemetry/trace/scope.h"
13 #include "opentelemetry/trace/span.h"
14 #include "opentelemetry/trace/span_context_kv_iterable_view.h"
15 #include "opentelemetry/trace/span_startoptions.h"
16 #include "opentelemetry/version.h"
17 
19 namespace trace
20 {
27 class Tracer
28 {
29 public:
30  virtual ~Tracer() = default;
40  const common::KeyValueIterable &attributes,
41  const SpanContextKeyValueIterable &links,
42  const StartSpanOptions &options = {}) noexcept = 0;
43 
45  const StartSpanOptions &options = {}) noexcept
46  {
47  return this->StartSpan(name, {}, {}, options);
48  }
49 
50  template <class T,
53  const T &attributes,
54  const StartSpanOptions &options = {}) noexcept
55  {
56  return this->StartSpan(name, attributes, {}, options);
57  }
58 
60  const common::KeyValueIterable &attributes,
61  const StartSpanOptions &options = {}) noexcept
62  {
63  return this->StartSpan(name, attributes, NullSpanContext(), options);
64  }
65 
66  template <class T,
67  class U,
71  const T &attributes,
72  const U &links,
73  const StartSpanOptions &options = {}) noexcept
74  {
75  return this->StartSpan(name, common::KeyValueIterableView<T>(attributes),
76  SpanContextKeyValueIterableView<U>(links), options);
77  }
78 
80  nostd::string_view name,
81  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
82  const StartSpanOptions &options = {}) noexcept
83  {
84 
85  return this->StartSpan(name, attributes, {}, options);
86  }
87 
88  template <class T,
91  nostd::string_view name,
92  const T &attributes,
93  std::initializer_list<
94  std::pair<SpanContext,
95  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>>>
96  links,
97  const StartSpanOptions &options = {}) noexcept
98  {
99  return this->StartSpan(
100  name, attributes,
101  nostd::span<const std::pair<SpanContext, std::initializer_list<std::pair<
103  links.begin(), links.end()},
104  options);
105  }
106 
107  template <class T,
110  nostd::string_view name,
111  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
112  const T &links,
113  const StartSpanOptions &options = {}) noexcept
114  {
115  return this->StartSpan(name,
116  nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
117  attributes.begin(), attributes.end()},
118  links, options);
119  }
120 
122  nostd::string_view name,
123  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
124  std::initializer_list<
125  std::pair<SpanContext,
126  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>>>
127  links,
128  const StartSpanOptions &options = {}) noexcept
129  {
130  return this->StartSpan(
131  name,
132  nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{attributes.begin(),
133  attributes.end()},
134  nostd::span<const std::pair<SpanContext, std::initializer_list<std::pair<
136  links.begin(), links.end()},
137  options);
138  }
139 
146  static Scope WithActiveSpan(nostd::shared_ptr<Span> &span) noexcept { return Scope{span}; }
147 
154  {
157  {
158  return nostd::get<nostd::shared_ptr<Span>>(active_span);
159  }
160  else
161  {
163  }
164  }
165 
166 #if OPENTELEMETRY_ABI_VERSION_NO >= 2
167 
175  bool Enabled() const noexcept { return OPENTELEMETRY_ATOMIC_READ_8(&this->enabled_) != 0; }
176 #endif
177 
178 #if OPENTELEMETRY_ABI_VERSION_NO == 1
179 
180  /*
181  * The following is removed from the API in ABI version 2.
182  * It belongs to the SDK.
183  */
184 
189  template <class Rep, class Period>
190  void ForceFlush(std::chrono::duration<Rep, Period> timeout) noexcept
191  {
192  this->ForceFlushWithMicroseconds(static_cast<uint64_t>(
193  std::chrono::duration_cast<std::chrono::microseconds>(timeout).count()));
194  }
195 
196  virtual void ForceFlushWithMicroseconds(uint64_t timeout) noexcept = 0;
197 
202  template <class Rep, class Period>
203  void Close(std::chrono::duration<Rep, Period> timeout) noexcept
204  {
205  this->CloseWithMicroseconds(static_cast<uint64_t>(
206  std::chrono::duration_cast<std::chrono::microseconds>(timeout).count()));
207  }
208 
209  virtual void CloseWithMicroseconds(uint64_t timeout) noexcept = 0;
210 
211 #endif /* OPENTELEMETRY_ABI_VERSION_NO */
212 
213 protected:
214 #if OPENTELEMETRY_ABI_VERSION_NO >= 2
215 
228  void UpdateEnabled(const bool enabled) noexcept
229  {
230  OPENTELEMETRY_ATOMIC_WRITE_8(&this->enabled_, enabled);
231  }
232 #endif
233 
234 private:
235 #if OPENTELEMETRY_ABI_VERSION_NO >= 2
236  // Variable to support implementation of Enabled method introduced in ABI V2.
237  // Mutable allows enabled_ to be used as 'bool *' (instead of 'const bool *'), with the
238  // OPENTELEMETRY_ATOMIC_READ_8 macro's internal casts when used from a const function.
239  // std::atomic can not be used here because it is not ABI compatible for OpenTelemetry C++ API.
240  mutable bool enabled_ = true;
241 #endif
242 };
243 } // namespace trace
trace::Scope
Controls how long a span is active.
Definition: includes/opentelemetry/trace/scope.h:25
trace
Definition: includes/opentelemetry/context/context_value.h:18
trace::Tracer::StartSpan
nostd::shared_ptr< Span > StartSpan(nostd::string_view name, std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >> attributes, const T &links, const StartSpanOptions &options={}) noexcept
Definition: 9.2/includes/opentelemetry/trace/tracer.h:109
trace::Tracer::WithActiveSpan
static Scope WithActiveSpan(nostd::shared_ptr< Span > &span) noexcept
Set the active span.
Definition: 9.2/includes/opentelemetry/trace/tracer.h:146
trace::StartSpanOptions
StartSpanOptions provides options to set properties of a Span at the time of its creation.
Definition: includes/opentelemetry/trace/span_startoptions.h:21
trace::Tracer::StartSpan
nostd::shared_ptr< Span > StartSpan(nostd::string_view name, std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >> attributes, std::initializer_list< std::pair< SpanContext, std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >>>> links, const StartSpanOptions &options={}) noexcept
Definition: 9.2/includes/opentelemetry/trace/tracer.h:121
absl::OTABSL_OPTION_NAMESPACE_NAME::variant
Definition: includes/opentelemetry/nostd/variant.h:61
trace::Tracer::StartSpan
nostd::shared_ptr< Span > StartSpan(nostd::string_view name, const T &attributes, const U &links, const StartSpanOptions &options={}) noexcept
Definition: 9.2/includes/opentelemetry/trace/tracer.h:70
trace::Tracer::GetCurrentSpan
static nostd::shared_ptr< Span > GetCurrentSpan() noexcept
Get the currently active span.
Definition: 9.2/includes/opentelemetry/trace/tracer.h:153
trace::SpanContext
Definition: includes/opentelemetry/trace/span_context.h:24
trace::DefaultSpan
DefaultSpan provides a non-operational Span that propagates the tracer context by wrapping it inside ...
Definition: includes/opentelemetry/trace/default_span.h:21
nostd::span::begin
T * begin() const noexcept
Definition: includes/opentelemetry/nostd/span.h:182
nostd::shared_ptr
Provide a type-erased version of std::shared_ptr that has ABI stability.
Definition: includes/opentelemetry/nostd/shared_ptr.h:28
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
trace::Tracer::StartSpan
nostd::shared_ptr< Span > StartSpan(nostd::string_view name, const common::KeyValueIterable &attributes, const StartSpanOptions &options={}) noexcept
Definition: 9.2/includes/opentelemetry/trace/tracer.h:59
nostd::span
Back port of std::span.
Definition: includes/opentelemetry/nostd/span.h:51
trace::Tracer::StartSpan
nostd::shared_ptr< Span > StartSpan(nostd::string_view name, const StartSpanOptions &options={}) noexcept
Definition: 9.2/includes/opentelemetry/trace/tracer.h:44
trace::Tracer::StartSpan
nostd::shared_ptr< Span > StartSpan(nostd::string_view name, const T &attributes, const StartSpanOptions &options={}) noexcept
Definition: 9.2/includes/opentelemetry/trace/tracer.h:52
trace::Tracer::StartSpan
virtual nostd::shared_ptr< Span > StartSpan(nostd::string_view name, const common::KeyValueIterable &attributes, const SpanContextKeyValueIterable &links, const StartSpanOptions &options={}) noexcept=0
Starts a span.
trace::Tracer::StartSpan
nostd::shared_ptr< Span > StartSpan(nostd::string_view name, const T &attributes, std::initializer_list< std::pair< SpanContext, std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >>>> links, const StartSpanOptions &options={}) noexcept
Definition: 9.2/includes/opentelemetry/trace/tracer.h:90
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
common::KeyValueIterable
Supports internal iteration over a collection of key-value pairs.
Definition: includes/opentelemetry/common/key_value_iterable.h:17
trace::SpanContextKeyValueIterableView
Definition: includes/opentelemetry/trace/span_context_kv_iterable_view.h:56
trace::Tracer::StartSpan
nostd::shared_ptr< Span > StartSpan(nostd::string_view name, std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >> attributes, const StartSpanOptions &options={}) noexcept
Definition: 9.2/includes/opentelemetry/trace/tracer.h:79
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
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
trace::Tracer::~Tracer
virtual ~Tracer()=default
trace::NullSpanContext
Null Span context that does not carry any information.
Definition: includes/opentelemetry/trace/span_context_kv_iterable.h:41
trace::kSpanKey
constexpr char kSpanKey[]
Definition: includes/opentelemetry/trace/span_metadata.h:23
context::RuntimeContext::GetValue
static ContextValue GetValue(nostd::string_view key, Context *context=nullptr) noexcept
Definition: includes/opentelemetry/context/runtime_context.h:132
nostd::holds_alternative
constexpr bool holds_alternative(const variant< Ts... > &v) noexcept
Definition: includes/opentelemetry/std/variant.h:218
nostd::string_view
std::string_view string_view
Definition: includes/opentelemetry/std/string_view.h:18
trace::SpanContext::GetInvalid
static SpanContext GetInvalid() noexcept
Definition: includes/opentelemetry/trace/span_context.h:86
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37