Skip to content

feat(sourcemap): Add wasm sourcemap support for inject and upload - #1629

Open
sentry-junior[bot] wants to merge 6 commits into
port/cli-1572-wasm-uploadfrom
port/cli-1588-wasm-sourcemaps
Open

sentry-junior[bot] wants to merge 6 commits into
port/cli-1572-wasm-uploadfrom
port/cli-1588-wasm-sourcemaps

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Ported from getsentry/cli#1588 by @d2anamaria, which is being closed as part of the getsentry/cli archive. This PR is stacked on #1628 (the port of cli#1572) and should merge after it; retarget it to main once #1628 lands.

Problem

sentry sourcemap inject and sentry sourcemap upload only look for .js, .cjs, and .mjs files. When Emscripten builds with -gsource-map, it writes an app.wasm.map file, and these commands never upload it. Even when the map gets to Sentry some other way, nothing links it to its module. Events identify a wasm module by its build_id custom section, but uploaded sourcemaps are matched by the debug_id inside the map JSON.

Solution

Both commands now handle <stem>.wasm + <stem>.wasm.map pairs next to JavaScript pairs.

  • The module's build_id decides the id. The CLI formats it as a dashed UUID and writes it into the map as debug_id / debugId.
  • A module with no build_id gets a random one first.
  • The module itself is never read as text.
  • Running the commands again changes nothing. If a map already has a different id, the module's id replaces it.
  • upload sends the module as minified_source and the map as source_map, both under the same id. --url-prefix, --strip-prefix, --strip-common-prefix, --release, and --dist all work for these pairs.
  • *.debug.wasm companions are skipped, because debug-files wasm-upload uploads them.
  • A directory without wasm behaves exactly as before.

Build-id stamping moves to lib/wasm/stamp.ts, so wasm-upload and the sourcemap path follow the same rule.

Relation to #2502

#2502 uploads the same <module>.wasm.map through debug-files upload as a wasmsourcemap debug file. Both ship: this PR serves the artifact-bundle path, #2502 the debug-file path that Symbolicator will read. They key the map the same way: the CLI's build_id decoding here gives the same debug ID that @sentry/symbolic 14.0.0-alpha.5 (used by debug-files upload) reports, and the debugId this PR writes into the map is the id getsentry/sentry#132523 stores the map under. Running sourcemap inject first also gives a module without a build_id the id that #2502 needs to pair its map.

Port notes

  • Conflicts were resolved against toolkit's newer runtime-registration and inline-sourcemap handling. The help text keeps toolkit's wording, and --strip-common-prefix still handles inline maps.
  • setSourcemapDebugId calls toolkit's mutateSourcemap without snippetLine, so mappings are not shifted. In the original PR this was the offsetMappings: false option.
  • Bot findings on cli#1588, now fixed:
    • With --dry-run, wasm pairs showed as unchanged even when the command would stamp them. mapWritten and moduleStamped now report what a real run would do, as injected does for JS.
    • The zero-pairs diagnostic counted files excluded by --ignore / --ignore-file, so ignoring every .wasm next to a valid pair reported "none pair up". Both diagnostic walks (JS and wasm) now apply the same matcher, which keeps the .wasm.map count in line with the JS tally it is subtracted from. The JS-only message on main had the same miscount and is fixed with it.
  • A glob upload target (sentry sourcemap upload './dist/**') narrows wasm pairs the same way it narrows JS pairs. A pair is kept when the module or its map matches.
  • Known limitations, carried over from the original PR:
    • Pairs are found by filename only. The module's sourceMappingURL section is not parsed.
    • Inline (data-URL) wasm sourcemaps are not supported.

sentry-cli v3 compatibility

  • v3 sourcemaps upload includes map in its default extensions, so it uploaded app.wasm.map by URL. v4 on main drops it. This PR brings it back, paired with the module.
  • v3 never wrote to .wasm files from sourcemaps inject/upload. This PR stamps a build_id into modules that have none. --no-rewrite keeps the v3 behavior: nothing is written, and the pair uploads by URL with whatever id the module already has.

