Sentry
Sentry is wired through Next.js instrumentation plus explicit capture calls in error boundaries. The setup is split into runtime-specific config files and a shared instrumentation entrypoint.
- instrumentation.ts
- instrumentation-client.ts
- sentry.server.config.ts
- sentry.edge.config.ts
- sentry.client.config.ts
- error.tsx
- global-error.tsx
- InlineErrorBoundary.tsx
- PageError.tsx
Instrumentation entrypoints
instrumentation.tsregisters Sentry based onprocess.env.NEXT_RUNTIMEand exportsonRequestErrorfor server and edge requests.instrumentation-client.tsimports the client config and exportsonRouterTransitionStartto track client navigations.
Next.js automatically picks up instrumentation.ts and instrumentation-client.ts when they live at the project root.
Runtime configuration
| Runtime | Config file | DSN source | Environment tag | Notes |
|---|---|---|---|---|
| Client | sentry.client.config.ts | NEXT_PUBLIC_SENTRY_DSN | NEXT_PUBLIC_ACTIVE_CHAIN | Debug on in non-production, sendDefaultPii: false, tracesSampleRate: 1, assigns window.Sentry. |
| Edge | sentry.edge.config.ts | SENTRY_DSN then NEXT_PUBLIC_SENTRY_DSN | SENTRY_ENVIRONMENT then NEXT_PUBLIC_ACTIVE_CHAIN | Uses the same defaults for PII and sampling as client and server. |
| Server | sentry.server.config.ts | SENTRY_DSN then NEXT_PUBLIC_SENTRY_DSN | SENTRY_ENVIRONMENT then NEXT_PUBLIC_ACTIVE_CHAIN | Debug on in non-production. Adds domain tag in production. |
Default behavior
sendDefaultPiiis disabled in all runtimes.tracesSampleRateis set to1across client, server, and edge.- A
domaintag is attached in production usingNEXT_PUBLIC_DOMAIN. - Each config logs its initialization details to the console (DSN present and environment).
Error capture sources
InlineErrorBoundarywraps section-level UI and reports exceptions with acomponenttag plus React component stack context.PageErrorcaptures page-level errors.global-error.tsxcaptures uncaught errors that bubble to the app root.onRequestErrorandonRouterTransitionStartare exported from instrumentation to hook into Next.js request and navigation flows.
Storybook safety
Storybook aliases @sentry/nextjs to a no-op mock so Sentry does not ship in the Storybook bundle. See dapp/.storybook/main.ts and dapp/.storybook/mocks/sentry.ts.
Environment variables
Set these in addition to the base .env config:
NEXT_PUBLIC_SENTRY_DSN(client and edge DSN)SENTRY_DSN(server and edge override)SENTRY_ENVIRONMENT(server and edge override)
See Environment Config for the full variable list.
Last updated on