11import type * as http from 'node:http' ;
22import type { Span } from '@opentelemetry/api' ;
3- import type { ExpressRequestInfo } from '@opentelemetry/instrumentation-express' ;
3+ import type { ExpressLayerType , ExpressRequestInfo } from '@opentelemetry/instrumentation-express' ;
44import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express' ;
55import type { IntegrationFn } from '@sentry/core' ;
66import {
@@ -26,11 +26,33 @@ type IgnoreMatcher = string | RegExp | ((path: string) => boolean);
2626
2727interface ExpressOptions {
2828 /**
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
3035 */
3136 ignoreLayers ?: IgnoreMatcher [ ] ;
3237 /**
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+ * ```
3456 */
3557 ignoreLayersType ?: ( 'router' | 'middleware' | 'request_handler' ) [ ] ;
3658}
@@ -74,7 +96,7 @@ export const instrumentExpress = generateInstrumentOnce(
7496 requestHook : span => requestHook ( span ) ,
7597 spanNameHook : ( info , defaultName ) => spanNameHook ( info , defaultName ) ,
7698 ignoreLayers : options . ignoreLayers ,
77- ignoreLayersType : options . ignoreLayersType as any ,
99+ ignoreLayersType : options . ignoreLayersType as ExpressLayerType [ ] ,
78100 } ) ,
79101) ;
80102
@@ -85,7 +107,7 @@ export const instrumentExpressV5 = generateInstrumentOnce(
85107 requestHook : span => requestHook ( span ) ,
86108 spanNameHook : ( info , defaultName ) => spanNameHook ( info , defaultName ) ,
87109 ignoreLayers : options . ignoreLayers ,
88- ignoreLayersType : options . ignoreLayersType as any ,
110+ ignoreLayersType : options . ignoreLayersType as ExpressLayerType [ ] ,
89111 } ) ,
90112) ;
91113
0 commit comments