Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(nextjs): Don't initialize Server SDK during build #9503

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,8 +13,6 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
routeHandler: F,
context: RouteHandlerContext,
): (...args: Parameters<F>) => ReturnType<F> extends Promise<unknown> ? ReturnType<F> : Promise<ReturnType<F>> {
addTracingExtensions();

const { method, parameterizedRoute, baggageHeader, sentryTraceHeader } = context;

return new Proxy(routeHandler, {
Expand Down
11 changes: 1 addition & 10 deletions packages/nextjs/src/common/wrapServerComponentWithSentry.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -19,8 +12,6 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => 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
Expand Down
10 changes: 9 additions & 1 deletion packages/nextjs/src/edge/index.ts
Original file line number Diff line number Diff line change
@@ -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 & {
Expand All @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down