return function zipkinRestifyMiddleware(req, res, next) { const readHeader = (header) => headerOption(req, header); const id = instrumentation.recordRequest(req.method, formatRequestUrl(req), readHeader); const onCloseOrFinish = () => { res.removeListener('close', onCloseOrFinish); res.removeListener('finish', onCloseOrFinish); tracer.scoped(() => { instrumentation.recordResponse(id, res.statusCode); }); }; res.once('close', onCloseOrFinish); res.once('finish', onCloseOrFinish); next(); };
tracer.scoped(() => { instrumentation.recordResponse(id, res.statusCode); });