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
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 8 additions & 7 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ integrations from the `Integrations.XXX` hash, is deprecated in favor of using t

The following list shows how integrations should be migrated:

| Old | New |
| ------------------------ | ------------------------------- |
| `new InboundFilters()` | `inboundFiltersIntegrations()` |
| `new FunctionToString()` | `functionToStringIntegration()` |
| `new LinkedErrors()` | `linkedErrorsIntegration()` |
| `new ModuleMetadata()` | `moduleMetadataIntegration()` |
| `new RequestData()` | `requestDataIntegration()` |
| Old | New | Packages |
| ------------------------ | ------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `new InboundFilters()` | `inboundFiltersIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
| `new FunctionToString()` | `functionToStringIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
| `new LinkedErrors()` | `linkedErrorsIntegration()` | `@sentry/core`, `@sentry/browser`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
| `new ModuleMetadata()` | `moduleMetadataIntegration()` | `@sentry/core`, `@sentry/browser` |
| `new RequestData()` | `requestDataIntegration()` | `@sentry/core`, `@sentry/node`, `@sentry/deno`, `@sentry/bun`, `@sentry/vercel-edge` |
| `new Wasm() ` | `wasmIntegration()` | `@sentry/wasm` |

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

Expand Down
107 changes: 56 additions & 51 deletions packages/wasm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,63 @@
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?

*
* @deprecated Use `wasmIntegration` export instead
*
* import { wasmIntegration } from '@sentry/wasm';
*
* ```
* Sentry.init({ integrations: [wasmIntegration()] });
* ```
*/
// 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 +78,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;
}
}