diff --git a/benchmark/core.js b/benchmark/core.js index ad9e51a2458..59d49ac3f0f 100644 --- a/benchmark/core.js +++ b/benchmark/core.js @@ -70,7 +70,7 @@ suite }) .add('Writer#append', { onStart () { - writer = new Writer({}, {}) + writer = new Writer({ sample: () => {} }, {}) }, fn () { writer.append(spanStub) diff --git a/src/opentracing/span.js b/src/opentracing/span.js index d0820b4550a..a1ee77bf538 100644 --- a/src/opentracing/span.js +++ b/src/opentracing/span.js @@ -124,7 +124,6 @@ class DatadogSpan extends Span { this._duration = finishTime - this._startTime this._spanContext._trace.finished.push(this) this._spanContext._isFinished = true - this._prioritySampler.sample(this) this._handle.finish() if (this._spanContext._sampled) { diff --git a/src/writer.js b/src/writer.js index 20d9cb0e963..9dc1a443534 100644 --- a/src/writer.js +++ b/src/writer.js @@ -25,6 +25,8 @@ class Writer { const trace = spanContext._trace if (trace.started.length === trace.finished.length) { + this._prioritySampler.sample(spanContext) + const formattedTrace = trace.finished.map(format) if (spanContext._sampling.drop === true) { diff --git a/test/opentracing/span.spec.js b/test/opentracing/span.spec.js index 2919afe4ad6..1cbac95cf79 100644 --- a/test/opentracing/span.spec.js +++ b/test/opentracing/span.spec.js @@ -230,15 +230,5 @@ describe('Span', () => { expect(recorder.record).to.have.been.calledOnce }) - - it('should generate sampling priority', () => { - prioritySampler.sample = span => { - span.context()._sampling.priority = 2 - } - span = new Span(tracer, recorder, sampler, prioritySampler, { operationName: 'operation' }) - span.finish() - - expect(span.context()._sampling.priority).to.equal(2) - }) }) }) diff --git a/test/writer.spec.js b/test/writer.spec.js index 639aa01acb3..759d1bc8f37 100644 --- a/test/writer.spec.js +++ b/test/writer.spec.js @@ -61,7 +61,8 @@ describe('Writer', () => { } prioritySampler = { - update: sinon.stub() + update: sinon.stub(), + sample: sinon.stub() } Writer = proxyquire('../src/writer', { @@ -112,6 +113,12 @@ describe('Writer', () => { expect(writer._queue).to.be.empty }) + + it('should generate sampling priority', () => { + writer.append(span) + + expect(prioritySampler.sample).to.have.been.calledWith(span.context()) + }) }) describe('flush', () => {