@@ -22,7 +22,7 @@ use tracing::Subscriber;
2222use tracing_core:: event:: Event ;
2323use tracing_core:: metadata:: Metadata ;
2424use tracing_core:: span:: { Attributes , Current , Id , Record } ;
25- use tracing_core:: { Level , LevelFilter } ;
25+ use tracing_core:: { Interest , Level , LevelFilter } ;
2626use tracing_serde:: AsSerde ;
2727
2828#[ derive( Debug , Clone ) ]
@@ -69,6 +69,11 @@ impl TracingSubscriber {
6969 EVENTS . with ( |events| events. borrow ( ) . clone ( ) )
7070 }
7171
72+ /// Returns all recorded spans as a HashMap
73+ pub fn get_all_spans ( & self ) -> HashMap < u64 , Value > {
74+ SPANS . with ( |spans| spans. borrow ( ) . clone ( ) )
75+ }
76+
7277 pub fn test_trace_records < F : Fn ( & HashMap < u64 , Value > , & Vec < Value > ) > ( & self , f : F ) {
7378 SPANS . with ( |spans| {
7479 EVENTS . with ( |events| {
@@ -88,6 +93,13 @@ impl TracingSubscriber {
8893}
8994
9095impl Subscriber for TracingSubscriber {
96+ fn register_callsite ( & self , _metadata : & ' static Metadata < ' static > ) -> Interest {
97+ // Return Interest::sometimes() to prevent the global interest cache from caching
98+ // our decision. This avoids race conditions when running tests in parallel,
99+ // since each call to enabled() will be re-evaluated per-thread.
100+ Interest :: sometimes ( )
101+ }
102+
91103 fn enabled ( & self , metadata : & Metadata < ' _ > ) -> bool {
92104 LEVEL_FILTER . with ( |level_filter| metadata. level ( ) <= & * level_filter. borrow ( ) )
93105 }
0 commit comments