@sentry/nextjs
Version:
Official Sentry SDK for Next.js
48 lines (44 loc) • 1.61 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const core = require('@sentry/core');
const responseEnd = require('./utils/responseEnd.js');
function wrapMiddlewareWithSentry(middleware) {
return new Proxy(middleware, {
apply: async (wrappingTarget, thisArg, args) => {
return core.withIsolationScope((isolationScope) => {
const req = args[0];
const currentScope = core.getCurrentScope();
if (req instanceof Request) {
isolationScope.setSDKProcessingMetadata({
normalizedRequest: core.winterCGRequestToRequestData(req)
});
currentScope.setTransactionName(`middleware ${req.method}`);
} else {
currentScope.setTransactionName("middleware");
}
const activeSpan = core.getActiveSpan();
if (activeSpan) {
const rootSpan = core.getRootSpan(activeSpan);
if (rootSpan) {
core.setCapturedScopesOnSpan(rootSpan, currentScope, isolationScope);
}
}
return core.handleCallbackErrors(
() => wrappingTarget.apply(thisArg, args),
(error) => {
core.captureException(error, {
mechanism: {
type: "auto.function.nextjs.wrap_middleware",
handled: false
}
});
},
() => {
responseEnd.waitUntil(responseEnd.flushSafelyWithTimeout());
}
);
});
}
});
}
exports.wrapMiddlewareWithSentry = wrapMiddlewareWithSentry;
//# sourceMappingURL=wrapMiddlewareWithSentry.js.map