Skip to content

ref(browser): Set more descriptive mechanism.type in browserApiErrorsIntergation #17251

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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ sentryTest('should capture target name in mechanism data', async ({ getLocalTest
type: 'Error',
value: 'event_listener_error',
mechanism: {
type: 'instrument',
type: 'auto.browser.browserapierrors.addEventListener',
handled: false,
data: {
function: 'addEventListener',
handler: 'functionListener',
target: 'EventTarget',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ sentryTest('should capture built-in handlers fn name in mechanism data', async (
type: 'Error',
value: 'event_listener_error',
mechanism: {
type: 'instrument',
type: 'auto.browser.browserapierrors.addEventListener',
handled: false,
data: {
function: 'addEventListener',
handler: 'clickHandler',
target: 'EventTarget',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sentryTest('should transparently remove event listeners from wrapped functions',
type: 'Error',
value: 'foo',
mechanism: {
type: 'instrument',
type: 'auto.browser.browserapierrors.addEventListener',
handled: false,
},
stacktrace: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ sentryTest(
type: 'Error',
value: 'event_listener_error',
mechanism: {
type: 'instrument',
type: 'auto.browser.browserapierrors.addEventListener',
handled: false,
data: {
function: 'addEventListener',
handler: '<anonymous>',
target: 'EventTarget',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sentryTest('should capture exceptions inside callback', async ({ getLocalTestUrl
type: 'Error',
value: 'requestAnimationFrame_error',
mechanism: {
type: 'instrument',
type: 'auto.browser.browserapierrors.requestAnimationFrame',
handled: false,
},
stacktrace: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sentryTest('Instrumentation should capture errors in setInterval', async ({ getL
type: 'Error',
value: 'setInterval_error',
mechanism: {
type: 'instrument',
type: 'auto.browser.browserapierrors.setInterval',
handled: false,
},
stacktrace: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ sentryTest('Instrumentation should capture errors in setTimeout', async ({ getLo
type: 'Error',
value: 'setTimeout_error',
mechanism: {
type: 'instrument',
type: 'auto.browser.browserapierrors.setTimeout',
handled: false,
data: {
function: 'setTimeout',
},
},
stacktrace: {
frames: expect.any(Array),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sentryTest(
type: 'Error',
value: 'setTimeout_error',
mechanism: {
type: 'instrument',
type: 'auto.browser.browserapierrors.setTimeout',
handled: false,
},
stacktrace: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ sentryTest(
type: 'Error',
value: 'xhr_error',
mechanism: {
type: 'instrument',
type: 'auto.browser.browserapierrors.xhr.onreadystatechange',
Copy link

Choose a reason for hiding this comment

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

Bug: Test Expectation Mismatch with Exception Data

The test expects the exception mechanism to omit the data field, but the _wrapXHR implementation still includes data: { handler: getFunctionName(original) }. The test expectation should be updated to match this, expecting data: { handler: expect.any(String) }.

Fix in Cursor Fix in Web

handled: false,
data: {
function: 'onreadystatechange',
},
},
stacktrace: {
frames: expect.any(Array),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('sends an error', async ({ page }) => {
type: 'TypeError',
value: 'this.nonExistentFunction is not a function',
mechanism: {
type: 'instrument',
type: 'auto.browser.browserapierrors.addEventListener',
handled: false,
},
},
Expand Down Expand Up @@ -55,7 +55,7 @@ test('assigns the correct transaction value after a navigation', async ({ page }
type: 'TypeError',
value: 'this.nonExistentFunction is not a function',
mechanism: {
type: 'instrument',
type: 'auto.browser.browserapierrors.addEventListener',
handled: false,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('sends an error', async ({ page }) => {
type: 'Error',
value: 'Error thrown from Svelte 5 E2E test app',
mechanism: {
type: 'instrument',
type: 'auto.browser.browserapierrors.addEventListener',
handled: false,
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function wrap<T extends WrappableFunction, NonFunction>(
return event;
});

// no need to add a mechanism here, we already add it via an event processor above
Copy link
Member Author

@Lms24 Lms24 Jul 31, 2025

Choose a reason for hiding this comment

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

wrap is only called by browserApiErrors, where I changed type below.

captureException(ex);
});

Expand Down
15 changes: 5 additions & 10 deletions packages/browser/src/integrations/browserapierrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ function _wrapTimeFunction(original: () => void): () => number {
const originalCallback = args[0];
args[0] = wrap(originalCallback, {
mechanism: {
data: { function: getFunctionName(original) },
handled: false,
type: 'instrument',
type: `auto.browser.browserapierrors.${getFunctionName(original)}`,
},
});
return original.apply(this, args);
Expand All @@ -123,11 +122,10 @@ function _wrapRAF(original: () => void): (callback: () => void) => unknown {
wrap(callback, {
mechanism: {
data: {
function: 'requestAnimationFrame',
handler: getFunctionName(original),
},
handled: false,
type: 'instrument',
type: 'auto.browser.browserapierrors.requestAnimationFrame',
},
}),
]);
Expand All @@ -146,11 +144,10 @@ function _wrapXHR(originalSend: () => void): () => void {
const wrapOptions = {
mechanism: {
data: {
function: prop,
handler: getFunctionName(original),
},
handled: false,
type: 'instrument',
type: `auto.browser.browserapierrors.xhr.${prop}`,
},
};

Expand Down Expand Up @@ -194,12 +191,11 @@ function _wrapEventTarget(target: string, integrationOptions: BrowserApiErrorsOp
fn.handleEvent = wrap(fn.handleEvent, {
mechanism: {
data: {
function: 'handleEvent',
handler: getFunctionName(fn),
target,
},
handled: false,
type: 'instrument',
type: 'auto.browser.browserapierrors.handleEvent',
},
});
}
Expand All @@ -216,12 +212,11 @@ function _wrapEventTarget(target: string, integrationOptions: BrowserApiErrorsOp
wrap(fn, {
mechanism: {
data: {
function: 'addEventListener',
handler: getFunctionName(fn),
target,
},
handled: false,
type: 'instrument',
type: 'auto.browser.browserapierrors.addEventListener',
},
}),
options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('should report a manually captured message on click with the correct stackt
type: 'Error',
value: 'ClickError',
stacktrace: { frames: expect.any(Array) },
mechanism: { type: 'instrument', handled: false },
mechanism: { type: 'auto.browser.browserapierrors.addEventListener', handled: false },
},
]);

Expand Down