-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
index.ts
66 lines (57 loc) · 1.97 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { defineIntegration } from '@sentry/core';
import type { Event, IntegrationFn, StackFrame } from '@sentry/types';
import { patchWebAssembly } from './patchWebAssembly';
import { getImage, getImages } from './registry';
const INTEGRATION_NAME = 'Wasm';
const _wasmIntegration = (() => {
return {
name: INTEGRATION_NAME,
setupOnce() {
patchWebAssembly();
},
processEvent(event: Event): Event {
let hasAtLeastOneWasmFrameWithImage = false;
if (event.exception && event.exception.values) {
event.exception.values.forEach(exception => {
if (exception.stacktrace && exception.stacktrace.frames) {
hasAtLeastOneWasmFrameWithImage =
hasAtLeastOneWasmFrameWithImage || patchFrames(exception.stacktrace.frames);
}
});
}
if (hasAtLeastOneWasmFrameWithImage) {
event.debug_meta = event.debug_meta || {};
event.debug_meta.images = [...(event.debug_meta.images || []), ...getImages()];
}
return event;
},
};
}) satisfies IntegrationFn;
export const wasmIntegration = defineIntegration(_wasmIntegration);
/**
* Patches a list of stackframes with wasm data needed for server-side symbolication
* if applicable. Returns true if the provided list of stack frames had at least one
* matching registered image.
*/
function patchFrames(frames: Array<StackFrame>): boolean {
let hasAtLeastOneWasmFrameWithImage = false;
frames.forEach(frame => {
if (!frame.filename) {
return;
}
const match = frame.filename.match(/^(.*?):wasm-function\[\d+\]:(0x[a-fA-F0-9]+)$/) as
| null
| [string, string, string];
if (match) {
const index = getImage(match[1]);
frame.instruction_addr = match[2];
frame.filename = match[1];
frame.platform = 'native';
if (index >= 0) {
frame.addr_mode = `rel:${index}`;
hasAtLeastOneWasmFrameWithImage = true;
}
}
});
return hasAtLeastOneWasmFrameWithImage;
}