Skip to content

Commit

Permalink
Use the existing context if any to start the web spans (#1647)
Browse files Browse the repository at this point in the history
* Use the existing context if any to start the web spans

* unit tests
  • Loading branch information
tianchu authored and rochdev committed Nov 2, 2021
1 parent fde5c0b commit e2982f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/dd-trace/src/plugins/util/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const web = {

// Extract the parent span from the headers and start a new span as its child
startChildSpan (tracer, name, headers) {
const childOf = tracer.extract(FORMAT_HTTP_HEADERS, headers)
const childOf = tracer.scope().active() || tracer.extract(FORMAT_HTTP_HEADERS, headers)
const span = tracer.startSpan(name, { childOf })

return span
Expand Down
9 changes: 9 additions & 0 deletions packages/dd-trace/test/plugins/util/web.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ describe('plugins/util/web', () => {
})
})

it('should set the parent from the active context if any', () => {
tracer.trace('aws.lambda', parentSpan => {
web.instrument(tracer, config, req, res, 'test.request', span => {
expect(span.context()._traceId.toString(10)).to.equal(parentSpan.context()._traceId.toString(10))
expect(span.context()._parentId.toString(10)).to.equal(parentSpan.context()._spanId.toString(10))
})
})
})

it('should set the service name', () => {
config.service = 'custom'

Expand Down

0 comments on commit e2982f3

Please sign in to comment.