Files
vibn-frontend/instrumentation-client.ts
Mark Henderson 9eab86f8c2 feat(observability): wire Sentry for runtime error capture
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>
2026-05-01 11:24:10 -07:00

36 lines
1.2 KiB
TypeScript

/**
* Next.js client-side instrumentation. Runs in the browser bundle
* before the app renders. Captures unhandled exceptions, promise
* rejections, and router navigation errors. Also enables Sentry
* Session Replay (free tier) so we can rewatch what the user was
* doing when an error fired — invaluable for solo-dev beta debugging.
*/
import * as Sentry from '@sentry/nextjs';
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
enabled: Boolean(process.env.NEXT_PUBLIC_SENTRY_DSN),
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT || process.env.NODE_ENV,
tracesSampleRate: 1.0,
// Session Replay: record a video-like reconstruction of the user's
// tab on every error, plus 10% of healthy sessions for context.
// Free tier covers this comfortably.
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
integrations: [
Sentry.replayIntegration({
// Mask all text/inputs by default — beta users may type
// anything into chat. Selectively unmask later if needed.
maskAllText: true,
blockAllMedia: true,
}),
],
});
// Required for client-side router transition errors to reach Sentry.
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;