Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sample decision name based on spec update #327

Merged
merged 3 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/include/opentelemetry/sdk/trace/sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ enum class Decision
{
// IsRecording() == false, span will not be recorded and all events and attributes will be
// dropped.
NOT_RECORD,
DROP,
// IsRecording() == true, but Sampled flag MUST NOT be set.
RECORD,
RECORD_ONLY,
// IsRecording() == true AND Sampled flag` MUST be set.
RECORD_AND_SAMPLE
};
Expand Down
6 changes: 3 additions & 3 deletions sdk/include/opentelemetry/sdk/trace/samplers/always_off.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ namespace trace
namespace trace_api = opentelemetry::trace;

/**
* The always off sampler always returns NOT_RECORD, effectively disabling
* The always off sampler always returns DROP, effectively disabling
* tracing functionality.
*/
class AlwaysOffSampler : public Sampler
{
public:
/**
* @return Returns NOT_RECORD always
* @return Returns DROP always
*/
SamplingResult ShouldSample(const trace_api::SpanContext * /*parent_context*/,
trace_api::TraceId /*trace_id*/,
nostd::string_view /*name*/,
trace_api::SpanKind /*span_kind*/,
const trace_api::KeyValueIterable & /*attributes*/) noexcept override
{
return {Decision::NOT_RECORD, nullptr};
return {Decision::DROP, nullptr};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ParentOrElseSampler : public Sampler
explicit ParentOrElseSampler(std::shared_ptr<Sampler> delegate_sampler) noexcept;
/** The decision either respects the parent span's sampling decision or delegates to
* delegateSampler for root spans
* @return Returns NOT_RECORD always
* @return Returns DROP always
*/
SamplingResult ShouldSample(const trace_api::SpanContext *parent_context,
trace_api::TraceId trace_id,
Expand Down
2 changes: 1 addition & 1 deletion sdk/include/opentelemetry/sdk/trace/samplers/probability.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ProbabilitySampler : public Sampler
explicit ProbabilitySampler(double probability);

/**
* @return Returns either RECORD_AND_SAMPLE or NOT_RECORD based on current
* @return Returns either RECORD_AND_SAMPLE or DROP based on current
* sampler configuration and provided parent_context / tracer_id. tracer_id
* is used as a pseudorandom value in conjunction with the predefined
* threshold to determine whether this trace should be sampled
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/trace/samplers/parent_or_else.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SamplingResult ParentOrElseSampler::ShouldSample(
return {Decision::RECORD_AND_SAMPLE, nullptr};
}

return {Decision::NOT_RECORD, nullptr};
return {Decision::DROP, nullptr};
}

nostd::string_view ParentOrElseSampler::GetDescription() const noexcept
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/trace/samplers/probability.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ SamplingResult ProbabilitySampler::ShouldSample(
}
else
{
return {Decision::NOT_RECORD, nullptr};
return {Decision::DROP, nullptr};
}
}

if (threshold_ == 0)
return {Decision::NOT_RECORD, nullptr};
return {Decision::DROP, nullptr};

if (CalculateThresholdFromBuffer(trace_id) <= threshold_)
{
return {Decision::RECORD_AND_SAMPLE, nullptr};
}

return {Decision::NOT_RECORD, nullptr};
return {Decision::DROP, nullptr};
}

nostd::string_view ProbabilitySampler::GetDescription() const noexcept
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/trace/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ nostd::shared_ptr<trace_api::Span> Tracer::StartSpan(
// TODO: replace nullptr with parent context in span context
auto sampling_result =
sampler_->ShouldSample(nullptr, trace_api::TraceId(), name, options.kind, attributes);
if (sampling_result.decision == Decision::NOT_RECORD)
if (sampling_result.decision == Decision::DROP)
{
auto span = nostd::shared_ptr<trace_api::Span>{
new (std::nothrow) trace_api::NoopSpan{this->shared_from_this()}};
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/trace/always_off_sampler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST(AlwaysOffSampler, ShouldSample)

auto sampling_result = sampler.ShouldSample(nullptr, trace_id, "", span_kind, view);

ASSERT_EQ(Decision::NOT_RECORD, sampling_result.decision);
ASSERT_EQ(Decision::DROP, sampling_result.decision);
ASSERT_EQ(nullptr, sampling_result.attributes);
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/test/trace/parent_or_else_sampler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST(ParentOrElseSampler, ShouldSample)
auto sampling_result = sampler_off.ShouldSample(nullptr, trace_id, "", span_kind, view);
auto sampling_result2 = sampler_on.ShouldSample(nullptr, trace_id, "", span_kind, view);

ASSERT_EQ(Decision::NOT_RECORD, sampling_result.decision);
ASSERT_EQ(Decision::DROP, sampling_result.decision);
ASSERT_EQ(Decision::RECORD_AND_SAMPLE, sampling_result2.decision);

// Case 2: Parent exists and SampledFlag is true
Expand All @@ -40,7 +40,7 @@ TEST(ParentOrElseSampler, ShouldSample)
// Case 3: Parent exists and SampledFlag is false
auto sampling_result4 =
sampler_on.ShouldSample(&parent_context_nonsampled, trace_id, "", span_kind, view);
ASSERT_EQ(Decision::NOT_RECORD, sampling_result4.decision);
ASSERT_EQ(Decision::DROP, sampling_result4.decision);
}

TEST(ParentOrElseSampler, GetDescription)
Expand Down
6 changes: 3 additions & 3 deletions sdk/test/trace/probability_sampler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TEST(ProbabilitySampler, ShouldSampleWithoutContext)

sampling_result = s1.ShouldSample(nullptr, valid_trace_id, "", span_kind, view);

ASSERT_EQ(Decision::NOT_RECORD, sampling_result.decision);
ASSERT_EQ(Decision::DROP, sampling_result.decision);
ASSERT_EQ(nullptr, sampling_result.attributes);

ProbabilitySampler s2(0.50000001);
Expand All @@ -89,7 +89,7 @@ TEST(ProbabilitySampler, ShouldSampleWithoutContext)

sampling_result = s3.ShouldSample(nullptr, valid_trace_id, "", span_kind, view);

ASSERT_EQ(Decision::NOT_RECORD, sampling_result.decision);
ASSERT_EQ(Decision::DROP, sampling_result.decision);
ASSERT_EQ(nullptr, sampling_result.attributes);

ProbabilitySampler s4(0.50000000);
Expand Down Expand Up @@ -117,7 +117,7 @@ TEST(ProbabilitySampler, ShouldSampleWithContext)

auto sampling_result = s1.ShouldSample(&c1, trace_id, "", span_kind, view);

ASSERT_EQ(Decision::NOT_RECORD, sampling_result.decision);
ASSERT_EQ(Decision::DROP, sampling_result.decision);
ASSERT_EQ(nullptr, sampling_result.attributes);

sampling_result = s1.ShouldSample(&c2, trace_id, "", span_kind, view);
Expand Down
2 changes: 1 addition & 1 deletion sdk/test/trace/tracer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ TEST(Tracer, StartSpanSampleOff)
tracer_off->StartSpan("span 2")->End();

// The span doesn't write any span data because the sampling decision is alway
// NOT_RECORD.
// DROP.
ASSERT_EQ(0, spans_received->size());
}

Expand Down