@@ -35,17 +35,6 @@ export interface EventFiltersOptions {
35
35
36
36
const INTEGRATION_NAME = 'EventFilters' ;
37
37
38
- const _eventFiltersIntegration = ( ( options : Partial < EventFiltersOptions > = { } ) => {
39
- return {
40
- name : INTEGRATION_NAME ,
41
- processEvent ( event , _hint , client ) {
42
- const clientOptions = client . getOptions ( ) ;
43
- const mergedOptions = _mergeOptions ( options , clientOptions ) ;
44
- return _shouldDropEvent ( event , mergedOptions ) ? null : event ;
45
- } ,
46
- } ;
47
- } ) satisfies IntegrationFn ;
48
-
49
38
/**
50
39
* An integration that filters out events (errors and transactions) based on:
51
40
*
@@ -59,7 +48,23 @@ const _eventFiltersIntegration = ((options: Partial<EventFiltersOptions> = {}) =
59
48
*
60
49
* Events filtered by this integration will not be sent to Sentry.
61
50
*/
62
- export const eventFiltersIntegration = defineIntegration ( _eventFiltersIntegration ) ;
51
+ export const eventFiltersIntegration = defineIntegration ( ( options : Partial < EventFiltersOptions > = { } ) => {
52
+ let mergedOptions : Partial < EventFiltersOptions > | undefined ;
53
+ return {
54
+ name : INTEGRATION_NAME ,
55
+ setup ( client ) {
56
+ const clientOptions = client . getOptions ( ) ;
57
+ mergedOptions = _mergeOptions ( options , clientOptions ) ;
58
+ } ,
59
+ processEvent ( event , _hint , client ) {
60
+ if ( ! mergedOptions ) {
61
+ const clientOptions = client . getOptions ( ) ;
62
+ mergedOptions = _mergeOptions ( options , clientOptions ) ;
63
+ }
64
+ return _shouldDropEvent ( event , mergedOptions ) ? null : event ;
65
+ } ,
66
+ } ;
67
+ } ) ;
63
68
64
69
/**
65
70
* An integration that filters out events (errors and transactions) based on:
@@ -102,66 +107,72 @@ function _mergeOptions(
102
107
}
103
108
104
109
function _shouldDropEvent ( event : Event , options : Partial < EventFiltersOptions > ) : boolean {
105
- if ( options . ignoreInternal && _isSentryError ( event ) ) {
106
- DEBUG_BUILD &&
107
- logger . warn ( `Event dropped due to being internal Sentry Error.\nEvent: ${ getEventDescription ( event ) } ` ) ;
108
- return true ;
109
- }
110
- if ( _isIgnoredError ( event , options . ignoreErrors ) ) {
111
- DEBUG_BUILD &&
112
- logger . warn (
113
- `Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${ getEventDescription ( event ) } ` ,
114
- ) ;
115
- return true ;
116
- }
117
- if ( _isUselessError ( event ) ) {
118
- DEBUG_BUILD &&
119
- logger . warn (
120
- `Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${ getEventDescription (
121
- event ,
122
- ) } `,
123
- ) ;
124
- return true ;
125
- }
126
- if ( _isIgnoredTransaction ( event , options . ignoreTransactions ) ) {
127
- DEBUG_BUILD &&
128
- logger . warn (
129
- `Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${ getEventDescription ( event ) } ` ,
130
- ) ;
131
- return true ;
132
- }
133
- if ( _isDeniedUrl ( event , options . denyUrls ) ) {
134
- DEBUG_BUILD &&
135
- logger . warn (
136
- `Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${ getEventDescription (
137
- event ,
138
- ) } .\nUrl: ${ _getEventFilterUrl ( event ) } `,
139
- ) ;
140
- return true ;
141
- }
142
- if ( ! _isAllowedUrl ( event , options . allowUrls ) ) {
143
- DEBUG_BUILD &&
144
- logger . warn (
145
- `Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${ getEventDescription (
146
- event ,
147
- ) } .\nUrl: ${ _getEventFilterUrl ( event ) } `,
148
- ) ;
149
- return true ;
110
+ if ( ! event . type ) {
111
+ // Filter errors
112
+
113
+ if ( options . ignoreInternal && _isSentryError ( event ) ) {
114
+ DEBUG_BUILD &&
115
+ logger . warn ( `Event dropped due to being internal Sentry Error.\nEvent: ${ getEventDescription ( event ) } ` ) ;
116
+ return true ;
117
+ }
118
+ if ( _isIgnoredError ( event , options . ignoreErrors ) ) {
119
+ DEBUG_BUILD &&
120
+ logger . warn (
121
+ `Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${ getEventDescription ( event ) } ` ,
122
+ ) ;
123
+ return true ;
124
+ }
125
+ if ( _isUselessError ( event ) ) {
126
+ DEBUG_BUILD &&
127
+ logger . warn (
128
+ `Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${ getEventDescription (
129
+ event ,
130
+ ) } `,
131
+ ) ;
132
+ return true ;
133
+ }
134
+ if ( _isDeniedUrl ( event , options . denyUrls ) ) {
135
+ DEBUG_BUILD &&
136
+ logger . warn (
137
+ `Event dropped due to being matched by \`denyUrls\` option.\nEvent: ${ getEventDescription (
138
+ event ,
139
+ ) } .\nUrl: ${ _getEventFilterUrl ( event ) } `,
140
+ ) ;
141
+ return true ;
142
+ }
143
+ if ( ! _isAllowedUrl ( event , options . allowUrls ) ) {
144
+ DEBUG_BUILD &&
145
+ logger . warn (
146
+ `Event dropped due to not being matched by \`allowUrls\` option.\nEvent: ${ getEventDescription (
147
+ event ,
148
+ ) } .\nUrl: ${ _getEventFilterUrl ( event ) } `,
149
+ ) ;
150
+ return true ;
151
+ }
152
+ } else if ( event . type === 'transaction' ) {
153
+ // Filter transactions
154
+
155
+ if ( _isIgnoredTransaction ( event , options . ignoreTransactions ) ) {
156
+ DEBUG_BUILD &&
157
+ logger . warn (
158
+ `Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${ getEventDescription ( event ) } ` ,
159
+ ) ;
160
+ return true ;
161
+ }
150
162
}
151
163
return false ;
152
164
}
153
165
154
166
function _isIgnoredError ( event : Event , ignoreErrors ?: Array < string | RegExp > ) : boolean {
155
- // If event.type, this is not an error
156
- if ( event . type || ! ignoreErrors || ! ignoreErrors . length ) {
167
+ if ( ! ignoreErrors ?. length ) {
157
168
return false ;
158
169
}
159
170
160
171
return getPossibleEventMessages ( event ) . some ( message => stringMatchesSomePattern ( message , ignoreErrors ) ) ;
161
172
}
162
173
163
174
function _isIgnoredTransaction ( event : Event , ignoreTransactions ?: Array < string | RegExp > ) : boolean {
164
- if ( event . type !== 'transaction' || ! ignoreTransactions || ! ignoreTransactions . length ) {
175
+ if ( ! ignoreTransactions ? .length ) {
165
176
return false ;
166
177
}
167
178
@@ -223,11 +234,6 @@ function _getEventFilterUrl(event: Event): string | null {
223
234
}
224
235
225
236
function _isUselessError ( event : Event ) : boolean {
226
- if ( event . type ) {
227
- // event is not an error
228
- return false ;
229
- }
230
-
231
237
// We only want to consider events for dropping that actually have recorded exception values.
232
238
if ( ! event . exception ?. values ?. length ) {
233
239
return false ;
0 commit comments