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,28 @@ 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+ console . log ( getPropagationContext ( ) ) ;
282+
283+ expect ( getPropagationContext ( ) ) . toEqual ( {
284+ traceId : '12312012123120121231201212312012' ,
285+ parentSpanId : '1121201211212012' ,
286+ spanId : expect . any ( String ) ,
287+ sampled : true ,
288+ dsc : { version : '1.0' , environment : 'production' } ,
289+ } ) ;
290+
269291 const transaction = ( res as any ) . __sentry_transaction ;
270292
271293 // since we have no tracesSampler defined, the default behavior (inherit if possible) applies
272294 expect ( transaction . traceId ) . toEqual ( '12312012123120121231201212312012' ) ;
273295 expect ( transaction . parentSpanId ) . toEqual ( '1121201211212012' ) ;
274- expect ( transaction . sampled ) . toEqual ( false ) ;
296+ expect ( transaction . sampled ) . toEqual ( true ) ;
275297 expect ( transaction . metadata ?. dynamicSamplingContext ) . toStrictEqual ( { version : '1.0' , environment : 'production' } ) ;
276298 } ) ;
277299
@@ -283,6 +305,8 @@ describe('tracingHandler', () => {
283305
284306 sentryTracingMiddleware ( req , res , next ) ;
285307
308+ expect ( getPropagationContext ( ) . dsc ) . toEqual ( { version : '1.0' , environment : 'production' } ) ;
309+
286310 const transaction = ( res as any ) . __sentry_transaction ;
287311 expect ( transaction . metadata ?. dynamicSamplingContext ) . toStrictEqual ( { version : '1.0' , environment : 'production' } ) ;
288312 } ) ;
0 commit comments