Repository navigation
chore(build): upload sentry source maps from the pages build - #145
Merged
Merged
Conversation
`vite.config.ts` set no `build.sourcemap`, so the default (`false`) applied and the build emitted no maps at all — every production frame from #108's telemetry pointed into a minified chunk. This is not "maps that weren't uploaded". Maps are now emitted as `'hidden'` (written, but no `sourceMappingURL` comment advertises them), uploaded by `@sentry/vite-plugin`, and deleted before the output is deployed. They must never reach `dist/`: `public/_headers` serves `/assets/*` CORS-open with a one-year immutable cache, so a shipped `.map` is an irrevocable publication of this repo's source from a host page we don't own. Both halves are gated on `SENTRY_AUTH_TOKEN`, the plugin AND `build.sourcemap`, so a build that cannot upload does not write maps at all. Local builds, CI, forks and `pnpm ladle:build` (which uses its own vite config) are byte-identical to before — measured: 370.0/371.8 KiB on both graphs, unchanged. `pnpm assert:maps` is the guarantee rather than the intention, per the `assert:css` precedent. It fails on a surviving `.map` AND on any `sourceMappingURL`, because `sourcemap: 'inline'` would embed every original source in the shipped JS while emitting no `.map` file for the first check to find. Verified against a real dist: it catches all 24 maps and exits 1. Two plugin defaults are overridden because they reach out of the widget. `release.inject` would write `window.SENTRY_RELEASE` onto the HOST page — the exact hazard #108 refused in the other direction — and `telemetry` posts build data from inside the deploy's critical path. `create`/`finalize`/`setCommits` are all off too: `create: false` alone still ran `sentry-cli releases finalize`, which needs scope we don't want to grant and whose failure would be reported as a failed map upload. An upload failure is loud but non-fatal. This widget deploys evergreen, and a bug fix should not be blocked by a telemetry outage — availability may degrade the diagnostics, never the safety, which is why `assert:maps` still fails the build if the maps are the thing left behind. Refs #130 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Symbolication needs a release OR a debug ID to match a frame to a map. `release` stays `undefined` — #108 pinned it because the SDK's default reads the HOST page's `window.SENTRY_RELEASE`, and #143 settled that this repo's version is "a marker, not a contract" for an evergreen deploy, so it is the wrong identity anyway. Debug IDs are per-build and need no release, which keeps that hazard shut; `vite.config.ts` blocks the plugin from injecting the global in reverse. That makes `debug_meta` load-bearing, and it sits one deletion away from gone. `prepareEvent` fills it from the injected debug IDs BEFORE `beforeSend` runs (verified in @sentry/core 10.69.0: `applyDebugIds` then `applyDebugMeta`, then `processBeforeSend`), and our hook survives only because it is a delete-list — the docblock beside it says "allowlist", and making that literally true would un-symbolicate every frame with the upload, the deletion gate and every other check still green. So it is a spec, not a comment. Mutation-tested: adding `delete event.debug_meta` turns it red. Refs #130 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The repo half and the dashboard half are documented separately on purpose, so merging this cannot be mistaken for completing it — the same care #143 took with its own unchecked list. Until the three variables are set on the `sahajatlas` Pages project, the build behaves exactly as it did before. environment.md gains the three build-time variables and the runbook: which Pages project (not `sahajatlas-design`, which builds through .ladle/vite.config.ts and cannot run the plugin — verified, not assumed), which environments, why all three or none, and the one criterion the repo cannot check for itself. CLAUDE.md records why the `_headers` rule it already documents is what makes a shipped map irrecoverable, and the size gate's new blind spot: the plugin only runs on a credentialed build, so CI measures ~2.1 KiB less than production ships. Refs #130 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deploying sahajatlas-design with
|
| Latest commit: |
93cb2e8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f0320e27.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://chore-sentry-sourcemaps.sahajatlas-design.pages.dev |
Deploying sahajatlas with
|
| Latest commit: |
93cb2e8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3c26928c.sahajatlas.pages.dev |
| Branch Preview URL: | https://chore-sentry-sourcemaps.sahajatlas.pages.dev |
H2, plus the vite.config comments review found asserting things the code does
not do.
**H2.** `vite.config.ts` is evaluated for EVERY Vite command, not just builds, so
the half-config throw fired on `vite dev` and `vite preview` too — both died with
"failed to load config". A contributor with an ambient SENTRY_AUTH_TOKEN from any
other Sentry-instrumented project could not start the dev server, and the error
talked about uploading source maps on a command that uploads nothing. The
justification for that throw — a deploy going green with every frame minified —
exists only for `command === 'build'`, so the config is now a function of
`{ command }`. Verified three ways: dev starts, preview starts, and a build with
a token but no org still fails loudly.
**M1.** The `errorHandler` comment named the wrong hazard and understated what
passing the handler disarms. `handleRecoverableError` only rethrows in the branch
where no handler was supplied, so supplying one also downgrades a failed
`deleteArtifacts()` — called with `throwByDefault: true` — from "fail the build"
to "log and exit 0, maps still on disk". THAT is the one path by which a map
could reach dist, and the real reason `assert:maps` exists. The converse is now
stated too: the gate cannot backstop a failed UPLOAD, because deletion runs in
`writeBundle`'s `finally` regardless.
**M2.** The docblock refused `release.inject` on the grounds that it writes a
host-page global while silently accepting two of our own. Debug-ID injection
writes `window._sentryDebugIds` and `_sentryDebugIdIdentifier` at module
evaluation. Recorded, with why they are accepted where SENTRY_RELEASE is not:
there is no option keeping debug-ID upload without injection, the map is additive
and stack-keyed so it cannot displace a host's entries, and nothing reads the
identifier at runtime.
**L1.** "Last:" described the array position, not the behaviour — the plugin
returns `enforce: 'pre'`, so Vite hoists it ahead of everything above regardless.
What makes it safe is the phase: it reads off disk in `writeBundle`.
**L2.** `/assets/*` is not the whole story — `embed.js.map` sits at the dist root,
outside that CORS+immutable rule. Still a disclosure, just a recallable one.
**L3.** Notes that the absolute delete glob is exposed to glob metacharacters in
the checkout path, and that `assert:maps` is the mitigation rather than escaping.
Refs #130
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
H1 said the gate's docblock claimed "CI and both Cloudflare Pages builds gate on it" when `sahajatlas-design` builds `pnpm ladle:build`, which never runs `pnpm build`. The security review independently reached the same file from the other direction: the gate is `dist`-only while `public/_headers` is copied into BOTH outputs, so a map in `build/` would be served under the same CORS-open, year-immutable rule. So the claim is made TRUE rather than deleted. The output directory is now an argument and `ladle:build` passes `../build` — 146 files scanned there. Latent today (Ladle builds through `.ladle/vite.config.ts`, which loads neither our `build.sourcemap` nor the plugin), but Ladle stories import the app's real `src/` tree, so anyone adding `sourcemap: true` to debug a story would have shipped it with no gate anywhere in the pipeline. Also from the security review: `assert:maps` now greps every emitted file for the value of SENTRY_AUTH_TOKEN when one is set. Vite cannot inline a variable without a `VITE_` prefix so this should be unreachable, but "should be" is what this file exists to replace, and it makes environment.md's claim that the output is grepped a gate rather than a habit. Costs nothing uncredentialed; an empty-string token (a declared-but-blank Cloudflare variable) is specced not to match every file. L4: the sourceMappingURL failure text said `build.sourcemap` must change, which is the wrong instruction when the cause is a dependency embedding the literal string — ordinary content in stack-trace libraries. It now names both causes and says to exempt the file by name rather than weaken the check. Refs #130 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
M3. The `beforeSend` docblock opened "An allowlist, not a blocklist — the event is rebuilt from what we know we put on it" four lines above `delete event.user / extra / contexts / breadcrumbs`. My previous commit annotated the discrepancy and left it standing, which is not a fix: a false claim that has been noticed is still the claim a future reader acts on. It also matters more than usual here, because that delete-list IS the only reason `debug_meta` survives to symbolicate anything. Rewritten to say what the code does, name a true allowlist as the stronger form still worth having, and say why it is not attempted here — enumerating the fields an event legitimately needs is a change to the seam deserving its own ticket, not a drive-by on a build-plumbing PR. Whoever does it is told to carry `debug_meta` across. The spec is strengthened the way review asked, as far as the SDK allows. Driving the real `applyDebugIds`/`applyDebugMeta` is not possible without a deep import into `build/esm/utils/` — `@sentry/core`'s exports map offers only `.`, `./server` and `./browser` — which is the library-internals coupling the tests rule forbids. So the fixture is typed as `NonNullable<Event['debug_meta']>` instead: a delete- list returns any key you hand it, so an invented fixture would pass even for a misspelled field, and binding it to the SDK's own type means a rename fails typecheck. Refs #130 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…oken file Two findings that both amount to "the dangerous path is the untested one". **L5.** Every CI step runs the UNcredentialed path, because CI has no token — so the first machine ever to execute map emission, deletion and the gate together was Cloudflare, on a production deploy. The new step builds with a dummy token against a closed port: the upload fails immediately and nothing leaves the runner, while everything around it is asserted — maps are emitted under a token, `errorHandler` keeps the failure non-fatal, deletion still runs in `writeBundle`'s `finally`, and `assert:maps` proves dist is clean. The token is a literal rather than a secret so this keeps working on forked PRs. **Security review, medium.** `.env.sentry-build-plugin` is where Sentry's own wizard and docs write SENTRY_AUTH_TOKEN, and `@sentry/vite-plugin` reads it at build time and Object.assign's it over `process.env`. It does not match `*.local`, so the default filename for a real secret was tracked in a public repo. The security-scan hook carries a SENTRY_AUTH_TOKEN pattern but only fires on agent-run git commands, not a human's terminal. Running that dry run locally also confirmed the runbook correction in the next commit: the upload really is `sourcemaps upload -p <project> --release <sha>`, release-scoped, even with all four release actions off. Refs #130 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
**Security review, medium — the runbook was wrong in a way that fails silently.** It said the token "does not need release-write scope" because the plugin sets `create`/`finalize`/`setCommits` to false. Those switch off the extra release CALLS, but the upload command itself is still release-scoped — observed in a real build log as `sourcemaps upload -p <project> --release <sha>`, because the plugin infers a release name from git regardless. An under-scoped token 403s, `errorHandler` logs it, the deploy goes green and production ships minified forever: the exact state #130 exists to end, reached through its own runbook. Now names `project:releases` + `org:read`, says to confirm against Sentry's docs, and says to read the first credentialed build log rather than assume. **M2, second half.** The ~2.1 KiB under-measurement was reported but its consequence was not: CLAUDE.md treats the size budget as a ratchet to lower whenever the payload shrinks, and lowering `BUDGET_KIB` to within 2.1 KiB of the CI number would make the PRODUCTION build fail a gate CI cannot reproduce. Stated as a constraint on that ratchet. CLAUDE.md also gains the corrected errorHandler story (deletion, not upload, is the path the gate closes) and the new offline dry-run step. Refs #130 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Ardnived
added a commit
that referenced
this pull request
Aug 11, 2026
Two conflicts, both from #146 editing the very sections this branch moved. README.md — #146 enriched the inline sizing section with #107's container-responsive behaviour; this branch had replaced that block with a pointer to docs/embedding.md. Kept the pointer, and ported #146's new facts INTO the guide's own "Sizing the element" section rather than dropping them: map-less now adapts to the element rather than the viewport, touch affordances deliberately follow the device instead, and map mode warns in the console when it is given a slot it cannot use. demo.html — #146 added the full-page-slot warning to the same comment where this branch replaced the dead API key with a placeholder. Kept both: the warning reads first, then the key instruction. The 1cf076ab literal stays gone; SahajCloud answers 403 to it, so restoring it would put the harness back to looking broken for a reason unrelated to the code under test. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.
Closes #130
#108 wired Sentry, so crashes arrive — but every production frame pointed into a minified chunk. The ticket's own verification found the cause:
vite.config.tsset nobuild.sourcemapat all, so Vite's default applied and the build emitted no maps whatsoever. This is not "maps that weren't uploaded".What changed
Maps are now emitted as
'hidden', uploaded by@sentry/vite-plugin, and deleted before the output is deployed. They must never ship:public/_headersserves/assets/*withAccess-Control-Allow-Origin: *andmax-age=31536000, immutable, so a shipped.mapis a CORS-open, year-cached copy of this repo's source, content-hashed and therefore unrecallable. (embed.js.mapis the one exception — dist root, outside that rule — which changes how long the mistake lasts, not whether it is one.)Both the plugin and
build.sourcemapare gated onSENTRY_AUTH_TOKEN, so a build that cannot upload does not write maps at all.pnpm assert:mapsis the guarantee rather than the intention, followingassert:css. It fails on a surviving.map, on anysourceMappingURL(the check that matters most —sourcemap: 'inline'embeds every source in the JS and emits no.mapfile), and on the auth token's value appearing anywhere in the output. It runs on both deploy targets.The release / debug-ID tension #108 flagged
release: undefinedstays. #108 pinned it because the SDK's default reads the host page'swindow.SENTRY_RELEASE; symbolication uses debug IDs, which need no release; and #143 settled that this repo deploys evergreen with a version that is "a marker, not a contract", so many builds share0.9.0while each has its own debug IDs.Verified against the installed plugin rather than recalled:
release.injectdefaults totrueand would writewindow.SENTRY_RELEASEonto the host page — #108's hazard in reverse — andcreate: falsealone still ransentry-cli releases finalize <sha>, whose failure would have been reported as "source-map upload failed". All four release actions are now off.Review round — both passes landed after the first push; 2 High, 3 Medium, 5 Low + 3 security Mediums, all fixed
Neither review found a way for a map to actually ship, and both confirmed the core claim under test. What they found was worse in a quieter way: guards that were wrong about their own scope.
throwran at config evaluation, so it fired for every Vite command.vite devandvite previewboth died with "failed to load config" — a contributor with an ambientSENTRY_AUTH_TOKENfrom another project could not start the dev server.{ command }; the throw is build-only. Verified dev starts, preview starts, half-configured build still fails loudly.sahajatlas-designbuildspnpm ladle:build, which never runspnpm build— and it contradicted this branch's own runbook.ladle:buildpasses../build(146 files scanned). Latent today, but Ladle imports the realsrc/tree.errorHandlercomment named the wrong hazard.handleRecoverableErrornever rethrows when a handler is set, so passing one also downgrades a failed deletion to "log and exit 0, maps on disk" — the one path a map could ship, and the real justification forassert:maps. Conversely the gate can not backstop a failed upload, since deletion runs infinallyregardless.release.injectfor writing a host global while silently accepting two of our own (_sentryDebugIds,_sentryDebugIdIdentifier). Plus: the 2.1 KiB under-measurement was reported without its ratchet hazard.BUDGET_KIBto within 2.1 KiB of the CI number makes production fail a gate CI cannot reproduce.beforeSenddocblock still opened "An allowlist, not a blocklist" above fourdeletecalls. My first pass annotated the discrepancy and left it — a noticed false claim is still the one a reader acts on, and that delete-list is the only reasondebug_metasurvives.Event['debug_meta']so a rename fails typecheck (the real functions aren't public API —@sentry/coreexports only././server/./browser)..env.sentry-build-plugin— which the plugin reads andObject.assigns overprocess.env, and where Sentry's wizard writes the token — did not match*.local..gitignore.sourcemaps upload -p <project> --release <sha>even with all four release actions off. An under-scoped token 403s → swallowed → green deploy, minified forever.project:releases+org:readand says to read the first credentialed build log. Confirmed in a real build log.enforce: 'pre');/assets/*doesn't coverembed.js.map; the absolute delete-glob is exposed to glob metacharacters in the checkout path; thesourceMappingURLfailure text gave the wrong instruction for a dependency embedding the literal.assert:mapsturns red.Verification
Build plumbing, so verified by building and inspecting output. End-to-end symbolication is NOT verified — that needs a real DSN and token.
lint/typecheck/test:runbuild+size, no tokenBUDGET_KIBunchanged at 395dist/cleanladle:buildwith all three setdev/previewwith ambient tokenaudit:checkThe gate is not vacuous — against a
dist/left holding maps it named all 24 and exited 1.sourcemap: 'hidden'costs zero; the whole +2.1 KiB is debug-ID injection, on credentialed builds only. Token containment: absent fromdist/, as are the org/project slugs — and now enforced by the gate rather than by a one-off grep.Not done here — merging this does NOT complete the ticket
Dashboard actions only; until they're done the build behaves exactly as before. Runbook in
.claude/docs/environment.md.VITE_SENTRY_DSN— the precondition; maps with no events are inert. Not currently set.project:releases+org:read(see sec-M3 above — the "no release scope" shortcut is wrong).SENTRY_AUTH_TOKEN,SENTRY_ORG,SENTRY_PROJECTtosahajatlas— production certainly, preview recommended. All three or none.sahajatlas-design.Implementation report:
.claude/reports/130-sentry-sourcemaps.md.