]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/opentelemetry-cpp/sdk/src/trace/samplers/parent.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / sdk / src / trace / samplers / parent.cc
CommitLineData
1e59de90
TL
1// Copyright The OpenTelemetry Authors
2// SPDX-License-Identifier: Apache-2.0
3
4#include "opentelemetry/sdk/trace/samplers/parent.h"
5
6namespace trace_api = opentelemetry::trace;
7
8OPENTELEMETRY_BEGIN_NAMESPACE
9namespace sdk
10{
11namespace trace
12{
13ParentBasedSampler::ParentBasedSampler(std::shared_ptr<Sampler> delegate_sampler) noexcept
14 : delegate_sampler_(delegate_sampler),
15 description_("ParentBased{" + std::string{delegate_sampler->GetDescription()} + "}")
16{}
17
18SamplingResult ParentBasedSampler::ShouldSample(
19 const trace_api::SpanContext &parent_context,
20 trace_api::TraceId trace_id,
21 nostd::string_view name,
22 trace_api::SpanKind span_kind,
23 const opentelemetry::common::KeyValueIterable &attributes,
24 const trace_api::SpanContextKeyValueIterable &links) noexcept
25{
26 if (!parent_context.IsValid())
27 {
28 // If no parent (root span) exists returns the result of the delegateSampler
29 return delegate_sampler_->ShouldSample(parent_context, trace_id, name, span_kind, attributes,
30 links);
31 }
32
33 // If parent exists:
34 if (parent_context.IsSampled())
35 {
36 return {Decision::RECORD_AND_SAMPLE, nullptr, parent_context.trace_state()};
37 }
38
39 return {Decision::DROP, nullptr, parent_context.trace_state()};
40}
41
42nostd::string_view ParentBasedSampler::GetDescription() const noexcept
43{
44 return description_;
45}
46} // namespace trace
47} // namespace sdk
48OPENTELEMETRY_END_NAMESPACE