11import type { Hub } from '@sentry/core' ;
22import * as sentryCore from '@sentry/core' ;
33import { setAsyncContextStrategy , Transaction } from '@sentry/core' ;
4- import type { Event } from '@sentry/types' ;
4+ import type { Event , PropagationContext } from '@sentry/types' ;
55import { SentryError } from '@sentry/utils' ;
66import * as http from 'http' ;
77
@@ -209,6 +209,11 @@ describe('tracingHandler', () => {
209209 jest . restoreAllMocks ( ) ;
210210 } ) ;
211211
212+ function getPropagationContext ( ) : PropagationContext {
213+ // @ts -expect-error accesing private property for test
214+ return hub . getScope ( ) . _propagationContext ;
215+ }
216+
212217 it ( 'creates a transaction when handling a request' , ( ) => {
213218 const startTransaction = jest . spyOn ( sentryCore , 'startTransaction' ) ;
214219
@@ -251,6 +256,13 @@ describe('tracingHandler', () => {
251256
252257 const transaction = ( res as any ) . __sentry_transaction ;
253258
259+ expect ( getPropagationContext ( ) ) . toEqual ( {
260+ traceId : '12312012123120121231201212312012' ,
261+ parentSpanId : '1121201211212012' ,
262+ spanId : expect . any ( String ) ,
263+ sampled : false ,
264+ } ) ;
265+
254266 // since we have no tracesSampler defined, the default behavior (inherit if possible) applies
255267 expect ( transaction . traceId ) . toEqual ( '12312012123120121231201212312012' ) ;
256268 expect ( transaction . parentSpanId ) . toEqual ( '1121201211212012' ) ;
@@ -260,18 +272,26 @@ describe('tracingHandler', () => {
260272
261273 it ( "pulls parent's data from tracing and baggage headers on the request" , ( ) => {
262274 req . headers = {
263- 'sentry-trace' : '12312012123120121231201212312012-1121201211212012-0 ' ,
275+ 'sentry-trace' : '12312012123120121231201212312012-1121201211212012-1 ' ,
264276 baggage : 'sentry-version=1.0,sentry-environment=production' ,
265277 } ;
266278
267279 sentryTracingMiddleware ( req , res , next ) ;
268280
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+
269289 const transaction = ( res as any ) . __sentry_transaction ;
270290
271291 // since we have no tracesSampler defined, the default behavior (inherit if possible) applies
272292 expect ( transaction . traceId ) . toEqual ( '12312012123120121231201212312012' ) ;
273293 expect ( transaction . parentSpanId ) . toEqual ( '1121201211212012' ) ;
274- expect ( transaction . sampled ) . toEqual ( false ) ;
294+ expect ( transaction . sampled ) . toEqual ( true ) ;
275295 expect ( transaction . metadata ?. dynamicSamplingContext ) . toStrictEqual ( { version : '1.0' , environment : 'production' } ) ;
276296 } ) ;
277297
@@ -283,6 +303,8 @@ describe('tracingHandler', () => {
283303
284304 sentryTracingMiddleware ( req , res , next ) ;
285305
306+ expect ( getPropagationContext ( ) . dsc ) . toEqual ( { version : '1.0' , environment : 'production' } ) ;
307+
286308 const transaction = ( res as any ) . __sentry_transaction ;
287309 expect ( transaction . metadata ?. dynamicSamplingContext ) . toStrictEqual ( { version : '1.0' , environment : 'production' } ) ;
288310 } ) ;
0 commit comments