Skip to content

feat(wasm): patch non-streaming load paths - #23767

Merged
andreiborza merged 6 commits into
developfrom
ana/feat/wasm-non-streaming
Sep 7, 2026
Merged

andreiborza merged 6 commits into
developfrom
ana/feat/wasm-non-streaming

Conversation

@d2anamaria

@d2anamaria d2anamaria commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Register wasm modules when apps load via fetch → arrayBuffer → WebAssembly.instantiate/compile, not only streaming APIs.

  • Patch Response.prototype.arrayBuffer and bytes so wasm buffers remember their fetch URL
  • Wrap WebAssembly.instantiate and compile to register modules after byte-based loads
  • Workers get non-streaming registration too, through the shared patchWebAssembly(register)
  • Add tests for tagged-buffer registration, untagged-buffer negative case, argument forwarding, and a browser test for fetch → arrayBuffer → instantiate

Registration only. Frames from buffer-compiled modules still carry wasm://wasm/<hash>, which nothing matches against the registered image, so debug_meta does not attach yet. That half is #23781.

Implementation

  • patchWasmResponse.ts tags wasm buffers in a WeakMap when read from a wasm-like Response; getWasmSourceUrl() resolves them at instantiate/compile time
  • Response patching goes through fill(), so a frozen Response.prototype cannot break Sentry.init()
  • patchWebAssembly() orchestrates response patching, non-streaming hooks, then streaming hooks (unchanged behavior)
  • Non-streaming hooks forward every argument and never let a registration failure reject the caller's promise
  • Skip registration when instantiate receives an already-compiled WebAssembly.Module

@d2anamaria
d2anamaria marked this pull request as draft August 31, 2026 12:44
@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 28.57 kB - -
@sentry/browser - with treeshaking flags 26.94 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.83 kB - -
@sentry/browser (incl. Tracing) 48.87 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.88 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.8 kB - -
@sentry/browser (incl. Tracing, Replay) 88.36 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.76 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 93.05 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 106.02 kB - -
@sentry/browser (incl. Feedback) 46.06 kB - -
@sentry/browser (incl. sendFeedback) 33.64 kB - -
@sentry/browser (incl. FeedbackAsync) 38.74 kB - -
@sentry/browser (incl. Metrics) 29.52 kB - -
@sentry/browser (incl. Logs) 29.81 kB - -
@sentry/browser (incl. Metrics & Logs) 30.45 kB - -
@sentry/react 30.32 kB - -
@sentry/react (incl. Tracing) 51.08 kB - -
@sentry/vue 35.74 kB - -
@sentry/vue (incl. Tracing) 51.14 kB - -
@sentry/svelte 28.6 kB - -
CDN Bundle 30.36 kB - -
CDN Bundle (incl. Tracing) 49.52 kB - -
CDN Bundle (incl. Logs, Metrics) 32.59 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 51.43 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.19 kB - -
CDN Bundle (incl. Tracing, Replay) 87 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.88 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.93 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.83 kB - -
CDN Bundle - uncompressed 89.97 kB - -
CDN Bundle (incl. Tracing) - uncompressed 147.57 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.27 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 153.26 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.43 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 267.07 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 272.74 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 280.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 286.43 kB - -
@sentry/nextjs (client) 53.7 kB - -
@sentry/sveltekit (client) 49.3 kB - -
@sentry/core/server 40.74 kB - -
@sentry/core/browser 13.42 kB - -
@sentry/node 124.12 kB +0.02% +20 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.51 kB - -
@sentry/node - without tracing 88.3 kB +0.03% +21 B 🔺
@sentry/node - without channel injection 103.42 kB +0.03% +21 B 🔺
@sentry/aws-serverless 96.67 kB +0.03% +28 B 🔺
@sentry/cloudflare (withSentry) - minified 200.81 kB - -
@sentry/cloudflare (withSentry) 499.76 kB - -

View base workflow run

