diff --git a/sdk/include/opentelemetry/sdk/trace/sampler.h b/sdk/include/opentelemetry/sdk/trace/sampler.h index 22ec6d52f1..374c333acd 100644 --- a/sdk/include/opentelemetry/sdk/trace/sampler.h +++ b/sdk/include/opentelemetry/sdk/trace/sampler.h @@ -1,6 +1,8 @@ #pragma once #include "opentelemetry/common/attribute_value.h" +#include "opentelemetry/nostd/string_view.h" +#include "opentelemetry/sdk/common/atomic_shared_ptr.h" #include "opentelemetry/trace/span.h" #include "opentelemetry/trace/trace_id.h" #include "opentelemetry/trace/tracer.h" @@ -18,26 +20,33 @@ namespace trace namespace trace_api = opentelemetry::trace; class Sampler { +private: + // Placeholder + class SpanContext + {}; + public: virtual ~Sampler() = default; /** * Called during Span creation to make a sampling decision. * - * @param parentContext TODO: the parent span's SpanContext. null if this is a root + * @param parent_context TODO: the parent span's SpanContext. null if this is a root * span. * @param traceId 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 parentLinks TODO: the parentLinks associated with the new Span. * @param spanKind the trace_api::SpanKind of the Span. - * @param attributes list of AttributeValue with their keys. + * @param attributes TODO: current map is a placeholder. + * list of AttributeValue with their keys. * @return sampling decision whether span should be sampled or not. * @since 0.1.0 */ virtual SamplingResult ShouldSample( + std::shared_ptr parent_context, trace_api::TraceId trace_id, - std::string name, + nostd::string_view name, trace_api::SpanKind span_kind, std::map attributes) noexcept = 0; @@ -54,6 +63,14 @@ class Sampler class SamplingResult { +private: + enum Decision + { + NOT_RECORD, + RECORD, + RECORD_AND_SAMPLE + }; + public: // TODO: add Decision enum virtual ~SamplingResult() = default; @@ -62,15 +79,16 @@ class SamplingResult * * @return TODO: Decision. */ - virtual bool GetDecision(); + virtual Decision GetDecision() const noexcept = 0; /** * Return attributes which will be attached to the span. * + * TODO: Change return value to nostd::span> * @return attributes added to span. These attributes should be added to the span only for root * span or when sampling decision isSampled() changes from false to true. */ - virtual std::map GetAttributes(); + virtual std::map GetAttributes() const noexcept = 0; }; } // namespace trace } // namespace sdk