build_id convention (getsentry/symbolic#1069)

The map is keyed by the convention-correct id, decoded from the build_id vector. The other readers now agree:

Caveats:

  • Events from SDKs older than 11.11.0 still carry the shifted id, so they won't match these maps.
  • @sentry/wasm 11.12.0 strips the length byte only from 16-byte ids. Modules linked with wasm-ld --build-id=sha1 (20 bytes) still report a shifted id, and that has to be fixed in the SDK.
  • Nothing resolves wasm frames through maps yet (symbolicator-js has no wasm path), so for now this upload lays groundwork.

Review fixes

  • A bare 16-byte build_id (written before the length prefix was standardized) is read as is, matching symbolic. Before, such a module got a second, random build_id, and symbolic and the SDK then read different ones. The fix is in feat(debug-files): Add wasm-upload command for WASM debug setup #1628 (lib/wasm/binary.ts).
  • A pair that can't be handled is skipped with a warning and left out of the upload: a .wasm that isn't a module, a map that isn't JSON, an unreadable build_id, or files that can't be written. Before, it threw after the JS files had already been rewritten. The map is checked before the module is stamped, so a skipped pair writes nothing.
  • Maps saved with a BOM are accepted.
  • A build_id too short to form a debug ID produces a warning.
  • Modules and maps are replaced through a temp file and rename, so an interrupted write can't leave a corrupt artifact.

Refs getsentry/cli#1588

via BYK, @betegon, @BYK.

--

View Session [Sentry]

@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 30, 2026 12:49pm UTC
sentry-local Ready Ready Preview Nov 30, 2026 12:49pm UTC

Request Review

@sentry-junior
sentry-junior Bot force-pushed the port/cli-1588-wasm-sourcemaps branch from a3b4624 to 9a44113 Compare October 23, 2026 13:39
@sentry-junior
sentry-junior Bot force-pushed the port/cli-1588-wasm-sourcemaps branch from 9a44113 to 39c9a29 Compare October 23, 2026 14:03
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
getsentry#1630)

## Summary

Angular 22.1 emits debug IDs in JavaScript comments and source maps
without Sentry's runtime registration snippet. The CLI treated those IDs
as proof of completed injection, leaving the bundle unable to register
its ID at runtime.

Preserve the existing ID and inject the missing snippet, adjusting
source map mappings once. Apply the same decision to external and inline
maps, automatic injection during upload, and dry-run reporting. Already
registered bundles, including legacy CLI snippets, remain
byte-identical; binary bundles with existing IDs and metadata-only build
injection retain their existing behavior.

Fixes getsentry#1629.

## Test plan

- 157 tests passed across nine related sourcemap, build-injection, and
binary-detection test files. The new missing-registration cases fail
against the original implementation.
- Built the Angular reproduction from the issue and ran the CLI: the
original implementation reported zero modified files and no runtime
snippet; the fix adds one snippet with the same UUID and shifts mappings
once. A second run leaves both files byte-identical.
- Lint, typecheck, docs fragment checks, and `git diff --check` passed.
Generated docs and SDK prerequisites produced no tracked generated
changes.
- Not run: live upload, browser event ingestion, native binary build, or
the full unit suite.
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
getsentry#1630)

## Summary

Angular 22.1 emits debug IDs in JavaScript comments and source maps
without Sentry's runtime registration snippet. The CLI treated those IDs
as proof of completed injection, leaving the bundle unable to register
its ID at runtime.

Preserve the existing ID and inject the missing snippet, adjusting
source map mappings once. Apply the same decision to external and inline
maps, automatic injection during upload, and dry-run reporting. Already
registered bundles, including legacy CLI snippets, remain
byte-identical; binary bundles with existing IDs and metadata-only build
injection retain their existing behavior.

Fixes getsentry#1629.

## Test plan

- 157 tests passed across nine related sourcemap, build-injection, and
binary-detection test files. The new missing-registration cases fail
against the original implementation.
- Built the Angular reproduction from the issue and ran the CLI: the
original implementation reported zero modified files and no runtime
snippet; the fix adds one snippet with the same UUID and shifts mappings
once. A second run leaves both files byte-identical.
- Lint, typecheck, docs fragment checks, and `git diff --check` passed.
Generated docs and SDK prerequisites produced no tracked generated
changes.
- Not run: live upload, browser event ingestion, native binary build, or
the full unit suite.
@BYK
BYK added this pull request to stack #2305 November 16, 2026 23:03
@BYK
BYK marked this pull request as ready for review November 16, 2026 23:03
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 16, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

sentry-junior Bot and others added 2 commits November 26, 2026 11:11
Ported from getsentry/cli#1588 by @d2anamaria. `sourcemap inject` and
`sourcemap upload` now handle `<stem>.wasm` + `<stem>.wasm.map` pairs: the
map takes the module's `build_id` as its debug ID, and a module without one
is stamped first.

Rebased onto the refreshed wasm-upload branch as one commit. It folds in the
earlier commits on this branch:
- feat(sourcemap): Add wasm sourcemap support for inject and upload
- fix(sourcemap): Skip unusable wasm pairs instead of failing the run
- test(sourcemap): Name wasm-upload companions the way it writes them
- fix(sourcemap): Explain wasm pairing when modules and maps don't match

Option types now accept explicit `undefined`, and tests use index access
on parsed maps, for main's exactOptionalPropertyTypes and
noPropertyAccessFromIndexSignature.

Refs getsentry/cli#1588

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Discovery skips files matched by --ignore / --ignore-file, but the
diagnostic that explains an empty result still counted them. Ignoring
every .wasm next to a valid pair reported "none pair up", and ignoring
every JS file reported JS files without maps. Both diagnostic walks now
apply the same matcher, so the .wasm.map count still lines up with the JS
tally it is subtracted from.

Also pins the --dry-run report for wasm pairs: a pair a real run would
stamp shows as modified, with its debug ID or (pending).

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cbf136c. Configure here.

Comment thread packages/cli/src/lib/sourcemap/wasm.ts Resolved
A wasm-only directory whose pairs all had to be skipped (a .wasm that
isn't a module, a broken map) still asked for credentials and uploaded
an empty bundle. Pairs are now checked read-only first, so that case
fails like an empty directory, or is a no-op with --allow-empty.

A map that parses but isn't a sourcemap object, such as [] or null,
threw a TypeError after the module was stamped. It is now rejected
before anything is written. If the map write itself fails after the
module got its build_id, the skip says so instead of claiming nothing
was written.

Co-Authored-By: BYK <burak.kaya@sentry.io>
Co-Authored-By: bete <miguel.betegon@sentry.io>
Brings in main via the base branch. Resolve the conflicts in
sourcemap/upload.ts and its test: adopt main's multi-prefix PathStrip
and stripPath for every URL, so urlRelativePath now strips with it for
both JS and wasm files. Wasm pairs still join the --strip-common-prefix
computation and the artifact list, which replaces the branch's
resolvePathPrefixToStrip helper. Main's sources stripping runs over every
source_map artifact, so it covers wasm maps too.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Brings in main via the base branch. Resolve the conflict in
sourcemap/upload.ts: with --allow-empty and a missing directory, skip
wasm pair discovery the same way main now skips JS pair discovery.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>

This branch was successfully deployed

2 active and 1 inactive (outdated) deployments
Preview – sentry-local — 456329b5 Deployed Nov 30, 2026 by vercel[bot]
Preview – cli — 456329b5 Deployed Nov 30, 2026 by vercel[bot]
Preview — 4225ea92 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants