Skip to content

Commit 9c6d19a

Browse files
committed
change approach
1 parent dde88ca commit 9c6d19a

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

packages/nextjs/src/client/index.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22
// can be removed once following issue is fixed: https://github.com/import-js/eslint-plugin-import/issues/703
33
/* eslint-disable import/export */
44
import type { Client, EventProcessor, Integration } from '@sentry/core';
5-
import { addEventProcessor, applySdkMetadata, consoleSandbox, getGlobalScope, GLOBAL_OBJ } from '@sentry/core';
5+
import {
6+
addEventProcessor,
7+
applySdkMetadata,
8+
consoleSandbox,
9+
envToBool,
10+
getGlobalScope,
11+
GLOBAL_OBJ,
12+
resolveSpotlightOptions,
13+
} from '@sentry/core';
614
import type { BrowserOptions } from '@sentry/react';
7-
import { getDefaultIntegrations as getReactDefaultIntegrations, init as reactInit } from '@sentry/react';
15+
import {
16+
getDefaultIntegrations as getReactDefaultIntegrations,
17+
init as reactInit,
18+
spotlightBrowserIntegration,
19+
} from '@sentry/react';
820
import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor';
921
import { getVercelEnv } from '../common/getVercelEnv';
1022
import { isRedirectNavigationError } from '../common/nextNavigationErrorUtils';
@@ -54,12 +66,32 @@ export function init(options: BrowserOptions): Client | undefined {
5466
removeIsrSsgTraceMetaTags();
5567
}
5668

57-
const opts = {
69+
const opts: BrowserOptions = {
5870
environment: getVercelEnv(true) || process.env.NODE_ENV,
5971
defaultIntegrations: getDefaultIntegrations(options),
6072
release: process.env._sentryRelease || globalWithInjectedValues._sentryRelease,
6173
...options,
62-
} satisfies BrowserOptions;
74+
};
75+
76+
// Auto-enable Spotlight in development mode from NEXT_PUBLIC_SENTRY_SPOTLIGHT env var
77+
// This code will be tree-shaken in production builds by Next.js
78+
if (process.env.NODE_ENV === 'development') {
79+
const envValue = process.env.NEXT_PUBLIC_SENTRY_SPOTLIGHT;
80+
// Only apply env var if user hasn't explicitly set spotlight option
81+
if (envValue !== undefined && options.spotlight === undefined) {
82+
const boolValue = envToBool(envValue, { strict: true });
83+
const spotlightConfig = boolValue !== null ? boolValue : envValue;
84+
const spotlightValue = resolveSpotlightOptions(undefined, spotlightConfig);
85+
86+
if (spotlightValue) {
87+
const spotlightArgs = typeof spotlightValue === 'string' ? { sidecarUrl: spotlightValue } : undefined;
88+
opts.integrations = [
89+
...(Array.isArray(opts.integrations) ? opts.integrations : []),
90+
spotlightBrowserIntegration(spotlightArgs),
91+
];
92+
}
93+
}
94+
}
6395

6496
applyTunnelRouteOption(opts);
6597
applySdkMetadata(opts, 'nextjs', ['nextjs', 'react']);

packages/nextjs/src/config/webpack.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,6 @@ export function constructWebpackConfigFunction({
9797
// `newConfig.module.rules` is required, so we don't have to keep asserting its existence
9898
const newConfig = setUpModuleRules(rawNewConfig);
9999

100-
// In development mode for client bundles, alias @sentry/browser to its development build
101-
// This enables development-only features like Spotlight auto-enablement from env vars
102-
if (isDev && !isServer) {
103-
newConfig.resolve = newConfig.resolve || {};
104-
newConfig.resolve.alias = newConfig.resolve.alias || {};
105-
// Use the CJS development build to avoid ESM 'export *' issues in Next.js client boundaries
106-
newConfig.resolve.alias['@sentry/browser$'] = '@sentry/browser/build/npm/cjs/dev/index.js';
107-
}
108-
109100
// Add a loader which will inject code that sets global values
110101
addValueInjectionLoader({
111102
newConfig,

0 commit comments

Comments
 (0)