NVIDIA DeepStream SDK API Reference

9.2 Release
includes/opentelemetry/trace/span.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 <cstdint>
7 
8 #include "opentelemetry/common/attribute_value.h"
9 #include "opentelemetry/common/key_value_iterable_view.h"
10 #include "opentelemetry/nostd/span.h"
11 #include "opentelemetry/nostd/string_view.h"
12 #include "opentelemetry/nostd/type_traits.h"
13 #include "opentelemetry/trace/span_context.h"
14 #include "opentelemetry/trace/span_context_kv_iterable.h"
15 #include "opentelemetry/trace/span_context_kv_iterable_view.h"
16 #include "opentelemetry/trace/span_metadata.h"
17 
18 #include "opentelemetry/version.h"
19 
21 namespace trace
22 {
23 
24 class Tracer;
25 
54 class Span
55 {
56 public:
57  // Note that Spans should be created using the Tracer class. Please refer to
58  // tracer.h for documentation.
59  Span() = default;
60 
61  // The Span destructor End()s the Span, if it hasn't been ended already.
62  virtual ~Span() = default;
63 
64  // Not copiable or movable.
65  Span(const Span &) = delete;
66  Span(Span &&) = delete;
67  Span &operator=(const Span &) = delete;
68  Span &operator=(Span &&) = delete;
69 
78  virtual void SetAttribute(nostd::string_view key,
79  const common::AttributeValue &value) noexcept = 0;
80 
81  // Adds an event to the Span.
82  virtual void AddEvent(nostd::string_view name) noexcept = 0;
83 
84  // Adds an event to the Span, with a custom timestamp.
85  virtual void AddEvent(nostd::string_view name, common::SystemTimestamp timestamp) noexcept = 0;
86 
87  // Adds an event to the Span, with a custom timestamp, and attributes.
88  virtual void AddEvent(nostd::string_view name,
89  common::SystemTimestamp timestamp,
90  const common::KeyValueIterable &attributes) noexcept = 0;
91 
92  virtual void AddEvent(nostd::string_view name,
93  const common::KeyValueIterable &attributes) noexcept
94  {
95  this->AddEvent(name, std::chrono::system_clock::now(), attributes);
96  }
97 
98  template <class T,
101  common::SystemTimestamp timestamp,
102  const T &attributes) noexcept
103  {
104  this->AddEvent(name, timestamp, common::KeyValueIterableView<T>{attributes});
105  }
106 
107  template <class T,
109  void AddEvent(nostd::string_view name, const T &attributes) noexcept
110  {
111  this->AddEvent(name, common::KeyValueIterableView<T>{attributes});
112  }
113 
115  common::SystemTimestamp timestamp,
116  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
117  attributes) noexcept
118  {
119  this->AddEvent(name, timestamp,
120  nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
121  attributes.begin(), attributes.end()});
122  }
123 
125  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
126  attributes) noexcept
127  {
128  this->AddEvent(name, std::chrono::system_clock::now(),
129  nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
130  attributes.begin(), attributes.end()});
131  }
132 
133 #if OPENTELEMETRY_ABI_VERSION_NO >= 2
134 
142  virtual void AddLink(const SpanContext &target,
143  const common::KeyValueIterable &attrs) noexcept = 0;
144 
152  virtual void AddLinks(const SpanContextKeyValueIterable &links) noexcept = 0;
153 
161  template <class U,
163  void AddLink(const SpanContext &target, const U &attrs)
164  {
166  this->AddLink(target, view);
167  }
168 
176  void AddLink(const SpanContext &target,
177  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attrs)
178  {
179  /* Build a container from std::initializer_list. */
181  attrs.begin(), attrs.end()};
182 
183  /* Build a view on the container. */
186  view(container);
187 
188  return this->AddLink(target, view);
189  }
190 
198  template <class U, nostd::enable_if_t<detail::is_span_context_kv_iterable<U>::value> * = nullptr>
199  void AddLinks(const U &links)
200  {
201  SpanContextKeyValueIterableView<U> view(links);
202  this->AddLinks(view);
203  }
204 
212  void AddLinks(
213  std::initializer_list<
214  std::pair<SpanContext,
215  std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>>>
216  links)
217  {
218  /* Build a container from std::initializer_list. */
219  nostd::span<const std::pair<
220  SpanContext, std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>>>
221  container{links.begin(), links.end()};
222 
223  /* Build a view on the container. */
224  SpanContextKeyValueIterableView<nostd::span<const std::pair<
225  SpanContext, std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>>>>
226  view(container);
227 
228  return this->AddLinks(view);
229  }
230 
231 #endif /* OPENTELEMETRY_ABI_VERSION_NO */
232 
233  // Sets the status of the span. The default status is Unset. Only the value of
234  // the last call will be
235  // recorded, and implementations are free to ignore previous calls.
236  virtual void SetStatus(StatusCode code, nostd::string_view description = "") noexcept = 0;
237 
238  // Updates the name of the Span. If used, this will override the name provided
239  // during creation.
240  virtual void UpdateName(nostd::string_view name) noexcept = 0;
241 
249  virtual void End(const trace::EndSpanOptions &options = {}) noexcept = 0;
250 
251  virtual trace::SpanContext GetContext() const noexcept = 0;
252 
253  // Returns true if this Span is recording tracing events (e.g. SetAttribute,
254  // AddEvent).
255  virtual bool IsRecording() const noexcept = 0;
256 };
257 
258 } // namespace trace
trace
Definition: includes/opentelemetry/context/context_value.h:18
trace::Span::AddEvent
void AddEvent(nostd::string_view name, const T &attributes) noexcept
Definition: includes/opentelemetry/trace/span.h:109
nostd
Definition: includes/opentelemetry/nostd/function_ref.h:14
trace::SpanContextKeyValueIterable
Supports internal iteration over a collection of SpanContext/key-value pairs.
Definition: includes/opentelemetry/trace/span_context_kv_iterable.h:18
absl::OTABSL_OPTION_NAMESPACE_NAME::variant
Definition: includes/opentelemetry/nostd/variant.h:61
trace::SpanContext
Definition: includes/opentelemetry/trace/span_context.h:24
trace::Span::Span
Span()=default
nostd::span::begin
T * begin() const noexcept
Definition: includes/opentelemetry/nostd/span.h:182
trace::Span
A Span represents a single operation within a Trace.
Definition: includes/opentelemetry/trace/span.h:54
trace::Span::SetAttribute
virtual void SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept=0
Sets an attribute on the Span (ABI).
trace::Span::operator=
Span & operator=(const Span &)=delete
common::SystemTimestamp
A timepoint relative to the system clock epoch.
Definition: includes/opentelemetry/common/timestamp.h:19
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
trace::Span::SetStatus
virtual void SetStatus(StatusCode code, nostd::string_view description="") noexcept=0
nostd::span
Back port of std::span.
Definition: includes/opentelemetry/nostd/span.h:51
trace::Span::End
virtual void End(const trace::EndSpanOptions &options={}) noexcept=0
Mark the end of the Span.
trace::Span::AddEvent
void AddEvent(nostd::string_view name, common::SystemTimestamp timestamp, const T &attributes) noexcept
Definition: includes/opentelemetry/trace/span.h:100
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
trace::Span::UpdateName
virtual void UpdateName(nostd::string_view name) noexcept=0
trace::Span::AddEvent
void AddEvent(nostd::string_view name, std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >> attributes) noexcept
Definition: includes/opentelemetry/trace/span.h:124
trace::Span::IsRecording
virtual bool IsRecording() const noexcept=0
trace::Span::AddEvent
virtual void AddEvent(nostd::string_view name, const common::KeyValueIterable &attributes) noexcept
Definition: includes/opentelemetry/trace/span.h:92
common::KeyValueIterable
Supports internal iteration over a collection of key-value pairs.
Definition: includes/opentelemetry/common/key_value_iterable.h:17
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::StatusCode
StatusCode
Definition: includes/opentelemetry/trace/span_metadata.h:27
trace::Span::AddEvent
virtual void AddEvent(nostd::string_view name) noexcept=0
trace::Span::GetContext
virtual trace::SpanContext GetContext() const noexcept=0
trace::Span::AddEvent
void AddEvent(nostd::string_view name, common::SystemTimestamp timestamp, std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >> attributes) noexcept
Definition: includes/opentelemetry/trace/span.h:114
nostd::string_view
std::string_view string_view
Definition: includes/opentelemetry/std/string_view.h:18
trace::Span::~Span
virtual ~Span()=default
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37