blob: 452ba924b4034d87f7b5ac43ad0503eec3163fcc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/trace/span.h"
#include "opentelemetry/trace/span_context.h"
#include "opentelemetry/trace/span_context_kv_iterable.h"
#include "opentelemetry/trace/trace_id.h"
#include "opentelemetry/trace/trace_state.h"
#include "opentelemetry/version.h"
#include <map>
#include <memory>
#include <string>
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace trace
{
/**
* A sampling Decision for a Span to be created.
*/
enum class Decision
{
// IsRecording() == false, span will not be recorded and all events and attributes will be
// dropped.
DROP,
// IsRecording() == true, but Sampled flag MUST NOT be set.
RECORD_ONLY,
// IsRecording() == true AND Sampled flag` MUST be set.
RECORD_AND_SAMPLE
};
/**
* The output of ShouldSample.
* It contains a sampling Decision and a set of Span Attributes.
*/
struct SamplingResult
{
Decision decision;
// A set of span Attributes that will also be added to the Span. Can be nullptr.
std::unique_ptr<const std::map<std::string, opentelemetry::common::AttributeValue>> attributes;
// The tracestate used by the span.
nostd::shared_ptr<opentelemetry::trace::TraceState> trace_state;
};
/**
* The Sampler interface allows users to create custom samplers which will return a
* SamplingResult based on information that is typically available just before the Span was created.
*/
class Sampler
{
public:
virtual ~Sampler() = default;
/**
* Called during Span creation to make a sampling decision.
*
* @param parent_context a const reference to the SpanContext of a parent Span.
* An invalid SpanContext if this is a root span.
* @param trace_id the TraceId for the new Span. This will be identical to that in
* the parentContext, unless this is a root span.
* @param name the name of the new Span.
* @param spanKind the opentelemetry::trace::SpanKind of the Span.
* @param attributes list of AttributeValue with their keys.
* @param links Collection of links that will be associated with the Span to be created.
* @return sampling result whether span should be sampled or not.
* @since 0.1.0
*/
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;
/**
* Returns the sampler name or short description with the configuration.
* This may be displayed on debug pages or in the logs.
*
* @return the description of this Sampler.
*/
virtual nostd::string_view GetDescription() const noexcept = 0;
};
} // namespace trace
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
|