@@ -125,16 +125,17 @@ test('Sends an API route transaction', async ({ baseURL }) => {
125
125
test ( 'API route transaction includes nest middleware span. Spans created in and after middleware are nested correctly' , async ( {
126
126
baseURL,
127
127
} ) => {
128
- const pageloadTransactionEventPromise = waitForTransaction ( 'nestjs' , transactionEvent => {
128
+ const transactionEventPromise = waitForTransaction ( 'nestjs' , transactionEvent => {
129
129
return (
130
130
transactionEvent ?. contexts ?. trace ?. op === 'http.server' &&
131
131
transactionEvent ?. transaction === 'GET /test-middleware-instrumentation'
132
132
) ;
133
133
} ) ;
134
134
135
- await fetch ( `${ baseURL } /test-middleware-instrumentation` ) ;
135
+ const response = await fetch ( `${ baseURL } /test-middleware-instrumentation` ) ;
136
+ expect ( response . status ) . toBe ( 200 ) ;
136
137
137
- const transactionEvent = await pageloadTransactionEventPromise ;
138
+ const transactionEvent = await transactionEventPromise ;
138
139
139
140
expect ( transactionEvent ) . toEqual (
140
141
expect . objectContaining ( {
@@ -200,3 +201,68 @@ test('API route transaction includes nest middleware span. Spans created in and
200
201
// 'ExampleMiddleware' is NOT the parent of 'test-controller-span'
201
202
expect ( testControllerSpan . parent_span_id ) . not . toBe ( exampleMiddlewareSpanId ) ;
202
203
} ) ;
204
+
205
+ test ( 'API route transaction includes nest guard span and span started in guard is nested correctly' , async ( {
206
+ baseURL,
207
+ } ) => {
208
+ const transactionEventPromise = waitForTransaction ( 'nestjs' , transactionEvent => {
209
+ return (
210
+ transactionEvent ?. contexts ?. trace ?. op === 'http.server' &&
211
+ transactionEvent ?. transaction === 'GET /test-guard-instrumentation'
212
+ ) ;
213
+ } ) ;
214
+
215
+ const response = await fetch ( `${ baseURL } /test-guard-instrumentation` ) ;
216
+ expect ( response . status ) . toBe ( 200 ) ;
217
+
218
+ const transactionEvent = await transactionEventPromise ;
219
+
220
+ expect ( transactionEvent ) . toEqual (
221
+ expect . objectContaining ( {
222
+ spans : expect . arrayContaining ( [
223
+ {
224
+ span_id : expect . any ( String ) ,
225
+ trace_id : expect . any ( String ) ,
226
+ data : {
227
+ 'sentry.op' : 'middleware.nestjs' ,
228
+ 'sentry.origin' : 'auto.middleware.nestjs' ,
229
+ } ,
230
+ description : 'ExampleGuard' ,
231
+ parent_span_id : expect . any ( String ) ,
232
+ start_timestamp : expect . any ( Number ) ,
233
+ timestamp : expect . any ( Number ) ,
234
+ status : 'ok' ,
235
+ op : 'middleware.nestjs' ,
236
+ origin : 'auto.middleware.nestjs' ,
237
+ } ,
238
+ ] ) ,
239
+ } ) ,
240
+ ) ;
241
+
242
+ const exampleGuardSpan = transactionEvent . spans . find ( span => span . description === 'ExampleGuard' ) ;
243
+ const exampleGuardSpanId = exampleGuardSpan ?. span_id ;
244
+
245
+ expect ( transactionEvent ) . toEqual (
246
+ expect . objectContaining ( {
247
+ spans : expect . arrayContaining ( [
248
+ {
249
+ span_id : expect . any ( String ) ,
250
+ trace_id : expect . any ( String ) ,
251
+ data : expect . any ( Object ) ,
252
+ description : 'test-guard-span' ,
253
+ parent_span_id : expect . any ( String ) ,
254
+ start_timestamp : expect . any ( Number ) ,
255
+ timestamp : expect . any ( Number ) ,
256
+ status : 'ok' ,
257
+ origin : 'manual' ,
258
+ } ,
259
+ ] ) ,
260
+ } ) ,
261
+ ) ;
262
+
263
+ // verify correct span parent-child relationships
264
+ const testGuardSpan = transactionEvent . spans . find ( span => span . description === 'test-guard-span' ) ;
265
+
266
+ // 'ExampleGuard' is the parent of 'test-guard-span'
267
+ expect ( testGuardSpan . parent_span_id ) . toBe ( exampleGuardSpanId ) ;
268
+ } ) ;
0 commit comments