Skip to content

Commit

Permalink
ref(wasm): Convert wasm integration to functional integration (#10230)
Browse files Browse the repository at this point in the history
We should think about moving the wasm integration into `@sentry/browser`
and removing `@sentry/wasm` all together. What do you think?
  • Loading branch information
AbhiPrasad committed Jan 19, 2024
1 parent 1cceeae commit 5f0b506
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 58 deletions.
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.
*
* @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;
}
}

0 comments on commit 5f0b506

Please sign in to comment.