Skip to content

Commit

Permalink
feat(span): use inject and extract for span context
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Marton committed Jul 3, 2017
1 parent 0c29447 commit dd3bd14
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/instrumentation/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ function patchModuleRoot (express, tracer) {
function middleware (req, res, next) {
// start
const url = `${req.protocol}://${req.hostname}${req.originalUrl}`
const parentSpanContextStr = req.headers['trace-span-context']
const parentSpanContext = parentSpanContextStr
? SpanContext.fromString(parentSpanContextStr)
: undefined

const parentSpanContext = tracer.extract(opentracing.FORMAT_HTTP_HEADERS, req.headers)
const span = cls.startRootSpan(tracer, OPERATION_NAME, parentSpanContext)

span.setTag(opentracing.Tags.HTTP_URL, url)
Expand Down
2 changes: 1 addition & 1 deletion src/instrumentation/httpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function patchHttp (http, tracer) {
options = _.isString(options) ? url.parse(options) : _.merge({}, options)
options.headers = options.headers || {}

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

const uri = extractUrl(options)
span.setTag(opentracing.Tags.HTTP_URL, uri)
Expand Down

0 comments on commit dd3bd14

Please sign in to comment.