UNPKG

@sentry/nextjs

Version:
177 lines (172 loc) 9.78 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const api = require('@opentelemetry/api'); const core = require('@sentry/core'); const opentelemetry = require('@sentry/opentelemetry'); const vercelEdge = require('@sentry/vercel-edge'); const debugBuild = require('../common/debug-build.js'); const nextSpanAttributes = require('../common/nextSpanAttributes.js'); const spanAttributesWithLogicAttached = require('../common/span-attributes-with-logic-attached.js'); const addHeadersAsAttributes = require('../common/utils/addHeadersAsAttributes.js'); const dropMiddlewareTunnelRequests = require('../common/utils/dropMiddlewareTunnelRequests.js'); const isBuild = require('../common/utils/isBuild.js'); const responseEnd = require('../common/utils/responseEnd.js'); const setUrlProcessingMetadata = require('../common/utils/setUrlProcessingMetadata.js'); const distDirRewriteFramesIntegration = require('./distDirRewriteFramesIntegration.js'); const enhanceMiddlewareRootSpan = require('../common/enhanceMiddlewareRootSpan.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 _error = require('../common/pages-router-instrumentation/_error.js'); const pinoIntegrationShim = require('../common/pinoIntegrationShim.js'); const nextSpan = require('../common/utils/nextSpan.js'); const wrapApiHandlerWithSentry = require('./wrapApiHandlerWithSentry.js'); const globalWithInjectedValues = core.GLOBAL_OBJ; function init(options = {}) { core.registerSpanErrorInstrumentation(); 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 `withSentryConfig({ disableLogger: true })` / `webpack.treeshake.removeDebugLogging: true`). Set that option to `false` to see Sentry debug output." ); } const customDefaultIntegrations = vercelEdge.getDefaultIntegrations(options); const distDirName = process.env._sentryRewriteFramesDistDir || globalWithInjectedValues._sentryRewriteFramesDistDir; if (distDirName) { customDefaultIntegrations.push(distDirRewriteFramesIntegration.distDirRewriteFramesIntegration({ distDirName })); } const isRunningOnCloudflare = responseEnd.isCloudflareWaitUntilAvailable(); const opts = { defaultIntegrations: customDefaultIntegrations, environment: options.environment || process.env.SENTRY_ENVIRONMENT, release: process.env._sentryRelease || globalWithInjectedValues._sentryRelease, ...options, // Override runtime to 'cloudflare' when running on OpenNext/Cloudflare ...isRunningOnCloudflare && { runtime: { name: "cloudflare" } } }; const nextjsIgnoreSpans = [ // (set in `dropMiddlewareTunnelRequests` during `spanStart`) { attributes: { [spanAttributesWithLogicAttached.TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION]: true } } ]; opts.ignoreSpans = [...opts.ignoreSpans || [], ...nextjsIgnoreSpans]; if (isRunningOnCloudflare) { core.applySdkMetadata(opts, "nextjs", ["nextjs", "cloudflare"]); } else { core.applySdkMetadata(opts, "nextjs", ["nextjs", "vercel-edge"]); } const client = vercelEdge.init(opts); client?.on("spanStart", (span) => { const spanAttributes = core.spanToJSON(span).data; const rootSpan = core.getRootSpan(span); const isRootSpan = span === rootSpan; dropMiddlewareTunnelRequests.dropMiddlewareTunnelRequests(span, spanAttributes); if (spanAttributes?.["next.span_type"] !== void 0) { span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, "auto"); } if (spanAttributes?.["next.span_type"] === "Middleware.execute") { span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, "http.server.middleware"); span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, "url"); } if (spanAttributes?.[nextSpanAttributes.ATTR_NEXT_SPAN_TYPE] === "BaseServer.handleRequest" && isRootSpan) { const scopes = core.getCapturedScopesOnSpan(span); const isolationScope = (scopes.isolationScope || core.getIsolationScope()).clone(); const scope = scopes.scope || core.getCurrentScope(); const currentScopesPointer = opentelemetry.getScopesFromContext(api.context.active()); if (currentScopesPointer) { currentScopesPointer.isolationScope = isolationScope; } core.setCapturedScopesOnSpan(span, scope, isolationScope); } if (isRootSpan) { const headers = core.getIsolationScope().getScopeData().sdkProcessingMetadata?.normalizedRequest?.headers; addHeadersAsAttributes.addHeadersAsAttributes(headers, rootSpan); } }); client?.on("preprocessEvent", (event) => { if (event.type === "transaction" && event.contexts?.trace?.data) { enhanceMiddlewareRootSpan.enhanceMiddlewareRootSpan({ attributes: event.contexts.trace.data, getName: () => event.transaction, setName: (name) => { event.transaction = name; }, setOp: (op) => { event.contexts.trace.op = op; } }); } setUrlProcessingMetadata.setUrlProcessingMetadata(event); }); client?.on("processSegmentSpan", (span) => { const attributes = span.attributes ?? (span.attributes = {}); enhanceMiddlewareRootSpan.enhanceMiddlewareRootSpan({ attributes, getName: () => span.name, setName: (name) => { span.name = name; }, setOp: (op) => { attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_OP] = op; } }); }); client?.on("spanEnd", (span) => { if (span === core.getRootSpan(span)) { responseEnd.waitUntil(responseEnd.flushSafelyWithTimeout()); } }); try { if (process.turbopack) { core.getGlobalScope().setTag("turbopack", true); core.getGlobalScope().setAttribute("turbopack", true); } } catch { } } function withSentryConfig(exportedUserNextConfig) { return exportedUserNextConfig; } 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.captureUnderscoreErrorException = _error.captureUnderscoreErrorException; exports.pinoIntegration = pinoIntegrationShim.pinoIntegration; exports.startInactiveSpan = nextSpan.startInactiveSpan; exports.startSpan = nextSpan.startSpan; exports.startSpanManual = nextSpan.startSpanManual; exports.wrapApiHandlerWithSentry = wrapApiHandlerWithSentry.wrapApiHandlerWithSentry; exports.init = init; exports.withSentryConfig = withSentryConfig; Object.prototype.hasOwnProperty.call(vercelEdge, '__proto__') && !Object.prototype.hasOwnProperty.call(exports, '__proto__') && Object.defineProperty(exports, '__proto__', { enumerable: true, value: vercelEdge['__proto__'] }); Object.keys(vercelEdge).forEach(k => { if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = vercelEdge[k]; }); //# sourceMappingURL=index.js.map