@@ -212,7 +212,7 @@ export function startInactiveSpan(options: StartSpanOptions): Span {
212212 if ( _shouldIgnoreStreamedSpan ( client , spanArguments ) ) {
213213 // purposefully not passing in the scope here because we don't want to set an
214214 // inactive span onto the scope (no exception for ignored spans)
215- return _createIgnoredSpan ( client , parentSpan ) ;
215+ return _createIgnoredSpan ( client , parentSpan , scope , false ) ;
216216 }
217217
218218 const shouldSkipSpan = options . onlyIfParent && ! parentSpan ;
@@ -469,9 +469,9 @@ function _startRootSpan(spanArguments: SentrySpanArguments, scope: Scope, parent
469469 const finalAttributes = mutableSpanSamplingData . spanAttributes ;
470470
471471 const currentPropagationContext = scope . getPropagationContext ( ) ;
472- const [ sampled , sampleRate , localSampleRateWasApplied ] = scope . getScopeData ( ) . sdkProcessingMetadata [
473- SUPPRESS_TRACING_KEY
474- ]
472+ const isTracingSuppressed = _isTracingSuppressed ( scope ) ;
473+
474+ const [ sampled , sampleRate , localSampleRateWasApplied ] = isTracingSuppressed
475475 ? [ false ]
476476 : sampleSpan (
477477 options ,
@@ -495,7 +495,7 @@ function _startRootSpan(spanArguments: SentrySpanArguments, scope: Scope, parent
495495 sampled,
496496 } ) ;
497497
498- if ( ! sampled && client && ! scope . getScopeData ( ) . sdkProcessingMetadata [ SUPPRESS_TRACING_KEY ] ) {
498+ if ( ! sampled && client && ! isTracingSuppressed ) {
499499 DEBUG_BUILD && debug . log ( '[Tracing] Discarding root span because its trace was not chosen to be sampled.' ) ;
500500 client . recordDroppedEvent ( 'sample_rate' , hasSpanStreamingEnabled ( client ) ? 'span' : 'transaction' ) ;
501501 }
@@ -513,7 +513,8 @@ function _startRootSpan(spanArguments: SentrySpanArguments, scope: Scope, parent
513513 */
514514function _startChildSpan ( parentSpan : Span , scope : Scope , spanArguments : SentrySpanArguments ) : Span {
515515 const { spanId, traceId } = parentSpan . spanContext ( ) ;
516- const sampled = scope . getScopeData ( ) . sdkProcessingMetadata [ SUPPRESS_TRACING_KEY ] ? false : spanIsSampled ( parentSpan ) ;
516+ const isTracingSuppressed = _isTracingSuppressed ( scope ) ;
517+ const sampled = isTracingSuppressed ? false : spanIsSampled ( parentSpan ) ;
517518
518519 const childSpan = sampled
519520 ? new SentrySpan ( {
@@ -539,7 +540,7 @@ function _startChildSpan(parentSpan: Span, scope: Scope, spanArguments: SentrySp
539540 // record a client outcome for the child.
540541 childSpan . dropReason = parentSpan . dropReason ;
541542 client . recordDroppedEvent ( parentSpan . dropReason , 'span' ) ;
542- } else if ( ! scope . getScopeData ( ) . sdkProcessingMetadata [ SUPPRESS_TRACING_KEY ] ) {
543+ } else if ( ! isTracingSuppressed ) {
543544 // Otherwise, the child is not sampled due to sampling of the parent span,
544545 // hence we record a sample_rate client outcome for the child.
545546 childSpan . dropReason = 'sample_rate' ;
@@ -612,17 +613,22 @@ function _shouldIgnoreStreamedSpan(client: Client | undefined, spanArguments: Se
612613function _createIgnoredSpan (
613614 client : Client | undefined ,
614615 parentSpan : SentrySpan | undefined ,
615- scope ?: Scope | undefined ,
616+ scope : Scope ,
617+ setSpanOnScope : boolean = true ,
616618) : SentryNonRecordingSpan {
617- client ?. recordDroppedEvent ( 'ignored' , 'span' ) ;
619+ if ( ! _isTracingSuppressed ( scope ) ) {
620+ // if someone actively suppressed tracing,
621+ // we don't want to record a client outcome for the ignored span
622+ client ?. recordDroppedEvent ( 'ignored' , 'span' ) ;
623+ }
618624
619625 const nonRecordingSpan = new SentryNonRecordingSpan ( {
620626 dropReason : 'ignored' ,
621627 // if there is a parent span, set the traceId of the parent span
622- traceId : parentSpan ?. spanContext ( ) . traceId ,
628+ traceId : parentSpan ?. spanContext ( ) . traceId ?? scope . getPropagationContext ( ) . traceId ,
623629 } ) ;
624630
625- if ( scope && ! parentSpan ) {
631+ if ( setSpanOnScope && ! parentSpan ) {
626632 // Put the ignored non-recording segment span onto the scope so that `getActiveSpan()` returns it
627633 // For child spans, we don't do this because there _is_ an active span on the scope. We can change
628634 // this if necessary.
@@ -632,6 +638,10 @@ function _createIgnoredSpan(
632638 return nonRecordingSpan ;
633639}
634640
635- function _isIgnoredSpan ( span : Span ) : boolean {
641+ function _isIgnoredSpan ( span : Span ) : span is SentryNonRecordingSpan {
636642 return span instanceof SentryNonRecordingSpan && span . dropReason === 'ignored' ;
637643}
644+
645+ function _isTracingSuppressed ( scope : Scope ) : boolean {
646+ return scope . getScopeData ( ) . sdkProcessingMetadata [ SUPPRESS_TRACING_KEY ] === true ;
647+ }
0 commit comments