Created
July 23, 2019 20:24
-
-
Save eyeezzi/1257c165e672610ab6047db8866539af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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