Skip to content

Commit

Permalink
Update AlwaysOffSampler to new sampler spec
Browse files Browse the repository at this point in the history
  • Loading branch information
nholbrook committed Jun 23, 2020
1 parent d4f1036 commit d5f5c14
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 68 deletions.
7 changes: 1 addition & 6 deletions sdk/include/opentelemetry/sdk/trace/always_off_sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ namespace trace_api = opentelemetry::trace;
class AlwaysOffSampler : public Sampler
{
public:
explicit AlwaysOffSampler() noexcept;

/**
* @return Returns NOT_RECORD always
*/
SamplingResult ShouldSample(
std::shared_ptr<SpanContext> parent_context,
const SpanContext *parent_context,
trace_api::TraceId trace_id,
nostd::string_view name,
trace_api::SpanKind span_kind,
Expand All @@ -31,9 +29,6 @@ class AlwaysOffSampler : public Sampler
* @return Description MUST be AlwaysOffSampler
*/
std::string GetDescription() const noexcept override;

private:
SamplingResult sampling_result_;
};
} // namespace trace
} // namespace sdk
Expand Down
74 changes: 37 additions & 37 deletions sdk/include/opentelemetry/sdk/trace/sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,72 +19,72 @@ namespace sdk
namespace trace
{
namespace trace_api = opentelemetry::trace;
class Sampler
/**
* NOT_RECORD - IsRecording() == false,
* span will not be recorded and all events and attributes will be dropped.
* RECORD - IsRecording() == true, but Sampled flag MUST NOT be set.
* RECORD_AND_SAMPLED - IsRecording() == true AND Sampled flag` MUST be set.
*/
enum class Decision
{
private:
// Placeholder
class SpanContext
{};
NOT_RECORD,
RECORD,
RECORD_AND_SAMPLE
};

/**
* A placeholder for common::AttributeKeyValue
* A key/value pair that can be used to set attributes.
*/
struct AttributeKeyValue {
nostd::string_view key;
common::AttributeValue value;
};

struct SamplingResult
{
Decision decision;
// TODO: Change AttributeKeyValue to common::AttributeKeyValue
std::unique_ptr<nostd::span<AttributeKeyValue>> attributes;
};

class Sampler
{
public:
// Placeholder
class SpanContext;
virtual ~Sampler() = default;
/**
* Called during Span creation to make a sampling decision.
*
* @param parent_context TODO: a shared pointer of the SpanContext of a parent Span.
* @param parent_context TODO: a shared pointer of the SpanContext of a parent Span.
* null 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 trace_api::SpanKind of the Span.
* @param attributes TODO: current map is a placeholder.
* @param attributes TODO: Change AttributeKeyValue to common::AttributeKeyValue
* list of AttributeValue with their keys.
* @param links TODO: 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(
std::shared_ptr<SpanContext> parent_context,
const SpanContext *parent_context,
trace_api::TraceId trace_id,
nostd::string_view name,
trace_api::SpanKind span_kind,
nostd::span<std::pair<nostd::string_view, common::AttributeValue>> attributes) noexcept = 0;
const nostd::span<AttributeKeyValue> &attributes) noexcept = 0;

/**
* Returns the sampler name or short description with the configuration.
* 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 std::string GetDescription() const noexcept = 0;
};

class SamplingResult
{
public:
enum Decision
{
NOT_RECORD,
RECORD,
RECORD_AND_SAMPLE
};
virtual ~SamplingResult() = default;
/**
* Return sampling decision.
*
* @return Decision.
*/
virtual Decision GetDecision() const noexcept = 0;

/**
* Return attributes which will be attached to the span.
*
* @return the immutable list of attributes added to span.
*/
virtual nostd::span<std::pair<nostd::string_view, common::AttributeValue>> GetAttributes() const
noexcept = 0;
};
} // namespace trace
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE
OPENTELEMETRY_END_NAMESPACE
36 changes: 11 additions & 25 deletions sdk/src/trace/always_off_sampler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,24 @@ namespace trace
{
namespace trace_api = opentelemetry::trace;

AlwaysOffSampler::AlwaysOffSampler() noexcept
: sampling_result_(new AlwaysOffSamplingResultImpl()) {}

SamplingResult AlwaysOffSampler::ShouldSample(
std::shared_ptr<SpanContext> parent_context,
const SpanContext *parent_context,
trace_api::TraceId trace_id,
nostd::string_view name,
trace_api::SpanKind span_kind,
const nostd::span<AttributeKeyValue> &attributes) noexcept override
const nostd::span<AttributeKeyValue> &attributes) noexcept
{
return sampling_result_;
return
{
Decision::NOT_RECORD,
std::unique_ptr<nostd::span<AttributeKeyValue>>(new nostd::span<AttributeKeyValue>())
};
}

std::string GetDescription() const noexcept override
std::string AlwaysOffSampler::GetDescription() const noexcept
{
return "AlwaysOffSampler";
}

class AlwaysOffSamplingResultImpl : public SamplingResult
{
public:
Decision GetDecision() const noexcept override
{
return decision_;
}

nostd::span<AttributeKeyValue> GetAttributes() const noexcept override
{
return attributes_;
}

private:
Decision decision_ = Decision::NOT_RECORD;
nostd::span<AttributeKeyValue> attributes_ = nostd::span();
};
} // namespace trace
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

0 comments on commit d5f5c14

Please sign in to comment.