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 references to the old trace IDs #426

Merged
merged 1 commit into from
Feb 5, 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
17 changes: 9 additions & 8 deletions src/opentracing/propagation/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
const Uint64BE = require('int64-buffer').Uint64BE
const DatadogSpanContext = require('../span_context')

const traceKey = 'dd.trace_id'
const spanKey = 'dd.span_id'

class LogPropagator {
inject (spanContext, carrier) {
carrier[traceKey] = spanContext.toTraceId()
carrier[spanKey] = spanContext.toSpanId()
if (!carrier) return

carrier.dd = {
trace_id: spanContext.toTraceId(),
span_id: spanContext.toSpanId()
}
}

extract (carrier) {
if (!carrier[traceKey] || !carrier[spanKey]) {
if (!carrier || !carrier.dd || !carrier.dd.trace_id || !carrier.dd.span_id) {
return null
}

const spanContext = new DatadogSpanContext({
traceId: new Uint64BE(carrier[traceKey], 10),
spanId: new Uint64BE(carrier[spanKey], 10)
traceId: new Uint64BE(carrier.dd.trace_id, 10),
spanId: new Uint64BE(carrier.dd.span_id, 10)
})

return spanContext
Expand Down
14 changes: 10 additions & 4 deletions test/opentracing/propagation/log.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ describe('LogPropagator', () => {
LogPropagator = require('../../../src/opentracing/propagation/log')
propagator = new LogPropagator()
log = {
'dd.trace_id': '123',
'dd.span_id': '18446744073709551160' // -456 casted to uint64
dd: {
trace_id: '123',
span_id: '18446744073709551160' // -456 casted to uint64
}
}
})

Expand All @@ -27,8 +29,12 @@ describe('LogPropagator', () => {

propagator.inject(spanContext, carrier)

expect(carrier).to.have.property('dd.trace_id', '123')
expect(carrier).to.have.property('dd.span_id', '18446744073709551160') // -456 casted to uint64
expect(carrier).to.deep.include({
dd: {
trace_id: '123',
span_id: '18446744073709551160' // -456 casted to uint64
}
})
})
})

Expand Down
6 changes: 4 additions & 2 deletions test/plugins/winston.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ describe('Plugin', () => {

it('should not alter the default behavior', () => {
const meta = {
'dd.trace_id': span.context().toTraceId(),
'dd.span_id': span.context().toSpanId()
dd: {
trace_id: span.context().toTraceId(),
span_id: span.context().toSpanId()
}
}

tracer.scopeManager().activate(span)
Expand Down