@@ -2,6 +2,7 @@ use futures::{Future, FutureExt};
22use std:: borrow:: Cow ;
33use std:: pin:: pin;
44use tokio:: sync:: oneshot;
5+ use tracing:: Span ;
56
67pub mod prometheus_handle;
78
@@ -40,13 +41,19 @@ where
4041 F : FnOnce ( ) -> R + Send + ' static ,
4142 R : Send + ' static ,
4243{
43- tokio:: task:: spawn_blocking ( f)
44- . await
45- . unwrap_or_else ( |e| match e. try_into_panic ( ) {
46- Ok ( panic_payload) => std:: panic:: resume_unwind ( panic_payload) ,
47- // the only other variant is cancelled, which shouldn't happen because we don't cancel it.
48- Err ( e) => panic ! ( "Unexpected JoinError: {e}" ) ,
49- } )
44+ // Ensure that `f` executes in the current span context.
45+ // If there is no current span, or it is disabled, `span` is disabled.
46+ let span = Span :: current ( ) ;
47+ tokio:: task:: spawn_blocking ( move || {
48+ let _enter = span. enter ( ) ;
49+ f ( )
50+ } )
51+ . await
52+ . unwrap_or_else ( |e| match e. try_into_panic ( ) {
53+ Ok ( panic_payload) => std:: panic:: resume_unwind ( panic_payload) ,
54+ // the only other variant is cancelled, which shouldn't happen because we don't cancel it.
55+ Err ( e) => panic ! ( "Unexpected JoinError: {e}" ) ,
56+ } )
5057}
5158
5259/// Await `fut`, while also polling `also`.
0 commit comments