@@ -9,38 +9,39 @@ use parking_lot::RwLock;
99use rand:: { self , Rng } ;
1010use std:: borrow:: Cow ;
1111use std:: error:: Error ;
12- use std:: sync:: Arc ;
12+ use std:: sync:: { Arc , LazyLock } ;
1313
1414pub ( crate ) type Tracer = cf_rustracing:: Tracer < BoxSampler < SpanContextState > , SpanContextState > ;
1515
16+ static INACTIVE_SPAN : LazyLock < RwLock < Span > > = LazyLock :: new ( || RwLock :: new ( Span :: inactive ( ) ) ) ;
17+
1618/// Shared span with mutability and additional reference tracking for
1719/// ad-hoc inspection.
1820#[ derive( Clone , Debug ) ]
1921pub ( crate ) enum SharedSpanHandle {
2022 Tracked ( Arc < LiveReferenceHandle < Arc < RwLock < Span > > > > ) ,
2123 Untracked ( Arc < RwLock < Span > > ) ,
24+ Inactive ,
2225}
2326
2427impl SharedSpanHandle {
2528 pub ( crate ) fn new ( span : Span ) -> Self {
26- let is_sampled = span. is_sampled ( ) ;
27-
28- TracingHarness :: get ( )
29- . active_roots
30- . track ( Arc :: new ( RwLock :: new ( span) ) , is_sampled)
29+ TracingHarness :: get ( ) . active_roots . track ( span)
3130 }
3231
3332 pub ( crate ) fn read ( & self ) -> parking_lot:: RwLockReadGuard < ' _ , Span > {
3433 match self {
3534 SharedSpanHandle :: Tracked ( handle) => handle. read ( ) ,
3635 SharedSpanHandle :: Untracked ( rw_lock) => rw_lock. read ( ) ,
36+ SharedSpanHandle :: Inactive => ( * INACTIVE_SPAN ) . read ( ) ,
3737 }
3838 }
3939
4040 pub ( crate ) fn write ( & self ) -> parking_lot:: RwLockWriteGuard < ' _ , Span > {
4141 match self {
4242 SharedSpanHandle :: Tracked ( handle) => handle. write ( ) ,
4343 SharedSpanHandle :: Untracked ( rw_lock) => rw_lock. write ( ) ,
44+ SharedSpanHandle :: Inactive => ( * INACTIVE_SPAN ) . write ( ) ,
4445 }
4546 }
4647}
@@ -50,6 +51,7 @@ impl From<SharedSpanHandle> for Arc<RwLock<Span>> {
5051 match value {
5152 SharedSpanHandle :: Tracked ( handle) => Arc :: clone ( & handle) ,
5253 SharedSpanHandle :: Untracked ( rw_lock) => Arc :: clone ( & rw_lock) ,
54+ SharedSpanHandle :: Inactive => Arc :: new ( RwLock :: new ( Span :: inactive ( ) ) ) ,
5355 }
5456 }
5557}
0 commit comments