@@ -281,11 +281,32 @@ export function startInactiveSpan(context: StartSpanOptions): Span | undefined {
281281 ? // eslint-disable-next-line deprecation/deprecation
282282 context . scope . getSpan ( )
283283 : getActiveSpan ( ) ;
284- return parentSpan
285- ? // eslint-disable-next-line deprecation/deprecation
286- parentSpan . startChild ( ctx )
287- : // eslint-disable-next-line deprecation/deprecation
288- hub . startTransaction ( ctx ) ;
284+
285+ if ( parentSpan ) {
286+ // eslint-disable-next-line deprecation/deprecation
287+ return parentSpan . startChild ( ctx ) ;
288+ } else {
289+ const isolationScope = getIsolationScope ( ) ;
290+ const scope = getCurrentScope ( ) ;
291+
292+ const { traceId, dsc, parentSpanId, sampled } = {
293+ ...isolationScope . getPropagationContext ( ) ,
294+ ...scope . getPropagationContext ( ) ,
295+ } ;
296+
297+ // eslint-disable-next-line deprecation/deprecation
298+ return hub . startTransaction ( {
299+ traceId,
300+ parentSpanId,
301+ parentSampled : sampled ,
302+ ...ctx ,
303+ metadata : {
304+ dynamicSamplingContext : dsc ,
305+ // eslint-disable-next-line deprecation/deprecation
306+ ...ctx . metadata ,
307+ } ,
308+ } ) ;
309+ }
289310}
290311
291312/**
@@ -365,11 +386,32 @@ function createChildSpanOrTransaction(
365386 if ( ! hasTracingEnabled ( ) ) {
366387 return undefined ;
367388 }
368- return parentSpan
369- ? // eslint-disable-next-line deprecation/deprecation
370- parentSpan . startChild ( ctx )
371- : // eslint-disable-next-line deprecation/deprecation
372- hub . startTransaction ( ctx ) ;
389+
390+ if ( parentSpan ) {
391+ // eslint-disable-next-line deprecation/deprecation
392+ return parentSpan . startChild ( ctx ) ;
393+ } else {
394+ const isolationScope = getIsolationScope ( ) ;
395+ const scope = getCurrentScope ( ) ;
396+
397+ const { traceId, dsc, parentSpanId, sampled } = {
398+ ...isolationScope . getPropagationContext ( ) ,
399+ ...scope . getPropagationContext ( ) ,
400+ } ;
401+
402+ // eslint-disable-next-line deprecation/deprecation
403+ return hub . startTransaction ( {
404+ traceId,
405+ parentSpanId,
406+ parentSampled : sampled ,
407+ ...ctx ,
408+ metadata : {
409+ dynamicSamplingContext : dsc ,
410+ // eslint-disable-next-line deprecation/deprecation
411+ ...ctx . metadata ,
412+ } ,
413+ } ) ;
414+ }
373415}
374416
375417/**
0 commit comments