Skip to content

Commit

Permalink
fix sampling priority being locked too early (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
rochdev authored May 1, 2019
1 parent 4b435cf commit 4a267c1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion benchmark/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ suite
})
.add('Writer#append', {
onStart () {
writer = new Writer({}, {})
writer = new Writer({ sample: () => {} }, {})
},
fn () {
writer.append(spanStub)
Expand Down
1 change: 0 additions & 1 deletion src/opentracing/span.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 0 additions & 10 deletions test/opentracing/span.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
9 changes: 8 additions & 1 deletion test/writer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ describe('Writer', () => {
}

prioritySampler = {
update: sinon.stub()
update: sinon.stub(),
sample: sinon.stub()
}

Writer = proxyquire('../src/writer', {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 4a267c1

Please sign in to comment.