@@ -19,6 +19,7 @@ use std::collections::HashMap;
1919
2020use serde_json:: { Value , json, to_string_pretty} ;
2121use tracing:: Subscriber ;
22+ use tracing_core:: Interest ;
2223use tracing_core:: event:: Event ;
2324use tracing_core:: metadata:: Metadata ;
2425use tracing_core:: span:: { Attributes , Current , Id , Record } ;
@@ -69,6 +70,11 @@ impl TracingSubscriber {
6970 EVENTS . with ( |events| events. borrow ( ) . clone ( ) )
7071 }
7172
73+ /// Returns all recorded spans as a HashMap
74+ pub fn get_all_spans ( & self ) -> HashMap < u64 , Value > {
75+ SPANS . with ( |spans| spans. borrow ( ) . clone ( ) )
76+ }
77+
7278 pub fn test_trace_records < F : Fn ( & HashMap < u64 , Value > , & Vec < Value > ) > ( & self , f : F ) {
7379 SPANS . with ( |spans| {
7480 EVENTS . with ( |events| {
@@ -88,6 +94,13 @@ impl TracingSubscriber {
8894}
8995
9096impl Subscriber for TracingSubscriber {
97+ fn register_callsite ( & self , _metadata : & ' static Metadata < ' static > ) -> Interest {
98+ // Return Interest::sometimes() to prevent the global interest cache from caching
99+ // our decision. This avoids race conditions when running tests in parallel,
100+ // since each call to enabled() will be re-evaluated per-thread.
101+ Interest :: sometimes ( )
102+ }
103+
91104 fn enabled ( & self , metadata : & Metadata < ' _ > ) -> bool {
92105 LEVEL_FILTER . with ( |level_filter| metadata. level ( ) <= & * level_filter. borrow ( ) )
93106 }
0 commit comments