Skip to content

feat(frontend): report error boundary crashes to Sentry with PII scrubbing and a feedback dialog - #392

Open
Anshuu2004 wants to merge 1 commit into
VarshithReddy2006:mainfrom
Anshuu2004:feat/issue-366-sentry-error-boundary
Open

Anshuu2004 wants to merge 1 commit into
VarshithReddy2006:mainfrom
Anshuu2004:feat/issue-366-sentry-error-boundary

Conversation

@Anshuu2004

Copy link
Copy Markdown
Contributor

Summary

Wires Sentry into the frontend error boundaries: crashes are reported (when VITE_SENTRY_DSN is set) with their component stack, everything that leaves the browser goes through a PII scrubber, and the crash fallback gets a "Report an issue" form next to Try Again.

Closes #366

What changed

  • @sentry/react ^11.12.0 added to frontend/package.json and package-lock.json (lockfile diff is additions only: @sentry/*, @sentry/conventions and web-vitals, no existing entry changed).
  • New frontend/src/lib/sentry.ts:
    • initSentry() is a no-op without VITE_SENTRY_DSN; with it, it calls Sentry.init once with beforeSend, beforeBreadcrumb and an event processor for feedback events (beforeSend never runs for those). Optional data collection is switched off (dataCollection: user info, cookies, headers, request/response bodies, query params, stack-frame variables) so the scrubbers are a second layer, not the only one. Newer Sentry majors collect most of that by default.
    • Pure scrubbers (scrubString, scrubValue, scrubEvent, scrubBreadcrumb): bearer tokens, bare JWTs, email addresses; values under keys like Authorization, Cookie, *token, *password, *secret, *apiKey, query_string, and the resume text fields (resumeText, rawText, ...); query string and fragment of url-like values under url/from/to; user.email, user.ip_address, user.username removed. They copy, never mutate, and cope with cycles and very deep objects.
    • captureBoundaryError() (calls Sentry.captureReactException, which attaches the component stack, and returns the event id) and sendCrashFeedback() (scrubs the note, captureFeedback linked to the crash event). Both swallow SDK errors so reporting can never break the fallback.
  • components/shared/ErrorBoundary.tsx: componentDidCatch reports the crash (replacing the placeholder comment), keeps the event id in state, fallback now has role="alert" and, when reporting is on, a "Report an issue" button that opens the new CrashFeedbackDialog (uses the existing Modal, so focus trap and Escape work). Try Again is the existing reset, which now also clears the event id.
  • components/ui/ErrorBoundary.tsx (the second boundary used by DashboardPage and FocusPage) reports crashes too, one line.
  • main.tsx calls initSentry(); .env.example documents VITE_SENTRY_DSN (empty = off).

Resume text is only recognised by field name (and token/email patterns in strings); free text inside an arbitrary string cannot be detected. The SDK's request bodies and query strings are off, and no code in the app attaches resume text to Sentry, so this covers the realistic paths.

How I tested

From frontend/, one file at a time:

  • npx vitest run src/lib/sentry.test.ts -> 25 passed (scrubbers, init gating, hook wiring, capture/feedback helpers; @sentry/react mocked with vi.mock)
  • npx vitest run src/components/shared/__tests__/ErrorBoundary.test.tsx -> 10 passed (catches and reports with component stack, no report button when Sentry is off, Try Again re-renders children, repeated crash reports again, custom fallback, feedback dialog send/failure/cancel, ui boundary reports)
  • With the boundary changes reverted, 7 of those 10 fail; they pass with the change.
  • npx vitest run src/pages/admin/BetaDashboardPage.test.tsx -> 4 passed (existing test that renders through the boundary imports).
  • Also checked outside the committed tests, in a throwaway jsdom test: the real @sentry/react 11.12.0 with a fake transport. The error event had the email, bearer token and resumeText masked, user reduced to { id }, and the request url without query string; the feedback event came out scrubbed as well (it was not before I added the event processor).
  • sentry.ts type-checks against the real @sentry/react 11.12.0 types.

Not tested

  • tsc -b, eslint and vite build on the whole frontend: the node_modules I had was missing @clerk/* and had older eslint plugins, so those runs fail the same way on main. The only tsc error mentioning files I touched is the missing @clerk/clerk-react module in main.tsx.
  • Existing tests that import the router or App (router.test.tsx, NotFoundPage.test.tsx, AccountGate.test.tsx) could not run here for the same missing @clerk reason; they fail identically without my change.
  • The tests ran on vitest 3.2.4 from that node_modules, not the 4.x in the lockfile.
  • Nothing was sent to a real Sentry project, and I did not click through the dialog in a browser.

Notes

…bbing and a feedback dialog

Sentry only starts when VITE_SENTRY_DSN is set. beforeSend, beforeBreadcrumb
and a feedback event processor mask bearer tokens, JWTs, emails, credential
and resume text keys and URL query strings. The error boundaries report the
crash with its component stack, and the fallback gets a Report an issue form
next to the existing Try Again.

Signed-off-by: Abhishek <abhishekcse2004@gmail.com>
@VarshithReddy2006 VarshithReddy2006 added enhancement New feature or request help wanted Extra attention is needed nsoc26 level2 5 points - UI, frontend components, layouts, styling, and page-level changes. labels Nov 16, 2026
@VarshithReddy2006

Copy link
Copy Markdown
Owner

@Anshuu2004 CI/CD checks are currently failing on Unit Tests:

AssertionError: expected undefined to match object { achievements: [], trust: { underReview: true } }
 ❯ src/__tests__/modules/profile/antiGaming.worker.test.ts:138:18

This failure occurs because public profiles are now private by default with opt-in publication (from PR #381).

Please rebase/merge the latest main into your branch and fix this issue immediately so that CI checks turn green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request help wanted Extra attention is needed level2 5 points - UI, frontend components, layouts, styling, and page-level changes. nsoc26

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(frontend,m10): implement Sentry error boundary with client breadcrumb PII redaction and feedback dialog

2 participants