@@ -111,8 +111,9 @@ function wrap(fn: Function): RequestHandler | ErrorRequestHandler {
111
111
112
112
switch ( arity ) {
113
113
case 2 : {
114
- return function ( this : NodeJS . Global , _req : Request , res : Response & SentryTracingResponse ) : any {
114
+ return function ( this : NodeJS . Global , req : Request , res : Response & SentryTracingResponse ) : any {
115
115
const transaction = res . __sentry_transaction ;
116
+ addExpressReqToTransaction ( transaction , req ) ;
116
117
if ( transaction ) {
117
118
const span = transaction . startChild ( {
118
119
description : fn . name ,
@@ -134,6 +135,7 @@ function wrap(fn: Function): RequestHandler | ErrorRequestHandler {
134
135
next : NextFunction ,
135
136
) : any {
136
137
const transaction = res . __sentry_transaction ;
138
+ addExpressReqToTransaction ( transaction , req ) ;
137
139
const span =
138
140
transaction &&
139
141
transaction . startChild ( {
@@ -158,6 +160,7 @@ function wrap(fn: Function): RequestHandler | ErrorRequestHandler {
158
160
next : NextFunction ,
159
161
) : any {
160
162
const transaction = res . __sentry_transaction ;
163
+ addExpressReqToTransaction ( transaction , req ) ;
161
164
const span =
162
165
transaction &&
163
166
transaction . startChild ( {
@@ -179,6 +182,23 @@ function wrap(fn: Function): RequestHandler | ErrorRequestHandler {
179
182
}
180
183
}
181
184
185
+ /**
186
+ * Set parameterized as transaction name e.g.: `GET /users/:id`
187
+ * Also adds more context data on the transaction from the request
188
+ */
189
+ function addExpressReqToTransaction ( transaction : Transaction | undefined , req : any ) : void {
190
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
191
+ if ( transaction ) {
192
+ if ( req . route && req . route . path ) {
193
+ transaction . name = `${ req . method } ${ req . route . path } ` ;
194
+ }
195
+ transaction . setData ( 'url' , req . originalUrl ) ;
196
+ transaction . setData ( 'baseUrl' , req . baseUrl ) ;
197
+ transaction . setData ( 'query' , req . query ) ;
198
+ }
199
+ /* eslint-enable @typescript-eslint/no-unsafe-member-access */
200
+ }
201
+
182
202
/**
183
203
* Takes all the function arguments passed to the original `app.use` call
184
204
* and wraps every function, as well as array of functions with a call to our `wrap` method.
0 commit comments