@@ -27,7 +27,7 @@ export class Dedupe implements Integration {
2727 if ( self ) {
2828 // Juuust in case something goes wrong
2929 try {
30- if ( _shouldDropEvent ( currentEvent , self . _previousEvent ) ) {
30+ if ( self . _shouldDropEvent ( currentEvent , self . _previousEvent ) ) {
3131 logger . warn ( `Event dropped due to being a duplicate of previously captured event.` ) ;
3232 return null ;
3333 }
@@ -40,164 +40,164 @@ export class Dedupe implements Integration {
4040 return currentEvent ;
4141 } ) ;
4242 }
43- }
44-
45- /** JSDoc */
46- function _shouldDropEvent ( currentEvent : Event , previousEvent ?: Event ) : boolean {
47- if ( ! previousEvent ) {
48- return false ;
49- }
50-
51- if ( _isSameMessageEvent ( currentEvent , previousEvent ) ) {
52- return true ;
53- }
5443
55- if ( _isSameExceptionEvent ( currentEvent , previousEvent ) ) {
56- return true ;
57- }
44+ /** JSDoc */
45+ private _shouldDropEvent ( currentEvent : Event , previousEvent ?: Event ) : boolean {
46+ if ( ! previousEvent ) {
47+ return false ;
48+ }
5849
59- return false ;
60- }
50+ if ( this . _isSameMessageEvent ( currentEvent , previousEvent ) ) {
51+ return true ;
52+ }
6153
62- /** JSDoc */
63- function _isSameMessageEvent ( currentEvent : Event , previousEvent : Event ) : boolean {
64- const currentMessage = currentEvent . message ;
65- const previousMessage = previousEvent . message ;
54+ if ( this . _isSameExceptionEvent ( currentEvent , previousEvent ) ) {
55+ return true ;
56+ }
6657
67- // If neither event has a message property, they were both exceptions, so bail out
68- if ( ! currentMessage && ! previousMessage ) {
6958 return false ;
7059 }
7160
72- // If only one event has a stacktrace, but not the other one, they are not the same
73- if ( ( currentMessage && ! previousMessage ) || ( ! currentMessage && previousMessage ) ) {
74- return false ;
75- }
61+ /** JSDoc */
62+ private _isSameMessageEvent ( currentEvent : Event , previousEvent : Event ) : boolean {
63+ const currentMessage = currentEvent . message ;
64+ const previousMessage = previousEvent . message ;
7665
77- if ( currentMessage !== previousMessage ) {
78- return false ;
79- }
66+ // If neither event has a message property, they were both exceptions, so bail out
67+ if ( ! currentMessage && ! previousMessage ) {
68+ return false ;
69+ }
8070
81- if ( ! _isSameFingerprint ( currentEvent , previousEvent ) ) {
82- return false ;
83- }
71+ // If only one event has a stacktrace, but not the other one, they are not the same
72+ if ( ( currentMessage && ! previousMessage ) || ( ! currentMessage && previousMessage ) ) {
73+ return false ;
74+ }
8475
85- if ( ! _isSameStacktrace ( currentEvent , previousEvent ) ) {
86- return false ;
87- }
76+ if ( currentMessage !== previousMessage ) {
77+ return false ;
78+ }
8879
89- return true ;
90- }
80+ if ( ! this . _isSameFingerprint ( currentEvent , previousEvent ) ) {
81+ return false ;
82+ }
9183
92- /** JSDoc */
93- function _isSameExceptionEvent ( currentEvent : Event , previousEvent : Event ) : boolean {
94- const previousException = _getExceptionFromEvent ( previousEvent ) ;
95- const currentException = _getExceptionFromEvent ( currentEvent ) ;
84+ if ( ! this . _isSameStacktrace ( currentEvent , previousEvent ) ) {
85+ return false ;
86+ }
9687
97- if ( ! previousException || ! currentException ) {
98- return false ;
88+ return true ;
9989 }
10090
101- if ( previousException . type !== currentException . type || previousException . value !== currentException . value ) {
102- return false ;
103- }
91+ /** JSDoc */
92+ private _getFramesFromEvent ( event : Event ) : StackFrame [ ] | undefined {
93+ const exception = event . exception ;
10494
105- if ( ! _isSameFingerprint ( currentEvent , previousEvent ) ) {
106- return false ;
95+ if ( exception ) {
96+ try {
97+ // @ts -ignore Object could be undefined
98+ return exception . values [ 0 ] . stacktrace . frames ;
99+ } catch ( _oO ) {
100+ return undefined ;
101+ }
102+ } else if ( event . stacktrace ) {
103+ return event . stacktrace . frames ;
104+ }
105+ return undefined ;
107106 }
108107
109- if ( ! _isSameStacktrace ( currentEvent , previousEvent ) ) {
110- return false ;
111- }
108+ /** JSDoc */
109+ private _isSameStacktrace ( currentEvent : Event , previousEvent : Event ) : boolean {
110+ let currentFrames = this . _getFramesFromEvent ( currentEvent ) ;
111+ let previousFrames = this . _getFramesFromEvent ( previousEvent ) ;
112112
113- return true ;
114- }
113+ // If neither event has a stacktrace, they are assumed to be the same
114+ if ( ! currentFrames && ! previousFrames ) {
115+ return true ;
116+ }
115117
116- /** JSDoc */
117- function _isSameStacktrace ( currentEvent : Event , previousEvent : Event ) : boolean {
118- let currentFrames = _getFramesFromEvent ( currentEvent ) ;
119- let previousFrames = _getFramesFromEvent ( previousEvent ) ;
118+ // If only one event has a stacktrace, but not the other one, they are not the same
119+ if ( ( currentFrames && ! previousFrames ) || ( ! currentFrames && previousFrames ) ) {
120+ return false ;
121+ }
122+
123+ currentFrames = currentFrames as StackFrame [ ] ;
124+ previousFrames = previousFrames as StackFrame [ ] ;
125+
126+ // If number of frames differ, they are not the same
127+ if ( previousFrames . length !== currentFrames . length ) {
128+ return false ;
129+ }
130+
131+ // Otherwise, compare the two
132+ for ( let i = 0 ; i < previousFrames . length ; i ++ ) {
133+ const frameA = previousFrames [ i ] ;
134+ const frameB = currentFrames [ i ] ;
135+
136+ if (
137+ frameA . filename !== frameB . filename ||
138+ frameA . lineno !== frameB . lineno ||
139+ frameA . colno !== frameB . colno ||
140+ frameA . function !== frameB . function
141+ ) {
142+ return false ;
143+ }
144+ }
120145
121- // If neither event has a stacktrace, they are assumed to be the same
122- if ( ! currentFrames && ! previousFrames ) {
123146 return true ;
124147 }
125148
126- // If only one event has a stacktrace, but not the other one, they are not the same
127- if ( ( currentFrames && ! previousFrames ) || ( ! currentFrames && previousFrames ) ) {
128- return false ;
149+ /** JSDoc */
150+ private _getExceptionFromEvent ( event : Event ) : Exception | undefined {
151+ return event . exception && event . exception . values && event . exception . values [ 0 ] ;
129152 }
130153
131- currentFrames = currentFrames as StackFrame [ ] ;
132- previousFrames = previousFrames as StackFrame [ ] ;
154+ /** JSDoc */
155+ private _isSameExceptionEvent ( currentEvent : Event , previousEvent : Event ) : boolean {
156+ const previousException = this . _getExceptionFromEvent ( previousEvent ) ;
157+ const currentException = this . _getExceptionFromEvent ( currentEvent ) ;
133158
134- // If number of frames differ, they are not the same
135- if ( previousFrames . length !== currentFrames . length ) {
136- return false ;
137- }
159+ if ( ! previousException || ! currentException ) {
160+ return false ;
161+ }
138162
139- // Otherwise, compare the two
140- for ( let i = 0 ; i < previousFrames . length ; i ++ ) {
141- const frameA = previousFrames [ i ] ;
142- const frameB = currentFrames [ i ] ;
143-
144- if (
145- frameA . filename !== frameB . filename ||
146- frameA . lineno !== frameB . lineno ||
147- frameA . colno !== frameB . colno ||
148- frameA . function !== frameB . function
149- ) {
163+ if ( previousException . type !== currentException . type || previousException . value !== currentException . value ) {
150164 return false ;
151165 }
152- }
153166
154- return true ;
155- }
167+ if ( ! this . _isSameFingerprint ( currentEvent , previousEvent ) ) {
168+ return false ;
169+ }
156170
157- /** JSDoc */
158- function _isSameFingerprint ( currentEvent : Event , previousEvent : Event ) : boolean {
159- let currentFingerprint = currentEvent . fingerprint ;
160- let previousFingerprint = previousEvent . fingerprint ;
171+ if ( ! this . _isSameStacktrace ( currentEvent , previousEvent ) ) {
172+ return false ;
173+ }
161174
162- // If neither event has a fingerprint, they are assumed to be the same
163- if ( ! currentFingerprint && ! previousFingerprint ) {
164175 return true ;
165176 }
166177
167- // If only one event has a fingerprint, but not the other one, they are not the same
168- if ( ( currentFingerprint && ! previousFingerprint ) || ( ! currentFingerprint && previousFingerprint ) ) {
169- return false ;
170- }
171-
172- currentFingerprint = currentFingerprint as string [ ] ;
173- previousFingerprint = previousFingerprint as string [ ] ;
178+ /** JSDoc */
179+ private _isSameFingerprint ( currentEvent : Event , previousEvent : Event ) : boolean {
180+ let currentFingerprint = currentEvent . fingerprint ;
181+ let previousFingerprint = previousEvent . fingerprint ;
174182
175- // Otherwise, compare the two
176- try {
177- return ! ! ( currentFingerprint . join ( '' ) === previousFingerprint . join ( '' ) ) ;
178- } catch ( _oO ) {
179- return false ;
180- }
181- }
183+ // If neither event has a fingerprint, they are assumed to be the same
184+ if ( ! currentFingerprint && ! previousFingerprint ) {
185+ return true ;
186+ }
182187
183- /** JSDoc */
184- function _getExceptionFromEvent ( event : Event ) : Exception | undefined {
185- return event . exception && event . exception . values && event . exception . values [ 0 ] ;
186- }
188+ // If only one event has a fingerprint, but not the other one, they are not the same
189+ if ( ( currentFingerprint && ! previousFingerprint ) || ( ! currentFingerprint && previousFingerprint ) ) {
190+ return false ;
191+ }
187192
188- /** JSDoc */
189- function _getFramesFromEvent ( event : Event ) : StackFrame [ ] | undefined {
190- const exception = event . exception ;
193+ currentFingerprint = currentFingerprint as string [ ] ;
194+ previousFingerprint = previousFingerprint as string [ ] ;
191195
192- if ( exception ) {
196+ // Otherwise, compare the two
193197 try {
194- // @ts -ignore Object could be undefined
195- return exception . values [ 0 ] . stacktrace . frames ;
198+ return ! ! ( currentFingerprint . join ( '' ) === previousFingerprint . join ( '' ) ) ;
196199 } catch ( _oO ) {
197- return undefined ;
200+ return false ;
198201 }
199- } else if ( event . stacktrace ) {
200- return event . stacktrace . frames ;
201202 }
202- return undefined ;
203203}
0 commit comments