ShiftFast Docs

Observability

How the kit reports errors, traces, session replays, and logs to Sentry, how to turn it on, and what to change for production.

The kit uses Sentry for error tracking, performance traces, session replay, and logs. It's wired into every Next.js runtime and stays silent until you set a DSN, so you can ignore it until you need it.

How it's wired

Next.js runs code in three places, and each gets its own Sentry setup, the layout Sentry's Next.js guide uses:

FileRuns inWhat it does
src/instrumentation-client.tsThe browserErrors, traces, session replay, and console logs from the client
sentry.server.config.tsNode.js (server)Errors, traces, and console logs from the server
sentry.edge.config.tsEdge runtimeThe same for edge code
src/instrumentation.tsServer startLoads the server or edge config in register() and exports onRequestError
src/app/global-error.tsxThe browserReports errors that reach the root error boundary with Sentry.captureException
next.config.tsBuildwithSentryConfig uploads source maps so stack traces show your original code

onRequestError is set to Sentry.captureRequestError, which captures errors from Server Components, middleware, and proxies, so server errors are reported without wrapping each route.

What's captured

  • Errors from the browser, the server, and edge code, with stack traces.
  • Performance traces, sampled at NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE (a share from 0 to 1; unset means 1 in development and 0.1 in production).
  • Session replay, in the browser only: 10% of normal sessions and 100% of sessions that hit an error (replaysSessionSampleRate and replaysOnErrorSampleRate in src/instrumentation-client.ts).
  • Logs: console.* calls at or above NEXT_PUBLIC_SENTRY_LOG_LEVEL (default warn, so console.warn and console.error) are sent to Sentry through consoleLoggingIntegration.

Turn it on

  1. Create a Next.js project in Sentry and copy its DSN from Settings → Projects → your project → Client Keys.
  2. Set the variables in .env (all are listed in Configuration):
NEXT_PUBLIC_SENTRY_DSN=https://...ingest.sentry.io/...
NEXT_PUBLIC_SENTRY_ENVIRONMENT=development
NEXT_PUBLIC_SENTRY_LOG_LEVEL=warn
  1. For readable stack traces in production, also set SENTRY_ORG, SENTRY_PROJECT, and SENTRY_AUTH_TOKEN where the app is built. withSentryConfig uses them to upload source maps during next build. Keep the auth token secret: it belongs in your CI or hosting settings, not in the repository.
  2. Restart the dev server, then trigger an error, for example by temporarily throwing in a page, and check that it appears in Sentry.

Without NEXT_PUBLIC_SENTRY_DSN, Sentry.init() still runs but sends nothing. That's the default, so a fresh clone reports nothing until you set it.

Before you go to production

  • Check the trace sample rate. When NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE is unset or empty, the kit traces every request in development and 10% (0.1) in production, the starting point Sentry's guide uses. Tracing every request in production can use up your Sentry quota, so only raise it on purpose, and adjust it to your traffic.
  • Set the environment. Use NEXT_PUBLIC_SENTRY_ENVIRONMENT=production (or staging) so issues from each deployment are separated.
  • Set the variables at build time. The NEXT_PUBLIC_SENTRY_* values are built into the browser code, so they must be set when next build runs. In Docker they're build arguments; see Docker.
  • Review replay privacy. Session replay records what users see. Check Sentry's replay privacy settings against what your app displays before enabling it in production, or set both replay rates to 0.

Remove Sentry

If you use another tool, delete sentry.server.config.ts, sentry.edge.config.ts, src/instrumentation-client.ts, and src/instrumentation.ts, remove the Sentry.captureException call from src/app/global-error.tsx, unwrap withSentryConfig in next.config.ts, drop the Sentry variables from src/lib/env.ts and src/lib/env.server.ts, and uninstall @sentry/nextjs.

On this page