Repository navigation
feat(frontend): report error boundary crashes to Sentry with PII scrubbing and a feedback dialog - #392
Open
Anshuu2004 wants to merge 1 commit into
Conversation
…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>
Owner
|
@Anshuu2004 CI/CD checks are currently failing on This failure occurs because public profiles are now private by default with opt-in publication (from PR #381). Please rebase/merge the latest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wires Sentry into the frontend error boundaries: crashes are reported (when
VITE_SENTRY_DSNis 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.0added tofrontend/package.jsonandpackage-lock.json(lockfile diff is additions only:@sentry/*,@sentry/conventionsandweb-vitals, no existing entry changed).frontend/src/lib/sentry.ts:initSentry()is a no-op withoutVITE_SENTRY_DSN; with it, it callsSentry.initonce withbeforeSend,beforeBreadcrumband an event processor for feedback events (beforeSendnever 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.scrubString,scrubValue,scrubEvent,scrubBreadcrumb): bearer tokens, bare JWTs, email addresses; values under keys likeAuthorization,Cookie,*token,*password,*secret,*apiKey,query_string, and the resume text fields (resumeText,rawText, ...); query string and fragment of url-like values underurl/from/to;user.email,user.ip_address,user.usernameremoved. They copy, never mutate, and cope with cycles and very deep objects.captureBoundaryError()(callsSentry.captureReactException, which attaches the component stack, and returns the event id) andsendCrashFeedback()(scrubs the note,captureFeedbacklinked to the crash event). Both swallow SDK errors so reporting can never break the fallback.components/shared/ErrorBoundary.tsx:componentDidCatchreports the crash (replacing the placeholder comment), keeps the event id in state, fallback now hasrole="alert"and, when reporting is on, a "Report an issue" button that opens the newCrashFeedbackDialog(uses the existingModal, so focus trap and Escape work). Try Again is the existingreset, 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.tsxcallsinitSentry();.env.exampledocumentsVITE_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/reactmocked withvi.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)npx vitest run src/pages/admin/BetaDashboardPage.test.tsx-> 4 passed (existing test that renders through the boundary imports).@sentry/react11.12.0 with a fake transport. The error event had the email, bearer token andresumeTextmasked,userreduced 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.tstype-checks against the real@sentry/react11.12.0 types.Not tested
tsc -b,eslintandvite buildon 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-reactmodule inmain.tsx.App(router.test.tsx,NotFoundPage.test.tsx,AccountGate.test.tsx) could not run here for the same missing@clerkreason; they fail identically without my change.Notes
.env.local.frontend/vercel.jsonhas no CSP yet; when feat(security,m10): implement Content-Security-Policy (CSP) headers for SPA and strict script-src nonce generation #363's follow-up adds one it needshttps://*.sentry.ioinconnect-src.