@@ -73,6 +73,14 @@ interface HttpOptions {
73
73
*/
74
74
ignoreIncomingRequests ?: ( urlPath : string , request : IncomingMessage ) => boolean ;
75
75
76
+ /**
77
+ * Do not capture spans for incoming HTTP requests with the given status codes.
78
+ * By default, spans with 404 status code are ignored.
79
+ *
80
+ * @default `[404]`
81
+ */
82
+ dropSpansForIncomingRequestStatusCodes ?: ( number | RegExp ) [ ] ;
83
+
76
84
/**
77
85
* Do not capture the request body for incoming HTTP requests to URLs where the given callback returns `true`.
78
86
* This can be useful for long running requests where the body is not needed and we want to avoid capturing it.
@@ -148,6 +156,8 @@ export function _shouldInstrumentSpans(options: HttpOptions, clientOptions: Part
148
156
* It creates breadcrumbs and spans for outgoing HTTP requests which will be attached to the currently active span.
149
157
*/
150
158
export const httpIntegration = defineIntegration ( ( options : HttpOptions = { } ) => {
159
+ const dropSpansForIncomingRequestStatusCodes = options . dropSpansForIncomingRequestStatusCodes ?? [ 404 ] ;
160
+
151
161
return {
152
162
name : INTEGRATION_NAME ,
153
163
setupOnce ( ) {
@@ -180,6 +190,22 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
180
190
instrumentOtelHttp ( instrumentationConfig ) ;
181
191
}
182
192
} ,
193
+ processEvent ( event ) {
194
+ // Drop transaction if it has a status code that should be ignored
195
+ if ( event . type === 'transaction' ) {
196
+ const statusCode = event . contexts ?. trace ?. data ?. [ 'http.response.status_code' ] ;
197
+ if (
198
+ typeof statusCode === 'number' &&
199
+ dropSpansForIncomingRequestStatusCodes . some ( code =>
200
+ typeof code === 'number' ? code === statusCode : code . test ( statusCode . toString ( ) ) ,
201
+ )
202
+ ) {
203
+ return null ;
204
+ }
205
+ }
206
+
207
+ return event ;
208
+ } ,
183
209
} ;
184
210
} ) ;
185
211
0 commit comments