]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Copyright The OpenTelemetry Authors |
2 | // SPDX-License-Identifier: Apache-2.0 | |
3 | ||
4 | #pragma once | |
5 | ||
6 | #include "opentelemetry/sdk/trace/sampler.h" | |
7 | ||
8 | OPENTELEMETRY_BEGIN_NAMESPACE | |
9 | namespace sdk | |
10 | { | |
11 | namespace trace | |
12 | { | |
13 | /** | |
14 | * The always on sampler is a default sampler which always return Decision::RECORD_AND_SAMPLE | |
15 | */ | |
16 | class AlwaysOnSampler : public Sampler | |
17 | { | |
18 | public: | |
19 | /** | |
20 | * @return Always return Decision RECORD_AND_SAMPLE | |
21 | */ | |
22 | inline SamplingResult ShouldSample( | |
23 | const opentelemetry::trace::SpanContext &parent_context, | |
24 | opentelemetry::trace::TraceId /*trace_id*/, | |
25 | nostd::string_view /*name*/, | |
26 | opentelemetry::trace::SpanKind /*span_kind*/, | |
27 | const opentelemetry::common::KeyValueIterable & /*attributes*/, | |
28 | const opentelemetry::trace::SpanContextKeyValueIterable & /*links*/) noexcept override | |
29 | { | |
30 | if (!parent_context.IsValid()) | |
31 | { | |
32 | return {Decision::RECORD_AND_SAMPLE, nullptr, opentelemetry::trace::TraceState::GetDefault()}; | |
33 | } | |
34 | else | |
35 | { | |
36 | return {Decision::RECORD_AND_SAMPLE, nullptr, parent_context.trace_state()}; | |
37 | } | |
38 | } | |
39 | ||
40 | /** | |
41 | * @return Description MUST be AlwaysOnSampler | |
42 | */ | |
43 | inline nostd::string_view GetDescription() const noexcept override { return "AlwaysOnSampler"; } | |
44 | }; | |
45 | } // namespace trace | |
46 | } // namespace sdk | |
47 | OPENTELEMETRY_END_NAMESPACE |