-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(wasm): map wasm:// stack frames to registered debug images #23999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5ae3418
feat(wasm): patch non-streaming load paths
d2anamaria 99a2a60
Forward extra arguments and guard buffer registration
andreiborza 2327538
Guard the Response prototype patching
andreiborza 8bfb52c
Drop the unnecessary double-cast
andreiborza 7799bee
Add a browser test for non-streaming registration
andreiborza 3211543
Guard every patch seam so the wasm integration never throws into user…
andreiborza 26c7182
fix(wasm): map Chrome wasm:// frames to debug images
d2anamaria 3645982
fix(wasm): treat same debug_id as one wasm:// image
d2anamaria 11b91d2
fix(wasm): match wasm:// frames via name section
d2anamaria a7e7efc
test(wasm): cover name-section wasm:// frame matching
d2anamaria 1c6d825
refactor(wasm): drop redundant patch guards and content sniffing
d2anamaria bafae46
Merge remote-tracking branch 'origin/develop' into ana/fix/wasm-worke…
timfish 59dee53
fix(wasm): match wasm:// frames on the name section and cover it end …
timfish bf10a60
Merge branch 'develop' into ana/fix/wasm-worker-non-streaming
timfish 3f6cdc4
Merge remote-tracking branch 'origin/develop' into ana/fix/wasm-worke…
timfish 8496e88
Merge remote-tracking branch 'origin/develop' into ana/fix/wasm-worke…
timfish e6c6089
fix(wasm): match wasm:// frames on the name section only
timfish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 6 additions & 11 deletions
17
dev-packages/browser-integration-tests/suites/wasm/instantiateBufferRegistration/init.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,15 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
| import { registerWebWorkerWasm } from '@sentry/wasm'; | ||
| import { wasmIntegration } from '@sentry/wasm'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| traceLifecycle: 'static', | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| }); | ||
|
|
||
| // `registerWebWorkerWasm` installs the same patches a worker would, and reports | ||
| // every registered module to the scope it is given. Collecting them here is the | ||
| // only way to observe registration from the page, since main-thread images stay | ||
| // module-internal until a frame matches one. | ||
| window.registeredImages = []; | ||
| registerWebWorkerWasm({ | ||
| self: { | ||
| postMessage: message => window.registeredImages.push(...(message._sentryWasmImages || [])), | ||
| integrations: [wasmIntegration()], | ||
| beforeSend: event => { | ||
| window.events.push(event); | ||
| return null; | ||
| }, | ||
| }); | ||
| window.events = []; |
20 changes: 14 additions & 6 deletions
20
dev-packages/browser-integration-tests/suites/wasm/instantiateBufferRegistration/subject.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,20 @@ | ||
| window.loadWasmFromBuffer = async () => { | ||
| const response = await fetch('https://localhost:5887/simple.wasm'); | ||
| const buffer = await response.arrayBuffer(); | ||
| window.getEvent = async () => { | ||
| function crash() { | ||
| throw new Error('whoops'); | ||
| } | ||
|
|
||
| await WebAssembly.instantiate(new Uint8Array(buffer), { | ||
| const response = await fetch('https://localhost:5887/named.wasm'); | ||
| const buffer = await response.arrayBuffer(); | ||
| const { instance } = await WebAssembly.instantiate(new Uint8Array(buffer), { | ||
| env: { | ||
| external_func: () => {}, | ||
| external_func: crash, | ||
| }, | ||
| }); | ||
|
|
||
| return window.registeredImages; | ||
| try { | ||
| instance.exports.internal_func(); | ||
| } catch (err) { | ||
| Sentry.captureException(err); | ||
| return window.events.pop(); | ||
| } | ||
| }; |
77 changes: 48 additions & 29 deletions
77
dev-packages/browser-integration-tests/suites/wasm/instantiateBufferRegistration/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,68 @@ | ||
| import type { Page, Route } from '@playwright/test'; | ||
| import { expect } from '@playwright/test'; | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import { sentryTest } from '../../../utils/fixtures'; | ||
| import { shouldSkipWASMTests } from '../../../utils/wasmHelpers'; | ||
|
|
||
| async function serveWasmFixture(page: Page): Promise<void> { | ||
| // `page.route` resolves with a `Disposable` as of Playwright 1.63, so it can't be returned directly. | ||
| await page.route('**/simple.wasm', (route: Route) => { | ||
| const wasmModule = fs.readFileSync(path.resolve(__dirname, '..', 'simple.wasm')); | ||
|
|
||
| return route.fulfill({ | ||
| status: 200, | ||
| body: wasmModule, | ||
| headers: { | ||
| 'Content-Type': 'application/wasm', | ||
| }, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| // `named.wasm` is `../simple.wasm` plus a module-name subsection (`namedmodule`) | ||
| // in its `name` section. Chrome labels bytes-compiled modules with that name | ||
| // as `wasm://wasm/namedmodule-<hash>`, not with the fetch URL. | ||
| sentryTest( | ||
| 'registers a module loaded via fetch, arrayBuffer and instantiate under its response url', | ||
| 'maps frames of a module compiled from fetched bytes to its debug image', | ||
| async ({ getLocalTestUrl, page, browserName }) => { | ||
| if (shouldSkipWASMTests(browserName)) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
| await serveWasmFixture(page); | ||
|
|
||
| await page.route('**/named.wasm', route => { | ||
| const wasmModule = fs.readFileSync(path.resolve(__dirname, '..', 'named.wasm')); | ||
|
|
||
| return route.fulfill({ | ||
| status: 200, | ||
| body: wasmModule, | ||
| headers: { | ||
| 'Content-Type': 'application/wasm', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| await page.goto(url); | ||
|
|
||
| const images = await page.evaluate(async () => { | ||
| const event = await page.evaluate(async () => { | ||
| // @ts-expect-error this function exists | ||
| return window.loadWasmFromBuffer(); | ||
| return window.getEvent(); | ||
| }); | ||
|
|
||
| expect(images).toEqual([ | ||
| { | ||
| type: 'wasm', | ||
| code_file: 'https://localhost:5887/simple.wasm', | ||
| code_id: '0ba020cdd2444f7eafdd25999a8e9010', | ||
| debug_file: null, | ||
| debug_id: '0ba020cdd2444f7eafdd25999a8e90100', | ||
| }, | ||
| ]); | ||
| expect(event.exception.values[0].stacktrace.frames).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| filename: 'https://localhost:5887/named.wasm', | ||
| function: 'namedmodule.internal_func', | ||
| in_app: true, | ||
| instruction_addr: '0x8c', | ||
| addr_mode: 'rel:0', | ||
| platform: 'native', | ||
| }), | ||
| expect.objectContaining({ | ||
| filename: expect.stringMatching(/subject\.bundle\.js$/), | ||
| function: 'crash', | ||
| in_app: true, | ||
| }), | ||
| ]), | ||
| ); | ||
|
|
||
| expect(event.debug_meta).toMatchObject({ | ||
| images: [ | ||
| { | ||
| code_file: 'https://localhost:5887/named.wasm', | ||
| code_id: '0ba020cdd2444f7eafdd25999a8e9010', | ||
| debug_file: null, | ||
| debug_id: '0ba020cdd2444f7eafdd25999a8e90100', | ||
| type: 'wasm', | ||
| }, | ||
| ], | ||
| }); | ||
| }, | ||
| ); | ||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a worker case? Only the main thread is covered right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a bytes-compiled case to the existing webWorker suite, using
named.wasmso Chrome produces thewasm://wasm/namedmodule-<hash>label.