Comment thread packages/wasm/test/patchWebAssembly.test.ts
@andreiborza
andreiborza requested review from msonnb and removed request for msonnb August 31, 2026 13:45
@d2anamaria
d2anamaria marked this pull request as ready for review August 31, 2026 17:13
@d2anamaria
d2anamaria requested a review from andreiborza August 31, 2026 17:14
d2anamaria and others added 2 commits August 31, 2026 23:37
- Patch `Response.prototype.arrayBuffer` and `bytes` to tag wasm buffers with `response.url` in a `WeakMap`
- Hook `WebAssembly.instantiate` and `compile` to use tagged URL to register module
- Skip registration when `instantiate` receives an already-compiled `WebAssembly.Module`
- Split `patchWebAssembly` into response, non-streaming, and streaming setup; guard non-streaming with `nonStreamingPatched`

- Add `patchWebAssembly.test.ts` for fetch → arrayBuffer → instantiate/compile
- Extend `webworker.test.ts` to restore patched globals and assert `instantiate` is hooked
@andreiborza
andreiborza force-pushed the ana/feat/wasm-non-streaming branch from 3a55a63 to 99a2a60 Compare August 31, 2026 22:15
Comment thread packages/wasm/src/patchWebAssembly.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 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 2327538. Configure here.

Comment thread packages/wasm/src/patchWasmResponse.ts Outdated
@andreiborza
andreiborza requested a review from a team as a code owner September 1, 2026 09:25
@andreiborza
andreiborza requested review from logaretm and msonnb and removed request for a team September 1, 2026 09:25
Comment thread packages/wasm/src/patchWasmResponse.ts Outdated
@andreiborza andreiborza changed the title feat(wasm): patch non-streaming load paths & dedupe web worker patching feat(wasm): patch non-streaming load paths Sep 1, 2026
Comment thread packages/wasm/src/patchWebAssembly.ts
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

👋 @andreiborza — Please review this PR when you get a chance!

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

👋 @logaretm, @msonnb — Please review this PR when you get a chance!

@andreiborza andreiborza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @d2anamaria, looks good!

@andreiborza
andreiborza merged commit 59496e0 into develop Sep 7, 2026
292 checks passed
@andreiborza
andreiborza deleted the ana/feat/wasm-non-streaming branch September 7, 2026 13:58
timfish added a commit that referenced this pull request Sep 25, 2026
Buffer-compiled wasm (fetch → arrayBuffer → instantiate, common in
workers) shows up in Chrome stacks as `wasm://wasm/<name>-<hash>`
instead of the fetch URL stored as `code_file`, so frames never link to
the debug image and symbolication fails.

## Solution

- At registration, read the wasm `name` custom section into an internal
`moduleName` on the image. It is stripped before the event is sent.
- In `patchFrames()`, when the exact `code_file` lookup misses, compare
the label's module name to the registered images. An image with a parsed
`moduleName` matches on that name only, because V8 builds the label from
the name section and nothing else. An image without one is guessed from
the fetch URL basename, including the wasm-bindgen `_bg.wasm` → `.wasm`
alias.
- Accept a match only when every candidate shares one `debug_id`, since
a page and a worker can register the same binary under different URLs.
- A label counts as hash-only when no `-<hash>` suffix was stripped, so
hex-looking module names such as `ed25519` still map.

## Decisions

- Every response body read is tagged with its URL, not only wasm-looking
ones. #23767 sniffed content type and file extension, which silently
dropped modules served as `application/octet-stream` or from
extension-less URLs. A tag is only read back after a `WebAssembly`
compile succeeded, so tagging a non-wasm buffer is never observable.
Body reads on responses without a URL are passed through untouched.
- The browser test loads a new fixture, `named.wasm`, which is
`simple.wasm` plus a module-name subsection. `simple.wasm` only carries
function names, so Chrome labels it hash-only and the mapping cannot be
exercised with it. Code offsets and `build_id` are unchanged.

## Limitations

- Hash-only `wasm://wasm/<hex>` labels are not mapped (#23781)
- Ambiguous names (same name, different `debug_id`) stay unmatched
- Other browsers and unnamed wasm are unchanged

---------

Co-authored-by: Andrei Borza <andrei.borza@sentry.io>
Co-authored-by: Tim Fish <tim@timfish.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants