Skip to content

feat(widget): wire sentry into the error-reporting seam #108

Closed

Description

@Ardnived

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.ts remains the single integration point — no Sentry.init elsewhere, no Sentry React boundary wrappers. reportInternalError forwards to Sentry when configured; console behaviour stays.
  • Extend coverage to ordinary boundary trips: call the seam from the ErrorBoundary onError hooks — ResetErrorBoundary (Fallbacks.tsx:877 onward, 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 at App.tsx:92 too) — so classified failures are captured with their ErrorKind (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/browser vs 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 — never location.href, because a host's query/fragment can carry reset tokens or emails. Sentry events must follow the same posture (no sendDefaultPii, 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_DSN set, a thrown boundary error arrives in Sentry carrying the classified ErrorKind as 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).
  • ResetErrorBoundary and the App-level boundary report through the seam; the existing Fallbacks.tsx:858 call site keeps working.
  • README CSP table updated additively with the Sentry ingest connect-src origin.
  • Host opt-out attribute considered; decision stated in the implementation report.
  • Lint + typecheck + pnpm test:run pass.
  • 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 / boundary onError wiring 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_DSN
  • README.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

Activity

  1. added 3 commits that reference this issue on Aug 8, 2026
    23509b8
    815afbc
    4d23099
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions