Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
rename option + simplify check
  • Loading branch information
chargome committed Dec 30, 2025
commit 86d701e11ff7fe52e00810c2fb24bc0b9bcffdcf
24 changes: 11 additions & 13 deletions packages/core/src/integrations/third-party-errors-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ interface Options {

/**
* @experimental
* If set to true, the integration will exclude frames that are internal to the Sentry SDK from the third-party frame detection.
* If set to true, the integration will ignore frames that are internal to the Sentry SDK from the third-party frame detection.
* Note that enabling this option might lead to errors being misclassified as third-party errors.
*/
experimentalExcludeSentryInternalFrames?: boolean;
ignoreSentryInternalFrames?: boolean;
}

/**
Expand Down Expand Up @@ -75,7 +75,7 @@ export const thirdPartyErrorFilterIntegration = defineIntegration((options: Opti
},

processEvent(event) {
const frameKeys = getBundleKeysForAllFramesWithFilenames(event, options.experimentalExcludeSentryInternalFrames);
const frameKeys = getBundleKeysForAllFramesWithFilenames(event, options.ignoreSentryInternalFrames);

if (frameKeys) {
const arrayMethod =
Expand Down Expand Up @@ -120,13 +120,11 @@ function isSentryInternalFrame(frame: StackFrame, frameIndex: number): boolean {
return false;
}

// Filename would look something like this: 'node_modules/@sentry/browser/build/npm/esm/helpers.js'
if (!frame.filename.includes('sentry') || !frame.filename.includes('helpers')) {
return false;
}

// Must have context_line with the exact fn.apply pattern (case-sensitive)
if (!frame.context_line.includes(SENTRY_INTERNAL_FN_APPLY)) {
if (
!frame.filename.includes('sentry') ||
!frame.filename.includes('helpers') || // Filename would look something like this: 'node_modules/@sentry/browser/build/npm/esm/helpers.js'
!frame.context_line.includes(SENTRY_INTERNAL_FN_APPLY) // Must have context_line with the exact fn.apply pattern
) {
return false;
}

Expand All @@ -145,7 +143,7 @@ function isSentryInternalFrame(frame: StackFrame, frameIndex: number): boolean {

function getBundleKeysForAllFramesWithFilenames(
event: Event,
excludeSentryInternalFrames?: boolean,
ignoreSentryInternalFrames?: boolean,
): string[][] | undefined {
const frames = getFramesFromEvent(event);

Expand All @@ -160,8 +158,8 @@ function getBundleKeysForAllFramesWithFilenames(
if (!frame.filename || (frame.lineno == null && frame.colno == null)) {
return false;
}
// Optionally exclude Sentry internal frames
return !excludeSentryInternalFrames || !isSentryInternalFrame(frame, index);
// Optionally ignore Sentry internal frames
return !ignoreSentryInternalFrames || !isSentryInternalFrame(frame, index);
})
.map(frame => {
if (!frame.module_metadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ describe('ThirdPartyErrorFilter', () => {
const integration = thirdPartyErrorFilterIntegration({
behaviour: 'drop-error-if-exclusively-contains-third-party-frames',
filterKeys: ['some-key'],
experimentalExcludeSentryInternalFrames: true,
ignoreSentryInternalFrames: true,
});

const event = clone(eventWithThirdPartyAndSentryInternalFrames);
Expand All @@ -380,7 +380,7 @@ describe('ThirdPartyErrorFilter', () => {
const integration = thirdPartyErrorFilterIntegration({
behaviour: 'drop-error-if-exclusively-contains-third-party-frames',
filterKeys: ['some-key'],
experimentalExcludeSentryInternalFrames: true,
ignoreSentryInternalFrames: true,
});

const event = clone(eventWithThirdPartySentryInternalAndFirstPartyFrames);
Expand All @@ -392,7 +392,7 @@ describe('ThirdPartyErrorFilter', () => {
const integration = thirdPartyErrorFilterIntegration({
behaviour: 'drop-error-if-exclusively-contains-third-party-frames',
filterKeys: ['some-key'],
experimentalExcludeSentryInternalFrames: false,
ignoreSentryInternalFrames: false,
});

const event = clone(eventWithThirdPartyAndSentryInternalFrames);
Expand All @@ -419,7 +419,7 @@ describe('ThirdPartyErrorFilter', () => {
const integration = thirdPartyErrorFilterIntegration({
behaviour: 'drop-error-if-contains-third-party-frames',
filterKeys: ['some-key'],
experimentalExcludeSentryInternalFrames: true,
ignoreSentryInternalFrames: true,
});

const event = clone(eventWithThirdPartyAndSentryInternalFrames);
Expand All @@ -431,7 +431,7 @@ describe('ThirdPartyErrorFilter', () => {
const integration = thirdPartyErrorFilterIntegration({
behaviour: 'drop-error-if-contains-third-party-frames',
filterKeys: ['some-key'],
experimentalExcludeSentryInternalFrames: true,
ignoreSentryInternalFrames: true,
});

const event = clone(eventWithThirdPartySentryInternalAndFirstPartyFrames);
Expand Down Expand Up @@ -478,7 +478,7 @@ describe('ThirdPartyErrorFilter', () => {
const integration = thirdPartyErrorFilterIntegration({
behaviour: 'drop-error-if-exclusively-contains-third-party-frames',
filterKeys: ['some-key'],
experimentalExcludeSentryInternalFrames: true,
ignoreSentryInternalFrames: true,
});

const event = clone(eventWithContextLine);
Expand Down Expand Up @@ -522,7 +522,7 @@ describe('ThirdPartyErrorFilter', () => {
const integration = thirdPartyErrorFilterIntegration({
behaviour: 'drop-error-if-exclusively-contains-third-party-frames',
filterKeys: ['some-key'],
experimentalExcludeSentryInternalFrames: true,
ignoreSentryInternalFrames: true,
});

const event = clone(eventWithPreContext);
Expand Down Expand Up @@ -566,7 +566,7 @@ describe('ThirdPartyErrorFilter', () => {
const integration = thirdPartyErrorFilterIntegration({
behaviour: 'drop-error-if-exclusively-contains-third-party-frames',
filterKeys: ['some-key'],
experimentalExcludeSentryInternalFrames: true,
ignoreSentryInternalFrames: true,
});

const event = clone(eventWithoutFnApply);
Expand Down Expand Up @@ -617,7 +617,7 @@ describe('ThirdPartyErrorFilter', () => {
const integration = thirdPartyErrorFilterIntegration({
behaviour: 'drop-error-if-exclusively-contains-third-party-frames',
filterKeys: ['some-key'],
experimentalExcludeSentryInternalFrames: true,
ignoreSentryInternalFrames: true,
});

const event = clone(eventWithSentryFrameNotLast);
Expand Down Expand Up @@ -662,7 +662,7 @@ describe('ThirdPartyErrorFilter', () => {
const integration = thirdPartyErrorFilterIntegration({
behaviour: 'drop-error-if-exclusively-contains-third-party-frames',
filterKeys: ['some-key'],
experimentalExcludeSentryInternalFrames: true,
ignoreSentryInternalFrames: true,
});

const event = clone(eventWithWrongFilename);
Expand Down
Loading