Skip to content

Commit 71e56e2

Browse files
authored
Skip report callback (#50)
* Before send event support * Skip report callback * Test name fix
1 parent 7bd533d commit 71e56e2

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

packages/sdk-core/src/BacktraceCoreClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ export abstract class BacktraceCoreClient {
153153
: new BacktraceReport(data, reportAttributes, [], {
154154
skipFrames: this.skipFrameOnMessage(data),
155155
});
156+
if (this.options.skipReport && this.options.skipReport(report)) {
157+
return;
158+
}
156159

157160
const backtraceData = this.generateSubmissionData(report);
158161
if (!backtraceData) {

packages/sdk-core/src/model/configuration/BacktraceConfiguration.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BacktraceAttachment } from '../attachment';
22
import { BacktraceData } from '../data/BacktraceData';
3+
import { BacktraceReport } from '../report/BacktraceReport';
34
import { BacktraceDatabaseConfiguration } from './BacktraceDatabaseConfiguration';
45

56
export interface BacktraceMetricsOptions {
@@ -64,6 +65,12 @@ export interface BacktraceConfiguration {
6465
*/
6566
beforeSend?: (data: BacktraceData) => BacktraceData | undefined;
6667

68+
/**
69+
* If you want to ignore specific types of error reports, we recommend that you use the skipReport callback.
70+
* By using it, based on the data generated in the report, you can decide to filter the report, or send it to
71+
* Backtrace.
72+
*/
73+
skipReport?: (report: BacktraceReport) => boolean;
6774
/**
6875
* Limits the number of reports the client will send per minute. If set to '0', there is no limit.
6976
* If set to a value greater than '0' and the value is reached, the client will not send any reports until the next minute.

packages/sdk-core/tests/client/clientCallbacksTests.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,35 @@ describe('Client callbacks tests', () => {
4747
expect(client.requestHandler.postError).not.toHaveBeenCalled();
4848
});
4949
});
50+
51+
describe('Report filtering tests', () => {
52+
it('Should send a report if the filter is not set', async () => {
53+
const client = BacktraceTestClient.buildFakeClient();
54+
55+
await client.send(new Error());
56+
expect(client.requestHandler.postError).toHaveBeenCalled();
57+
});
58+
59+
it('Should send a report if the filter returns false ', async () => {
60+
const client = BacktraceTestClient.buildFakeClient({
61+
skipReport: () => {
62+
return false;
63+
},
64+
});
65+
66+
await client.send(new Error());
67+
expect(client.requestHandler.postError).toHaveBeenCalled();
68+
});
69+
70+
it('Should not send a report if the filter returns true ', async () => {
71+
const client = BacktraceTestClient.buildFakeClient({
72+
skipReport: () => {
73+
return true;
74+
},
75+
});
76+
77+
await client.send(new Error());
78+
expect(client.requestHandler.postError).not.toHaveBeenCalled();
79+
});
80+
});
5081
});

0 commit comments

Comments
 (0)