@@ -773,6 +773,7 @@ mod tests {
773773 use hyperlight_testing:: tracing_subscriber:: TracingSubscriber ;
774774 use tracing:: Level ;
775775 use tracing_core:: Subscriber ;
776+ use tracing_core:: callsite:: rebuild_interest_cache;
776777 use uuid:: Uuid ;
777778
778779 /// Helper to extract a string value from nested JSON: obj["span"]["attributes"][key]
@@ -793,19 +794,25 @@ mod tests {
793794 let subscriber = TracingSubscriber :: new ( Level :: TRACE ) ;
794795
795796 tracing:: subscriber:: with_default ( subscriber. clone ( ) , || {
797+ // Rebuild the global callsite interest cache so that all callsites
798+ // (including those already registered by other test threads with the
799+ // no-op subscriber) are re-evaluated against our TracingSubscriber.
800+ // Without this, a race condition can cause #[instrument] spans in
801+ // production code to be permanently disabled via Interest::never().
802+ rebuild_interest_cache ( ) ;
803+
796804 let correlation_id = Uuid :: new_v4 ( ) . to_string ( ) ;
797805 let _span = tracing:: error_span!( "test_trace_logs" , %correlation_id) . entered ( ) ;
798806
799- // Verify we're in span 1 with correct name
800- let ( span_id , span_meta) = subscriber
807+ // Verify we're in a span with correct name
808+ let ( test_span_id , span_meta) = subscriber
801809 . current_span ( )
802810 . into_inner ( )
803811 . expect ( "Should be inside a span" ) ;
804- assert_eq ! ( span_id. into_u64( ) , 1 , "Should be in span 1" ) ;
805812 assert_eq ! ( span_meta. name( ) , "test_trace_logs" ) ;
806813
807814 // Verify correlation_id was recorded
808- let span_data = subscriber. get_span ( 1 ) ;
815+ let span_data = subscriber. get_span ( test_span_id . into_u64 ( ) ) ;
809816 let recorded_id =
810817 get_span_attr ( & span_data, "correlation_id" ) . expect ( "correlation_id not found" ) ;
811818 assert_eq ! ( recorded_id, correlation_id) ;
@@ -816,16 +823,31 @@ mod tests {
816823 let result = UninitializedSandbox :: new ( GuestBinary :: FilePath ( bad_path) , None ) ;
817824 assert ! ( result. is_err( ) , "Sandbox creation should fail" ) ;
818825
819- // Verify we're still in span 1 ( our test span)
820- let ( span_id , _) = subscriber
826+ // Verify we're still in our test span
827+ let ( current_id , _) = subscriber
821828 . current_span ( )
822829 . into_inner ( )
823830 . expect ( "Should still be inside a span" ) ;
824- assert_eq ! ( span_id. into_u64( ) , 1 , "Should still be in span 1" ) ;
831+ assert_eq ! (
832+ current_id. into_u64( ) ,
833+ test_span_id. into_u64( ) ,
834+ "Should still be in the test span"
835+ ) ;
825836
826- // Verify span 2 was created by UninitializedSandbox::new
827- let inner_span_meta = subscriber. get_span_metadata ( 2 ) ;
828- assert_eq ! ( inner_span_meta. name( ) , "new" ) ;
837+ // Verify a span named "new" was created by UninitializedSandbox::new
838+ // (look up by name rather than hardcoded ID to avoid fragility)
839+ let all_spans = subscriber. get_all_spans ( ) ;
840+ let new_span_entry = all_spans
841+ . iter ( )
842+ . find ( |( & id, _) | {
843+ id != test_span_id. into_u64 ( )
844+ && subscriber. get_span_metadata ( id) . name ( ) == "new"
845+ } )
846+ . expect ( "Expected a span named 'new' from UninitializedSandbox::new" ) ;
847+ assert_eq ! (
848+ subscriber. get_span_metadata( * new_span_entry. 0 ) . name( ) ,
849+ "new"
850+ ) ;
829851
830852 // Verify the error event was emitted
831853 let events = subscriber. get_events ( ) ;
0 commit comments