From c919c48b7eab0e98e99b6c89c16e910b10ed1e0a Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Wed, 17 Jan 2024 15:22:39 -0500 Subject: [PATCH 1/2] ref(wasm): Convert wasm integration to functional integration --- packages/wasm/src/index.ts | 99 ++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/packages/wasm/src/index.ts b/packages/wasm/src/index.ts index 49487167e346..977cea8a753e 100644 --- a/packages/wasm/src/index.ts +++ b/packages/wasm/src/index.ts @@ -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. + */ +// 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): boolean { let haveWasm = false; frames.forEach(frame => { @@ -24,52 +70,3 @@ function patchFrames(frames: Array): 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; - } -} From e136a8f021e75440d3a3701a61605eeda91dd778 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 18 Jan 2024 09:23:46 -0500 Subject: [PATCH 2/2] add deprecation for wasm integration --- MIGRATION.md | 15 ++++++++------- packages/wasm/src/index.ts | 8 ++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index df21637dc6a4..7e89369a9713 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -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()` diff --git a/packages/wasm/src/index.ts b/packages/wasm/src/index.ts index 977cea8a753e..e84d4c880bd5 100644 --- a/packages/wasm/src/index.ts +++ b/packages/wasm/src/index.ts @@ -40,6 +40,14 @@ export const wasmIntegration = defineIntegration(_wasmIntegration); * * 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<