@@ -19,13 +19,15 @@ describe('sentryMiddleware', () => {
1919 return { } as Span | undefined ;
2020 } ) ;
2121 const setUserMock = vi . fn ( ) ;
22+ const setSDKProcessingMetadataMock = vi . fn ( ) ;
2223
2324 beforeEach ( ( ) => {
2425 vi . spyOn ( SentryNode , 'getCurrentScope' ) . mockImplementation ( ( ) => {
2526 return {
2627 setUser : setUserMock ,
2728 setPropagationContext : vi . fn ( ) ,
2829 getSpan : getSpanMock ,
30+ setSDKProcessingMetadata : setSDKProcessingMetadataMock ,
2931 } as any ;
3032 } ) ;
3133 vi . spyOn ( SentryNode , 'getActiveSpan' ) . mockImplementation ( getSpanMock ) ;
@@ -60,15 +62,12 @@ describe('sentryMiddleware', () => {
6062 {
6163 attributes : {
6264 'sentry.origin' : 'auto.http.astro' ,
63- } ,
64- data : {
6565 method : 'GET' ,
6666 url : 'https://mydomain.io/users/123/details' ,
6767 [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'route' ,
6868 } ,
6969 name : 'GET /users/[id]/details' ,
7070 op : 'http.server' ,
71- status : 'ok' ,
7271 } ,
7372 expect . any ( Function ) , // the `next` function
7473 ) ;
@@ -97,15 +96,12 @@ describe('sentryMiddleware', () => {
9796 {
9897 attributes : {
9998 'sentry.origin' : 'auto.http.astro' ,
100- } ,
101- data : {
10299 method : 'GET' ,
103100 url : 'http://localhost:1234/a%xx' ,
104101 [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
105102 } ,
106103 name : 'GET a%xx' ,
107104 op : 'http.server' ,
108- status : 'ok' ,
109105 } ,
110106 expect . any ( Function ) , // the `next` function
111107 ) ;
@@ -142,8 +138,8 @@ describe('sentryMiddleware', () => {
142138 } ) ;
143139 } ) ;
144140
145- it ( 'attaches client IP and request headers if options are set ' , async ( ) => {
146- const middleware = handleRequest ( { trackClientIp : true , trackHeaders : true } ) ;
141+ it ( 'attaches client IP if `trackClientIp=true` ' , async ( ) => {
142+ const middleware = handleRequest ( { trackClientIp : true } ) ;
147143 const ctx = {
148144 request : {
149145 method : 'GET' ,
@@ -162,17 +158,36 @@ describe('sentryMiddleware', () => {
162158 await middleware ( ctx , next ) ;
163159
164160 expect ( setUserMock ) . toHaveBeenCalledWith ( { ip_address : '192.168.0.1' } ) ;
161+ } ) ;
165162
166- expect ( startSpanSpy ) . toHaveBeenCalledWith (
167- expect . objectContaining ( {
168- data : expect . objectContaining ( {
169- headers : {
170- 'some-header' : 'some-value' ,
171- } ,
163+ it ( 'attaches request as SDK processing metadata' , async ( ) => {
164+ const middleware = handleRequest ( { } ) ;
165+ const ctx = {
166+ request : {
167+ method : 'GET' ,
168+ url : '/users' ,
169+ headers : new Headers ( {
170+ 'some-header' : 'some-value' ,
172171 } ) ,
173- } ) ,
174- expect . any ( Function ) , // the `next` function
175- ) ;
172+ } ,
173+ clientAddress : '192.168.0.1' ,
174+ params : { } ,
175+ url : new URL ( 'https://myDomain.io/users/' ) ,
176+ } ;
177+ const next = vi . fn ( ( ) => nextResult ) ;
178+
179+ // @ts -expect-error, a partial ctx object is fine here
180+ await middleware ( ctx , next ) ;
181+
182+ expect ( setSDKProcessingMetadataMock ) . toHaveBeenCalledWith ( {
183+ request : {
184+ method : 'GET' ,
185+ url : '/users' ,
186+ headers : new Headers ( {
187+ 'some-header' : 'some-value' ,
188+ } ) ,
189+ } ,
190+ } ) ;
176191 } ) ;
177192
178193 it ( 'injects tracing <meta> tags into the HTML of a pageload response' , async ( ) => {
0 commit comments