UNPKG

@sentry/nextjs

Version:
186 lines (181 loc) • 10.3 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const core = require('@sentry/core'); const node = require('@sentry/node'); const debugBuild = require('../common/debug-build.js'); const devErrorSymbolicationEventProcessor = require('../common/devErrorSymbolicationEventProcessor.js'); const dropReactControlFlowErrors = require('../common/utils/dropReactControlFlowErrors.js'); const dropMiddlewareTunnelRequests = require('../common/utils/dropMiddlewareTunnelRequests.js'); const isBuild = require('../common/utils/isBuild.js'); const responseEnd = require('../common/utils/responseEnd.js'); const distDirRewriteFramesIntegration = require('./distDirRewriteFramesIntegration.js'); const nextSentryPropagator = require('./nextSentryPropagator.js'); const serverSpanHooks = require('./serverSpanHooks.js'); const prepareSafeIdGeneratorContext = require('./prepareSafeIdGeneratorContext.js'); const useCacheInstrumentation = require('./useCacheInstrumentation.js'); const _error = require('../common/pages-router-instrumentation/_error.js'); const nextSpan = require('../common/utils/nextSpan.js'); const wrapGetStaticPropsWithSentry = require('../common/pages-router-instrumentation/wrapGetStaticPropsWithSentry.js'); const wrapGetInitialPropsWithSentry = require('../common/pages-router-instrumentation/wrapGetInitialPropsWithSentry.js'); const wrapAppGetInitialPropsWithSentry = require('../common/pages-router-instrumentation/wrapAppGetInitialPropsWithSentry.js'); const wrapDocumentGetInitialPropsWithSentry = require('../common/pages-router-instrumentation/wrapDocumentGetInitialPropsWithSentry.js'); const wrapErrorGetInitialPropsWithSentry = require('../common/pages-router-instrumentation/wrapErrorGetInitialPropsWithSentry.js'); const wrapGetServerSidePropsWithSentry = require('../common/pages-router-instrumentation/wrapGetServerSidePropsWithSentry.js'); const wrapServerComponentWithSentry = require('../common/wrapServerComponentWithSentry.js'); const wrapRouteHandlerWithSentry = require('../common/wrapRouteHandlerWithSentry.js'); const wrapApiHandlerWithSentryVercelCrons = require('../common/pages-router-instrumentation/wrapApiHandlerWithSentryVercelCrons.js'); const wrapMiddlewareWithSentry = require('../common/wrapMiddlewareWithSentry.js'); const wrapPageComponentWithSentry = require('../common/pages-router-instrumentation/wrapPageComponentWithSentry.js'); const wrapGenerationFunctionWithSentry = require('../common/wrapGenerationFunctionWithSentry.js'); const withServerActionInstrumentation = require('../common/withServerActionInstrumentation.js'); const captureRequestError = require('../common/captureRequestError.js'); const wrapApiHandlerWithSentry = require('../common/pages-router-instrumentation/wrapApiHandlerWithSentry.js'); const prerenderContext = require('./prerenderContext.js'); const globalWithInjectedValues = core.GLOBAL_OBJ; prepareSafeIdGeneratorContext.prepareSafeIdGeneratorContext(); const ErrorBoundary = (props) => { if (!props.children) { return null; } if (typeof props.children === "function") { return props.children(); } return props.children; }; function createReduxEnhancer() { return (createStore) => createStore; } function withErrorBoundary(WrappedComponent) { return WrappedComponent; } function showReportDialog() { return; } function getCloudflareRuntimeConfig() { if (responseEnd.isCloudflareWaitUntilAvailable()) { return { runtime: { name: "cloudflare" } }; } return void 0; } function init(options) { prepareSafeIdGeneratorContext.prepareSafeIdGeneratorContext(); if (isBuild.isBuild()) { return; } if (!debugBuild.DEBUG_BUILD && options.debug) { console.warn( "[@sentry/nextjs] You have enabled `debug: true`, but Sentry debug logging was removed from your bundle (likely via `bundleSizeOptimizations.excludeDebugStatements: true` or `webpack.treeshake.removeDebugLogging: true`). Set that option to `false` to see Sentry debug output." ); } const customDefaultIntegrations = node.getDefaultIntegrations(options).filter((integration) => integration.name !== "Http").concat( // We are using the HTTP integration without instrumenting incoming HTTP requests because Next.js does that by itself. node.httpIntegration({ disableIncomingRequestSpans: true }) ); if (options.enableOpenTelemetrySetup ?? true) { process.env.NEXT_OTEL_FETCH_DISABLED = "1"; } const distDirName = process.env._sentryRewriteFramesDistDir || globalWithInjectedValues._sentryRewriteFramesDistDir; if (distDirName) { customDefaultIntegrations.push(distDirRewriteFramesIntegration.distDirRewriteFramesIntegration({ distDirName })); } customDefaultIntegrations.push(useCacheInstrumentation.nextjsUseCacheIntegration()); const cloudflareConfig = getCloudflareRuntimeConfig(); const opts = { environment: options.environment || process.env.SENTRY_ENVIRONMENT || core.getVercelEnv() || process.env.NODE_ENV, release: process.env._sentryRelease || globalWithInjectedValues._sentryRelease, defaultIntegrations: customDefaultIntegrations, // Next.js emits its own OpenTelemetry spans, so it defaults to registering the Sentry tracer // provider (unlike most Node-based SDKs). A user-provided value still overrides this via `...options`. enableOpenTelemetrySetup: true, ...options, // Override runtime to 'cloudflare' when running on OpenNext/Cloudflare ...cloudflareConfig }; opts.ignoreSpans = [...opts.ignoreSpans || [], ...serverSpanHooks.NEXTJS_SERVER_IGNORE_SPANS, ...dropMiddlewareTunnelRequests.getTunnelRouteIgnoreSpans()]; if (debugBuild.DEBUG_BUILD && opts.debug) { core.debug.enable(); } debugBuild.DEBUG_BUILD && core.debug.log("Initializing SDK..."); const isOwnedByCloudflare = responseEnd.isAsyncContextOwnedByCloudflare(); const existingClient = core._INTERNAL_getActiveClient(); if (existingClient && !isOwnedByCloudflare) { debugBuild.DEBUG_BUILD && core.debug.log("SDK already initialized"); return existingClient; } core.applySdkMetadata(opts, "nextjs", ["nextjs", cloudflareConfig ? "cloudflare" : "node"]); const client = isOwnedByCloudflare ? void 0 : node.init(opts); if (client) { serverSpanHooks.addNextjsServerSpanHooks(client); } else if (isOwnedByCloudflare) { responseEnd.setCloudflareWorkerRelease(opts.release); } if (client?.traceProvider) { nextSentryPropagator.registerNextSentryPropagator(client.traceProvider); } let eventProcessorTarget = client; if (isOwnedByCloudflare) { const globalScope = core.getGlobalScope(); const isAdded = globalScope.getScopeData().eventProcessors.some((processor) => processor.id === "DropReactControlFlowErrors"); eventProcessorTarget = isAdded ? void 0 : globalScope; } if (!responseEnd.isAsyncContextOwnedByNextjsCloudflare()) { eventProcessorTarget?.addEventProcessor(dropReactControlFlowErrors.dropReactControlFlowErrorsEventProcessor); } if (process.env.NODE_ENV === "development") { eventProcessorTarget?.addEventProcessor(devErrorSymbolicationEventProcessor.devErrorSymbolicationEventProcessor); } try { if (process.turbopack) { core.getGlobalScope().setTag("turbopack", true); core.getGlobalScope().setAttribute("turbopack", true); } } catch { } if (isOwnedByCloudflare) { debugBuild.DEBUG_BUILD && core.debug.log( "The client of `withSentry` handles this Worker, so `init` creates no client and only applies `release`. Set the other options in `withSentry`." ); } else { debugBuild.DEBUG_BUILD && core.debug.log("SDK successfully initialized"); } return client; } exports.pinoIntegration = node.pinoIntegration; exports.vercelAIIntegration = node.vercelAIIntegration; exports.NextSentryPropagator = nextSentryPropagator.NextSentryPropagator; exports.captureUnderscoreErrorException = _error.captureUnderscoreErrorException; exports.startInactiveSpan = nextSpan.startInactiveSpan; exports.startSpan = nextSpan.startSpan; exports.startSpanManual = nextSpan.startSpanManual; exports.wrapGetStaticPropsWithSentry = wrapGetStaticPropsWithSentry.wrapGetStaticPropsWithSentry; exports.wrapGetInitialPropsWithSentry = wrapGetInitialPropsWithSentry.wrapGetInitialPropsWithSentry; exports.wrapAppGetInitialPropsWithSentry = wrapAppGetInitialPropsWithSentry.wrapAppGetInitialPropsWithSentry; exports.wrapDocumentGetInitialPropsWithSentry = wrapDocumentGetInitialPropsWithSentry.wrapDocumentGetInitialPropsWithSentry; exports.wrapErrorGetInitialPropsWithSentry = wrapErrorGetInitialPropsWithSentry.wrapErrorGetInitialPropsWithSentry; exports.wrapGetServerSidePropsWithSentry = wrapGetServerSidePropsWithSentry.wrapGetServerSidePropsWithSentry; exports.wrapServerComponentWithSentry = wrapServerComponentWithSentry.wrapServerComponentWithSentry; exports.wrapRouteHandlerWithSentry = wrapRouteHandlerWithSentry.wrapRouteHandlerWithSentry; exports.wrapApiHandlerWithSentryVercelCrons = wrapApiHandlerWithSentryVercelCrons.wrapApiHandlerWithSentryVercelCrons; exports.wrapMiddlewareWithSentry = wrapMiddlewareWithSentry.wrapMiddlewareWithSentry; exports.wrapPageComponentWithSentry = wrapPageComponentWithSentry.wrapPageComponentWithSentry; exports.wrapGenerationFunctionWithSentry = wrapGenerationFunctionWithSentry.wrapGenerationFunctionWithSentry; exports.withServerActionInstrumentation = withServerActionInstrumentation.withServerActionInstrumentation; exports.captureRequestError = captureRequestError.captureRequestError; exports.wrapApiHandlerWithSentry = wrapApiHandlerWithSentry.wrapApiHandlerWithSentry; exports.markPrerendersOnTracerProvider = prerenderContext.markPrerendersOnTracerProvider; exports.ErrorBoundary = ErrorBoundary; exports.createReduxEnhancer = createReduxEnhancer; exports.init = init; exports.showReportDialog = showReportDialog; exports.withErrorBoundary = withErrorBoundary; Object.prototype.hasOwnProperty.call(node, '__proto__') && !Object.prototype.hasOwnProperty.call(exports, '__proto__') && Object.defineProperty(exports, '__proto__', { enumerable: true, value: node['__proto__'] }); Object.keys(node).forEach(function (k) { if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = node[k]; }); //# sourceMappingURL=index.js.map