Skip to content

Commit

Permalink
ignore noop spans
Browse files Browse the repository at this point in the history
  • Loading branch information
iunanua committed Jan 2, 2025
1 parent 4d6a8e3 commit a874ba9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/dd-trace/src/priority_sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ class PrioritySampler {
if (!span || !this.validate(samplingPriority)) return

const context = this._getContext(span)
const root = context._trace.started[0]

if (!root) return // noop span

context._sampling.priority = samplingPriority
context._sampling.mechanism = mechanism

const root = context._trace.started[0]

log.trace(span, samplingPriority, mechanism)

this._addDecisionMaker(root)
}

Expand Down
10 changes: 10 additions & 0 deletions packages/dd-trace/test/priority_sampler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,16 @@ describe('PrioritySampler', () => {
expect(context._sampling.mechanism).to.equal(SAMPLING_MECHANISM_APPSEC)
expect(context._trace.tags[DECISION_MAKER_KEY]).to.equal('-0')
})

it('should ignore noop spans', () => {
context._trace.started[0] = undefined // noop

prioritySampler.setPriority(span, USER_KEEP, SAMPLING_MECHANISM_APPSEC)

expect(context._sampling.priority).to.undefined
expect(context._sampling.mechanism).to.undefined
expect(context._trace.tags[DECISION_MAKER_KEY]).to.undefined
})
})

describe('keepTrace', () => {
Expand Down

0 comments on commit a874ba9

Please sign in to comment.