Program Listing for File sampler.h
↰ Return to documentation for file (/home/docs/checkouts/readthedocs.org/user_builds/opentelemetry-cpp/checkouts/v1.3.0/sdk/include/opentelemetry/sdk/trace/sampler.h
)
// 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
{
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
};
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;
};
class Sampler
{
public:
virtual ~Sampler() = default;
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;
virtual nostd::string_view GetDescription() const noexcept = 0;
};
} // namespace trace
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE