@@ -12,7 +12,12 @@ import {
1212 withIsolationScope ,
1313} from '@sentry/node' ;
1414import type { Client , Scope , Span , SpanAttributes } from '@sentry/types' ;
15- import { addNonEnumerableProperty , objectify , stripUrlQueryAndFragment } from '@sentry/utils' ;
15+ import {
16+ addNonEnumerableProperty ,
17+ objectify ,
18+ stripUrlQueryAndFragment ,
19+ winterCGRequestToRequestData ,
20+ } from '@sentry/utils' ;
1621import type { APIContext , MiddlewareResponseHandler } from 'astro' ;
1722
1823type MiddlewareOptions = {
@@ -86,11 +91,13 @@ async function instrumentRequest(
8691
8792 const isDynamicPageRequest = checkIsDynamicPageRequest ( ctx ) ;
8893
94+ const request = ctx . request ;
95+
8996 const { method, headers } = isDynamicPageRequest
90- ? ctx . request
91- : // headers can only be accessed in dynamic routes. Accessing `ctx. request.headers` in a static route
97+ ? request
98+ : // headers can only be accessed in dynamic routes. Accessing `request.headers` in a static route
9299 // will make the server log a warning.
93- { method : ctx . request . method , headers : undefined } ;
100+ { method : request . method , headers : undefined } ;
94101
95102 return continueTrace (
96103 {
@@ -101,7 +108,7 @@ async function instrumentRequest(
101108 getCurrentScope ( ) . setSDKProcessingMetadata ( {
102109 // We store the request on the current scope, not isolation scope,
103110 // because we may have multiple requests nested inside each other
104- request : isDynamicPageRequest ? ctx . request : { method, url : ctx . request . url } ,
111+ request : isDynamicPageRequest ? winterCGRequestToRequestData ( request ) : { method, url : request . url } ,
105112 } ) ;
106113
107114 if ( options . trackClientIp && isDynamicPageRequest ) {
0 commit comments