@@ -27,7 +27,7 @@ export class Dedupe implements Integration {
27
27
if ( self ) {
28
28
// Juuust in case something goes wrong
29
29
try {
30
- if ( _shouldDropEvent ( currentEvent , self . _previousEvent ) ) {
30
+ if ( self . _shouldDropEvent ( currentEvent , self . _previousEvent ) ) {
31
31
logger . warn ( `Event dropped due to being a duplicate of previously captured event.` ) ;
32
32
return null ;
33
33
}
@@ -40,164 +40,164 @@ export class Dedupe implements Integration {
40
40
return currentEvent ;
41
41
} ) ;
42
42
}
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
- }
54
43
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
+ }
58
49
59
- return false ;
60
- }
50
+ if ( this . _isSameMessageEvent ( currentEvent , previousEvent ) ) {
51
+ return true ;
52
+ }
61
53
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
+ }
66
57
67
- // If neither event has a message property, they were both exceptions, so bail out
68
- if ( ! currentMessage && ! previousMessage ) {
69
58
return false ;
70
59
}
71
60
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 ;
76
65
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
+ }
80
70
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
+ }
84
75
85
- if ( ! _isSameStacktrace ( currentEvent , previousEvent ) ) {
86
- return false ;
87
- }
76
+ if ( currentMessage !== previousMessage ) {
77
+ return false ;
78
+ }
88
79
89
- return true ;
90
- }
80
+ if ( ! this . _isSameFingerprint ( currentEvent , previousEvent ) ) {
81
+ return false ;
82
+ }
91
83
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
+ }
96
87
97
- if ( ! previousException || ! currentException ) {
98
- return false ;
88
+ return true ;
99
89
}
100
90
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 ;
104
94
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 ;
107
106
}
108
107
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 ) ;
112
112
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
+ }
115
117
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
+ }
120
145
121
- // If neither event has a stacktrace, they are assumed to be the same
122
- if ( ! currentFrames && ! previousFrames ) {
123
146
return true ;
124
147
}
125
148
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 ] ;
129
152
}
130
153
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 ) ;
133
158
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
+ }
138
162
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 ) {
150
164
return false ;
151
165
}
152
- }
153
166
154
- return true ;
155
- }
167
+ if ( ! this . _isSameFingerprint ( currentEvent , previousEvent ) ) {
168
+ return false ;
169
+ }
156
170
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
+ }
161
174
162
- // If neither event has a fingerprint, they are assumed to be the same
163
- if ( ! currentFingerprint && ! previousFingerprint ) {
164
175
return true ;
165
176
}
166
177
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 ;
174
182
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
+ }
182
187
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
+ }
187
192
188
- /** JSDoc */
189
- function _getFramesFromEvent ( event : Event ) : StackFrame [ ] | undefined {
190
- const exception = event . exception ;
193
+ currentFingerprint = currentFingerprint as string [ ] ;
194
+ previousFingerprint = previousFingerprint as string [ ] ;
191
195
192
- if ( exception ) {
196
+ // Otherwise, compare the two
193
197
try {
194
- // @ts -ignore Object could be undefined
195
- return exception . values [ 0 ] . stacktrace . frames ;
198
+ return ! ! ( currentFingerprint . join ( '' ) === previousFingerprint . join ( '' ) ) ;
196
199
} catch ( _oO ) {
197
- return undefined ;
200
+ return false ;
198
201
}
199
- } else if ( event . stacktrace ) {
200
- return event . stacktrace . frames ;
201
202
}
202
- return undefined ;
203
203
}
0 commit comments