|
2 | 2 | // can be removed once following issue is fixed: https://github.com/import-js/eslint-plugin-import/issues/703 |
3 | 3 | /* eslint-disable import/export */ |
4 | 4 | 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'; |
6 | 14 | 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'; |
8 | 20 | import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor'; |
9 | 21 | import { getVercelEnv } from '../common/getVercelEnv'; |
10 | 22 | import { isRedirectNavigationError } from '../common/nextNavigationErrorUtils'; |
@@ -54,12 +66,32 @@ export function init(options: BrowserOptions): Client | undefined { |
54 | 66 | removeIsrSsgTraceMetaTags(); |
55 | 67 | } |
56 | 68 |
|
57 | | - const opts = { |
| 69 | + const opts: BrowserOptions = { |
58 | 70 | environment: getVercelEnv(true) || process.env.NODE_ENV, |
59 | 71 | defaultIntegrations: getDefaultIntegrations(options), |
60 | 72 | release: process.env._sentryRelease || globalWithInjectedValues._sentryRelease, |
61 | 73 | ...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 | + } |
63 | 95 |
|
64 | 96 | applyTunnelRouteOption(opts); |
65 | 97 | applySdkMetadata(opts, 'nextjs', ['nextjs', 'react']); |
|
0 commit comments