Skip to content

fix(observability): make Sentry route errors, releases and environments usable - #76

Merged
Programcode merged 1 commit into
mainfrom
fix/sentry-release-and-route-errors
Sep 28, 2026
Merged

Programcode merged 1 commit into
mainfrom
fix/sentry-release-and-route-errors

Conversation

@Programcode

@Programcode Programcode commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

What was wrong

Checking the live site showed three problems in the Sentry setup:

  1. Every route crash was reported as new Error("Route rendering failed") with the error boundary's own stack. Sentry grouped all crashes into one issue that pointed at the wrong code.
  2. release was unset. Sentry discards sessions without a release, so release health was empty and errors couldn't be tied to a deploy. No source maps were uploaded either, so stack traces were minified.
  3. environment was Vite's MODE, which is production for every Vercel build, including previews.

Changes

  • Route crashes. toTelemetrySafeError in src/lib/observability.ts keeps the original error name, if it looks like *Error, and its code-location stack frames. It still replaces the message. The privacy result is unchanged: the original message is cut from V8 stacks before filtering, and only lines pointing at a URL or absolute path survive. cause is dropped and no component stack is sent. The privacy policy already discloses stack traces to Sentry.
  • Release and environment. vite.config.ts injects the commit SHA and VERCEL_ENV at build time. The SHA comes from VERCEL_GIT_COMMIT_SHA, then GITHUB_SHA, then git rev-parse HEAD. Both Vercel variables are available at build time according to Vercel's system environment variable docs.
  • Source maps. @sentry/vite-plugin runs only when SENTRY_AUTH_TOKEN, SENTRY_ORG and SENTRY_PROJECT are all set. It builds hidden maps, uploads them and deletes them from dist/. Without those variables the build is unchanged and emits no maps.

Needs Adam

Source map upload stays off until these are added to the Vercel project for Production and Preview:

  • SENTRY_AUTH_TOKEN: a Sentry organization token with source map upload scope;
  • SENTRY_ORG and SENTRY_PROJECT: the slugs.

Not changed on purpose

PostHog keeps persistence: "memory" and never calls identify, so each page load is a new anonymous person. That makes retention and unique-user numbers meaningless. The privacy text in all three locales promises that persistent browser storage is disabled. Changing this means choosing between two approaches, and both are privacy and consent decisions:

  • persistent storage, which needs consent;
  • identify with the Supabase user ID, which is a new identifier that would have to be disclosed.

Verification

  • A new test that the route error keeps the ExplodingRoute frame failed before the change and passes after it. There are also unit tests for V8 and Gecko stacks, multi-line messages, frame-shaped message lines, unsafe names and non-Error values.
  • npm run lint, npm run typecheck, npm test -- --coverage (1086 tests) and npm run build pass.
  • A build with a dummy DSN, VERCEL_GIT_COMMIT_SHA and VERCEL_ENV=preview put release:"abc123deadbeef",environment:"preview" into the Sentry.init call, with no .map files.
  • A build with a bogus token exited 0. It logged a 401, deleted the maps and left no sourceMappingURL.
  • Not verified: a real upload, which needs the token.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Error reports now include the deployment environment and build commit when available.
    • Route crash reports preserve useful error types and stack frames while replacing the original message.
    • Production builds upload hidden source maps when the required Sentry settings are configured; uploaded maps are removed from the build output.
  • Documentation

    • Updated guidance on error reporting, build settings, and source-map uploads, including behavior when settings are missing or uploads fail.

Copilot AI lite review requested due to automatic review settings September 28, 2026 17:43
@vercel

vercel Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
debate-navigator Ready Ready Preview Sep 28, 2026 5:54pm UTC

@Programcode

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

Run ID: 1e2e8d63-af8f-44df-ab19-828171a4926d

📥 Commits

