Skip to content

Instantly share code, notes, and snippets.

@tedsuo
Created November 11, 2020 23:21
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/c74985480a7661a157b23c4308fe43a8 to your computer and use it in GitHub Desktop.
Save tedsuo/c74985480a7661a157b23c4308fe43a8 to your computer and use it in GitHub Desktop.
node_span_start.js
app.get('/hello', (req, res) => {
// start a new span named “sleeper”
const childSpan = tracer.startSpan("sleeper");
setTimeout(()=> {
// childSpan works normally when referenced
childSpan.addEvent('finished sleeping');
// However, starting a span does not automatically
// set it to the current span. getCurrentSpan still
// returns the parent span.
tracer.getCurrentSpan();
res.status(200).send('Hello World');
// Ending the span is a requirement. It measures the duration
// of the operation, and then sends the span to the exporter.
childSpan.end();
}, 300);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment