diff --git a/lib/datadog/tracing/trace_operation.rb b/lib/datadog/tracing/trace_operation.rb index 599c949f83..548ca5918d 100644 --- a/lib/datadog/tracing/trace_operation.rb +++ b/lib/datadog/tracing/trace_operation.rb @@ -137,13 +137,12 @@ def priority_sampled? end def keep! - self.sampled = true self.sampling_priority = Sampling::Ext::Priority::USER_KEEP set_tag(Tracing::Metadata::Ext::Distributed::TAG_DECISION_MAKER, Tracing::Sampling::Ext::Decision::MANUAL) + self.sampled = true # Just in case the in-app sampler had decided to drop this span, we revert that decision. end def reject! - self.sampled = false self.sampling_priority = Sampling::Ext::Priority::USER_REJECT set_tag(Tracing::Metadata::Ext::Distributed::TAG_DECISION_MAKER, Tracing::Sampling::Ext::Decision::MANUAL) end diff --git a/spec/datadog/tracing/integration_spec.rb b/spec/datadog/tracing/integration_spec.rb index 7451845926..1822f7eb18 100644 --- a/spec/datadog/tracing/integration_spec.rb +++ b/spec/datadog/tracing/integration_spec.rb @@ -775,7 +775,10 @@ def sample!(trace) it 'drops trace at application side' do expect(tracer.writer).to_not receive(:write) - tracer.trace('span') { |_, trace| trace.reject! } + tracer.trace('span') do |_, trace| + trace.reject! + trace.sampled = false + end end end diff --git a/spec/datadog/tracing/trace_operation_spec.rb b/spec/datadog/tracing/trace_operation_spec.rb index 68a4039cef..a8c4933c9d 100644 --- a/spec/datadog/tracing/trace_operation_spec.rb +++ b/spec/datadog/tracing/trace_operation_spec.rb @@ -871,18 +871,17 @@ it 'does not modify sampled?' do expect { reject! } - .to change { trace_op.sampled? } - .from(true).to(false) + .to_not change { trace_op.sampled? } + .from(true) end context 'when #sampled was true' do before { trace_op.sampled = true } - it 'sets sampled? to false' do + it 'does not change sampled?' do expect { reject! } - .to change { trace_op.sampled? } + .to_not change { trace_op.sampled? } .from(true) - .to(false) end end