@@ -370,9 +370,13 @@ function getAcs(): AsyncContextStrategy {
370370 return getAsyncContextStrategy ( carrier ) ;
371371}
372372
373- function _startRootSpan ( spanArguments : SentrySpanArguments , scope : Scope , parentSampled ?: boolean ) : SentrySpan {
373+ function _startRootSpan (
374+ spanArguments : SentrySpanArguments ,
375+ scope : Scope ,
376+ parentSampled ?: boolean ,
377+ ) : SentrySpan | SentryNonRecordingSpan {
374378 const client = getClient ( ) ;
375- const options : Partial < ClientOptions > = ( client && client . getOptions ( ) ) || { } ;
379+ const options : Partial < ClientOptions > = client ? .getOptions ( ) || { } ;
376380
377381 const { name = '' , attributes } = spanArguments ;
378382 const [ sampled , sampleRate ] = scope . getScopeData ( ) . sdkProcessingMetadata [ SUPPRESS_TRACING_KEY ]
@@ -387,14 +391,16 @@ function _startRootSpan(spanArguments: SentrySpanArguments, scope: Scope, parent
387391 } ,
388392 } ) ;
389393
390- const rootSpan = new SentrySpan ( {
391- ...spanArguments ,
392- attributes : {
393- [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'custom' ,
394- ...spanArguments . attributes ,
395- } ,
396- sampled,
397- } ) ;
394+ const rootSpan = sampled
395+ ? new SentrySpan ( {
396+ ...spanArguments ,
397+ attributes : {
398+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'custom' ,
399+ ...spanArguments . attributes ,
400+ } ,
401+ sampled,
402+ } )
403+ : new SentryNonRecordingSpan ( { traceId : spanArguments . traceId } ) ;
398404
399405 if ( ! sampled && client ) {
400406 DEBUG_BUILD && logger . log ( '[Tracing] Discarding root span because its trace was not chosen to be sampled.' ) ;
0 commit comments