Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix sampling priority being locked too early #544

Merged
merged 3 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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