Skip to content
Merged
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
3 changes: 3 additions & 0 deletions packages/sdk-core/src/BacktraceCoreClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions packages/sdk-core/tests/client/clientCallbacksTests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});