Reviewing files that changed from the base of the PR and between f0f2f75 and ba0c9b4.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • docs/architecture.md
  • docs/development.md
  • docs/operations.md
  • package.json
  • src/App.tsx
  • src/lib/observability.ts
  • src/test/app-route-analytics-error-boundary.test.tsx
  • src/test/observability.test.ts
  • src/vite-env.d.ts
  • vite.config.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change sanitizes route errors before Sentry capture. It also configures Sentry release and environment metadata, and conditionally enables source-map generation and upload during Vite builds.

Changes

Sentry observability

Layer / File(s) Summary
Route error sanitization and capture
src/lib/observability.ts, src/App.tsx, src/test/observability.test.ts, src/test/app-route-analytics-error-boundary.test.tsx, docs/architecture.md
toTelemetrySafeError replaces the error message and retains only recognized error names and stack frames. The route error boundary captures the sanitized error. Tests cover sanitized stack output and error handling.
Sentry build configuration and metadata
src/vite-env.d.ts, vite.config.ts, src/lib/observability.ts, package.json, src/test/observability.test.ts, docs/development.md, docs/operations.md
Vite resolves a release from available commit identifiers and configures Sentry release and environment values. When the credentials and release are available, the build enables hidden source maps and Sentry upload. Tests and documentation cover the settings and behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RouteErrorBoundary
  participant toTelemetrySafeError
  participant Sentry
  RouteErrorBoundary->>toTelemetrySafeError: Caught error and route failure message
  toTelemetrySafeError-->>RouteErrorBoundary: Sanitized error and filtered frames
  RouteErrorBoundary->>Sentry: Capture sanitized error
Loading

Architecture Summary

Architecture risk: 🔵 Low · up to ba0c9

The change affects 4 systems.

Changed systems: src, docs, package.json, vite.config.ts

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 5 changed files map to changed impact.
  • observed — docs (service) was modified; 3 changed files map to changed impact.
  • observed — package.json (service) was modified; 1 changed file maps to changed impact.
  • observed — vite.config.ts (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in docs/architecture.md: The Observability description now documents Sentry release and environment metadata, and states that route-crash messages are replaced while error types and stack frames are retained.
  • observed — Modified behavior in docs/development.md: Added documentation that production builds read the Sentry build variables SENTRY_AUTH_TOKEN, SENTRY_ORG, and SENTRY_PROJECT, while local builds leave them unset and skip source map upload; linked to the operations secrets documentation.
  • observed — Modified behavior in docs/operations.md: Adds documentation for the three Sentry build variables, conditional source-map creation and upload, cleanup, non-fatal upload errors, release SHA fallback order, Sentry environment selection, and the requirement to enable Vercel system environment variables.
  • observed — Modified behavior in package.json: Adds @sentry/vite-plugin at version ^5.4.0 to the development dependencies.

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Essentials by visiting https://app.coderabbit.ai/settings/billing.

Comment @coderabbitai help to get the list of available commands.

…ts usable

Route crashes were all reported as one synthetic error with the boundary's
stack, so Sentry grouped every crash into a single issue. They now keep the
original error type and code-location frames while the message, which can
carry user text, is still replaced.

Sentry events now carry the commit SHA as release and VERCEL_ENV as
environment, so release health works and previews stop reporting as
production. Hidden source maps are uploaded and deleted when
SENTRY_AUTH_TOKEN, SENTRY_ORG and SENTRY_PROJECT are set.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 58 minutes.

@Programcode

Copy link
Copy Markdown
Owner Author

Local verification on rebased head ba0c9b4 (GitHub Actions jobs are not starting because of an account billing/spending-limit block): npm ci, lint, typecheck, 1100 unit tests with coverage, docs:check, build, and Playwright desktop+mobile Chromium (226 passed, 6 skipped) all pass.

@Programcode

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@Programcode
Programcode merged commit f98624f into main Sep 28, 2026
5 of 8 checks passed

This branch was successfully deployed

1 active deployment
Preview — ba0c9b44 Deployed Sep 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants