Skip to content
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
5 changes: 4 additions & 1 deletion packages/nextjs/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ export function init(userOptions: NodeOptions): NodeClient | undefined {
// Before `init`, which applies it to the managed tunnel of `serveTunnelIntegration` or `tunnelRoute`.
const tunnelRoute = getTunnelRouteServerOptions();
setTunnelDefaults({ basePath: getInjectedBasePath(), tunnel: tunnelRoute, forward: forwardTunnelRequest });
if (tunnelRoute) {
// On a Vercel deployment the generated tunnel route serves these requests. A hook that answers before Next.js runs
// keeps the function invocation open until it times out. `vercel dev` gets no generated route, so it keeps the hook.
const isServedByVercelTunnelRoute = !!process.env.VERCEL && process.env.VERCEL_ENV !== 'development';
if (tunnelRoute && !isServedByVercelTunnelRoute) {
installTunnelHooks();
}

Expand Down
16 changes: 16 additions & 0 deletions packages/nextjs/test/serverSdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ describe('Server init()', () => {
fetchSpy.mockRestore();
});

it.each([
['off Vercel', {}, 1],
['in `vercel dev`', { VERCEL: '1', VERCEL_ENV: 'development' }, 1],
['on a Vercel deployment', { VERCEL: '1', VERCEL_ENV: 'production' }, 0],
])('installs the tunnel hooks %s only without the generated route', (_description, env, calls) => {
globalWithInjectedValues._sentryTunnelRoute = '/monitoring';
Object.entries(env).forEach(([name, value]) => vi.stubEnv(name, value));
const installTunnelHooks = vi.spyOn(SentryNode, '_INTERNAL_installTunnelHooks').mockImplementation(() => {});

init({ dsn: TEST_DSN });

expect(installTunnelHooks).toHaveBeenCalledTimes(calls);
installTunnelHooks.mockRestore();
vi.unstubAllEnvs();
});

it("serves the path derived from the DSN under the app's `basePath` for `tunnelRoute: true`", () => {
globalWithInjectedValues._sentryBasePath = '/docs';
globalWithInjectedValues._sentryTunnelRoute = 'true';
Expand Down
Loading