UNPKG

@sentry/nextjs

Version:
54 lines (50 loc) 2.08 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const core = require('@sentry/core'); const nextNavigationErrorUtils = require('./nextNavigationErrorUtils.js'); const responseEnd = require('./utils/responseEnd.js'); function wrapServerComponentWithSentry(appDirComponent, context) { return new Proxy(appDirComponent, { apply: (originalFunction, thisArg, args) => { const isolationScope = core.getIsolationScope(); const headersDict = context.headers ? core.winterCGHeadersToDict(context.headers) : void 0; isolationScope.setSDKProcessingMetadata({ normalizedRequest: { headers: headersDict } }); return core.handleCallbackErrors( () => originalFunction.apply(thisArg, args), (error) => { const span = core.getActiveSpan(); const { componentRoute, componentType } = context; let shouldCapture = true; isolationScope.setTransactionName(`${componentType} Server Component (${componentRoute})`); if (span) { if (nextNavigationErrorUtils.isNotFoundNavigationError(error)) { shouldCapture = false; span.setStatus({ code: core.SPAN_STATUS_ERROR, message: "not_found" }); } else if (nextNavigationErrorUtils.isRedirectNavigationError(error)) { shouldCapture = false; span.setStatus({ code: core.SPAN_STATUS_OK }); } else { span.setStatus({ code: core.SPAN_STATUS_ERROR, message: "internal_error" }); } } if (shouldCapture) { core.captureException(error, { mechanism: { handled: false, type: "auto.function.nextjs.server_component" } }); } }, () => { responseEnd.waitUntil(responseEnd.flushSafelyWithTimeout()); } ); } }); } exports.wrapServerComponentWithSentry = wrapServerComponentWithSentry; //# sourceMappingURL=wrapServerComponentWithSentry.js.map