NVIDIA DeepStream SDK API Reference

9.2 Release
9.2/includes/opentelemetry/sdk/trace/sampler.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 <map>
7 #include <memory>
8 #include <string>
9 
10 #include "opentelemetry/common/attribute_value.h"
11 #include "opentelemetry/nostd/shared_ptr.h"
12 #include "opentelemetry/nostd/string_view.h"
13 #include "opentelemetry/trace/span_metadata.h"
14 #include "opentelemetry/trace/trace_id.h"
15 #include "opentelemetry/version.h"
16 
18 namespace common
19 {
20 class KeyValueIterable;
21 } // namespace common
22 
23 namespace trace
24 {
25 class SpanContext;
26 class SpanContextKeyValueIterable;
27 class TraceState;
28 } // namespace trace
29 
30 namespace sdk
31 {
32 namespace trace
33 {
37 enum class Decision
38 {
39  // IsRecording() == false, span will not be recorded and all events and attributes will be
40  // dropped.
41  DROP,
42  // IsRecording() == true, but Sampled flag MUST NOT be set.
44  // IsRecording() == true AND Sampled flag` MUST be set.
46 };
47 
52 struct SamplingResult
53 {
55  // A set of span Attributes that will also be added to the Span. Can be nullptr.
56  std::unique_ptr<const std::map<std::string, opentelemetry::common::AttributeValue>> attributes;
57  // The tracestate used by the span.
59 
60  inline bool IsRecording()
61  {
63  }
64  inline bool IsSampled() { return decision == Decision::RECORD_AND_SAMPLE; }
65 };
66 
71 class Sampler
72 {
73 public:
74  virtual ~Sampler() = default;
90  virtual SamplingResult ShouldSample(
91  const opentelemetry::trace::SpanContext &parent_context,
92  opentelemetry::trace::TraceId trace_id,
93  nostd::string_view name,
95  const opentelemetry::common::KeyValueIterable &attributes,
96  const opentelemetry::trace::SpanContextKeyValueIterable &links) noexcept = 0;
97 
104  virtual nostd::string_view GetDescription() const noexcept = 0;
105 };
106 } // namespace trace
107 } // namespace sdk
sdk::trace::Sampler::ShouldSample
virtual SamplingResult ShouldSample(const opentelemetry::trace::SpanContext &parent_context, opentelemetry::trace::TraceId trace_id, nostd::string_view name, opentelemetry::trace::SpanKind span_kind, const opentelemetry::common::KeyValueIterable &attributes, const opentelemetry::trace::SpanContextKeyValueIterable &links) noexcept=0
Called during Span creation to make a sampling decision.
trace
Definition: includes/opentelemetry/context/context_value.h:18
sdk::trace::Decision::RECORD_AND_SAMPLE
@ RECORD_AND_SAMPLE
trace::SpanKind
SpanKind
Definition: includes/opentelemetry/trace/span_metadata.h:13
nostd::shared_ptr< opentelemetry::trace::TraceState >
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
sdk::trace::SamplingResult::decision
Decision decision
Definition: includes/opentelemetry/sdk/trace/sampler.h:54
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
sdk::trace::SamplingResult::attributes
std::unique_ptr< const std::map< std::string, opentelemetry::common::AttributeValue > > attributes
Definition: includes/opentelemetry/sdk/trace/sampler.h:56
sdk::trace::Decision
Decision
A sampling Decision for a Span to be created.
Definition: includes/opentelemetry/sdk/trace/sampler.h:37
sdk::trace::SamplingResult::trace_state
nostd::shared_ptr< opentelemetry::trace::TraceState > trace_state
Definition: includes/opentelemetry/sdk/trace/sampler.h:58
sdk
Definition: includes/opentelemetry/sdk/common/atomic_shared_ptr.h:13
sdk::trace::Decision::DROP
@ DROP
sdk::trace::SamplingResult::IsSampled
bool IsSampled()
Definition: 9.2/includes/opentelemetry/sdk/trace/sampler.h:64
sdk::trace::Sampler::GetDescription
virtual nostd::string_view GetDescription() const noexcept=0
Returns the sampler name or short description with the configuration.
sdk::trace::SamplingResult::IsRecording
bool IsRecording()
Definition: 9.2/includes/opentelemetry/sdk/trace/sampler.h:60
sdk::trace::Decision::RECORD_ONLY
@ RECORD_ONLY
sdk::trace::Sampler::~Sampler
virtual ~Sampler()=default
common
Definition: includes/opentelemetry/common/attribute_value.h:14
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37