diff --git a/packages/browser-integration-tests/suites/public-api/wrap/init.js b/packages/browser-integration-tests/suites/public-api/wrap/init.js new file mode 100644 index 000000000000..d8c94f36fdd0 --- /dev/null +++ b/packages/browser-integration-tests/suites/public-api/wrap/init.js @@ -0,0 +1,7 @@ +import * as Sentry from '@sentry/browser'; + +window.Sentry = Sentry; + +Sentry.init({ + dsn: 'https://public@dsn.ingest.sentry.io/1337', +}); diff --git a/packages/browser-integration-tests/suites/public-api/wrap/subject.js b/packages/browser-integration-tests/suites/public-api/wrap/subject.js new file mode 100644 index 000000000000..e7c0f6db282e --- /dev/null +++ b/packages/browser-integration-tests/suites/public-api/wrap/subject.js @@ -0,0 +1,3 @@ +Sentry.wrap(() => { + throw new Error('test'); +}); diff --git a/packages/browser-integration-tests/suites/public-api/wrap/test.ts b/packages/browser-integration-tests/suites/public-api/wrap/test.ts new file mode 100644 index 000000000000..2c5735b670a4 --- /dev/null +++ b/packages/browser-integration-tests/suites/public-api/wrap/test.ts @@ -0,0 +1,21 @@ +import { expect } from '@playwright/test'; +import type { Event } from '@sentry/types'; + +import { sentryTest } from '../../../utils/fixtures'; +import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers'; + +sentryTest('should capture an error within `wrap` and mark it as unhandled', async ({ getLocalTestPath, page }) => { + const url = await getLocalTestPath({ testDir: __dirname }); + + const eventData = await getFirstSentryEnvelopeRequest(page, url); + + expect(eventData.exception?.values).toHaveLength(1); + expect(eventData.exception?.values?.[0]).toMatchObject({ + type: 'Error', + value: 'test', + mechanism: { + type: 'instrument', + handled: false, + }, + }); +}); diff --git a/packages/browser/src/sdk.ts b/packages/browser/src/sdk.ts index 45fd26c75745..e3a4ebb58c45 100644 --- a/packages/browser/src/sdk.ts +++ b/packages/browser/src/sdk.ts @@ -198,7 +198,12 @@ export function onLoad(callback: () => void): void { */ // eslint-disable-next-line @typescript-eslint/no-explicit-any export function wrap(fn: (...args: any) => any): any { - return internalWrap(fn)(); + return internalWrap(fn, { + mechanism: { + type: 'instrument', + handled: false, + }, + })(); } function startSessionOnHub(hub: Hub): void {