Skip to content

Commit

Permalink
Fix trace kIsSampled flag set incorrectly (#1465)
Browse files Browse the repository at this point in the history
  • Loading branch information
luyor authored Jul 1, 2022
1 parent 7b0bb14 commit 4c08919
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions sdk/include/opentelemetry/sdk/trace/sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ struct SamplingResult
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;

inline bool IsRecording()
{
return decision == Decision::RECORD_ONLY || decision == Decision::RECORD_AND_SAMPLE;
}
inline bool IsSampled() { return decision == Decision::RECORD_AND_SAMPLE; }
};

/**
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/trace/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ nostd::shared_ptr<trace_api::Span> Tracer::StartSpan(

auto sampling_result = context_->GetSampler().ShouldSample(parent_context, trace_id, name,
options.kind, attributes, links);
auto trace_flags = sampling_result.decision == Decision::DROP
? trace_api::TraceFlags{}
: trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled};
auto trace_flags = sampling_result.IsSampled()
? trace_api::TraceFlags{trace_api::TraceFlags::kIsSampled}
: trace_api::TraceFlags{};

auto span_context = std::unique_ptr<trace_api::SpanContext>(new trace_api::SpanContext(
trace_id, span_id, trace_flags, false,
sampling_result.trace_state ? sampling_result.trace_state
: is_parent_span_valid ? parent_context.trace_state()
: trace_api::TraceState::GetDefault()));

if (sampling_result.decision == Decision::DROP)
if (!sampling_result.IsRecording())
{
// create no-op span with valid span-context.

Expand Down

0 comments on commit 4c08919

Please sign in to comment.