From 1f2a2f1947aca2c377639139057e565df6bd93cc Mon Sep 17 00:00:00 2001 From: Sebastian Munoz Date: Wed, 25 Nov 2026 12:40:20 +0100 Subject: [PATCH 1/9] feat(debug-files): Register wasmsourcemap as a debug file format Refs TGDX-153 --- src/sentry/constants.py | 1 + src/sentry/models/debugfile.py | 3 +++ tests/sentry/models/test_debugfile.py | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/sentry/constants.py b/src/sentry/constants.py index 1562c2fa1b18..c08a5191a52a 100644 --- a/src/sentry/constants.py +++ b/src/sentry/constants.py @@ -375,6 +375,7 @@ def parse_log_level(level: str | None) -> LogLevel | None: "application/x-il2cpp-json": "il2cpp", "application/x-portable-pdb": "portablepdb", "application/x-dartsymbolmap+json": "dartsymbolmap", + "application/x-wasm-sourcemap+json": "wasmsourcemap", } NATIVE_UNKNOWN_STRING = "" diff --git a/src/sentry/models/debugfile.py b/src/sentry/models/debugfile.py index b96996398203..758003fc214c 100644 --- a/src/sentry/models/debugfile.py +++ b/src/sentry/models/debugfile.py @@ -95,6 +95,8 @@ def _dif_file_extension(file_format: str, file_type: str | None) -> str: return ".json" if file_format == "dartsymbolmap": return ".json" + if file_format == "wasmsourcemap": + return ".wasm.map" return "" @@ -500,6 +502,7 @@ def _get_dif_object_name(meta: DifMeta) -> str: "uuidmap", "il2cpp", "dartsymbolmap", + "wasmsourcemap", ): return meta.name if meta.file_format == "breakpad": diff --git a/tests/sentry/models/test_debugfile.py b/tests/sentry/models/test_debugfile.py index 7087bdde1010..b78733f588a3 100644 --- a/tests/sentry/models/test_debugfile.py +++ b/tests/sentry/models/test_debugfile.py @@ -193,6 +193,30 @@ def test_file_extension_dartsymbolmap(self) -> None: # Verify that file_extension returns .json assert dif.file_extension == ".json" + def test_file_extension_wasmsourcemap(self) -> None: + """Test that wasmsourcemap files return .wasm.map file extension.""" + # Create a file with wasmsourcemap content type + file = File.objects.create( + name="wasmsourcemap", + type="project.dif", + headers={"Content-Type": "application/x-wasm-sourcemap+json"}, + ) + + # Create a ProjectDebugFile + dif = ProjectDebugFile.objects.create( + file=file, + checksum="test-checksum", + object_name="main.dart.wasm.map", + cpu_name="any", + project_id=self.project.id, + debug_id="bda18fd8-5d4a-4eb8-9302-2d6bfad846b1", + data={}, + ) + + # Verify that file_extension returns .wasm.map and that the format returns wasmsourcemap + assert dif.file_extension == ".wasm.map" + assert dif.file_format == "wasmsourcemap" + def test_file_extension_macho_dbg(self) -> None: """Test that macho files return empty file extension.""" file = File.objects.create( From ad25451c33782a62f32e04403aef946fe1605e92 Mon Sep 17 00:00:00 2001 From: Sebastian Munoz Date: Wed, 25 Nov 2026 12:59:47 +0100 Subject: [PATCH 2/9] feat(debug-files): Detect WASM source maps among JSON debug files 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 --- src/sentry/models/debugfile.py | 76 +++++++++++++++++++++------ tests/sentry/models/test_debugfile.py | 4 +- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/src/sentry/models/debugfile.py b/src/sentry/models/debugfile.py index 758003fc214c..ac42523d6389 100644 --- a/src/sentry/models/debugfile.py +++ b/src/sentry/models/debugfile.py @@ -831,12 +831,63 @@ class DifKind(enum.Enum): Object = enum.auto() BcSymbolMap = enum.auto() UuidMap = enum.auto() - Il2Cpp = enum.auto() + # A JSON object: an il2cpp line mapping or a WASM source map. They can only be told apart + # once the JSON is parsed, see `detect_dif_from_path`. + JsonObject = enum.auto() DartSymbolMap = enum.auto() # TODO(flub): should we include proguard? The tradeoff is that we'd be matching the # regex of it twice. That cost is probably not too great to worry about. +def _load_json(path: str) -> Any: + try: + with open(path, "rb") as fp: + return json.load(fp) + except json.JSONDecodeError as e: + logger.debug("File failed to load as JSON: %s", path) + raise BadDif("Invalid JSON: %s" % e) + + +def _is_source_map(data: Any) -> bool: + """Whether a parsed JSON document looks like a source map (any version).""" + return ( + isinstance(data, dict) and "version" in data and ("mappings" in data or "sections" in data) + ) + + +def _detect_wasm_source_map( + data: dict[str, Any], path: str, name: str | None, debug_id: str | None +) -> list[DifMeta]: + if data["version"] != 3: + raise BadDif("Unsupported source map version: %r" % data["version"]) + if "sections" in data: + raise BadDif("Index source maps are not supported") + if debug_id is None: + raise BadDif("Missing debug_id for wasmsourcemap") + try: + debug_id = normalize_debug_id(debug_id) + except SymbolicError as e: + raise BadDif("Invalid debug_id for wasmsourcemap: %s" % e) + logger.debug("File loaded as wasmsourcemap: %s", path) + return [ + DifMeta( + file_format="wasmsourcemap", + arch="any", + debug_id=debug_id, + name=name, + path=path, + data={"features": []}, + ) + ] + + +def _detect_il2cpp(path: str, name: str | None, debug_id: str | None) -> list[DifMeta]: + if debug_id is None: + raise BadDif("Missing debug_id for il2cpp") + logger.debug("File loaded as il2cpp: %s", path) + return [DifMeta(file_format="il2cpp", arch="any", debug_id=debug_id, name=name, path=path)] + + def determine_dif_kind(path: str) -> DifKind: """Returns the :class:`DifKind` detected at `path`.""" # TODO(flub): Using just the filename might be sufficient. But the cost of opening a @@ -848,8 +899,8 @@ def determine_dif_kind(path: str) -> DifKind: return DifKind.BcSymbolMap elif data.startswith(b" None: def test_dartsymbolmap_file_dict_format() -> None: """Test that dict format JSON files are detected as Il2Cpp, not dartsymbolmap.""" - # Note: Files starting with '{' are detected as Il2Cpp files, not dartsymbolmap - # This is because determine_dif_kind() checks for '{' before '[' and assigns Il2Cpp + # Note: Files starting with '{' are detected as JsonObject files, not dartsymbolmap + # This is because determine_dif_kind() checks for '{' before '[' and assigns JsonObject with tempfile.NamedTemporaryFile(mode="w", suffix=".json") as f: f.write('{"xyz": "ExceptionClass", "abc": "DatabaseError"}') f.flush() From 835ed67fa98bb84a125309f7a374c22b354d65c2 Mon Sep 17 00:00:00 2001 From: Sebastian Munoz Date: Wed, 25 Nov 2026 13:12:49 +0100 Subject: [PATCH 3/9] test(debug-files): Cover WASM source map detection Also create the wasmsourcemap extension test's models through the test factories. Refs TGDX-153 --- tests/sentry/models/test_debugfile.py | 69 +++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/tests/sentry/models/test_debugfile.py b/tests/sentry/models/test_debugfile.py index 9888131c3882..420bc6d81f3c 100644 --- a/tests/sentry/models/test_debugfile.py +++ b/tests/sentry/models/test_debugfile.py @@ -5,6 +5,7 @@ import time import zipfile from io import BytesIO +from pathlib import Path from typing import IO, Any from unittest.mock import MagicMock, patch @@ -17,6 +18,7 @@ from symbolic.debuginfo import Archive from sentry.models.debugfile import ( + BadDif, DifMeta, ProjectDebugFile, create_debug_file_from_dif, @@ -196,19 +198,17 @@ def test_file_extension_dartsymbolmap(self) -> None: def test_file_extension_wasmsourcemap(self) -> None: """Test that wasmsourcemap files return .wasm.map file extension.""" # Create a file with wasmsourcemap content type - file = File.objects.create( - name="wasmsourcemap", + file = self.create_file( + name="main.dart.wasm.map", type="project.dif", headers={"Content-Type": "application/x-wasm-sourcemap+json"}, ) # Create a ProjectDebugFile - dif = ProjectDebugFile.objects.create( + dif = self.create_dif_file( file=file, - checksum="test-checksum", object_name="main.dart.wasm.map", cpu_name="any", - project_id=self.project.id, debug_id="bda18fd8-5d4a-4eb8-9302-2d6bfad846b1", data={}, ) @@ -888,3 +888,62 @@ def test_dartsymbolmap_file_missing_debug_id() -> None: with pytest.raises(BadDif, match="Missing debug_id for dartsymbolmap"): detect_dif_from_path(f.name, name="dartsymbolmap.json", debug_id=None) + + +WASM_SOURCE_MAP = '{"version": 3, "sources": ["src/main.c"], "names": [], "mappings": "AAAA"}' + + +def _detect_json_file(tmp_path: Path, content: str, debug_id: str | None) -> list[DifMeta]: + path = tmp_path / "main.wasm.map" + path.write_text(content) + return detect_dif_from_path(str(path), name="main.wasm.map", debug_id=debug_id) + + +def test_wasm_source_map_detected(tmp_path: Path) -> None: + detected = _detect_json_file( + tmp_path, WASM_SOURCE_MAP, debug_id="BDA18FD8-5D4A-4EB8-9302-2D6BFAD846B1" + ) + + assert len(detected) == 1 + dif_meta = detected[0] + assert dif_meta.file_format == "wasmsourcemap" + assert dif_meta.arch == "any" + # Symbolicator looks files up by the normalized (lowercase) debug id. + assert dif_meta.debug_id == "bda18fd8-5d4a-4eb8-9302-2d6bfad846b1" + assert dif_meta.name == "main.wasm.map" + assert dif_meta.data == {"features": []} + + +def test_wasm_source_map_unsupported_version(tmp_path: Path) -> None: + content = '{"version": 4, "sources": [], "names": [], "mappings": "AAAA"}' + + with pytest.raises(BadDif, match="Unsupported source map version: 4"): + _detect_json_file(tmp_path, content, debug_id="bda18fd8-5d4a-4eb8-9302-2d6bfad846b1") + + +def test_wasm_source_map_index_map_rejected(tmp_path: Path) -> None: + content = '{"version": 3, "sections": [{"offset": {"line": 0, "column": 0}, "map": {}}]}' + + with pytest.raises(BadDif, match="Index source maps are not supported"): + _detect_json_file(tmp_path, content, debug_id="bda18fd8-5d4a-4eb8-9302-2d6bfad846b1") + + +def test_wasm_source_map_missing_debug_id(tmp_path: Path) -> None: + with pytest.raises(BadDif, match="Missing debug_id for wasmsourcemap"): + _detect_json_file(tmp_path, WASM_SOURCE_MAP, debug_id=None) + + +def test_wasm_source_map_invalid_debug_id(tmp_path: Path) -> None: + with pytest.raises(BadDif, match="Invalid debug_id for wasmsourcemap"): + _detect_json_file(tmp_path, WASM_SOURCE_MAP, debug_id="not-a-debug-id") + + +def test_il2cpp_still_detected_alongside_wasm_source_maps(tmp_path: Path) -> None: + """A JSON object that is not a source map keeps being stored as il2cpp.""" + content = '{"/src/Game.cpp": {"12": {"cs_file": "Game.cs", "cs_line": 3}}}' + + detected = _detect_json_file(tmp_path, content, debug_id="bda18fd8-5d4a-4eb8-9302-2d6bfad846b1") + + assert len(detected) == 1 + assert detected[0].file_format == "il2cpp" + assert detected[0].data is None From 90c7324ee043c2f5ee5c1715c340d36babea7424 Mon Sep 17 00:00:00 2001 From: Sebastian Munoz Date: Wed, 25 Nov 2026 13:31:59 +0100 Subject: [PATCH 4/9] fix(debug-files): Never clean up a WASM source map because of its module 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 --- src/sentry/models/debugfile.py | 6 +++++ tests/sentry/models/test_debugfile.py | 36 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/sentry/models/debugfile.py b/src/sentry/models/debugfile.py index ac42523d6389..8993b384d49c 100644 --- a/src/sentry/models/debugfile.py +++ b/src/sentry/models/debugfile.py @@ -446,6 +446,7 @@ def clean_redundant_difs(project: Project, debug_id: str) -> None: bcsymbolmap_seen = False uuidmap_seen = False il2cpp_seen = False + wasmsourcemap_seen = False for i, dif in enumerate(difs): mime_type = dif.get_content_type() if mime_type == DIF_MIMETYPES["bcsymbolmap"]: @@ -463,6 +464,11 @@ def clean_redundant_difs(project: Project, debug_id: str) -> None: il2cpp_seen = True else: dif.delete() + elif mime_type == DIF_MIMETYPES["wasmsourcemap"]: + if not wasmsourcemap_seen: + wasmsourcemap_seen = True + else: + dif.delete() else: # We always keep the latest file. If it has no features, likely the # previous files did not have features either and will be removed, or we diff --git a/tests/sentry/models/test_debugfile.py b/tests/sentry/models/test_debugfile.py index 420bc6d81f3c..3fb4001755ab 100644 --- a/tests/sentry/models/test_debugfile.py +++ b/tests/sentry/models/test_debugfile.py @@ -606,6 +606,42 @@ def test_skip_redundant_dif(self) -> None: assert not created2 assert dif1 == dif2 + def test_keep_wasm_source_map_with_its_module(self) -> None: + # The CLI may upload the map before the module. Both share the debug id. + file = self.create_stored_file(b"source map") + source_map, created1 = self.create_dif( + file=file, file_format="wasmsourcemap", arch="any", data={"features": []} + ) + + file = self.create_stored_file(b"wasm module") + module, created2 = self.create_dif( + file=file, file_format="wasm", arch="wasm32", data={"features": ["symtab", "debug"]} + ) + + assert created1 and created2 + assert ProjectDebugFile.objects.filter(id=source_map.id).exists() + assert ProjectDebugFile.objects.filter(id=module.id).exists() + + def test_remove_older_wasm_source_map(self) -> None: + file = self.create_stored_file(b"wasm module") + module, _ = self.create_dif( + file=file, file_format="wasm", arch="wasm32", data={"features": ["symtab", "debug"]} + ) + + file = self.create_stored_file(b"first source map") + old_map, _ = self.create_dif( + file=file, file_format="wasmsourcemap", arch="any", data={"features": []} + ) + + file = self.create_stored_file(b"second source map") + new_map, _ = self.create_dif( + file=file, file_format="wasmsourcemap", arch="any", data={"features": []} + ) + + assert not ProjectDebugFile.objects.filter(id=old_map.id).exists() + assert ProjectDebugFile.objects.filter(id=new_map.id).exists() + assert ProjectDebugFile.objects.filter(id=module.id).exists() + def test_remove_redundant_dif(self) -> None: file = self.create_stored_file(b"first debug symbols") dif1, created1 = self.create_dif(file=file, data={"features": ["debug"]}) From 0006299cb841b354de7de8f4f770f0937161db32 Mon Sep 17 00:00:00 2001 From: Sebastian Munoz Date: Wed, 25 Nov 2026 13:42:03 +0100 Subject: [PATCH 5/9] test(debug-files): Upload, list and download WASM source maps end to end Refs TGDX-153 --- .../sentry/api/endpoints/test_debug_files.py | 33 +++++++++++++++++++ tests/sentry/tasks/test_assemble.py | 23 +++++++++++++ 2 files changed, 56 insertions(+) diff --git a/tests/sentry/api/endpoints/test_debug_files.py b/tests/sentry/api/endpoints/test_debug_files.py index 983e1011b7f1..5edf7e68ce91 100644 --- a/tests/sentry/api/endpoints/test_debug_files.py +++ b/tests/sentry/api/endpoints/test_debug_files.py @@ -1,10 +1,12 @@ import os import zipfile +from hashlib import sha1 from io import BytesIO from unittest.mock import patch from uuid import uuid4 import requests +from django.core.files.base import ContentFile from django.core.files.uploadedfile import SimpleUploadedFile from django.http import HttpResponse from django.urls import reverse @@ -17,8 +19,10 @@ create_dif_from_file, ) from sentry.models.files.file import File +from sentry.models.files.fileblob import FileBlob from sentry.models.release import Release from sentry.models.releasefile import ReleaseFile +from sentry.tasks.assemble import assemble_dif from sentry.testutils.cases import APITestCase from sentry.testutils.helpers.response import close_streaming_response from sentry.testutils.objectstore import debug_files_test_both_backends @@ -254,6 +258,35 @@ def test_wasm_legacy_ids_old_upload(self) -> None: # The file that we find should have the legacy debug ID. assert response.data[0]["debugId"] == "10da03eb-5d63-d750-faab-0fb8e7cc12a1" + def test_wasm_source_map_listed_with_its_module(self) -> None: + self._upload_wasm() + + # The source map shares the debug id of the module it was built with. + debug_id = "da03eb5d-63d7-50fa-ab0f-b8e7cc12a1c3" + source_map = b'{"version": 3, "sources": ["src/main.c"], "names": [], "mappings": "AAAA"}' + blob = FileBlob.from_file_with_organization(ContentFile(source_map), self.organization) + assemble_dif( + project_id=self.project.id, + name="index.wasm.map", + checksum=sha1(source_map).hexdigest(), + chunks=[blob.checksum], + debug_id=debug_id, + ) + + # This is the query Symbolicator sends to find the files for a module. + response = self.client.get(f"{self.url}?debug_id={debug_id}") + assert response.status_code == 200, response.content + difs_by_type = {dif["symbolType"]: dif for dif in response.data} + assert sorted(difs_by_type) == ["wasm", "wasmsourcemap"] + + source_map_dif = difs_by_type["wasmsourcemap"] + assert source_map_dif["debugId"] == debug_id + assert source_map_dif["objectName"] == "index.wasm.map" + + # Symbolicator then downloads the file by id. + response = self.client.get(f"{self.url}?id={source_map_dif['id']}") + self._assert_successful_download(response, source_map, filename=f"{debug_id}.wasm.map") + def _do_test_dsyms_by_debugid_and_codeid( self, query: tuple[str, ...], files: list[tuple[bool, str, str]] ) -> None: diff --git a/tests/sentry/tasks/test_assemble.py b/tests/sentry/tasks/test_assemble.py index ee8e5b67653c..90422d65994f 100644 --- a/tests/sentry/tasks/test_assemble.py +++ b/tests/sentry/tasks/test_assemble.py @@ -244,6 +244,29 @@ def test_assemble_debug_id_override(self) -> None: assert dif.get_content_type() == "text/x-breakpad" assert dif.debug_id == "67e9247c-814e-392b-a027-dbde6748fcbf-beef" + def test_assemble_wasm_source_map(self) -> None: + source_map = b'{"version": 3, "sources": ["src/main.c"], "names": [], "mappings": "AAAA"}' + blob = FileBlob.from_file_with_organization(ContentFile(source_map), self.organization) + total_checksum = sha1(source_map).hexdigest() + + assemble_dif( + project_id=self.project.id, + name="main.wasm.map", + checksum=total_checksum, + chunks=[blob.checksum], + debug_id="DA03EB5D-63D7-50FA-AB0F-B8E7CC12A1C3", + ) + + status, _ = get_assemble_status(AssembleTask.DIF, self.project.id, total_checksum) + assert status == ChunkFileState.OK + + dif = ProjectDebugFile.objects.get(project_id=self.project.id, checksum=total_checksum) + assert dif.get_content_type() == "application/x-wasm-sourcemap+json" + assert dif.file_format == "wasmsourcemap" + # Symbolicator looks files up by the normalized (lowercase) debug id. + assert dif.debug_id == "da03eb5d-63d7-50fa-ab0f-b8e7cc12a1c3" + assert dif.object_name == "main.wasm.map" + @requires_objectstore class ArtifactBundleBackendChangeTest(BaseAssembleTest): From 83f1ff5e42ddaf3a3c1cab4ea4a54fb90e2d193e Mon Sep 17 00:00:00 2001 From: Sebastian Munoz Date: Wed, 25 Nov 2026 21:50:44 +0100 Subject: [PATCH 6/9] fix(debug-files): Don't let a newer companion file make cleanup delete 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 --- src/sentry/models/debugfile.py | 8 ++++-- tests/sentry/models/test_debugfile.py | 37 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/sentry/models/debugfile.py b/src/sentry/models/debugfile.py index 8993b384d49c..2399a99f8d73 100644 --- a/src/sentry/models/debugfile.py +++ b/src/sentry/models/debugfile.py @@ -447,7 +447,10 @@ def clean_redundant_difs(project: Project, debug_id: str) -> None: uuidmap_seen = False il2cpp_seen = False wasmsourcemap_seen = False - for i, dif in enumerate(difs): + # Whether a file has been kept by the generic rule below. The companion files above share the + # debug id but never add to `all_features`, so they must not count as a newer file there. + generic_seen = False + for dif in difs: mime_type = dif.get_content_type() if mime_type == DIF_MIMETYPES["bcsymbolmap"]: if not bcsymbolmap_seen: @@ -473,9 +476,10 @@ def clean_redundant_difs(project: Project, debug_id: str) -> None: # We always keep the latest file. If it has no features, likely the # previous files did not have features either and will be removed, or we # keep both. Subsequent uploads will remove this file later. - if i > 0 and dif.features <= all_features: + if generic_seen and dif.features <= all_features: dif.delete() else: + generic_seen = True all_features.update(dif.features) diff --git a/tests/sentry/models/test_debugfile.py b/tests/sentry/models/test_debugfile.py index 3fb4001755ab..5b2614536439 100644 --- a/tests/sentry/models/test_debugfile.py +++ b/tests/sentry/models/test_debugfile.py @@ -622,6 +622,43 @@ def test_keep_wasm_source_map_with_its_module(self) -> None: assert ProjectDebugFile.objects.filter(id=source_map.id).exists() assert ProjectDebugFile.objects.filter(id=module.id).exists() + def test_keep_module_without_features_when_map_is_newer(self) -> None: + # A fully stripped module has no features. The newer map must not make the generic rule + # treat it as redundant. + file = self.create_stored_file(b"stripped wasm module") + module, _ = self.create_dif( + file=file, file_format="wasm", arch="wasm32", data={"features": []} + ) + + file = self.create_stored_file(b"source map") + source_map, _ = self.create_dif( + file=file, file_format="wasmsourcemap", arch="any", data={"features": []} + ) + + assert ProjectDebugFile.objects.filter(id=module.id).exists() + assert ProjectDebugFile.objects.filter(id=source_map.id).exists() + + def test_remove_older_module_when_map_is_newest(self) -> None: + # The generic rule still replaces an older module, even when a map is the newest file. + file = self.create_stored_file(b"first wasm module") + old_module, _ = self.create_dif( + file=file, file_format="wasm", arch="wasm32", data={"features": []} + ) + + file = self.create_stored_file(b"second wasm module") + new_module, _ = self.create_dif( + file=file, file_format="wasm", arch="wasm32", data={"features": []} + ) + + file = self.create_stored_file(b"source map") + source_map, _ = self.create_dif( + file=file, file_format="wasmsourcemap", arch="any", data={"features": []} + ) + + assert not ProjectDebugFile.objects.filter(id=old_module.id).exists() + assert ProjectDebugFile.objects.filter(id=new_module.id).exists() + assert ProjectDebugFile.objects.filter(id=source_map.id).exists() + def test_remove_older_wasm_source_map(self) -> None: file = self.create_stored_file(b"wasm module") module, _ = self.create_dif( From 372958daa124479a2c898353a888ad08411b5207 Mon Sep 17 00:00:00 2001 From: Sebastian Munoz Date: Wed, 25 Nov 2026 21:52:10 +0100 Subject: [PATCH 7/9] feat(debug-files): Use the debug id embedded in a WASM source map 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 --- src/sentry/models/debugfile.py | 50 +++++++++++++++++++++++---- tests/sentry/models/test_debugfile.py | 41 ++++++++++++++++++++++ 2 files changed, 85 insertions(+), 6 deletions(-) diff --git a/src/sentry/models/debugfile.py b/src/sentry/models/debugfile.py index 2399a99f8d73..ff715527a152 100644 --- a/src/sentry/models/debugfile.py +++ b/src/sentry/models/debugfile.py @@ -865,6 +865,49 @@ def _is_source_map(data: Any) -> bool: ) +def _try_normalize_debug_id(debug_id: str) -> str | None: + try: + return normalize_debug_id(debug_id) + except SymbolicError: + return None + + +def _wasm_source_map_debug_id(data: dict[str, Any], debug_id: str | None) -> str: + """The normalized debug id to store a WASM source map under. + + A map can carry its own id in `debugId` (the source map debug id proposal, which Emscripten + fills with the module's build id) or in the legacy `debug_id`. That id wins over the one the + client sends. Without either, the client must send the module's build id. + """ + embedded = data.get("debugId") + if embedded is None: + embedded = data.get("debug_id") + + if embedded is None: + if debug_id is None: + raise BadDif("Missing debug_id for wasmsourcemap") + try: + return normalize_debug_id(debug_id) + except SymbolicError as e: + raise BadDif("Invalid debug_id for wasmsourcemap: %s" % e) + + if not isinstance(embedded, str): + raise BadDif("Invalid debugId in wasmsourcemap: %r" % embedded) + try: + embedded = normalize_debug_id(embedded) + except SymbolicError as e: + raise BadDif("Invalid debugId in wasmsourcemap: %s" % e) + + if debug_id is not None and _try_normalize_debug_id(debug_id) != embedded: + # Symbolicator finds the map by the module's build id. A map stamped with another id is + # stored, but never paired with its module. + logger.warning( + "wasmsourcemap.debug_id_mismatch", + extra={"embedded_debug_id": embedded, "debug_id": debug_id}, + ) + return embedded + + def _detect_wasm_source_map( data: dict[str, Any], path: str, name: str | None, debug_id: str | None ) -> list[DifMeta]: @@ -872,12 +915,7 @@ def _detect_wasm_source_map( raise BadDif("Unsupported source map version: %r" % data["version"]) if "sections" in data: raise BadDif("Index source maps are not supported") - if debug_id is None: - raise BadDif("Missing debug_id for wasmsourcemap") - try: - debug_id = normalize_debug_id(debug_id) - except SymbolicError as e: - raise BadDif("Invalid debug_id for wasmsourcemap: %s" % e) + debug_id = _wasm_source_map_debug_id(data, debug_id) logger.debug("File loaded as wasmsourcemap: %s", path) return [ DifMeta( diff --git a/tests/sentry/models/test_debugfile.py b/tests/sentry/models/test_debugfile.py index 5b2614536439..be044e7ac583 100644 --- a/tests/sentry/models/test_debugfile.py +++ b/tests/sentry/models/test_debugfile.py @@ -1011,6 +1011,47 @@ def test_wasm_source_map_invalid_debug_id(tmp_path: Path) -> None: _detect_json_file(tmp_path, WASM_SOURCE_MAP, debug_id="not-a-debug-id") +def test_wasm_source_map_embedded_debug_id(tmp_path: Path) -> None: + # Emscripten writes the module's build id into the map, without hyphens. + content = '{"version": 3, "debugId": "3B5EA884827C57BDAF43D4AEE910713C", "mappings": "AAAA"}' + + detected = _detect_json_file(tmp_path, content, debug_id=None) + + assert len(detected) == 1 + assert detected[0].file_format == "wasmsourcemap" + assert detected[0].debug_id == "3b5ea884-827c-57bd-af43-d4aee910713c" + + +def test_wasm_source_map_embedded_debug_id_wins(tmp_path: Path) -> None: + content = ( + '{"version": 3, "debugId": "3b5ea884-827c-57bd-af43-d4aee910713c", "mappings": "AAAA"}' + ) + + detected = _detect_json_file(tmp_path, content, debug_id="bda18fd8-5d4a-4eb8-9302-2d6bfad846b1") + + assert len(detected) == 1 + assert detected[0].debug_id == "3b5ea884-827c-57bd-af43-d4aee910713c" + + +def test_wasm_source_map_legacy_embedded_debug_id(tmp_path: Path) -> None: + content = ( + '{"version": 3, "debug_id": "3b5ea884-827c-57bd-af43-d4aee910713c", "mappings": "AAAA"}' + ) + + detected = _detect_json_file(tmp_path, content, debug_id=None) + + assert len(detected) == 1 + assert detected[0].debug_id == "3b5ea884-827c-57bd-af43-d4aee910713c" + + +@pytest.mark.parametrize("embedded", ['"not-a-debug-id"', "42"]) +def test_wasm_source_map_invalid_embedded_debug_id(tmp_path: Path, embedded: str) -> None: + content = '{"version": 3, "debugId": %s, "mappings": "AAAA"}' % embedded + + with pytest.raises(BadDif, match="Invalid debugId in wasmsourcemap"): + _detect_json_file(tmp_path, content, debug_id="bda18fd8-5d4a-4eb8-9302-2d6bfad846b1") + + def test_il2cpp_still_detected_alongside_wasm_source_maps(tmp_path: Path) -> None: """A JSON object that is not a source map keeps being stored as il2cpp.""" content = '{"/src/Game.cpp": {"12": {"cs_file": "Game.cs", "cs_line": 3}}}' From a707605ac96bf68e6337ed78a1525c2df84d3d10 Mon Sep 17 00:00:00 2001 From: Sebastian Munoz Date: Thu, 26 Nov 2026 14:54:42 +0100 Subject: [PATCH 8/9] ref(debug-files): Clarify the WASM source map debug id mismatch comment --- src/sentry/models/debugfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sentry/models/debugfile.py b/src/sentry/models/debugfile.py index ff715527a152..372b3c191bbd 100644 --- a/src/sentry/models/debugfile.py +++ b/src/sentry/models/debugfile.py @@ -899,8 +899,8 @@ def _wasm_source_map_debug_id(data: dict[str, Any], debug_id: str | None) -> str raise BadDif("Invalid debugId in wasmsourcemap: %s" % e) if debug_id is not None and _try_normalize_debug_id(debug_id) != embedded: - # Symbolicator finds the map by the module's build id. A map stamped with another id is - # stored, but never paired with its module. + # Symbolicator looks up the map by the module's build id. A map stamped with another id is + # stored under its own id, so it is never paired with the module it was uploaded next to. logger.warning( "wasmsourcemap.debug_id_mismatch", extra={"embedded_debug_id": embedded, "debug_id": debug_id}, From b7fb7bf46f0d64a5a60e8fa5e823987bf7a24267 Mon Sep 17 00:00:00 2001 From: Sebastian Munoz Date: Mon, 30 Nov 2026 11:55:55 +0100 Subject: [PATCH 9/9] fix(debug-files): Store the legacy WASM debug id on WASM source maps 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 --- src/sentry/models/debugfile.py | 1 + tests/sentry/api/endpoints/test_debug_files.py | 6 ++++++ tests/sentry/models/test_debugfile.py | 1 + 3 files changed, 8 insertions(+) diff --git a/src/sentry/models/debugfile.py b/src/sentry/models/debugfile.py index 182a197cc51f..61681e21889b 100644 --- a/src/sentry/models/debugfile.py +++ b/src/sentry/models/debugfile.py @@ -923,6 +923,7 @@ def _detect_wasm_source_map( file_format="wasmsourcemap", arch="any", debug_id=debug_id, + legacy_debug_id=wasm_legacy_debug_id(debug_id), name=name, path=path, data={"features": []}, diff --git a/tests/sentry/api/endpoints/test_debug_files.py b/tests/sentry/api/endpoints/test_debug_files.py index 5edf7e68ce91..c0570465668f 100644 --- a/tests/sentry/api/endpoints/test_debug_files.py +++ b/tests/sentry/api/endpoints/test_debug_files.py @@ -287,6 +287,12 @@ def test_wasm_source_map_listed_with_its_module(self) -> None: response = self.client.get(f"{self.url}?id={source_map_dif['id']}") self._assert_successful_download(response, source_map, filename=f"{debug_id}.wasm.map") + # Events from SDKs with the old WASM build id bug send the legacy id (INGEST-1282). + # The map must be found by it too, not only the module. + response = self.client.get(f"{self.url}?debug_id=10da03eb-5d63-d750-faab-0fb8e7cc12a1") + assert response.status_code == 200, response.content + assert sorted(dif["symbolType"] for dif in response.data) == ["wasm", "wasmsourcemap"] + def _do_test_dsyms_by_debugid_and_codeid( self, query: tuple[str, ...], files: list[tuple[bool, str, str]] ) -> None: diff --git a/tests/sentry/models/test_debugfile.py b/tests/sentry/models/test_debugfile.py index 07f588ca421e..e4b45f430f1e 100644 --- a/tests/sentry/models/test_debugfile.py +++ b/tests/sentry/models/test_debugfile.py @@ -995,6 +995,7 @@ def test_wasm_source_map_detected(tmp_path: Path) -> None: assert dif_meta.arch == "any" # Symbolicator looks files up by the normalized (lowercase) debug id. assert dif_meta.debug_id == "bda18fd8-5d4a-4eb8-9302-2d6bfad846b1" + assert dif_meta.legacy_debug_id == "10bda18f-d85d-4a4e-b893-022d6bfad846" assert dif_meta.name == "main.wasm.map" assert dif_meta.data == {"features": []}