Repository navigation
feat(debug-files): Add wasm-upload command for WASM debug setup - #1628
sentry-junior[bot] wants to merge 28 commits into
Conversation
Preparing WebAssembly for Sentry took two tools: `wasm-split` to inject a `build_id` and pull DWARF into a companion, then `debug-files upload` on that companion. Nothing flagged modules built without usable debug info, so the mistake only surfaced as an unsymbolicated stack trace. `sentry debug-files wasm-upload <path>...` does both steps. It scans for `.wasm` modules, and for each one with inline DWARF it injects a `build_id` if missing, writes a `<stem>.<build_id>.debug.wasm` companion (keeping the Code section, since DWARF addresses are relative to it), strips `.debug_*` from the deployable in place, points it at the companion via `external_debug_info`, and uploads the companion. Modules that can't be split are still stamped and reported with a warning; `--require-dwarf` turns that into a CI failure. `--wait`/`--wait-for` parsing, source-file reading, and the ignore matcher move into shared helpers so `upload`, `bundle-sources`, and the sourcemap commands reuse them instead of carrying copies. Ported from getsentry/cli#1572, which is being closed with the repo archive. Co-Authored-By: BYK <burak.kaya@sentry.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
`--out-dir` was passed directly to `writeFile`. If the directory didn't exist yet, including the documented `./symbols` example, the command threw ENOENT before writing any companion. The command now creates the companion's directory first. Co-Authored-By: BYK <burak.kaya@sentry.io>
`wasm-upload` stripped modules in place and wrote companions before resolving the org, project, and chunk-upload options. A missing target or an auth failure then aborted after the files had changed, leaving stripped modules whose companions were never uploaded. When an upload will run, the target is now resolved before any module is touched, the same way `debug-files upload` does it. A module whose `external_debug_info` companion was missing also got a random `build_id` stamped on the skip path. If the companion showed up later, that random id could never match it, so the pair could no longer be repaired. These modules are now left unstamped.
Adapt wasm-upload to conventions that landed on main: completion-tagged parsers for every flag and positional, examples in command metadata, the sentry`...` usage-hint tag, and the toolkit-core Markdown builders. Co-Authored-By: BYK <burak.kaya@sentry.io>
Bring in main through the rebased #1628 and fit wasm pairs into what landed there: - `sourcemap upload <glob>` now narrows wasm pairs the way it narrows JS pairs: a pair is kept when the module or its map matches, and the zero-pairs diagnostic counts only matching files so the `.wasm.map` subtraction lines up with the JS tally. - `--dry-run` now reports what a real run would change. `mapWritten` and `moduleStamped` were always false in a dry run, so `sourcemap inject --dry-run` counted every wasm pair as skipped. `setSourcemapDebugId` returns `changed` instead of `written` to say the same in both modes. - `relativePosix` is shared with JS discovery instead of duplicated. Co-Authored-By: bete <28983162+betegon@users.noreply.github.com> Co-Authored-By: BYK <burak.kaya@sentry.io>
A module that still had inline DWARF and an `external_debug_info` pointer left by another tool kept the old pointer next to the new one after `wasm-upload` split it. `inspectWasm` reads the last pointer and the companion lookup reads the first, so the two could follow different files. The split now drops any existing pointer before appending the one for the new companion. `splitWasm` itself is unchanged, so `wasm-split` keeps parity with the Rust tool.
Producers that predate the tool-conventions length prefix write the id as a bare 16-byte body. The decoder rejected it, so callers treated the module as unstamped and appended a second, random build_id. symbolic reads the last section and @sentry/wasm the first, so events stopped matching both maps and debug files for a module that matched before. Read a 16-byte body as is, mirroring getsentry/symbolic#1093. Co-Authored-By: bete <28983162+betegon@users.noreply.github.com>
wasm-upload skipped every *.debug.wasm, so a real debug build named app.debug.wasm was never uploaded. Companions are now recognized by the name this command writes (<stem>.<build_id>.debug.wasm), by another module's external_debug_info, or by sharing a build id with a sibling <stem>.wasm (wasm-split -d with a remote --external-dwarf-url). A *.debug.wasm with a differently identified sibling is prepared as a module. One with no sibling is skipped with a warning, since splitting a companion would strip the DWARF its module points at. Co-Authored-By: bete <28983162+betegon@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3f580b3. Configure here.
Dropping companions could leave nothing to prepare, but the command still resolved the org, project, and auth before noticing. A normal run over a directory of wasm-split companions then failed with a missing org/project error. The empty check now runs after companions are dropped.
…ntry#1628) ## Summary Shared issue links use an org-scoped public endpoint that returns `id`. The CLI was calling the retired unscoped endpoint and expecting `groupID`, so valid links could not resolve. Resolve the organization from the URL or existing context, validate the shared issue ID, and fetch full details through the authenticated org-scoped API. Support canonical `/organizations/<org>/share/issue/<shareId>/` URLs alongside SaaS subdomain links. Public share requests remain unauthenticated, with existing host-scoped custom headers preserved. Legacy links without organization context now produce a context error. Supersedes getsentry#1401. ## Test plan - 380 tests passed across the shared API, issue resolver, URL/argument parsers, and host/header security suites. - All six shared-link resolver regression cases fail against the original `main` implementation and pass with this change. - Full `tsc --noEmit`, `pnpm run lint`, `pnpm run check:errors`, and `git diff --check` passed. - Generated schema/docs/SDK prerequisites completed without tracked generated changes. - No live shared-link request, full unit suite, E2E suite, or packaging build was run.
Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Main now builds with exactOptionalPropertyTypes and noPropertyAccessFromIndexSignature. PrepareOptions takes the possibly-undefined flag values wasm-upload passes, and the test reads SENTRY_PLAIN_OUTPUT with index access. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
| | `<path...>` | WebAssembly files or directories to scan | | ||
|
|
||
| **Flags:** | ||
| - `--dry-run - Classify modules without writing or uploading anything` |
There was a problem hiding this comment.
Short for this should be -n if it's available as that's the common shorthand for dry run flags, right?
| - `--dry-run - Classify modules without writing or uploading anything` | ||
| - `--no-upload - Split modules but do not upload the companions` | ||
| - `--require-dwarf - Fail if any scanned module lacks DWARF debug info` | ||
| - `--out-dir <value> - Directory for *.debug.wasm companions (modules are stripped in place)` |
There was a problem hiding this comment.
Should we add -o as a shorthand for this?
| - `--build-id <value> - Use this UUID as the build id instead of a random one (one .wasm file only)` | ||
| - `--include-sources - Also upload a source bundle for each companion` | ||
| - `--ignore <value>... - Skip files and folders matching this glob (repeatable)` | ||
| - `--ignore-file <value> - Skip files and folders listed in this ignore file` |
There was a problem hiding this comment.
Done in #2721: sourcemap resolve, inject and upload take a repeatable --ignore-file, with a shared flag and a CI check so they can't drift.
| - `--ignore <value>... - Skip files and folders matching this glob (repeatable)` | ||
| - `--ignore-file <value> - Skip files and folders listed in this ignore file` | ||
| - `--wait - Wait for server-side processing and report any errors` | ||
| - `--wait-for <value> - Wait up to this many seconds for server-side processing` |
There was a problem hiding this comment.
Align these wait flags with the rest of sourcemap uploads we reworked recently and make sure these can never diverge again. A common helper and/or an oxlint rule should do it.
There was a problem hiding this comment.
Aligning this for 4.0.0 in a separate PR off main for debug-files upload; wasm-upload adopts it once that lands.
| */ | ||
| export function readSourceFile(sourcePath: string): Uint8Array | null { | ||
| try { | ||
| return readFileSync(sourcePath); |
There was a problem hiding this comment.
Kept sync: createSourceBundle and createIl2cppLineMapping hand this callback to @sentry/symbolic's WASM binding, which calls it synchronously from Rust mid-write. Async needs an async provider in @sentry/symbolic (or pre-reading every source into memory), so I'd do that as a follow-up.
| */ | ||
| export async function replaceFile( | ||
| path: string, | ||
| data: string | Uint8Array, |
There was a problem hiding this comment.
Wouldn't it be cheaper to open the file in append or rw mode and modify in-place?
|
|
||
| /** Path relative to the module, for its `external_debug_info` section. */ | ||
| function externalDebugInfoPath(wasmPath: string, companion: string): string { | ||
| return relative(dirname(wasmPath), companion).split(sep).join("/"); |
There was a problem hiding this comment.
The pointer is stored inside the module and read on any OS, so it has to use /. Added a comment.
| externalDebugInfo: null, | ||
| }; | ||
| for (const section of sections) { | ||
| surveySection(found, section); |
There was a problem hiding this comment.
What's the point of having this as a separate function if it modifies its arguments in-place?
| try { | ||
| const companion = await inspectWasmFile(path); | ||
| return companion.quality === "dwarf" ? companion.buildId : null; | ||
| } catch (error) { |
| } | ||
|
|
||
| /** Whether `path` is `root` or sits below it. */ | ||
| function isInside(root: string, path: string): boolean { |
There was a problem hiding this comment.
Don't we have these helpers in the code base already?
- Add -n for --dry-run (shared DRY_RUN_FLAG/DRY_RUN_ALIASES) and -o for --out-dir, and make --ignore-file repeatable. - Check explicitly named files by their WebAssembly header, not their extension. Directory walks keep the .wasm filter. - Read companions and stat explicit paths in parallel with p-limit, and scan path arguments in parallel while keeping argument order. - Narrow the catches in readSourceFile and readCompanionBuildId: a missing file is still expected, other read errors are reported. - Derive the scan's skip list from a VCS-and-dependency subset of DEFAULT_SKIP_DIRS, and format debug ids with the uuid library. - Return a fresh survey from surveySection instead of mutating its argument.
`sourcemap resolve` took one `--ignore-file`. Make it variadic, the way #1628 defines it for `debug-files wasm-upload`, and let `buildIgnoreMatcher` take one path or a list, with the same signature that PR gives it. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
- Move the containment check and the reference resolver from the wasm prepare step into src/lib/path-utils.ts (isPathInside, isRemoteUrl, resolveLocalReference), and use them where sourcemap inject, snapshot archive extraction and the DSN home-directory guard repeated the logic. - Explain in replaceFile why it writes a temp file and renames it. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Two DWARF modules with the same file name and build_id sharing a companion folder (as with --out-dir) both split to the same <stem>.<build_id>.debug.wasm, so the later one replaced the companion the earlier module points at. Read every module's build_id header up front, keep the first module for each companion path and skip the rest with a warning naming the module that keeps it. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Resolve conflicts with main's mapBounded / no-await-in-loop change: - sourcemap upload and inject: keep main's CONCURRENCY_LIMIT import from scan/constants and this branch's buildIgnoreMatcher import. - dif/scan: keep this branch's parallel scanFiles, which replaces the sequential loop main annotated. Main's new no-await-in-loop rule also flags six sequential awaits this branch added in wasm-upload and wasm/prepare; annotate them with the reason they stay sequential, as main does, without changing behavior.
Adopt #2721's shared upload flags: - wasm-upload uses WAIT_FLAG (--wait[=seconds]) and IGNORE_FILE_FLAG from lib/upload-flags.ts; --wait-for is gone. - Delete debug-files/wait.ts; debug-files upload keeps main's flags. - buildIgnoreMatcher stays in lib/sourcemap/inject.ts as on main; drop this branch's copy in lib/scan and point wasm-upload at main's. - Regenerate the sentry-cli skill reference for wasm-upload.
The header surveys (external_debug_info pointers, sibling build ids, companion collision targets), the explicit-path checks and the companion reads before upload are independent reads, so run them through mapBounded instead of one at a time or through p-limit directly. Preparing modules and walking one module's sections stay sequential: each section starts after the one before it, and a split holds the whole module in memory several times over.
Brings in main's mapBounded and shared upload flags through #1628. Keep both import blocks in sourcemap upload, and mark syncWasmPairs' loop for the new no-await-in-loop rule with the reason it stays sequential.
getsentry#2721) `sentry debug-files upload` and `sentry react-native gradle`/`xcode` took `--wait` and `--wait-for <secs>`, while `sentry sourcemap upload` takes `--wait[=seconds]`. `--ignore-file` was single-use on the sourcemap commands but repeatable in getsentry#1628's `wasm-upload`. This aligns both flags for 4.0.0. - `parseWaitSeconds` moves from `commands/sourcemap/upload.ts` to a new `lib/upload-flags.ts`, next to `waitLimitMs`, which converts the parsed value to milliseconds (`0` = no limit). - `debug-files upload` now has one `--wait[=seconds]` flag (inline-only, like sourcemap upload): bare `--wait` waits up to 300s, `--wait=600` changes the limit, `--wait=0` waits with no limit. - Breaking: `--wait-for` is dropped from `debug-files upload`, not aliased, the same as `sourcemap upload` did. The v3 migration guide gets a matching line: replace `--wait-for 600` with `--wait=600`. - `DEBUG_FILES_MAX_WAIT_MS` had no other users and is removed; the default limit stays 300s. - Breaking: `react-native gradle` and `react-native xcode` move to the same `--wait[=seconds]` and drop `--wait-for` with no alias; the migration guide line names them too. `resolveUploadWait` is removed. - `--ignore-file` is now repeatable on `sourcemap resolve`, `inject` and `upload`, as in getsentry#1628's `wasm-upload`. `buildIgnoreMatcher` takes one path or a list, with the same signature as in getsentry#1628. - Every command with these flags uses the shared `WAIT_FLAG`/`IGNORE_FILE_FLAG` from `lib/upload-flags.ts`, and the new `sentry-cli/use-shared-upload-flags` Oxlint rule rejects an inline `wait` or `ignore-file` flag in `src/commands/` (a command may spread the constant and override only `brief`). - Not changed: `debug-files upload` does not wait by default in CI and has no `--no-wait`, unlike `sourcemap upload`. Related: getsentry#1628 defines `--ignore-file`, `--wait` and `--wait-for` inline in `wasm-upload`. After this merges it needs to use `IGNORE_FILE_FLAG` and `WAIT_FLAG` and drop `--wait-for`, or the new lint rule fails. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A2fc2fd075226f2172fc7e913cbafd467 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A2fc2fd075226f2172fc7e913cbafd467) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A2fc2fd075226f2172fc7e913cbafd467/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <126780+BYK@users.noreply.github.com>
main now lints tests for awaits in loops, so the wasm tests run their independent fixture writes and reads with Promise.all. The collision test keeps its sequential prepare loop, like the command.
Use the shared NO_WAIT_FLAG and resolveUploadWait, like debug-files upload and sourcemap upload. In CI the command now waits up to five minutes and fails if processing fails; --no-wait keeps the old behavior.
Brings in main's shared --no-wait handling through #1628. Keep the ValidationError import in sourcemap upload, which main dropped but the wasm pair check still uses.

Ported from getsentry/cli#1572 by @d2anamaria, which is being closed as part of the
getsentry/cliarchive. Toolkit already had the low-level pieces (lib/wasm/binary.ts,build-id.ts,split.ts,sentry wasm-split). Nothing on main or in another open PR covers this command.Problem
Getting WebAssembly ready for Sentry takes two tools today. You run
wasm-splitto inject abuild_idand move DWARF into a companion file. Then you runsentry debug-files upload --type wasmon that companion. If a module was built without usable debug info, nothing tells you. You find out later from an unsymbolicated stack trace.Before / after
Before (v3, and
maintoday):You name the companion yourself, run this once per module, and get no warning when a module has no DWARF.
After:
One command for every module under
dist/. On an Emscripten fixture (emcc -g):dist/app.wasm.debug_*sections.debug_*, onebuild_id,external_debug_infopointing at the companion. Same path, so the deploy doesn't change.-ddist/app.<build_id>.debug.wasm(87,151 bytes), uploadedbuild_idand a warning.--require-dwarffails the run.wasm-splitagain would strip an already-stripped modulealready-prepared, no bytes changeSolution
sentry debug-files wasm-upload <path>...does both steps. It scans the paths for.wasmmodules. For each module that has inline DWARF, it:build_idif the module doesn't have one.<stem>.<build_id>.debug.wasmcompanion. The companion keeps the Code section, because DWARF addresses are relative to it..debug_*sections from the deployable module in place, so the artifact keeps its path.external_debug_info, replacing any pointer a previous tool left.A module that can't be split still gets a
build_idand a warning.--require-dwarfturns that warning into a failure for CI. If a module has a companion but nobuild_id, the command repairs the pair instead of only warning about it. Running the command again on the same files is safe.--dry-runand--no-uploadwork without credentials. The org, project, and auth are resolved before any module is modified, so a missing one fails before anything is stripped.--wait[=seconds]and the repeatable--ignore-fileare the sharedWAIT_FLAGandIGNORE_FILE_FLAGfromlib/upload-flags.ts(#2721), and ignore patterns go through the sharedbuildIgnoreMatcherinlib/sourcemap/inject.ts.The command also moves
readSourceFileintocommands/debug-files/read-file.ts, as asked in review on the original PR;uploadandbundle-sourcesnow import it instead of keeping their own copies.Which
*.debug.wasmfiles are companionsA companion is a full copy of its module, so its contents can't tell it apart from a module with DWARF. Splitting a companion by mistake strips the DWARF its module points at. A scanned
*.debug.wasmis treated as a companion only when:<stem>.<build_id>.debug.wasmname this command writes, orexternal_debug_infopoints at it, or<stem>.debug.wasmnext to a<stem>.wasmwith the samebuild_id. This is whatwasm-split -d app.debug.wasmleaves, including with a remote--external-dwarf-url.A
<stem>.debug.wasmwhose sibling has a differentbuild_idis a separate debug build, so it's prepared and uploaded like any module. One with no sibling can't be told apart, so it's skipped with a warning that names the file.build_id convention
The
build_idsection body is a varuint32 length prefix followed by the id, and the CLI reads the id after the prefix. A body of exactly 16 bytes with no prefix (the legacy form some producers write) is read as a raw UUID, the way symbolic reads it. It is not stamped again: a secondbuild_idwould make symbolic (last section wins) and@sentry/wasm(first section wins) disagree.The readers on the other side now agree with this: symbolic#1093 (14.0.0-alpha.4), getsentry/sentry#128493 (stores the correct id plus the legacy shifted one), and
@sentry/wasm11.11.0 (sentry-javascript#24857). One gap remains on the SDK side:@sentry/wasm11.12.0 only strips the prefix for 16-byte ids, so awasm-ld --build-id=sha1module (20-byte id) still produces events with the shifted id. That needs a fix in@sentry/wasm, not here.Review notes carried over from cli#1572
preparetowasm-uploadafter BYK pointed out thatpreparedoesn't suggest an upload and only applies to wasm.build_id, as agreed in review.lib/wasm/prepare.tsyet, so that file needs the closest look here.sentry-cli v3 compatibility
v3 documents WASM as
wasm-split app.wasm -d app.debug.wasm --stripfollowed bysentry-cli debug-files upload. That flow still works unchanged in v4 (sentry wasm-splittakes the same flags).wasm-uploadis a new v4 shortcut and changes no existing command. Runningwasm-uploadover a directory that the v3 flow already processed leaves theapp.debug.wasmcompanion alone.Refs getsentry/cli#1572
via BYK, @betegon, @BYK.
--
View Session [Sentry]