Skip to content

Commit daf1357

Browse files
committed
feat: Compare fingerprints for exceptionEvents
1 parent 858554b commit daf1357

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

packages/browser/src/integrations/dedupe.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,14 @@ export class Dedupe implements Integration {
4040
return false;
4141
}
4242

43-
if (this.isSameMessage(currentEvent, previousEvent)) {
44-
if (!this.isSameFingerprint(currentEvent, previousEvent)) {
45-
return false;
46-
}
47-
48-
if (!this.isSameStacktrace(currentEvent, previousEvent)) {
49-
return false;
50-
}
51-
43+
if (this.isSameMessageEvent(currentEvent, previousEvent)) {
5244
logger.warn(
5345
`Event dropped due to being a duplicate of previous event (same message).\n Event: ${currentEvent.event_id}`,
5446
);
5547
return true;
5648
}
5749

58-
if (this.isSameException(currentEvent, previousEvent)) {
50+
if (this.isSameExceptionEvent(currentEvent, previousEvent)) {
5951
logger.warn(
6052
`Event dropped due to being a duplicate of previous event (same exception).\n Event: ${currentEvent.event_id}`,
6153
);
@@ -66,7 +58,7 @@ export class Dedupe implements Integration {
6658
}
6759

6860
/** JSDoc */
69-
private isSameMessage(currentEvent: SentryEvent, previousEvent: SentryEvent): boolean {
61+
private isSameMessageEvent(currentEvent: SentryEvent, previousEvent: SentryEvent): boolean {
7062
const currentMessage = currentEvent.message;
7163
const previousMessage = previousEvent.message;
7264

@@ -80,8 +72,19 @@ export class Dedupe implements Integration {
8072
return false;
8173
}
8274

83-
// Otherwise, compare the two
84-
return currentMessage === previousMessage;
75+
if (currentMessage !== previousMessage) {
76+
return false;
77+
}
78+
79+
if (!this.isSameFingerprint(currentEvent, previousEvent)) {
80+
return false;
81+
}
82+
83+
if (!this.isSameStacktrace(currentEvent, previousEvent)) {
84+
return false;
85+
}
86+
87+
return true;
8588
}
8689

8790
/** JSDoc */
@@ -149,7 +152,7 @@ export class Dedupe implements Integration {
149152
}
150153

151154
/** JSDoc */
152-
private isSameException(currentEvent: SentryEvent, previousEvent: SentryEvent): boolean {
155+
private isSameExceptionEvent(currentEvent: SentryEvent, previousEvent: SentryEvent): boolean {
153156
const previousException = this.getExceptionFromEvent(previousEvent);
154157
const currentException = this.getExceptionFromEvent(currentEvent);
155158

@@ -161,7 +164,15 @@ export class Dedupe implements Integration {
161164
return false;
162165
}
163166

164-
return this.isSameStacktrace(currentEvent, previousEvent);
167+
if (!this.isSameFingerprint(currentEvent, previousEvent)) {
168+
return false;
169+
}
170+
171+
if (!this.isSameStacktrace(currentEvent, previousEvent)) {
172+
return false;
173+
}
174+
175+
return true;
165176
}
166177

167178
/** JSDoc */

packages/browser/test/integrations/dedupe.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const exceptionEvent = {
5151
},
5252
],
5353
},
54+
fingerprint: ['MrSnuffles'],
5455
};
5556

5657
describe('Dedupe', () => {
@@ -101,6 +102,11 @@ describe('Dedupe', () => {
101102
});
102103

103104
describe('shouldDropEvent(exceptionEvent)', () => {
105+
it('should not drop if there was no previous event', () => {
106+
const event = clone(exceptionEvent);
107+
expect(dedupe.shouldDropEvent(event)).equal(false);
108+
});
109+
104110
it('should drop when events type, value and stacktrace are the same', () => {
105111
const event = clone(exceptionEvent);
106112
expect(dedupe.shouldDropEvent(event, event)).equal(true);
@@ -126,5 +132,30 @@ describe('Dedupe', () => {
126132
eventB.exception.values[0].stacktrace.frames[0].colno = 1337;
127133
expect(dedupe.shouldDropEvent(eventA, eventB)).equal(false);
128134
});
135+
136+
it('should drop if there are two events with same exception and no fingerprints', () => {
137+
const eventA = clone(exceptionEvent);
138+
delete eventA.fingerprint;
139+
const eventB = clone(exceptionEvent);
140+
delete eventB.fingerprint;
141+
expect(dedupe.shouldDropEvent(eventA, eventB)).equal(true);
142+
});
143+
144+
it('should drop if there are two events with same exception and same fingerprints', () => {
145+
const eventA = clone(exceptionEvent);
146+
const eventB = clone(exceptionEvent);
147+
expect(dedupe.shouldDropEvent(eventA, eventB)).equal(true);
148+
});
149+
150+
it('should not drop if there are two events with same exception but different fingerprints', () => {
151+
const eventA = clone(exceptionEvent);
152+
const eventB = clone(exceptionEvent);
153+
eventA.fingerprint = ['Birdperson'];
154+
const eventC = clone(exceptionEvent);
155+
delete eventC.fingerprint;
156+
expect(dedupe.shouldDropEvent(eventA, eventB)).equal(false);
157+
expect(dedupe.shouldDropEvent(eventA, eventC)).equal(false);
158+
expect(dedupe.shouldDropEvent(eventB, eventC)).equal(false);
159+
});
129160
});
130161
});

0 commit comments

Comments
 (0)