diff --git a/packages/core/src/app/common/error/SentryErrorLogger.spec.ts b/packages/core/src/app/common/error/SentryErrorLogger.spec.ts index 2a5b167fe7..7339074628 100644 --- a/packages/core/src/app/common/error/SentryErrorLogger.spec.ts +++ b/packages/core/src/app/common/error/SentryErrorLogger.spec.ts @@ -65,6 +65,68 @@ describe('SentryErrorLogger', () => { expect(clientOptions.sampleRate).toBe(0.123); }); + it('does not log exception event if it relates to convertcart', () => { + new SentryErrorLogger(config); + + const clientOptions: BrowserOptions = (init as jest.Mock).mock.calls[0][0]; + /* eslint-disable @typescript-eslint/naming-convention */ + const event = { + breadcrumbs: [ + { + timestamp: 1667952544.208, + category: 'fetch', + data: { + method: 'POST', + url: 'https://dc4.convertcart.com/event/v3/94892041/123.123', + status_code: 200, + }, + type: 'http', + }, + { + timestamp: 1667952544.549, + category: 'fetch', + data: { + method: 'GET', + url: '/api/storefront/checkouts/abcdefg', + status_code: 200, + }, + type: 'http', + }, + ], + exception: { + values: [ + { + type: 'TypeError', + value: "Cannot read properties of null (reading 'setAttribute')", + stacktrace: { + frames: [ + { + filename: 'app:///608-12345.js', + function: 'u', + in_app: true, + lineno: 1, + colno: 10602, + }, + ], + }, + mechanism: { + type: 'instrument', + handled: true, + data: { + function: 'setInterval', + }, + }, + }, + ], + }, + }; + /* eslint-enable @typescript-eslint/naming-convention */ + const hint = { originalException: new Error('Unexpected error') }; + + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + expect(clientOptions.beforeSend!(event, hint)).toBeNull(); + }); + it('does not log exception event if it does not contain stacktrace', () => { new SentryErrorLogger(config); @@ -169,7 +231,7 @@ describe('SentryErrorLogger', () => { expect(init).toHaveBeenCalledWith( expect.objectContaining({ - denyUrls: ['polyfill~checkout', 'sentry~checkout'], + denyUrls: ['polyfill~checkout', 'sentry~checkout', 'convertcart'], }), ); }); diff --git a/packages/core/src/app/common/error/SentryErrorLogger.ts b/packages/core/src/app/common/error/SentryErrorLogger.ts index de0c8ddb77..0c782dfc27 100644 --- a/packages/core/src/app/common/error/SentryErrorLogger.ts +++ b/packages/core/src/app/common/error/SentryErrorLogger.ts @@ -45,7 +45,7 @@ export default class SentryErrorLogger implements ErrorLogger { init({ sampleRate: SAMPLE_RATE, beforeSend: this.handleBeforeSend, - denyUrls: [...(config.denyUrls || []), 'polyfill~checkout', 'sentry~checkout'], + denyUrls: [...(config.denyUrls || []), 'polyfill~checkout', 'sentry~checkout', 'convertcart'], integrations: [ new Integrations.GlobalHandlers({ onerror: false, @@ -135,6 +135,12 @@ export default class SentryErrorLogger implements ErrorLogger { } private handleBeforeSend: (event: Event, hint?: EventHint) => Event | null = (event, hint) => { + if ( + event.breadcrumbs?.filter((breadcrumb) => breadcrumb.data?.url.includes('convertcart')) + ) { + return null; + } + if (event.exception) { if ( !this.shouldReportExceptions(