From a874ba972bfa4c9c3103f6ba6de6381c1edb0603 Mon Sep 17 00:00:00 2001 From: Igor Unanua Date: Thu, 2 Jan 2025 11:39:24 +0100 Subject: [PATCH] ignore noop spans --- packages/dd-trace/src/priority_sampler.js | 6 ++++-- packages/dd-trace/test/priority_sampler.spec.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/dd-trace/src/priority_sampler.js b/packages/dd-trace/src/priority_sampler.js index 3a89f71f664..7497f1f919c 100644 --- a/packages/dd-trace/src/priority_sampler.js +++ b/packages/dd-trace/src/priority_sampler.js @@ -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) } diff --git a/packages/dd-trace/test/priority_sampler.spec.js b/packages/dd-trace/test/priority_sampler.spec.js index 88c134a5758..2c1a2e273bd 100644 --- a/packages/dd-trace/test/priority_sampler.spec.js +++ b/packages/dd-trace/test/priority_sampler.spec.js @@ -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', () => {