Created
November 11, 2020 23:25
-
-
Save tedsuo/ca68170275da3fc8ccbb9fd7886e8dd7 to your computer and use it in GitHub Desktop.
node_with_span.js
This file contains 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
app.get('/hello', (req, res) => { | |
// start a new span named “sleeper” | |
const childSpan = tracer.startSpan("sleeper"); | |
// use withSpan to create a new context | |
tracer.withSpan(childSpan,()=> { | |
setTimeout(()=> { | |
// getCurrentSpan now correctly returns childSpan | |
const span = tracer.getCurrentSpan(); | |
span.addEvent('sending response'); | |
res.status(200).send('Hello World'); | |
span.end(); | |
}, 300); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment