Skip to content

Commit 5f0b506

Browse files
authored
ref(wasm): Convert wasm integration to functional integration (#10230)
We should think about moving the wasm integration into `@sentry/browser` and removing `@sentry/wasm` all together. What do you think?
1 parent 1cceeae commit 5f0b506

File tree

2 files changed

+64
-58
lines changed

2 files changed

+64
-58
lines changed

MIGRATION.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ integrations from the `Integrations.XXX` hash, is deprecated in favor of using t
2828

2929
The following list shows how integrations should be migrated:
3030

31-
| Old | New |
32-
| ------------------------ | ------------------------------- |
33-
| `new InboundFilters()` | `inboundFiltersIntegrations()` |
34-
| `new FunctionToString()` | `functionToStringIntegration()` |
35-
| `new LinkedErrors()` | `linkedErrorsIntegration()` |
36-
| `new ModuleMetadata()` | `moduleMetadataIntegration()` |
37-
| `new RequestData()` | `requestDataIntegration()` |
31+
| Old | New | Packages |
32+
| ------------------------ | ------------------------------- | ------------------------------------------------------------------------------------------------------- |
33+
| `new InboundFilters()` | `inboundFiltersIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
34+
| `new FunctionToString()` | `functionToStringIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
35+
| `new LinkedErrors()` | `linkedErrorsIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
36+
| `new ModuleMetadata()` | `moduleMetadataIntegration()` | `@sentry/core`, `@sentry/browser` |
37+
| `new RequestData()` | `requestDataIntegration()` | `@sentry/core`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
38+
| `new Wasm() ` | `wasmIntegration()` | `@sentry/wasm` |
3839

3940
## Deprecate `hub.bindClient()` and `makeMain()`
4041

packages/wasm/src/index.ts

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,63 @@
1-
import type { Event, Integration, StackFrame } from '@sentry/types';
1+
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
2+
import type { Event, Integration, IntegrationClass, IntegrationFn, StackFrame } from '@sentry/types';
23

34
import { patchWebAssembly } from './patchWebAssembly';
45
import { getImage, getImages } from './registry';
56

6-
/** plz don't */
7+
const INTEGRATION_NAME = 'Wasm';
8+
9+
const _wasmIntegration = (() => {
10+
return {
11+
name: INTEGRATION_NAME,
12+
setupOnce() {
13+
patchWebAssembly();
14+
},
15+
processEvent(event: Event): Event {
16+
let haveWasm = false;
17+
18+
if (event.exception && event.exception.values) {
19+
event.exception.values.forEach(exception => {
20+
if (exception.stacktrace && exception.stacktrace.frames) {
21+
haveWasm = haveWasm || patchFrames(exception.stacktrace.frames);
22+
}
23+
});
24+
}
25+
26+
if (haveWasm) {
27+
event.debug_meta = event.debug_meta || {};
28+
event.debug_meta.images = [...(event.debug_meta.images || []), ...getImages()];
29+
}
30+
31+
return event;
32+
},
33+
};
34+
}) satisfies IntegrationFn;
35+
36+
export const wasmIntegration = defineIntegration(_wasmIntegration);
37+
38+
/**
39+
* Process WASM stack traces to support server-side symbolication.
40+
*
41+
* This also hooks the WebAssembly loading browser API so that module
42+
* registrations are intercepted.
43+
*
44+
* @deprecated Use `wasmIntegration` export instead
45+
*
46+
* import { wasmIntegration } from '@sentry/wasm';
47+
*
48+
* ```
49+
* Sentry.init({ integrations: [wasmIntegration()] });
50+
* ```
51+
*/
52+
// eslint-disable-next-line deprecation/deprecation
53+
export const Wasm = convertIntegrationFnToClass(INTEGRATION_NAME, wasmIntegration) as IntegrationClass<
54+
Integration & { processEvent: (event: Event) => Event }
55+
>;
56+
57+
/**
58+
* Patches a list of stackframes with wasm data needed for server-side symbolication
59+
* if applicable. Returns true if any frames were patched.
60+
*/
761
function patchFrames(frames: Array<StackFrame>): boolean {
862
let haveWasm = false;
963
frames.forEach(frame => {
@@ -24,52 +78,3 @@ function patchFrames(frames: Array<StackFrame>): boolean {
2478
});
2579
return haveWasm;
2680
}
27-
28-
/**
29-
* Process WASM stack traces to support server-side symbolication.
30-
*
31-
* This also hooks the WebAssembly loading browser API so that module
32-
* registraitons are intercepted.
33-
*/
34-
export class Wasm implements Integration {
35-
/**
36-
* @inheritDoc
37-
*/
38-
public static id: string = 'Wasm';
39-
40-
/**
41-
* @inheritDoc
42-
*/
43-
public name: string;
44-
45-
public constructor() {
46-
this.name = Wasm.id;
47-
}
48-
49-
/**
50-
* @inheritDoc
51-
*/
52-
public setupOnce(_addGlobalEventProcessor: unknown, _getCurrentHub: unknown): void {
53-
patchWebAssembly();
54-
}
55-
56-
/** @inheritDoc */
57-
public processEvent(event: Event): Event {
58-
let haveWasm = false;
59-
60-
if (event.exception && event.exception.values) {
61-
event.exception.values.forEach(exception => {
62-
if (exception?.stacktrace?.frames) {
63-
haveWasm = haveWasm || patchFrames(exception.stacktrace.frames);
64-
}
65-
});
66-
}
67-
68-
if (haveWasm) {
69-
event.debug_meta = event.debug_meta || {};
70-
event.debug_meta.images = [...(event.debug_meta.images || []), ...getImages()];
71-
}
72-
73-
return event;
74-
}
75-
}

0 commit comments

Comments
 (0)