diff --git a/packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts b/packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts index a4d7a96b94fd..42fecd1d39ff 100644 --- a/packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts +++ b/packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts @@ -1,4 +1,4 @@ -import { addTracingExtensions, captureException, flush, getCurrentHub, runWithAsyncContext, trace } from '@sentry/core'; +import { captureException, flush, getCurrentHub, runWithAsyncContext, trace } from '@sentry/core'; import { addExceptionMechanism, tracingContextFromHeaders } from '@sentry/utils'; import { isRedirectNavigationError } from './nextNavigationErrorUtils'; @@ -13,8 +13,6 @@ export function wrapRouteHandlerWithSentry any>( routeHandler: F, context: RouteHandlerContext, ): (...args: Parameters) => ReturnType extends Promise ? ReturnType : Promise> { - addTracingExtensions(); - const { method, parameterizedRoute, baggageHeader, sentryTraceHeader } = context; return new Proxy(routeHandler, { diff --git a/packages/nextjs/src/common/wrapServerComponentWithSentry.ts b/packages/nextjs/src/common/wrapServerComponentWithSentry.ts index 360b169c7b37..6efa50d2b804 100644 --- a/packages/nextjs/src/common/wrapServerComponentWithSentry.ts +++ b/packages/nextjs/src/common/wrapServerComponentWithSentry.ts @@ -1,11 +1,4 @@ -import { - addTracingExtensions, - captureException, - flush, - getCurrentHub, - runWithAsyncContext, - startTransaction, -} from '@sentry/core'; +import { captureException, flush, getCurrentHub, runWithAsyncContext, startTransaction } from '@sentry/core'; import { addExceptionMechanism, tracingContextFromHeaders } from '@sentry/utils'; import { isNotFoundNavigationError, isRedirectNavigationError } from '../common/nextNavigationErrorUtils'; @@ -19,8 +12,6 @@ export function wrapServerComponentWithSentry any> appDirComponent: F, context: ServerComponentContext, ): F { - addTracingExtensions(); - const { componentRoute, componentType } = context; // Even though users may define server components as async functions, for the client bundles diff --git a/packages/nextjs/src/edge/index.ts b/packages/nextjs/src/edge/index.ts index 07c6de85e92c..7c66d8f1fb7f 100644 --- a/packages/nextjs/src/edge/index.ts +++ b/packages/nextjs/src/edge/index.ts @@ -1,10 +1,12 @@ -import { SDK_VERSION } from '@sentry/core'; +import { addTracingExtensions, SDK_VERSION } from '@sentry/core'; import { RewriteFrames } from '@sentry/integrations'; import type { SdkMetadata } from '@sentry/types'; import { addOrUpdateIntegration, escapeStringForRegex, GLOBAL_OBJ } from '@sentry/utils'; import type { VercelEdgeOptions } from '@sentry/vercel-edge'; import { init as vercelEdgeInit } from '@sentry/vercel-edge'; +import { isBuild } from '../common/utils/isBuild'; + export type EdgeOptions = VercelEdgeOptions; const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & { @@ -13,6 +15,12 @@ const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & { /** Inits the Sentry NextJS SDK on the Edge Runtime. */ export function init(options: VercelEdgeOptions = {}): void { + addTracingExtensions(); + + if (isBuild()) { + return; + } + const opts = { _metadata: {} as SdkMetadata, ...options, diff --git a/packages/nextjs/src/server/index.ts b/packages/nextjs/src/server/index.ts index cfbe245ca936..822f2619d127 100644 --- a/packages/nextjs/src/server/index.ts +++ b/packages/nextjs/src/server/index.ts @@ -1,3 +1,4 @@ +import { addTracingExtensions } from '@sentry/core'; import { RewriteFrames } from '@sentry/integrations'; import type { NodeOptions } from '@sentry/node'; import { configureScope, getCurrentHub, init as nodeInit, Integrations } from '@sentry/node'; @@ -63,6 +64,12 @@ const IS_VERCEL = !!process.env.VERCEL; /** Inits the Sentry NextJS SDK on node. */ export function init(options: NodeOptions): void { + addTracingExtensions(); + + if (isBuild()) { + return; + } + const opts = { environment: process.env.SENTRY_ENVIRONMENT || getVercelEnv(false) || process.env.NODE_ENV, ...options,