Created
November 11, 2020 23:21
-
-
Save tedsuo/c74985480a7661a157b23c4308fe43a8 to your computer and use it in GitHub Desktop.
node_span_start.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"); | |
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