Sentry

Error tracking and performance monitoring for both frontend and backend. Captures unhandled exceptions, performance traces, and session replays to aid debugging in deployed environments.

Architecture

ComponentPathPurpose
Backend setuptop of backend/src/index.ts@sentry/bun init before any other imports, beforeSend scrubbing
Backend capturebackend/src/middleware/errorHandler.tsSentry.captureException with user context
Frontend setupfrontend/src/main.tsx@sentry/react init, tracing, session replay, error boundary

There is no separate lib/sentry.ts — backend init lives directly at the top of index.ts so it runs before everything else.

Configuration

VariablePurpose
SENTRY_DSN_BACKENDBackend error reporting endpoint
VITE_SENTRY_DSN_FRONTENDFrontend DSN (build-time, public)

Secrets live in Infisical (EU) and sync natively to Fly.io. See Deployment Pipeline.

Environment Awareness

Sentry is enabled in all cloud deploymentsAPP_ENV in development, preview, staging, production (rationale: fail fast, catch errors early). Excluded: local (docker-compose) and test (CI). Events are tagged with:

  • environment: the APP_ENV value
  • release: COMMIT_SHA or FLY_IMAGE_REF from CI/CD

Performance sampling: tracesSampleRate is 0.1 in production, 1.0 everywhere else.

Backend Integration

The error handler middleware (backend/src/middleware/errorHandler.ts) is the last middleware in the Backend Middleware pipeline. It:

  1. Catches all unhandled exceptions from routes and services
  2. Attaches request context (URL, method, user ID) and captures to Sentry (cloud envs with DSN only)
  3. Returns a structured JSON error response to the client

See Error Handling Pattern for the error response format.

Sensitive Data Scrubbing

The backend beforeSend hook (in index.ts) strips sensitive fields before events leave the process — case-insensitive matching on patterns including password, passwordHash, token, accessToken, refreshToken, resetToken, secret, apiKey, privateKey, credential, authorization, plus auth/cookie headers. The frontend beforeSend scrubs sensitive breadcrumb data (form inputs such as passwords).

Frontend Integration

frontend/src/main.tsx (@sentry/react) includes:

FeatureDetail
Error boundarySentry.ErrorBoundary wrapping the app with ErrorFallback
Session replayreplayIntegration with maskAllText, blockAllMedia, maskAllInputs
Performance tracingbrowserTracingIntegration
Breadcrumb scrubbingbeforeSend removes password fields from breadcrumb data