@@ -20,7 +20,6 @@ export const withSentry = (handler: NextApiHandler): WrappedNextApiHandler => {
20
20
if ( currentScope ) {
21
21
currentScope . addEventProcessor ( event => addRequestDataToEvent ( event , req as NextRequest ) ) ;
22
22
23
- // We only want to record page and API requests
24
23
if ( hasTracingEnabled ( ) ) {
25
24
// If there is a trace header set, extract the data from it (parentSpanId, traceId, and sampling decision)
26
25
let traceparentData ;
@@ -34,20 +33,18 @@ export const withSentry = (handler: NextApiHandler): WrappedNextApiHandler => {
34
33
let reqPath = stripUrlQueryAndFragment ( url ) ;
35
34
// Replace with placeholder
36
35
if ( req . query ) {
36
+ // TODO get this from next if possible, to avoid accidentally replacing non-dynamic parts of the path if
37
+ // they match dynamic parts
37
38
for ( const [ key , value ] of Object . entries ( req . query ) ) {
38
39
reqPath = reqPath . replace ( `${ value } ` , `[${ key } ]` ) ;
39
40
}
40
41
}
41
-
42
- // requests for pages will only ever be GET requests, so don't bother to include the method in the transaction
43
- // name; requests to API routes could be GET, POST, PUT, etc, so do include it there
44
- const namePrefix = `${ ( req . method || 'GET' ) . toUpperCase ( ) } ` ;
42
+ const reqMethod = `${ ( req . method || 'GET' ) . toUpperCase ( ) } ` ;
45
43
46
44
const transaction = startTransaction (
47
45
{
48
- name : `${ namePrefix } ${ reqPath } ` ,
46
+ name : `${ reqMethod } ${ reqPath } ` ,
49
47
op : 'http.server' ,
50
- metadata : { requestPath : reqPath } ,
51
48
...traceparentData ,
52
49
} ,
53
50
// extra context passed to the `tracesSampler`
@@ -57,7 +54,7 @@ export const withSentry = (handler: NextApiHandler): WrappedNextApiHandler => {
57
54
}
58
55
}
59
56
60
- return await handler ( req , res ) ; // Call Handler
57
+ return await handler ( req , res ) ; // Call original handler
61
58
} catch ( e ) {
62
59
withScope ( scope => {
63
60
scope . addEventProcessor ( event => {
@@ -74,10 +71,6 @@ export const withSentry = (handler: NextApiHandler): WrappedNextApiHandler => {
74
71
if ( transaction ) {
75
72
transaction . setHttpStatus ( res . statusCode ) ;
76
73
77
- // we'll collect this data in a more targeted way in the event processor we added above,
78
- // `addRequestDataToEvent`
79
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
80
- delete transaction . metadata . requestPath ;
81
74
82
75
transaction . finish ( ) ;
83
76
}
0 commit comments