Repository navigation
Description
Summary
Product direction (confirmed):
We should implement error reporting using Sentry.
Today there is zero production error signal (.claude/reports/RELEASE_READINESS.md §9): when the widget breaks on a host page, nobody finds out unless a user emails a screenshot. reportInternalError (src/lib/report.ts:165-171) is the designed single seam for exactly this — its docblock says "This is the single call site for a real error reporter … wiring Sentry or similar means changing this function and nothing else", and documents why it wasn't wired at the time: a new dependency in a public bundle, needs a DSN, and every host page must allow its connect-src. Those costs are now accepted; this ticket pays them deliberately. Today the seam is console-only and called from exactly one place — the fallback-of-the-fallback (src/components/molecules/Fallbacks/Fallbacks.tsx:858, onError={(cause) => reportInternalError(cause, 'FallbackPanel')}) — so ordinary boundary trips produce no telemetry at all.
(Line refs are current on the in-flight feat/classify-errors branch — the readiness report cites Fallbacks.tsx:666 pre-branch. Coordinate with #89 landing; symbols are stable even where lines drift.)
Proposed changes
- Sentry via the seam, and only the seam.
src/lib/report.tsremains the single integration point — noSentry.initelsewhere, no Sentry React boundary wrappers.reportInternalErrorforwards to Sentry when configured; console behaviour stays. - Extend coverage to ordinary boundary trips: call the seam from the ErrorBoundary
onErrorhooks —ResetErrorBoundary(Fallbacks.tsx:877onward, the shared boundary every call site goes through) and the App-level boundary (src/App.tsx:71<ResetErrorBoundary FallbackComponent={ErrorFallback}>; consider the null-fallback boundary atApp.tsx:92too) — so classified failures are captured with theirErrorKind(classifyError,src/lib/report.ts) as a tag:offline | server | not-found | config | contract | unknown. - Lazy-load the SDK — it must NOT join the eager graph. The eager payload is already 477 KiB gz (report §1.1). Dynamic
import()on first error is the suggested pattern; evaluate@sentry/browservs the leaner@sentry/core+ minimal transport. The chosen approach's gz cost must be stated in the implementation report (measure the eager payload — entry + every modulepreload, gz — both ways). - DSN via
VITE_SENTRY_DSN: absent → exactly today's console behaviour, zero bundle and zero network cost. Document in.env/.claude/docs/environment.md. - PII scrubbing consistent with the existing policy:
hostPageUrl()(src/lib/report.ts:213-221, rationale in the docblock above it) deliberately captures origin + path only — neverlocation.href, because a host's query/fragment can carry reset tokens or emails. Sentry events must follow the same posture (nosendDefaultPii, no session replay, host URL trimmed the same way). - Never-throw contract: the seam runs inside error fallbacks — a Sentry failure (rejected dynamic import, transport error, host CSP block) must be swallowed. The existing try/catch pattern extends to the async path; a host page whose CSP blocks the ingest origin must see no new console noise beyond the existing log.
- Docs: add the Sentry ingest origin to the README's integrator CSP table (
connect-src) — additively. Consider a host opt-out attribute (e.g.telemetry="off") and state the decision. - Interplay, not dependency: feat(widget): submit issue reports to the SahajCloud endpoint #80 fixes the user-facing report FORM delivery (the human path); this ticket is the automatic telemetry path. They share the privacy posture, not code paths.
Acceptance criteria
- With
VITE_SENTRY_DSNset, a thrown boundary error arrives in Sentry carrying the classifiedErrorKindas a tag and an origin+path-only host page URL. - Without the DSN, behaviour is identical to today (console only) and no Sentry code ships in any chunk that loads.
- Sentry is reachable ONLY through
src/lib/report.ts— grep shows no other import site. - Sentry loads via dynamic import on first error; the eager payload (entry + modulepreloads, gz, measured both ways) is unchanged; the SDK approach and its gz cost are stated in the implementation report.
- A Sentry failure never escapes the seam — covered by a unit test (transport that rejects / import that fails → no throw).
-
ResetErrorBoundaryand the App-level boundary report through the seam; the existingFallbacks.tsx:858call site keeps working. - README CSP table updated additively with the Sentry ingest
connect-srcorigin. - Host opt-out attribute considered; decision stated in the implementation report.
- Lint + typecheck +
pnpm test:runpass. - Write an implementation report to
.claude/reports/<issue-number>-<short-slug>.md— in the MAIN checkout at /Users/devindra/Documents/Projects/SahajAtlasWeb even when implementing from a worktree (the folder is gitignored) — covering what changed, what was deliberately NOT changed, and which readiness-report findings are resolved.
Files affected
src/lib/report.ts— the seam (and the only Sentry integration point)src/components/molecules/Fallbacks/Fallbacks.tsx—ResetErrorBoundary/ boundaryonErrorwiring only (surgical — siblings own other regions of this file)src/App.tsx— boundary props only (surgical — siblings own other regions).env/.claude/docs/environment.md—VITE_SENTRY_DSNREADME.md— CSP table row (additive)pnpm-lock.yaml(shared)
Parallel implementation: this ticket OWNS the files/regions listed above; sibling release-hardening tickets run concurrently — avoid edits outside owned files except strictly additive ones.
References
.claude/reports/RELEASE_READINESS.md§9 (Monitoring & support), Appendix Dsrc/lib/report.tsdocblock — the designed seam and its original non-goal rationale- feat(widget): classify errors and show only the actions that can help #89 (error classification — supplies the
ErrorKindthis ticket tags with; in flight onfeat/classify-errors) - feat(widget): submit issue reports to the SahajCloud endpoint #80 (report-issue form delivery — the human-report sibling)
- docs(widget): publish an accurate integrator guide #93 (integrator guide — owns the broader CSP documentation; this ticket only adds its row)
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity
feat(widget): wire sentry into the error-reporting seam
docs(widget): document the sentry ingest origin and its opt-out
fix(widget): stop the sentry client reaching out of the widget
chore(build): upload sentry source maps from the pages build (#145)