1
1
import type { Hub } from '@sentry/core' ;
2
2
import * as sentryCore from '@sentry/core' ;
3
3
import { setAsyncContextStrategy , Transaction } from '@sentry/core' ;
4
- import type { Event } from '@sentry/types' ;
4
+ import type { Event , PropagationContext } from '@sentry/types' ;
5
5
import { SentryError } from '@sentry/utils' ;
6
6
import * as http from 'http' ;
7
7
@@ -209,6 +209,11 @@ describe('tracingHandler', () => {
209
209
jest . restoreAllMocks ( ) ;
210
210
} ) ;
211
211
212
+ function getPropagationContext ( ) : PropagationContext {
213
+ // @ts -expect-error accesing private property for test
214
+ return hub . getScope ( ) . _propagationContext ;
215
+ }
216
+
212
217
it ( 'creates a transaction when handling a request' , ( ) => {
213
218
const startTransaction = jest . spyOn ( sentryCore , 'startTransaction' ) ;
214
219
@@ -251,6 +256,13 @@ describe('tracingHandler', () => {
251
256
252
257
const transaction = ( res as any ) . __sentry_transaction ;
253
258
259
+ expect ( getPropagationContext ( ) ) . toEqual ( {
260
+ traceId : '12312012123120121231201212312012' ,
261
+ parentSpanId : '1121201211212012' ,
262
+ spanId : expect . any ( String ) ,
263
+ sampled : false ,
264
+ } ) ;
265
+
254
266
// since we have no tracesSampler defined, the default behavior (inherit if possible) applies
255
267
expect ( transaction . traceId ) . toEqual ( '12312012123120121231201212312012' ) ;
256
268
expect ( transaction . parentSpanId ) . toEqual ( '1121201211212012' ) ;
@@ -260,18 +272,26 @@ describe('tracingHandler', () => {
260
272
261
273
it ( "pulls parent's data from tracing and baggage headers on the request" , ( ) => {
262
274
req . headers = {
263
- 'sentry-trace' : '12312012123120121231201212312012-1121201211212012-0 ' ,
275
+ 'sentry-trace' : '12312012123120121231201212312012-1121201211212012-1 ' ,
264
276
baggage : 'sentry-version=1.0,sentry-environment=production' ,
265
277
} ;
266
278
267
279
sentryTracingMiddleware ( req , res , next ) ;
268
280
281
+ expect ( getPropagationContext ( ) ) . toEqual ( {
282
+ traceId : '12312012123120121231201212312012' ,
283
+ parentSpanId : '1121201211212012' ,
284
+ spanId : expect . any ( String ) ,
285
+ sampled : true ,
286
+ dsc : { version : '1.0' , environment : 'production' } ,
287
+ } ) ;
288
+
269
289
const transaction = ( res as any ) . __sentry_transaction ;
270
290
271
291
// since we have no tracesSampler defined, the default behavior (inherit if possible) applies
272
292
expect ( transaction . traceId ) . toEqual ( '12312012123120121231201212312012' ) ;
273
293
expect ( transaction . parentSpanId ) . toEqual ( '1121201211212012' ) ;
274
- expect ( transaction . sampled ) . toEqual ( false ) ;
294
+ expect ( transaction . sampled ) . toEqual ( true ) ;
275
295
expect ( transaction . metadata ?. dynamicSamplingContext ) . toStrictEqual ( { version : '1.0' , environment : 'production' } ) ;
276
296
} ) ;
277
297
@@ -283,6 +303,8 @@ describe('tracingHandler', () => {
283
303
284
304
sentryTracingMiddleware ( req , res , next ) ;
285
305
306
+ expect ( getPropagationContext ( ) . dsc ) . toEqual ( { version : '1.0' , environment : 'production' } ) ;
307
+
286
308
const transaction = ( res as any ) . __sentry_transaction ;
287
309
expect ( transaction . metadata ?. dynamicSamplingContext ) . toStrictEqual ( { version : '1.0' , environment : 'production' } ) ;
288
310
} ) ;
0 commit comments