@sentry/nextjs
Version:
Official Sentry SDK for Next.js
38 lines (31 loc) • 1.09 kB
JavaScript
import { getActiveSpan } from '@sentry/core';
import { withEdgeWrapping } from '../common/utils/edgeWrapperUtils.js';
/**
* Wraps a Next.js edge route handler with Sentry error and performance instrumentation.
*/
function wrapApiHandlerWithSentry(
handler,
parameterizedRoute,
) {
return new Proxy(handler, {
apply: (wrappingTarget, thisArg, args) => {
const req = args[0];
const activeSpan = getActiveSpan();
const wrappedHandler = withEdgeWrapping(wrappingTarget, {
spanDescription:
activeSpan || !(req instanceof Request)
? `handler (${parameterizedRoute})`
: `${req.method} ${parameterizedRoute}`,
spanOp: activeSpan ? 'function' : 'http.server',
mechanismFunctionName: 'wrapApiHandlerWithSentry',
});
return wrappedHandler.apply(thisArg, args);
},
});
}
/**
* @deprecated Use `wrapApiHandlerWithSentry` instead.
*/
const withSentryAPI = wrapApiHandlerWithSentry;
export { withSentryAPI, wrapApiHandlerWithSentry };
//# sourceMappingURL=wrapApiHandlerWithSentry.js.map