feat: report browser and server errors to GlitchTip #30

Merged
ronnyandre merged 1 commit from feat/glitchtip into main 2026-11-17 12:04:34 +01:00
Owner

Adds GlitchTip (Sentry-protocol) error reporting for both the browser and the server. It does nothing unless GLITCHTIP_DSN is set. The variable is read at runtime, so it can be set in Dokploy without a rebuild.

What's included

  • Server: a request middleware and a global function middleware in src/start.ts capture errors from server functions and API routes, then re-throw them unchanged. Server-function errors are tagged with the function name and file. @sentry/node is imported dynamically inside .server() bodies, so it stays out of the client bundle (checked in .output/public).
  • Browser: @sentry/browser loads after hydration through named re-exports in src/lib/_sentry-browser.ts, so it's a 29 KB gzipped chunk rather than 147 KB with the whole namespace. RouteErrorPage reports errors caught by the router's error boundary.
  • Tunnel: /api/glitchtip/envelope forwards only envelopes addressed to our own project, with a 512 KB cap, so it can't be used as an open relay. Because of the tunnel, the CSP doesn't change (connect-src 'self').
  • Noise and privacy: isExpectedError filters out redirects, not-found, Unauthorized/Forbidden and Cannot delete:. Only the user id is sent: no email, cookies, request headers or bodies.
  • Docs: pattern #13 added to CLAUDE.md, and the new env vars added to README.md.

Testing

  • pnpm typecheck, pnpm lint and pnpm build pass. pnpm test passes (253 tests, 27 of them new in src/lib/glitchtip.test.ts). One full run had a single failure I couldn't identify, and it hasn't come back in three reruns.
  • Production build against a fake GlitchTip receiver:
    • The tunnel forwarded an envelope for our project (200) and refused one with a foreign DSN (403).
    • The DSN reaches the browser in the SSR payload.
    • A server error arrived with its tags and no cookies, and an Unauthorized error was filtered out.
  • Not checked in a real browser. After deploying, run setTimeout(() => { throw new Error('glitchtip test') }) in the DevTools console and confirm the event shows up in GlitchTip.

Deploy

Set GLITCHTIP_DSN in Dokploy. GLITCHTIP_ENVIRONMENT and GLITCHTIP_RELEASE are optional.

Follow-ups

  • Upload source maps, so browser stack traces aren't minified.
  • An error from a server function that also reaches the router's error page is reported twice.

🤖 Generated with Claude Code

Adds GlitchTip (Sentry-protocol) error reporting for both the browser and the server. It does nothing unless `GLITCHTIP_DSN` is set. The variable is read at runtime, so it can be set in Dokploy without a rebuild. ## What's included - **Server:** a request middleware and a global function middleware in `src/start.ts` capture errors from server functions and API routes, then re-throw them unchanged. Server-function errors are tagged with the function name and file. `@sentry/node` is imported dynamically inside `.server()` bodies, so it stays out of the client bundle (checked in `.output/public`). - **Browser:** `@sentry/browser` loads after hydration through named re-exports in `src/lib/_sentry-browser.ts`, so it's a 29 KB gzipped chunk rather than 147 KB with the whole namespace. `RouteErrorPage` reports errors caught by the router's error boundary. - **Tunnel:** `/api/glitchtip/envelope` forwards only envelopes addressed to our own project, with a 512 KB cap, so it can't be used as an open relay. Because of the tunnel, the CSP doesn't change (`connect-src 'self'`). - **Noise and privacy:** `isExpectedError` filters out redirects, not-found, `Unauthorized`/`Forbidden` and `Cannot delete:`. Only the user id is sent: no email, cookies, request headers or bodies. - **Docs:** pattern #13 added to `CLAUDE.md`, and the new env vars added to `README.md`. ## Testing - `pnpm typecheck`, `pnpm lint` and `pnpm build` pass. `pnpm test` passes (253 tests, 27 of them new in `src/lib/glitchtip.test.ts`). One full run had a single failure I couldn't identify, and it hasn't come back in three reruns. - Production build against a fake GlitchTip receiver: - The tunnel forwarded an envelope for our project (200) and refused one with a foreign DSN (403). - The DSN reaches the browser in the SSR payload. - A server error arrived with its tags and no cookies, and an `Unauthorized` error was filtered out. - Not checked in a real browser. After deploying, run `setTimeout(() => { throw new Error('glitchtip test') })` in the DevTools console and confirm the event shows up in GlitchTip. ## Deploy Set `GLITCHTIP_DSN` in Dokploy. `GLITCHTIP_ENVIRONMENT` and `GLITCHTIP_RELEASE` are optional. ## Follow-ups - Upload source maps, so browser stack traces aren't minified. - An error from a server function that also reaches the router's error page is reported twice. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sentry-protocol error reporting, a no-op unless GLITCHTIP_DSN is set.

- Server: request + global function middleware in start.ts capture and
  re-throw; @sentry/node is imported dynamically inside .server() bodies so
  it never reaches the client bundle.
- Browser: @sentry/browser lazy-loaded after hydration via named
  re-exports (~29 KB gz), plus RouteErrorPage reporting.
- Same-origin tunnel /api/glitchtip/envelope forwards only envelopes for
  our own DSN, so the CSP stays connect-src 'self'.
- Expected outcomes (redirects, not-found, auth, "Cannot delete:") are
  filtered; only the user id is sent, no email/cookies/headers/bodies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ronnyandre/fliary!30
No description provided.