NVIDIA DeepStream SDK API Reference

9.2 Release
includes/opentelemetry/sdk/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 <stdint.h>
7 
8 #include "opentelemetry/common/key_value_iterable.h"
9 #include "opentelemetry/nostd/shared_ptr.h"
10 #include "opentelemetry/nostd/string_view.h"
11 #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
12 #include "opentelemetry/sdk/resource/resource.h"
13 #include "opentelemetry/sdk/trace/id_generator.h"
14 #include "opentelemetry/sdk/trace/processor.h"
15 #include "opentelemetry/sdk/trace/sampler.h"
16 #include "opentelemetry/sdk/trace/tracer_config.h"
17 #include "opentelemetry/sdk/trace/tracer_context.h"
18 #include "opentelemetry/trace/noop.h"
19 #include "opentelemetry/trace/span.h"
20 #include "opentelemetry/trace/span_context_kv_iterable.h"
21 #include "opentelemetry/trace/span_startoptions.h"
22 #include "opentelemetry/trace/tracer.h"
23 #include "opentelemetry/version.h"
24 
26 namespace sdk
27 {
28 namespace trace
29 {
30 
31 using namespace opentelemetry::sdk::instrumentationscope;
32 
33 class Tracer final : public opentelemetry::trace::Tracer,
34  public std::enable_shared_from_this<Tracer>
35 {
36 public:
38  explicit Tracer(std::shared_ptr<TracerContext> context,
39  std::unique_ptr<InstrumentationScope> instrumentation_scope =
40  InstrumentationScope::Create("")) noexcept;
41 
43  nostd::string_view name,
44  const opentelemetry::common::KeyValueIterable &attributes,
45  const opentelemetry::trace::SpanContextKeyValueIterable &links,
46  const opentelemetry::trace::StartSpanOptions &options = {}) noexcept override;
47 
48 #if OPENTELEMETRY_ABI_VERSION_NO >= 2
49 
53  template <class Rep, class Period>
54  void ForceFlush(std::chrono::duration<Rep, Period> timeout) noexcept
55  {
56  this->ForceFlushWithMicroseconds(static_cast<uint64_t>(
57  std::chrono::duration_cast<std::chrono::microseconds>(timeout).count()));
58  }
59 
60  void ForceFlushWithMicroseconds(uint64_t timeout) noexcept;
61 
66  template <class Rep, class Period>
67  void Close(std::chrono::duration<Rep, Period> timeout) noexcept
68  {
69  this->CloseWithMicroseconds(static_cast<uint64_t>(
70  std::chrono::duration_cast<std::chrono::microseconds>(timeout).count()));
71  }
72 
73  void CloseWithMicroseconds(uint64_t timeout) noexcept;
74 #else
75  /* Exposed in the API in ABI version 1, but does not belong to the API */
76  void ForceFlushWithMicroseconds(uint64_t timeout) noexcept override;
77 
78  void CloseWithMicroseconds(uint64_t timeout) noexcept override;
79 #endif
80 
82  SpanProcessor &GetProcessor() noexcept { return context_->GetProcessor(); }
83 
85  IdGenerator &GetIdGenerator() const noexcept { return context_->GetIdGenerator(); }
86 
88  const InstrumentationScope &GetInstrumentationScope() const noexcept
89  {
90  return *instrumentation_scope_;
91  }
92 
93  OPENTELEMETRY_DEPRECATED_MESSAGE("Please use GetInstrumentationScope instead")
94  const InstrumentationScope &GetInstrumentationLibrary() const noexcept
95  {
96  return GetInstrumentationScope();
97  }
98 
100  const opentelemetry::sdk::resource::Resource &GetResource() { return context_->GetResource(); }
101 
102  // Note: Test only
103  Sampler &GetSampler() { return context_->GetSampler(); }
104 
105 private:
106  // order of declaration is important here - instrumentation scope should destroy after
107  // tracer-context.
108  std::shared_ptr<InstrumentationScope> instrumentation_scope_;
109  std::shared_ptr<TracerContext> context_;
110  TracerConfig tracer_config_;
111  static const std::shared_ptr<opentelemetry::trace::NoopTracer> kNoopTracer;
112 };
113 } // namespace trace
114 } // namespace sdk
sdk::trace::Tracer::GetProcessor
SpanProcessor & GetProcessor() noexcept
Returns the configured span processor.
Definition: includes/opentelemetry/sdk/trace/tracer.h:82
trace
Definition: includes/opentelemetry/context/context_value.h:18
sdk::trace::IdGenerator
IdGenerator provides an interface for generating Trace Id and Span Id.
Definition: includes/opentelemetry/sdk/trace/id_generator.h:17
sdk::trace::Sampler
The Sampler interface allows users to create custom samplers which will return a SamplingResult based...
Definition: includes/opentelemetry/sdk/trace/sampler.h:71
sdk::trace::Tracer::GetSampler
Sampler & GetSampler()
Definition: includes/opentelemetry/sdk/trace/tracer.h:103
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
context
Definition: includes/opentelemetry/context/context.h:16
sdk::trace::Tracer
Definition: includes/opentelemetry/sdk/trace/tracer.h:33
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
sdk::trace::Tracer::GetInstrumentationScope
const InstrumentationScope & GetInstrumentationScope() const noexcept
Returns the associated instrumentation scope.
Definition: includes/opentelemetry/sdk/trace/tracer.h:88
sdk::trace::Tracer::GetIdGenerator
IdGenerator & GetIdGenerator() const noexcept
Returns the configured Id generator.
Definition: includes/opentelemetry/sdk/trace/tracer.h:85
sdk
Definition: includes/opentelemetry/sdk/common/atomic_shared_ptr.h:13
sdk::trace::SpanProcessor
Span processor allow hooks for span start and end method invocations.
Definition: includes/opentelemetry/sdk/trace/processor.h:29
sdk::trace::Tracer::GetResource
const opentelemetry::sdk::resource::Resource & GetResource()
Returns the currently configured resource.
Definition: includes/opentelemetry/sdk/trace/tracer.h:100
OPENTELEMETRY_DEPRECATED_MESSAGE
#define OPENTELEMETRY_DEPRECATED_MESSAGE(msg)
Definition: includes/opentelemetry/common/macros.h:244
sdk::trace::TracerConfig
TracerConfig defines various configurable aspects of a Tracer's behavior.
Definition: includes/opentelemetry/sdk/trace/tracer_config.h:19
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37