@@ -5,6 +5,7 @@ import { dropUndefinedKeys, logger, tracingContextFromHeaders } from '@sentry/ut
5
5
import { DEBUG_BUILD } from '../debug-build' ;
6
6
import { getCurrentScope , withScope } from '../exports' ;
7
7
import type { Hub } from '../hub' ;
8
+ import { getIsolationScope } from '../hub' ;
8
9
import { getCurrentHub } from '../hub' ;
9
10
import { handleCallbackErrors } from '../utils/handleCallbackErrors' ;
10
11
import { hasTracingEnabled } from '../utils/hasTracingEnabled' ;
@@ -172,11 +173,32 @@ export function startInactiveSpan(context: StartSpanOptions): Span | undefined {
172
173
? // eslint-disable-next-line deprecation/deprecation
173
174
context . scope . getSpan ( )
174
175
: 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
+ }
180
202
}
181
203
182
204
/**
@@ -256,11 +278,32 @@ function createChildSpanOrTransaction(
256
278
if ( ! hasTracingEnabled ( ) ) {
257
279
return undefined ;
258
280
}
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
+ }
264
307
}
265
308
266
309
/**
0 commit comments