Skip to content

Commit dd3bd14

Browse files
author
Peter Marton
committed
feat(span): use inject and extract for span context
1 parent 0c29447 commit dd3bd14

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

Diff for: src/instrumentation/express.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ function patchModuleRoot (express, tracer) {
2929
function middleware (req, res, next) {
3030
// start
3131
const url = `${req.protocol}://${req.hostname}${req.originalUrl}`
32-
const parentSpanContextStr = req.headers['trace-span-context']
33-
const parentSpanContext = parentSpanContextStr
34-
? SpanContext.fromString(parentSpanContextStr)
35-
: undefined
36-
32+
const parentSpanContext = tracer.extract(opentracing.FORMAT_HTTP_HEADERS, req.headers)
3733
const span = cls.startRootSpan(tracer, OPERATION_NAME, parentSpanContext)
3834

3935
span.setTag(opentracing.Tags.HTTP_URL, url)

Diff for: src/instrumentation/httpClient.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function patchHttp (http, tracer) {
5454
options = _.isString(options) ? url.parse(options) : _.merge({}, options)
5555
options.headers = options.headers || {}
5656

57-
options.headers['trace-span-context'] = span.context().toString()
57+
tracer.inject(span, opentracing.FORMAT_HTTP_HEADERS, options.headers)
5858

5959
const uri = extractUrl(options)
6060
span.setTag(opentracing.Tags.HTTP_URL, uri)

0 commit comments

Comments
 (0)