Skip to content
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

ref(wasm): Convert wasm integration to functional integration #10230

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
99 changes: 48 additions & 51 deletions packages/wasm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
import type { Event, Integration, StackFrame } from '@sentry/types';
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
import type { Event, Integration, IntegrationClass, IntegrationFn, StackFrame } from '@sentry/types';

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

/** plz don't */
const INTEGRATION_NAME = 'Wasm';

const _wasmIntegration = (() => {
return {
name: INTEGRATION_NAME,
setupOnce() {
patchWebAssembly();
},
processEvent(event: Event): Event {
let haveWasm = false;

if (event.exception && event.exception.values) {
event.exception.values.forEach(exception => {
if (exception.stacktrace && exception.stacktrace.frames) {
haveWasm = haveWasm || patchFrames(exception.stacktrace.frames);
}
});
}

if (haveWasm) {
event.debug_meta = event.debug_meta || {};
event.debug_meta.images = [...(event.debug_meta.images || []), ...getImages()];
}

return event;
},
};
}) satisfies IntegrationFn;

export const wasmIntegration = defineIntegration(_wasmIntegration);

/**
* Process WASM stack traces to support server-side symbolication.
*
* This also hooks the WebAssembly loading browser API so that module
* registrations are intercepted.
Copy link
Member

Choose a reason for hiding this comment

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

while at it, let's deprecate this in favor of the function?

*/
// eslint-disable-next-line deprecation/deprecation
export const Wasm = convertIntegrationFnToClass(INTEGRATION_NAME, wasmIntegration) as IntegrationClass<
Integration & { processEvent: (event: Event) => Event }
>;

/**
* Patches a list of stackframes with wasm data needed for server-side symbolication
* if applicable. Returns true if any frames were patched.
*/
function patchFrames(frames: Array<StackFrame>): boolean {
let haveWasm = false;
frames.forEach(frame => {
Expand All @@ -24,52 +70,3 @@ function patchFrames(frames: Array<StackFrame>): boolean {
});
return haveWasm;
}

/**
* Process WASM stack traces to support server-side symbolication.
*
* This also hooks the WebAssembly loading browser API so that module
* registraitons are intercepted.
*/
export class Wasm implements Integration {
/**
* @inheritDoc
*/
public static id: string = 'Wasm';

/**
* @inheritDoc
*/
public name: string;

public constructor() {
this.name = Wasm.id;
}

/**
* @inheritDoc
*/
public setupOnce(_addGlobalEventProcessor: unknown, _getCurrentHub: unknown): void {
patchWebAssembly();
}

/** @inheritDoc */
public processEvent(event: Event): Event {
let haveWasm = false;

if (event.exception && event.exception.values) {
event.exception.values.forEach(exception => {
if (exception?.stacktrace?.frames) {
haveWasm = haveWasm || patchFrames(exception.stacktrace.frames);
}
});
}

if (haveWasm) {
event.debug_meta = event.debug_meta || {};
event.debug_meta.images = [...(event.debug_meta.images || []), ...getImages()];
}

return event;
}
}