@sentry/tracing#extractTraceparentData JavaScript Examples
The following examples show how to use
@sentry/tracing#extractTraceparentData.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: handlers.js From Kadena-Mining-Stratum with GNU General Public License v2.0 | 6 votes |
/**
* Express-compatible tracing handler.
* @see Exposed as `Handlers.tracingHandler`
*/
export function tracingHandler() {
return function sentryTracingMiddleware(req, res, next) {
// TODO: At this point `req.route.path` (which we use in `extractTransaction`) is not available
// but `req.path` or `req.url` should do the job as well. We could unify this here.
var reqMethod = (req.method || '').toUpperCase();
var reqUrl = req.url && stripUrlQueryAndFragment(req.url);
// If there is a trace header set, we extract the data from it (parentSpanId, traceId, and sampling decision)
var traceparentData;
if (req.headers && isString(req.headers['sentry-trace'])) {
traceparentData = extractTraceparentData(req.headers['sentry-trace']);
}
var transaction = startTransaction(__assign({ name: reqMethod + " " + reqUrl, op: 'http.server' }, traceparentData));
// We put the transaction on the scope so users can attach children to it
getCurrentHub().configureScope(function (scope) {
scope.setSpan(transaction);
});
// We also set __sentry_transaction on the response so people can grab the transaction there to add
// spans to it later.
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
res.__sentry_transaction = transaction;
res.once('finish', function () {
transaction.setHttpStatus(res.statusCode);
transaction.finish();
});
next();
};
}