@@ -69,15 +69,6 @@ export function startSpan<T>(options: StartSpanOptions, callback: (span: Span) =
6969 const scope = getCurrentScope ( ) ;
7070 const parentSpan = getParentSpan ( scope , customParentSpan ) ;
7171
72- const client = getClient ( ) ;
73- if ( _shouldIgnoreStreamedSpan ( client , spanArguments ) ) {
74- return handleCallbackErrors (
75- ( ) => callback ( _createIgnoredSpan ( client , parentSpan , scope ) ) ,
76- ( ) => { } ,
77- ( ) => { } ,
78- ) ;
79- }
80-
8172 const shouldSkipSpan = options . onlyIfParent && ! parentSpan ;
8273 const activeSpan = shouldSkipSpan
8374 ? new SentryNonRecordingSpan ( )
@@ -88,7 +79,10 @@ export function startSpan<T>(options: StartSpanOptions, callback: (span: Span) =
8879 scope,
8980 } ) ;
9081
91- if ( ! _isIgnoredSpan ( activeSpan ) ) {
82+ // Ignored root spans still need to be set on scope so that `getActiveSpan()` returns them
83+ // and descendants are also non-recording. Ignored child spans don't need this because
84+ // the parent span is already on scope.
85+ if ( ! _isIgnoredSpan ( activeSpan ) || ! parentSpan ) {
9286 _setSpanForScope ( scope , activeSpan ) ;
9387 }
9488
@@ -138,14 +132,6 @@ export function startSpanManual<T>(options: StartSpanOptions, callback: (span: S
138132 const scope = getCurrentScope ( ) ;
139133 const parentSpan = getParentSpan ( scope , customParentSpan ) ;
140134
141- const client = getClient ( ) ;
142- if ( _shouldIgnoreStreamedSpan ( client , spanArguments ) ) {
143- return handleCallbackErrors (
144- ( ) => callback ( _createIgnoredSpan ( client , parentSpan , scope ) , ( ) => { } ) ,
145- ( ) => { } ,
146- ) ;
147- }
148-
149135 const shouldSkipSpan = options . onlyIfParent && ! parentSpan ;
150136 const activeSpan = shouldSkipSpan
151137 ? new SentryNonRecordingSpan ( )
@@ -156,7 +142,9 @@ export function startSpanManual<T>(options: StartSpanOptions, callback: (span: S
156142 scope,
157143 } ) ;
158144
159- if ( ! _isIgnoredSpan ( activeSpan ) ) {
145+ // We don't set ignored child spans onto the scope because there likely is an active,
146+ // unignored span on the scope already.
147+ if ( ! _isIgnoredSpan ( activeSpan ) || ! parentSpan ) {
160148 _setSpanForScope ( scope , activeSpan ) ;
161149 }
162150
@@ -208,13 +196,6 @@ export function startInactiveSpan(options: StartSpanOptions): Span {
208196 const scope = getCurrentScope ( ) ;
209197 const parentSpan = getParentSpan ( scope , customParentSpan ) ;
210198
211- const client = getClient ( ) ;
212- if ( _shouldIgnoreStreamedSpan ( client , spanArguments ) ) {
213- // purposefully not passing in the scope here because we don't want to set an
214- // inactive span onto the scope (no exception for ignored spans)
215- return _createIgnoredSpan ( client , parentSpan , scope , false ) ;
216- }
217-
218199 const shouldSkipSpan = options . onlyIfParent && ! parentSpan ;
219200
220201 if ( shouldSkipSpan ) {
@@ -370,6 +351,20 @@ function createChildOrRootSpan({
370351 return span ;
371352 }
372353
354+ const client = getClient ( ) ;
355+ if ( _shouldIgnoreStreamedSpan ( client , spanArguments ) ) {
356+ if ( ! _isTracingSuppressed ( scope ) ) {
357+ // if tracing is actively suppressed (Sentry.suppressTracing(...)),
358+ // we don't want to record a client outcome for the ignored span
359+ client ?. recordDroppedEvent ( 'ignored' , 'span' ) ;
360+ }
361+
362+ return new SentryNonRecordingSpan ( {
363+ dropReason : 'ignored' ,
364+ traceId : parentSpan ?. spanContext ( ) . traceId ?? scope . getPropagationContext ( ) . traceId ,
365+ } ) ;
366+ }
367+
373368 const isolationScope = getIsolationScope ( ) ;
374369
375370 let span : Span ;
@@ -609,35 +604,6 @@ function _shouldIgnoreStreamedSpan(client: Client | undefined, spanArguments: Se
609604 ) ;
610605}
611606
612- /* creates a non-recording span that is marked as ignored and sets it on the scope if applicable */
613- function _createIgnoredSpan (
614- client : Client | undefined ,
615- parentSpan : SentrySpan | undefined ,
616- scope : Scope ,
617- setSpanOnScope : boolean = true ,
618- ) : SentryNonRecordingSpan {
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- }
624-
625- const nonRecordingSpan = new SentryNonRecordingSpan ( {
626- dropReason : 'ignored' ,
627- // if there is a parent span, set the traceId of the parent span
628- traceId : parentSpan ?. spanContext ( ) . traceId ?? scope . getPropagationContext ( ) . traceId ,
629- } ) ;
630-
631- if ( setSpanOnScope && ! parentSpan ) {
632- // Put the ignored non-recording segment span onto the scope so that `getActiveSpan()` returns it
633- // For child spans, we don't do this because there _is_ an active span on the scope. We can change
634- // this if necessary.
635- _setSpanForScope ( scope , nonRecordingSpan ) ;
636- }
637-
638- return nonRecordingSpan ;
639- }
640-
641607function _isIgnoredSpan ( span : Span ) : span is SentryNonRecordingSpan {
642608 return span instanceof SentryNonRecordingSpan && span . dropReason === 'ignored' ;
643609}
0 commit comments