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' ;
2
3
3
4
import { patchWebAssembly } from './patchWebAssembly' ;
4
5
import { getImage , getImages } from './registry' ;
5
6
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
+ */
7
61
function patchFrames ( frames : Array < StackFrame > ) : boolean {
8
62
let haveWasm = false ;
9
63
frames . forEach ( frame => {
@@ -24,52 +78,3 @@ function patchFrames(frames: Array<StackFrame>): boolean {
24
78
} ) ;
25
79
return haveWasm ;
26
80
}
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