Adds @sentry/nextjs v10 with the Next.js 16 instrumentation pattern:
- instrumentation.ts — server + edge runtime init
- instrumentation-client.ts — browser init with Session Replay
(free tier, mask all text/inputs by
default since chat content is sensitive)
- app/global-error.tsx — catches root-layout crashes that escape
every other error boundary
- app/sentry-example-page — verification page; click both buttons
- next.config.ts — wrapped with withSentryConfig, source
maps upload to Sentry on every build,
client error events tunneled through
/monitoring to bypass ad-blockers
Runtime capture works as soon as NEXT_PUBLIC_SENTRY_DSN is in Coolify
env (already added). Full source-map de-minification of prod stack
traces requires SENTRY_AUTH_TOKEN in Coolify env — pending user.
Co-authored-by: Cursor <cursoragent@cursor.com>
42 lines
1.6 KiB
TypeScript
42 lines
1.6 KiB
TypeScript
/**
|
|
* Next.js server-side instrumentation entry point.
|
|
*
|
|
* Runs once per server runtime (Node.js or Edge). We branch on
|
|
* NEXT_RUNTIME because Sentry exposes different SDK surfaces for
|
|
* each — Node gets the full node SDK, Edge gets a slimmer one.
|
|
*
|
|
* Required hook for Sentry's Next.js integration to capture
|
|
* server-side exceptions and route handler errors. See
|
|
* https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation
|
|
*/
|
|
|
|
import * as Sentry from '@sentry/nextjs';
|
|
|
|
export async function register() {
|
|
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
Sentry.init({
|
|
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
|
|
// Adjust later when traffic ramps; 100% sampling is fine for a
|
|
// pre-launch beta with low volume.
|
|
tracesSampleRate: 1.0,
|
|
// Don't send events when DSN is missing (e.g. local dev without
|
|
// Sentry env). Prevents the SDK from logging warnings to stdout.
|
|
enabled: Boolean(process.env.NEXT_PUBLIC_SENTRY_DSN),
|
|
environment: process.env.SENTRY_ENVIRONMENT || process.env.NODE_ENV,
|
|
});
|
|
}
|
|
|
|
if (process.env.NEXT_RUNTIME === 'edge') {
|
|
Sentry.init({
|
|
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
|
|
tracesSampleRate: 1.0,
|
|
enabled: Boolean(process.env.NEXT_PUBLIC_SENTRY_DSN),
|
|
environment: process.env.SENTRY_ENVIRONMENT || process.env.NODE_ENV,
|
|
});
|
|
}
|
|
}
|
|
|
|
// Required for nested React Server Component errors to reach Sentry.
|
|
// See https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#errors-from-nested-react-server-components
|
|
export const onRequestError = Sentry.captureRequestError;
|