Tracing requests on the server.
const app = express();
app.get('/api', function(req, res) {
const serverSpan = opentracing.globalTracer().startSpan('api', {
childOf: tracer.extract(opentracing.FORMAT_TEXT_MAP, req.headers),
tags: {
'http.method': 'GET',
'http.url': `http://${req.headers.host}${req.url}`,
}
});
/**
* Business logic
*/
res.writeHead(200);
res.end('/api');
serverSpan.setTag('http.status_code', 200);
serverSpan.finish();
});