diff --git a/packages/sdk-core/src/BacktraceCoreClient.ts b/packages/sdk-core/src/BacktraceCoreClient.ts index 6e28694e..d6ec9cca 100644 --- a/packages/sdk-core/src/BacktraceCoreClient.ts +++ b/packages/sdk-core/src/BacktraceCoreClient.ts @@ -153,6 +153,9 @@ export abstract class BacktraceCoreClient { : new BacktraceReport(data, reportAttributes, [], { skipFrames: this.skipFrameOnMessage(data), }); + if (this.options.skipReport && this.options.skipReport(report)) { + return; + } const backtraceData = this.generateSubmissionData(report); if (!backtraceData) { diff --git a/packages/sdk-core/src/model/configuration/BacktraceConfiguration.ts b/packages/sdk-core/src/model/configuration/BacktraceConfiguration.ts index 847d1a28..8dd31aca 100644 --- a/packages/sdk-core/src/model/configuration/BacktraceConfiguration.ts +++ b/packages/sdk-core/src/model/configuration/BacktraceConfiguration.ts @@ -1,5 +1,6 @@ import { BacktraceAttachment } from '../attachment'; import { BacktraceData } from '../data/BacktraceData'; +import { BacktraceReport } from '../report/BacktraceReport'; import { BacktraceDatabaseConfiguration } from './BacktraceDatabaseConfiguration'; export interface BacktraceMetricsOptions { @@ -64,6 +65,12 @@ export interface BacktraceConfiguration { */ beforeSend?: (data: BacktraceData) => BacktraceData | undefined; + /** + * If you want to ignore specific types of error reports, we recommend that you use the skipReport callback. + * By using it, based on the data generated in the report, you can decide to filter the report, or send it to + * Backtrace. + */ + skipReport?: (report: BacktraceReport) => boolean; /** * Limits the number of reports the client will send per minute. If set to '0', there is no limit. * If set to a value greater than '0' and the value is reached, the client will not send any reports until the next minute. diff --git a/packages/sdk-core/tests/client/clientCallbacksTests.spec.ts b/packages/sdk-core/tests/client/clientCallbacksTests.spec.ts index 895317fa..16853d70 100644 --- a/packages/sdk-core/tests/client/clientCallbacksTests.spec.ts +++ b/packages/sdk-core/tests/client/clientCallbacksTests.spec.ts @@ -47,4 +47,35 @@ describe('Client callbacks tests', () => { expect(client.requestHandler.postError).not.toHaveBeenCalled(); }); }); + + describe('Report filtering tests', () => { + it('Should send a report if the filter is not set', async () => { + const client = BacktraceTestClient.buildFakeClient(); + + await client.send(new Error()); + expect(client.requestHandler.postError).toHaveBeenCalled(); + }); + + it('Should send a report if the filter returns false ', async () => { + const client = BacktraceTestClient.buildFakeClient({ + skipReport: () => { + return false; + }, + }); + + await client.send(new Error()); + expect(client.requestHandler.postError).toHaveBeenCalled(); + }); + + it('Should not send a report if the filter returns true ', async () => { + const client = BacktraceTestClient.buildFakeClient({ + skipReport: () => { + return true; + }, + }); + + await client.send(new Error()); + expect(client.requestHandler.postError).not.toHaveBeenCalled(); + }); + }); });