@@ -19,13 +19,15 @@ describe('sentryMiddleware', () => {
19
19
return { } as Span | undefined ;
20
20
} ) ;
21
21
const setUserMock = vi . fn ( ) ;
22
+ const setSDKProcessingMetadataMock = vi . fn ( ) ;
22
23
23
24
beforeEach ( ( ) => {
24
25
vi . spyOn ( SentryNode , 'getCurrentScope' ) . mockImplementation ( ( ) => {
25
26
return {
26
27
setUser : setUserMock ,
27
28
setPropagationContext : vi . fn ( ) ,
28
29
getSpan : getSpanMock ,
30
+ setSDKProcessingMetadata : setSDKProcessingMetadataMock ,
29
31
} as any ;
30
32
} ) ;
31
33
vi . spyOn ( SentryNode , 'getActiveSpan' ) . mockImplementation ( getSpanMock ) ;
@@ -60,15 +62,12 @@ describe('sentryMiddleware', () => {
60
62
{
61
63
attributes : {
62
64
'sentry.origin' : 'auto.http.astro' ,
63
- } ,
64
- data : {
65
65
method : 'GET' ,
66
66
url : 'https://mydomain.io/users/123/details' ,
67
67
[ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'route' ,
68
68
} ,
69
69
name : 'GET /users/[id]/details' ,
70
70
op : 'http.server' ,
71
- status : 'ok' ,
72
71
} ,
73
72
expect . any ( Function ) , // the `next` function
74
73
) ;
@@ -97,15 +96,12 @@ describe('sentryMiddleware', () => {
97
96
{
98
97
attributes : {
99
98
'sentry.origin' : 'auto.http.astro' ,
100
- } ,
101
- data : {
102
99
method : 'GET' ,
103
100
url : 'http://localhost:1234/a%xx' ,
104
101
[ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'url' ,
105
102
} ,
106
103
name : 'GET a%xx' ,
107
104
op : 'http.server' ,
108
- status : 'ok' ,
109
105
} ,
110
106
expect . any ( Function ) , // the `next` function
111
107
) ;
@@ -142,8 +138,8 @@ describe('sentryMiddleware', () => {
142
138
} ) ;
143
139
} ) ;
144
140
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 } ) ;
147
143
const ctx = {
148
144
request : {
149
145
method : 'GET' ,
@@ -162,17 +158,36 @@ describe('sentryMiddleware', () => {
162
158
await middleware ( ctx , next ) ;
163
159
164
160
expect ( setUserMock ) . toHaveBeenCalledWith ( { ip_address : '192.168.0.1' } ) ;
161
+ } ) ;
165
162
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' ,
172
171
} ) ,
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
+ } ) ;
176
191
} ) ;
177
192
178
193
it ( 'injects tracing <meta> tags into the HTML of a pageload response' , async ( ) => {
0 commit comments