Skip to content

Instantly share code, notes, and snippets.

@tedsuo
Created November 11, 2020 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedsuo/ca68170275da3fc8ccbb9fd7886e8dd7 to your computer and use it in GitHub Desktop.
Save tedsuo/ca68170275da3fc8ccbb9fd7886e8dd7 to your computer and use it in GitHub Desktop.
node_with_span.js
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