Skip to content

chore(build): upload sentry source maps from the pages build #130

Closed

Description

@Ardnived

Summary

#108 wired Sentry into reportInternalError (src/lib/report.ts), so production failures now produce telemetry. They produce far less actionable telemetry than the issue list makes it look: vite.config.ts sets no build.sourcemap, so Vite's default (false) applies and the build emits no maps at all — every production stack frame points into a minified, content-hashed chunk. Triage today rests on the free-form message plus two tags (atlas.kind, atlas.context). This ticket closes that gap. It splits cleanly into two halves that must not be conflated: what the repo can do (generate maps, upload them at build time, guarantee they are never deployed) and what is a Cloudflare Pages dashboard action (the auth token and org/project variables), because this repo controls no Pages build configuration — build command and output directory live in the dashboard, and the only repo-level deploy files are public/_redirects and public/_headers.

Proposed changes

Repo-side

  • Emit source maps, and do not advertise them. Add build.sourcemap to vite.config.ts. Prefer 'hidden': maps are written, but no //# sourceMappingURL= comment is appended to the shipped JS, so nothing points a stranger's devtools at them even in the window before they are removed.
  • Upload at build time, then delete — do not deploy the maps. This is the explicit decision the ticket asks for and the answer is upload-then-delete. The widget is a public bundle embedded in third-party pages; public/_headers serves /assets/* with Access-Control-Allow-Origin: * and a one-year immutable cache, so a .map that reaches dist/ is a permanently cached, CORS-open copy of our unminified source on somebody else's page load. @sentry/vite-plugin supports exactly this (sourcemaps.filesToDeleteAfterUpload); a post-build script is the alternative if the plugin is declined.
  • The plugin must be inert without credentials. pnpm dev, pnpm build locally, CI's build job, pnpm ladle:build and forked PRs all run without a token and must behave exactly as today — no upload attempt, no warning-as-error, no build failure. Gate the plugin on the token's presence.
  • Guard the deletion with an assertion, not an intention. pnpm build already ends in pnpm assert:css (scripts/assert-css-scoped.mjs) — the precedent for a build-output invariant. Add the equivalent: fail the build if any .map survives in dist/. Without it, a plugin-option rename in a future major silently starts publishing source.
  • Decide the release/artifact identity explicitly, and write down why. src/lib/report.ts:325 sets release: undefined deliberately — the SDK's default reads window.SENTRY_RELEASE?.id, a global belonging to the host page, which would stamp our events with a stranger's deploy version. Debug IDs injected by the bundler plugin into both the chunk and its map resolve frames without any release at all, which keeps that hazard closed; if a release string is wanted anyway (for regression tracking), it must be an explicit build-time value, never the inherited default. environment is already import.meta.env.MODE (report.ts:305).
  • Keep the token out of the bundle, and prove it. SENTRY_AUTH_TOKEN must not carry a VITE_ prefix — only VITE_-prefixed vars reach the bundle — and the built output must be grepped to confirm the value appears nowhere in dist/.
  • Re-measure the size budget. Debug-ID injection adds a small per-chunk payload and sourcemap changes the emitted JS. pnpm size gates both graphs against BUDGET_KIB in scripts/check-bundle-size.mjs; feat(widget): wire sentry into the error-reporting seam #108 left ~13.9 KiB (standalone) / ~12.3 KiB (embed) of headroom. Report the before/after and do not raise the budget silently. Note the gate walks the JS import graph only, so .map files never enter it — the size check is not a substitute for the deletion assertion.
  • Document it. .claude/docs/environment.md and README.md — the new build-time variables, that they are build-time only, and the dashboard steps below.

Dashboard actions (cannot be done from this repo — list them in the report as a runbook)

  • Provision the Sentry project and an auth token scoped to release/source-map upload only.
  • Add SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT to the sahajatlas Cloudflare Pages project's environment variables (production, and preview if preview builds should also upload — state the choice). The sahajatlas-design Ladle project does not need them; say so explicitly rather than leaving it open.
  • VITE_SENTRY_DSN is a precondition for end-to-end verification. It is deliberately absent from .env (see the comment at .env:6-12) and set per-environment in the dashboard. If no DSN is provisioned yet, source-map upload can still be implemented and verified locally against the built output, but the "frames resolve in Sentry" criterion cannot pass — say which state the PR shipped in rather than implying the loop is closed.
  • The two operational settings feat(widget): wire sentry into the error-reporting seam #108 flagged and this ticket does not change: enable "Prevent Storing of IP Addresses", and set a short retention.

Acceptance criteria

  • A production build with credentials present uploads maps and leaves zero .map files in dist/ — asserted by a build step that fails otherwise, not by inspection.
  • A production build without credentials succeeds and is byte-comparable to today's apart from the sourcemap-related emit; nothing is uploaded and no error or warning is raised. Verified for local pnpm build, the CI build job, and pnpm ladle:build.
  • SENTRY_AUTH_TOKEN is not VITE_-prefixed and its value appears nowhere in dist/ (grep the built output and state the command used).
  • pnpm size reported before and after for both graphs; BUDGET_KIB unchanged, or the new value and its justification stated in the report.
  • The release/debug-id decision is implemented and explained, and release: undefined in src/lib/report.ts either stays with its reasoning intact or is replaced by an explicit build-time value that cannot fall back to the host's global.
  • Given a provisioned DSN, a real error thrown on the deployed preview resolves to original file and line in Sentry. If no DSN exists yet, the report states this is deferred and gives the exact steps to verify once one does.
  • The dashboard runbook (variables, which project, which environments) is written into .claude/docs/environment.md and the implementation report.
  • pnpm lint && pnpm typecheck && pnpm test:run && pnpm build pass; CI green including the Dependency Audit gate for any new dev dependency.
  • 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 exactly which steps remain manual.

Files affected

  • vite.config.ts — build.sourcemap and the upload plugin
  • package.json / pnpm-lock.yaml — the build-time plugin as a dev dependency; possibly a new scripts entry
  • scripts/assert-no-sourcemaps.mjs (new, or folded into an existing post-build assertion)
  • .claude/docs/environment.md, README.md, .env (comment only, alongside the existing VITE_SENTRY_DSN note)
  • src/lib/report.ts — only if a release identifier is adopted; leave the rest of the file alone

Parallel implementation: this ticket OWNS the files listed above. Sibling tickets may run concurrently — avoid edits outside owned files except strictly additive ones. src/lib/report.ts in particular is a shared surface; touch only the release option if the decision requires it.

References

  • feat(widget): wire sentry into the error-reporting seam #108 (feat(widget): wire sentry into the error-reporting seam) / PR feat(widget): wire sentry into the error-reporting seam #123 — .claude/reports/108-sentry-reporting.md, "Deliberately NOT changed": "No source-map upload… Without it, production stack frames point into minified chunks… Highest-value follow-up."
  • .claude/reports/RELEASE_READINESS.md §9 (Monitoring & support, grade D)
  • src/lib/report.ts:305, :318-326 — environment, and why release is pinned to undefined
  • public/_headers — /assets/* CORS * + one-year immutable cache, the reason a shipped .map is not recoverable
  • scripts/check-bundle-size.mjs (BUDGET_KIB) and scripts/assert-css-scoped.mjs (the build-invariant precedent)
  • chore(build): version the embed bundle and add a changelog #94 (chore(build): version the embed bundle and add a changelog) — where a real release identifier would come from, if one is wanted
  • CLAUDE.md → Deployment — Pages build config lives in the dashboard, not the repo

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