Skip to content

Commit

Permalink
Merge pull request #1 from carbon3d/trace-id
Browse files Browse the repository at this point in the history
attach trace id to express req
  • Loading branch information
nhanphan authored Nov 19, 2019
2 parents 85ba4a6 + f27b8d5 commit 0459f1f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/instrumentation/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function patch (express, tracers) {
[Tags.HTTP_URL]: url,
[Tags.HTTP_METHOD]: req.method
})

if (spans[0] && spans[0].context()) {
req.traceId = spans[0].context().traceIdStr
}
if (req.connection.remoteAddress) {
spans.forEach((span) => span.log({ peerRemoteAddress: req.connection.remoteAddress }))
}
Expand Down
3 changes: 2 additions & 1 deletion src/instrumentation/express.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ describe('instrumentation: express', () => {
mockSpan = {
setTag: this.sandbox.spy(),
log: this.sandbox.spy(),
finish: this.sandbox.spy()
finish: this.sandbox.spy(),
context: () => {return {traceIdStr: 'cd085dc813af7cb1'}}
}

this.sandbox.stub(cls, 'startRootSpan').callsFake(() => mockSpan)
Expand Down
6 changes: 4 additions & 2 deletions src/instrumentation/expressError.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ describe('instrumentation: expressError', () => {
beforeEach(function () {
tracer = new Tracer()
mockRootSpan = {
setTag: this.sandbox.spy()
setTag: this.sandbox.spy(),
context: () => {return {traceIdStr: 'cd085dc813af7cb1'}}
}
mockChildSpan = {
setTag: this.sandbox.spy(),
log: this.sandbox.spy(),
finish: this.sandbox.spy()
finish: this.sandbox.spy(),
context: () => {return {traceIdStr: 'cd085dc813af7cb1'}}
}

this.sandbox.stub(cls, 'getRootSpan').callsFake(() => mockRootSpan)
Expand Down

0 comments on commit 0459f1f

Please sign in to comment.