NVIDIA DeepStream SDK API Reference

9.2 Release
9.2/includes/opentelemetry/plugin/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 <memory>
7 
8 #include "opentelemetry/common/key_value_iterable.h"
9 #include "opentelemetry/plugin/detail/tracer_handle.h" // IWYU pragma: export
10 #include "opentelemetry/trace/span_context_kv_iterable.h"
11 #include "opentelemetry/trace/tracer.h"
12 #include "opentelemetry/version.h"
13 
15 namespace plugin
16 {
17 
18 class DynamicLibraryHandle;
19 
20 class Span final : public trace::Span
21 {
22 public:
23  Span(std::shared_ptr<trace::Tracer> &&tracer, const nostd::shared_ptr<trace::Span> &span) noexcept
24  : tracer_{std::move(tracer)}, span_{span}
25  {}
26 
27  // trace::Span
28  void SetAttribute(nostd::string_view name, const common::AttributeValue &value) noexcept override
29  {
30  span_->SetAttribute(name, value);
31  }
32 
33  void AddEvent(nostd::string_view name) noexcept override { span_->AddEvent(name); }
34 
35  void AddEvent(nostd::string_view name, common::SystemTimestamp timestamp) noexcept override
36  {
37  span_->AddEvent(name, timestamp);
38  }
39 
41  const common::KeyValueIterable &attributes) noexcept override
42  {
43  span_->AddEvent(name, attributes);
44  }
45 
47  common::SystemTimestamp timestamp,
48  const common::KeyValueIterable &attributes) noexcept override
49  {
50  span_->AddEvent(name, timestamp, attributes);
51  }
52 
53 #if OPENTELEMETRY_ABI_VERSION_NO >= 2
54  void AddLink(const trace::SpanContext &target,
55  const common::KeyValueIterable &attrs) noexcept override
56  {
57  span_->AddLink(target, attrs);
58  }
59 
60  void AddLinks(const trace::SpanContextKeyValueIterable &links) noexcept override
61  {
62  span_->AddLinks(links);
63  }
64 #endif
65 
66  void SetStatus(trace::StatusCode code, nostd::string_view description) noexcept override
67  {
68  span_->SetStatus(code, description);
69  }
70 
71  void UpdateName(nostd::string_view name) noexcept override { span_->UpdateName(name); }
72 
73  void End(const trace::EndSpanOptions &options = {}) noexcept override { span_->End(options); }
74 
75  bool IsRecording() const noexcept override { return span_->IsRecording(); }
76 
77  trace::SpanContext GetContext() const noexcept override { return span_->GetContext(); }
78 
79 private:
80  std::shared_ptr<trace::Tracer> tracer_;
82 };
83 
84 class Tracer final : public trace::Tracer, public std::enable_shared_from_this<Tracer>
85 {
86 public:
87  Tracer(std::shared_ptr<DynamicLibraryHandle> library_handle,
88  std::unique_ptr<TracerHandle> &&tracer_handle) noexcept
89  : library_handle_{std::move(library_handle)}, tracer_handle_{std::move(tracer_handle)}
90  {
91 #if OPENTELEMETRY_ABI_VERSION_NO >= 2
92  UpdateEnabled(true);
93 #endif
94  }
95 
96  // trace::Tracer
98  nostd::string_view name,
99  const common::KeyValueIterable &attributes,
101  const trace::StartSpanOptions &options = {}) noexcept override
102  {
103  auto span = tracer_handle_->tracer().StartSpan(name, attributes, links, options);
104  if (span == nullptr)
105  {
106  return nostd::shared_ptr<trace::Span>(nullptr);
107  }
108  return nostd::shared_ptr<trace::Span>{new (std::nothrow) Span{this->shared_from_this(), span}};
109  }
110 
111 #if OPENTELEMETRY_ABI_VERSION_NO == 1
112 
113  void ForceFlushWithMicroseconds(uint64_t timeout) noexcept override
114  {
115  tracer_handle_->tracer().ForceFlushWithMicroseconds(timeout);
116  }
117 
118  void CloseWithMicroseconds(uint64_t timeout) noexcept override
119  {
120  tracer_handle_->tracer().CloseWithMicroseconds(timeout);
121  }
122 
123 #endif /* OPENTELEMETRY_ABI_VERSION_NO */
124 
125 private:
126  // Note: The order is important here.
127  //
128  // It's undefined behavior to close the library while a loaded tracer is still active.
129  std::shared_ptr<DynamicLibraryHandle> library_handle_;
130  std::unique_ptr<TracerHandle> tracer_handle_;
131 };
132 } // namespace plugin
trace::EndSpanOptions
EndSpanOptions provides options to set properties of a Span when it is ended.
Definition: includes/opentelemetry/trace/span_metadata.h:38
plugin::Span::AddEvent
void AddEvent(nostd::string_view name, common::SystemTimestamp timestamp) noexcept override
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:35
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::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
plugin::Tracer::StartSpan
nostd::shared_ptr< trace::Span > StartSpan(nostd::string_view name, const common::KeyValueIterable &attributes, const trace::SpanContextKeyValueIterable &links, const trace::StartSpanOptions &options={}) noexcept override
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:97
trace::SpanContext
Definition: includes/opentelemetry/trace/span_context.h:24
plugin::Span::GetContext
trace::SpanContext GetContext() const noexcept override
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:77
nostd::shared_ptr< trace::Span >
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).
plugin::Tracer::Tracer
Tracer(std::shared_ptr< DynamicLibraryHandle > library_handle, std::unique_ptr< TracerHandle > &&tracer_handle) noexcept
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:87
common::SystemTimestamp
A timepoint relative to the system clock epoch.
Definition: includes/opentelemetry/common/timestamp.h:19
plugin::Span::SetStatus
void SetStatus(trace::StatusCode code, nostd::string_view description) noexcept override
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:66
trace::Tracer
Handles span creation and in-process context propagation.
Definition: includes/opentelemetry/trace/tracer.h:27
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
plugin::Span::AddEvent
void AddEvent(nostd::string_view name) noexcept override
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:33
plugin::Span::End
void End(const trace::EndSpanOptions &options={}) noexcept override
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:73
plugin::Span::Span
Span(std::shared_ptr< trace::Tracer > &&tracer, const nostd::shared_ptr< trace::Span > &span) noexcept
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:23
plugin::Span::IsRecording
bool IsRecording() const noexcept override
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:75
trace::Span::End
virtual void End(const trace::EndSpanOptions &options={}) noexcept=0
Mark the end of the Span.
plugin::Span::SetAttribute
void SetAttribute(nostd::string_view name, const common::AttributeValue &value) noexcept override
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:28
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
plugin
Definition: includes/opentelemetry/plugin/dynamic_load.h:19
trace::Span::UpdateName
virtual void UpdateName(nostd::string_view name) noexcept=0
absl::move
constexpr absl::OTABSL_OPTION_NAMESPACE_NAME::remove_reference_t< T > && move(T &&t) noexcept
Definition: includes/opentelemetry/nostd/internal/absl/utility/utility.h:199
trace::Span::IsRecording
virtual bool IsRecording() const noexcept=0
common::KeyValueIterable
Supports internal iteration over a collection of key-value pairs.
Definition: includes/opentelemetry/common/key_value_iterable.h:17
trace::StatusCode
StatusCode
Definition: includes/opentelemetry/trace/span_metadata.h:27
trace::Span::AddEvent
virtual void AddEvent(nostd::string_view name) noexcept=0
plugin::Span::UpdateName
void UpdateName(nostd::string_view name) noexcept override
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:71
trace::Span::GetContext
virtual trace::SpanContext GetContext() const noexcept=0
plugin::Span::AddEvent
void AddEvent(nostd::string_view name, const common::KeyValueIterable &attributes) noexcept override
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:40
plugin::Span::AddEvent
void AddEvent(nostd::string_view name, common::SystemTimestamp timestamp, const common::KeyValueIterable &attributes) noexcept override
Definition: 9.2/includes/opentelemetry/plugin/tracer.h:46
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37