Skip to content

feat(debug-files): Store WASM source maps as debug files - #132523

Open
Sebassmaster wants to merge 10 commits into
masterfrom
sebastianmunoz/tgdx-153-11-add-wasm-source-maps-as-a-new
Open

Sebassmaster wants to merge 10 commits into
masterfrom
sebastianmunoz/tgdx-153-11-add-wasm-source-maps-as-a-new

Conversation

@Sebassmaster

@Sebassmaster Sebassmaster commented Nov 25, 2026 •

Copy link
Copy Markdown

Important

Don't merge until getsentry/symbolicator#2229 is deployed. Symbolicator fails to parse a debug file list that contains an unknown symbolType, which would hide the .wasm module itself. That is what happened with dartsymbolmap in getsentry/symbolicator#1803.

Sentry now stores WASM source maps (.wasm.map, as written by Emscripten and dart2wasm) as debug files, with the new format wasmsourcemap. They are uploaded through the regular DIF assemble endpoint and served from /files/dsyms/, so Symbolicator can find them by debug id next to the .wasm module. Symbolicator doesn't use them yet; that comes later in the project. This lets WASM apps symbolicate from a source map instead of DWARF, which blocks the compiler's full optimizations.

Until now every uploaded JSON object (anything starting with {) was stored as an il2cpp line mapping, so a source map would have been silently misfiled. determine_dif_kind can only see the first bytes, so the decision now happens after the JSON is parsed:

  • DifKind.Il2Cpp is renamed to DifKind.JsonObject, which says what the sniff actually knows.
  • A document with version and mappings (or sections) is treated as a source map. Any other JSON object is still il2cpp, with unchanged behavior.
  • Only version 3 maps are accepted. Index maps (sections) are rejected. Both get an explicit upload error instead of falling back to il2cpp.
  • The map is stored under its own debugId (or the legacy debug_id) when it has one: Emscripten fills it with the module's build id. Otherwise the client must send debug_id (the .wasm build id). Either way the id is normalized, because Symbolicator looks files up by exact match on the normalized id. An embedded id that differs from the client's wins and is logged, since such a map would not pair with its module.

Two things worth a look in review:

  • Cleanup. The map shares its debug id with the module but has no features, so the generic rule in clean_redundant_difs would delete it whenever the module is uploaded after it. il2cpp had the same bug (fix: Prevent il2cpp DIFs from being cleaned #35843). Maps now only replace older maps. The generic rule also no longer counts a newer companion file (map, il2cpp, BCSymbolMap, UUID map) as the newer file, which could delete a module without features, such as a fully stripped .wasm uploaded before its map.
  • Features. Maps are stored with data={"features": []}. A non-null data keeps checksum dedup working. I left out "mapping" on purpose: the Dart lookup (find_by_debug_ids(..., features=["mapping"])) doesn't filter by format, and could otherwise pick up a WASM source map that shares a debug id with a Dart symbol map.

The frontend label for the new type will be a separate PR.

Refs TGDX-153

🤖 Generated with Claude Code

Files starting with { were all stored as il2cpp. Parse the JSON once and treat
source maps (version 3, no index maps) as wasmsourcemap, with a normalized debug id.

Refs TGDX-153
Also create the wasmsourcemap extension test's models through the test factories.

Refs TGDX-153
The map shares its debug id with the .wasm module but has no features, so the generic
cleanup rule deleted it whenever the module was uploaded after it. Keep only the newest
map per debug id, like il2cpp.

Refs TGDX-153
@linear-code

linear-code Bot commented Nov 25, 2026

Copy link
Copy Markdown

TGDX-153

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 25, 2026
@Sebassmaster
Sebassmaster marked this pull request as ready for review November 25, 2026 13:48
@Sebassmaster
Sebassmaster requested review from a team as code owners November 25, 2026 13:48
@Sebassmaster Sebassmaster self-assigned this Nov 25, 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.

Comment thread src/sentry/models/debugfile.py Resolved

@loewenheim loewenheim 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.

Very nice start! I only have one criticism:

Like il2cpp, the map carries no id of its own

This isn't quite true, sourcemaps can contain debug IDs (under the key "debugId"). Whether a sourcemap emitted by a WASM compiler actually does that is a different question, but I believe we should handle this case from the start. I would give the ID contained in the map precedence over one that is passed separately.

@Sebassmaster

Copy link
Copy Markdown
Author

Tested end to end against a local devserver running this branch, with the CLI from getsentry/toolkit#2502:

  • Built a small C program with Emscripten 7.0.1 (emcc -O2 -gsource-map -Wl,--build-id), which produces app.wasm and a version 3 app.wasm.map.
  • sentry debug-files upload --wait uploaded both with the module's build id as the debug id. Both finished as ok.
  • GET /files/dsyms/?debug_id=… returns both rows. The map has symbolType: wasmsourcemap, the module's debug id, content type application/x-wasm-sourcemap+json, cpuName: any and features: []. It is no longer filed as il2cpp.
  • GET /files/dsyms/?id=… downloads both files byte for byte after decompression. Objectstore serves them with content-encoding: zstd, as it does for every DIF.
  • Uploading both again leaves exactly one module and one map, so the cleanup rule keeps the map next to its module.

🤖 Generated with Claude Code

Sebassmaster and others added 2 commits November 25, 2026 21:50
…e a module

clean_redundant_difs kept the newest file by position, so when a companion file (a WASM source map, il2cpp mapping, BCSymbolMap or UUID map) was the newest, an older module with no features compared against an empty feature set and was deleted. A fully stripped WASM module uploaded before its source map hit this. Only files handled by the generic rule now count as newer.

Refs TGDX-153

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Source maps can carry their own debug id in debugId (the source map debug id proposal) or the legacy debug_id key, and Emscripten fills it with the module's build id. That id now takes precedence over the one the client sends, so the client no longer has to send one for such maps. A malformed embedded id rejects the upload, and an id that differs from the client's is logged, since the map would then not pair with its module.

Refs TGDX-153

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Sebassmaster

Copy link
Copy Markdown
Author

Good catch, thanks. Done in 372958d: the map's own debugId (or the legacy debug_id, which the sourcemap crate also accepts) now takes precedence over the id the client sends, and the client doesn't need to send one for such maps. A malformed embedded id rejects the upload.

This turned out to matter in practice: a current Emscripten (-gsource-map) writes the module's build id into the map as debugId, without hyphens, so the precedence keeps the map paired with its module.

One thing I'd like your view on: if the embedded id differs from the one the client sends, the map is stored under the embedded id, and Symbolicator, which looks up the module's build id, never finds it next to the module. For now I log a warning in that case. Would you rather reject such uploads?

I also updated the PR description.

🤖 Generated with Claude Code

@loewenheim

Copy link
Copy Markdown
Contributor

One thing I'd like your view on: if the embedded id differs from the one the client sends, the map is stored under the embedded id, and Symbolicator, which looks up the module's build id, never finds it next to the module. For now I log a warning in that case. Would you rather reject such uploads?

For native debug files (like WASM files) we take the included ID as the truth and only allow overriding if they agree on the first 36 characters (everything except the age part), cf.

obj_id = obj.debug_id
if obj_id and debug_id and obj_id[:36] == debug_id[:36]:
obj_id = debug_id

I don't believe sourcemap debug IDs ever even have an age, so we should just take the embedded debug ID if it's present and only use the user-supplied one as a substitute if it's missing.

@Sebassmaster

Copy link
Copy Markdown
Author

One thing I'd like your view on: if the embedded id differs from the one the client sends, the map is stored under the embedded id, and Symbolicator, which looks up the module's build id, never finds it next to the module. For now I log a warning in that case. Would you rather reject such uploads?

For native debug files (like WASM files) we take the included ID as the truth and only allow overriding if they agree on the first 36 characters (everything except the age part), cf.

obj_id = obj.debug_id
if obj_id and debug_id and obj_id[:36] == debug_id[:36]:
obj_id = debug_id

I don't believe sourcemap debug IDs ever even have an age, so we should just take the embedded debug ID if it's present and only use the user-supplied one as a substitute if it's missing.

Got that,

One thing I'd like your view on: if the embedded id differs from the one the client sends, the map is stored under the embedded id, and Symbolicator, which looks up the module's build id, never finds it next to the module. For now I log a warning in that case. Would you rather reject such uploads?

For native debug files (like WASM files) we take the included ID as the truth and only allow overriding if they agree on the first 36 characters (everything except the age part), cf.

obj_id = obj.debug_id
if obj_id and debug_id and obj_id[:36] == debug_id[:36]:
obj_id = debug_id

I don't believe sourcemap debug IDs ever even have an age, so we should just take the embedded debug ID if it's present and only use the user-supplied one as a substitute if it's missing.

Got that, we are already implementing that logic (embedded taking precedence over user supplied one), so we are good in this regards.

…noz/tgdx-153-11-add-wasm-source-maps-as-a-new

@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 1 potential issue.

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 1a69dd2. Configure here.

Comment thread src/sentry/models/debugfile.py Resolved
Events from SDKs with the old WASM build id bug look files up by the legacy id. The module stores it, but the map did not, so those events found the module without its map.

Refs TGDX-153

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Sebassmaster

Copy link
Copy Markdown
Author

Very nice start! I only have one criticism:

Like il2cpp, the map carries no id of its own

This isn't quite true, sourcemaps can contain debug IDs (under the key "debugId"). Whether a sourcemap emitted by a WASM compiler actually does that is a different question, but I believe we should handle this case from the start. I would give the ID contained in the map precedence over one that is passed separately.

Thank you for catching this, this has been handled in 372958d.

This branch was successfully deployed

1 active (outdated) deployment
Preview — 1a69dd26 Deployed Nov 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants