Skip to content

Instantly share code, notes, and snippets.

@eyeezzi
Created July 23, 2019 20:24
Show Gist options
  • Save eyeezzi/1257c165e672610ab6047db8866539af to your computer and use it in GitHub Desktop.
Save eyeezzi/1257c165e672610ab6047db8866539af to your computer and use it in GitHub Desktop.
/* api-service */
app.use('/api/v1/whereami', async (req, res, next) => {
const parentSpan = createContinuationSpan(tracer, req, 'whereami-request')
const childSpan = tracer.startSpan('city-from-ip', {childOf: parentSpan})
const _ = await axios.get(`http://ip-api.com/json/${req.ip}`)
childSpan.finish()
// Do more work and create more children spans.
parentSpan.finish()
})
function createContinuationSpan(tracer, req, spanName) {
const incomingSpanContext = tracer.extract(opentracing.FORMAT_HTTP_HEADERS, req.headers)
if (incomingSpanContext == null) {
return tracer.startSpan(spanName)
}
return tracer.startSpan(spanName, {childOf: incomingSpanContext})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment