Skip to content

Commit efade0f

Browse files
fix(web): enable Sentry tracing and restore client-side Sentry
Renames sentry.client.config.ts to instrumentation-client.ts, which Next.js loads itself. The old file was only wired in by @sentry/nextjs' webpack plugin, which never runs: next build defaults to Turbopack in Next 16, and next.config.mjs defines a turbopack block, so Next's "webpack config with no turbopack config" guard passes silently. Client errors, replays and spans were therefore never reported in production. Exports onRouterTransitionStart so App Router client-side navigations are instrumented as spans; Next only reads that export from instrumentation-client.ts. Sets tracesSampleRate on client, server and edge. Tracing is off unless this option is present at all, since hasSpansEnabled() checks for non-nullish. Sampling every trace for now to get a read on span volume before tuning the rate down. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a1b71c3 commit efade0f

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

packages/web/src/sentry.client.config.ts renamed to packages/web/src/instrumentation-client.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// This file configures the initialization of Sentry on the client.
22
// The config you add here will be used whenever a users loads a page in their browser.
33
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
4+
//
5+
// Must be named `instrumentation-client.ts`. Next.js loads this file itself, whereas
6+
// `sentry.client.config.ts` is only picked up by @sentry/nextjs' webpack plugin,
7+
// which never runs since `next build` defaults to Turbopack.
48

59
import * as Sentry from "@sentry/nextjs";
610

@@ -9,9 +13,15 @@ if (!!process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN && !!process.env.NEXT_PUBLIC_SEN
913
dsn: process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN,
1014
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
1115

16+
tracesSampleRate: 1.0,
17+
1218
// Setting this option to true will print useful information to the console while you're setting up Sentry.
1319
debug: false,
1420
});
1521
} else {
1622
console.debug("[client] Sentry was not initialized");
1723
}
24+
25+
// Instruments App Router client-side navigations as spans. Next.js only reads this
26+
// export from `instrumentation-client.ts`. A no-op when Sentry is uninitialized.
27+
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;

packages/web/src/sentry.edge.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ if (!!process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN && !!process.env.NEXT_PUBLIC_SEN
1010
dsn: process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN,
1111
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
1212

13+
tracesSampleRate: 1.0,
14+
1315
// Setting this option to true will print useful information to the console while you're setting up Sentry.
1416
debug: false,
1517
});

packages/web/src/sentry.server.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ if (!!process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN && !!process.env.NEXT_PUBLIC_SEN
1212
dsn: process.env.NEXT_PUBLIC_SENTRY_WEBAPP_DSN,
1313
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
1414

15+
tracesSampleRate: 1.0,
16+
1517
// Setting this option to true will print useful information to the console while you're setting up Sentry.
1618
debug: false,
1719
});

0 commit comments

Comments
 (0)