@@ -213,6 +213,37 @@ describe('getTraceData', () => {
213213 } ) ;
214214 } ) ;
215215
216+ it ( 'does not defer DSC to the scope for an onlyIfParent placeholder in tracing mode' , ( ) => {
217+ // With tracing enabled, an `onlyIfParent` placeholder without a parent is a non-recording span.
218+ // Its `sentry-trace` is read from the span (`-0`), so unlike a TwP placeholder its DSC must not
219+ // defer to the scope's continued decision (`sampled=true`) — otherwise the two headers disagree.
220+ setupClient ( { tracesSampleRate : 1 } ) ;
221+
222+ getCurrentScope ( ) . setPropagationContext ( {
223+ traceId : '12345678901234567890123456789012' ,
224+ sampleRand : 0.42 ,
225+ sampled : true ,
226+ dsc : {
227+ environment : 'production' ,
228+ public_key : '123' ,
229+ trace_id : '12345678901234567890123456789012' ,
230+ sampled : 'true' ,
231+ transaction : 'continued-root-txn' ,
232+ } ,
233+ } ) ;
234+
235+ startSpan ( { name : 'child' , onlyIfParent : true } , ( ) => {
236+ const data = getTraceData ( ) ;
237+
238+ expect ( data [ 'sentry-trace' ] ) . toMatch ( / ^ 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 - [ a - f 0 - 9 ] { 16 } - 0 $ / ) ;
239+ // The baggage agrees with the `-0` decision instead of carrying the upstream `sampled=true`.
240+ expect ( data . baggage ) . toContain ( 'sentry-sampled=false' ) ;
241+ expect ( data . baggage ) . not . toContain ( 'sentry-sampled=true' ) ;
242+ expect ( data . baggage ) . not . toContain ( 'sentry-transaction=continued-root-txn' ) ;
243+ expect ( data . baggage ) . toContain ( 'sentry-trace_id=12345678901234567890123456789012' ) ;
244+ } ) ;
245+ } ) ;
246+
216247 it ( 'keeps an explicit negative sampling decision for an active unsampled span' , ( ) => {
217248 setupClient ( { tracesSampleRate : 0 } ) ;
218249
0 commit comments