Skip to content

Commit

Permalink
Merge pull request #3296 from DataDog/keep-reject
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc authored Dec 6, 2023
2 parents 9df7a53 + 3b6a1fc commit cfc5ab3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
3 changes: 1 addition & 2 deletions lib/datadog/tracing/trace_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion spec/datadog/tracing/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 4 additions & 5 deletions spec/datadog/tracing/trace_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cfc5ab3

Please sign in to comment.