@@ -5,6 +5,7 @@ import { dropUndefinedKeys, logger, tracingContextFromHeaders } from '@sentry/ut
55import { DEBUG_BUILD } from '../debug-build' ;
66import { getCurrentScope , withScope } from '../exports' ;
77import type { Hub } from '../hub' ;
8+ import { getIsolationScope } from '../hub' ;
89import { getCurrentHub } from '../hub' ;
910import { handleCallbackErrors } from '../utils/handleCallbackErrors' ;
1011import { hasTracingEnabled } from '../utils/hasTracingEnabled' ;
@@ -172,11 +173,32 @@ export function startInactiveSpan(context: StartSpanOptions): Span | undefined {
172173 ? // eslint-disable-next-line deprecation/deprecation
173174 context . scope . getSpan ( )
174175 : getActiveSpan ( ) ;
175- return parentSpan
176- ? // eslint-disable-next-line deprecation/deprecation
177- parentSpan . startChild ( ctx )
178- : // eslint-disable-next-line deprecation/deprecation
179- hub . startTransaction ( ctx ) ;
176+
177+ if ( parentSpan ) {
178+ // eslint-disable-next-line deprecation/deprecation
179+ return parentSpan . startChild ( ctx ) ;
180+ } else {
181+ const isolationScope = getIsolationScope ( ) ;
182+ const scope = getCurrentScope ( ) ;
183+
184+ const { traceId, dsc, parentSpanId, sampled } = {
185+ ...isolationScope . getPropagationContext ( ) ,
186+ ...scope . getPropagationContext ( ) ,
187+ } ;
188+
189+ // eslint-disable-next-line deprecation/deprecation
190+ return hub . startTransaction ( {
191+ traceId,
192+ parentSpanId,
193+ parentSampled : sampled ,
194+ ...ctx ,
195+ metadata : {
196+ dynamicSamplingContext : dsc ,
197+ // eslint-disable-next-line deprecation/deprecation
198+ ...ctx . metadata ,
199+ } ,
200+ } ) ;
201+ }
180202}
181203
182204/**
@@ -256,11 +278,32 @@ function createChildSpanOrTransaction(
256278 if ( ! hasTracingEnabled ( ) ) {
257279 return undefined ;
258280 }
259- return parentSpan
260- ? // eslint-disable-next-line deprecation/deprecation
261- parentSpan . startChild ( ctx )
262- : // eslint-disable-next-line deprecation/deprecation
263- hub . startTransaction ( ctx ) ;
281+
282+ if ( parentSpan ) {
283+ // eslint-disable-next-line deprecation/deprecation
284+ return parentSpan . startChild ( ctx ) ;
285+ } else {
286+ const isolationScope = getIsolationScope ( ) ;
287+ const scope = getCurrentScope ( ) ;
288+
289+ const { traceId, dsc, parentSpanId, sampled } = {
290+ ...isolationScope . getPropagationContext ( ) ,
291+ ...scope . getPropagationContext ( ) ,
292+ } ;
293+
294+ // eslint-disable-next-line deprecation/deprecation
295+ return hub . startTransaction ( {
296+ traceId,
297+ parentSpanId,
298+ parentSampled : sampled ,
299+ ...ctx ,
300+ metadata : {
301+ dynamicSamplingContext : dsc ,
302+ // eslint-disable-next-line deprecation/deprecation
303+ ...ctx . metadata ,
304+ } ,
305+ } ) ;
306+ }
264307}
265308
266309/**
0 commit comments