1
1
import type * as http from 'node:http' ;
2
2
import type { Span } from '@opentelemetry/api' ;
3
- import type { ExpressRequestInfo } from '@opentelemetry/instrumentation-express' ;
3
+ import type { ExpressLayerType , ExpressRequestInfo } from '@opentelemetry/instrumentation-express' ;
4
4
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express' ;
5
5
import type { IntegrationFn } from '@sentry/core' ;
6
6
import {
@@ -26,11 +26,33 @@ type IgnoreMatcher = string | RegExp | ((path: string) => boolean);
26
26
27
27
interface ExpressOptions {
28
28
/**
29
- * Ignore specific layers based on their path
29
+ * Ignore specific layers based on their path.
30
+ *
31
+ * Accepts an array of matchers that can be:
32
+ * - String: exact path match
33
+ * - RegExp: pattern matching
34
+ * - Function: custom logic that receives the path and returns boolean
30
35
*/
31
36
ignoreLayers ?: IgnoreMatcher [ ] ;
32
37
/**
33
- * Ignore specific layers based on their type
38
+ * Ignore specific layers based on their type.
39
+ *
40
+ * Available layer types:
41
+ * - 'router': Express router layers
42
+ * - 'middleware': Express middleware layers
43
+ * - 'request_handler': Express request handler layers
44
+ *
45
+ * @example
46
+ * ```javascript
47
+ * // Ignore only middleware layers
48
+ * ignoreLayersType: ['middleware']
49
+ *
50
+ * // Ignore multiple layer types
51
+ * ignoreLayersType: ['middleware', 'router']
52
+ *
53
+ * // Ignore all layer types (effectively disables tracing)
54
+ * ignoreLayersType: ['middleware', 'router', 'request_handler']
55
+ * ```
34
56
*/
35
57
ignoreLayersType ?: ( 'router' | 'middleware' | 'request_handler' ) [ ] ;
36
58
}
@@ -74,7 +96,7 @@ export const instrumentExpress = generateInstrumentOnce(
74
96
requestHook : span => requestHook ( span ) ,
75
97
spanNameHook : ( info , defaultName ) => spanNameHook ( info , defaultName ) ,
76
98
ignoreLayers : options . ignoreLayers ,
77
- ignoreLayersType : options . ignoreLayersType as any ,
99
+ ignoreLayersType : options . ignoreLayersType as ExpressLayerType [ ] ,
78
100
} ) ,
79
101
) ;
80
102
@@ -85,7 +107,7 @@ export const instrumentExpressV5 = generateInstrumentOnce(
85
107
requestHook : span => requestHook ( span ) ,
86
108
spanNameHook : ( info , defaultName ) => spanNameHook ( info , defaultName ) ,
87
109
ignoreLayers : options . ignoreLayers ,
88
- ignoreLayersType : options . ignoreLayersType as any ,
110
+ ignoreLayersType : options . ignoreLayersType as ExpressLayerType [ ] ,
89
111
} ) ,
90
112
) ;
91
113
0 commit comments