11import { deepReadDirSync } from '@sentry/node' ;
2- import { Transaction } from '@sentry/types' ;
32import { getActiveTransaction , hasTracingEnabled } from '@sentry/tracing' ;
3+ import { Event as SentryEvent , Transaction } from '@sentry/types' ;
44import { fill , logger } from '@sentry/utils' ;
55import * as domain from 'domain' ;
66import * as http from 'http' ;
@@ -30,6 +30,7 @@ interface Server {
3030interface NextRequest extends http . IncomingMessage {
3131 cookies : Record < string , string > ;
3232 url : string ;
33+ query : { [ key : string ] : string } ;
3334}
3435
3536interface NextResponse extends http . ServerResponse {
@@ -200,6 +201,8 @@ function makeWrappedReqHandler(origReqHandler: ReqHandler): WrappedReqHandler {
200201 const currentScope = Sentry . getCurrentHub ( ) . getScope ( ) ;
201202
202203 if ( currentScope ) {
204+ currentScope . addEventProcessor ( event => addRequestDataToEvent ( event , req ) ) ;
205+
203206 // We only want to record page and API requests
204207 if ( hasTracingEnabled ( ) && shouldTraceRequest ( req . url , publicDirFiles ) ) {
205208 // pull off query string, if any
@@ -222,6 +225,8 @@ function makeWrappedReqHandler(origReqHandler: ReqHandler): WrappedReqHandler {
222225 if ( transaction ) {
223226 transaction . setHttpStatus ( res . statusCode ) ;
224227
228+ // we'll collect this data in a more targeted way in the event processor we added above,
229+ // `addRequestDataToEvent`
225230 delete transaction . metadata . request ;
226231
227232 // Push `transaction.finish` to the next event loop so open spans have a chance to finish before the
@@ -280,3 +285,16 @@ function shouldTraceRequest(url: string, publicDirFiles: Set<string>): boolean {
280285 // `static` is a deprecated but still-functional location for static resources
281286 return ! url . startsWith ( '/_next/' ) && ! url . startsWith ( '/static/' ) && ! publicDirFiles . has ( url ) ;
282287}
288+
289+ function addRequestDataToEvent ( event : SentryEvent , req : NextRequest ) : SentryEvent {
290+ event . request = {
291+ // TODO body/data
292+ url : req . url . split ( '?' ) [ 0 ] ,
293+ cookies : req . cookies ,
294+ headers : req . headers as { [ key : string ] : string } ,
295+ method : req . method ,
296+ query_string : req . query ,
297+ } ;
298+
299+ return event ;
300+ }
0 commit comments