@@ -9,6 +9,7 @@ use std::time::Duration;
99use arc_swap:: ArcSwap ;
1010use tokio:: sync:: { Mutex , Semaphore , mpsc, oneshot} ;
1111use tokio:: task:: JoinHandle ;
12+ #[ cfg( feature = "trace" ) ]
1213use tracing:: { error, trace, warn} ;
1314
1415use crate :: error:: { ConfigError , EventBusError } ;
@@ -349,6 +350,7 @@ impl EventBus {
349350 return Err ( EventBusError :: Stopped ) ;
350351 }
351352
353+ #[ cfg( feature = "trace" ) ]
352354 trace ! ( "event_bus.subscribe {:?}" , & registered. name) ;
353355 let id = self . next_subscription_id ( ) ;
354356 let listener = ( registered. register ) ( id, subscription_policy, once) ;
@@ -357,7 +359,7 @@ impl EventBus {
357359 registry. add_listener ( TypeId :: of :: < E > ( ) , std:: any:: type_name :: < E > ( ) , listener) ;
358360 self . refresh_snapshot_locked ( & registry) . await ;
359361
360- Ok ( Subscription :: new ( id, self . clone ( ) ) )
362+ Ok ( Subscription :: new ( id, registered . name , self . clone ( ) ) )
361363 }
362364
363365 /// Register a sync handler that receives [`DeadLetter`] events.
@@ -450,7 +452,7 @@ impl EventBus {
450452 let mut registry = self . inner . registry . lock ( ) . await ;
451453 registry. add_global_middleware ( id, erased) ;
452454 self . refresh_snapshot_locked ( & registry) . await ;
453- Ok ( Subscription :: new ( id, self . clone ( ) ) )
455+ Ok ( Subscription :: new ( id, None , self . clone ( ) ) )
454456 }
455457
456458 /// Add a global **sync** middleware that intercepts all event types.
@@ -474,7 +476,7 @@ impl EventBus {
474476 let mut registry = self . inner . registry . lock ( ) . await ;
475477 registry. add_global_middleware ( id, erased) ;
476478 self . refresh_snapshot_locked ( & registry) . await ;
477- Ok ( Subscription :: new ( id, self . clone ( ) ) )
479+ Ok ( Subscription :: new ( id, None , self . clone ( ) ) )
478480 }
479481
480482 /// Add an async middleware scoped to a single event type `E`.
@@ -514,7 +516,7 @@ impl EventBus {
514516 let mut registry = self . inner . registry . lock ( ) . await ;
515517 registry. add_typed_middleware ( TypeId :: of :: < E > ( ) , std:: any:: type_name :: < E > ( ) , slot. clone ( ) ) ;
516518 self . refresh_snapshot_locked ( & registry) . await ;
517- Ok ( Subscription :: new ( slot. id , self . clone ( ) ) )
519+ Ok ( Subscription :: new ( slot. id , None , self . clone ( ) ) )
518520 }
519521
520522 /// Add a **sync** middleware scoped to a single event type `E`.
@@ -549,7 +551,7 @@ impl EventBus {
549551 let mut registry = self . inner . registry . lock ( ) . await ;
550552 registry. add_typed_middleware ( TypeId :: of :: < E > ( ) , std:: any:: type_name :: < E > ( ) , slot. clone ( ) ) ;
551553 self . refresh_snapshot_locked ( & registry) . await ;
552- Ok ( Subscription :: new ( slot. id , self . clone ( ) ) )
554+ Ok ( Subscription :: new ( slot. id , None , self . clone ( ) ) )
553555 }
554556
555557 async fn publish_erased (
@@ -645,11 +647,12 @@ impl EventBus {
645647 tokio:: spawn ( async move {
646648 let _keep = permit;
647649 let dispatch_ctx = bus. inner . full_dispatch_context ( ) ;
648- if let Err ( err ) = bus
650+ if let Err ( _err ) = bus
649651 . publish_erased ( TypeId :: of :: < E > ( ) , Arc :: new ( event) , std:: any:: type_name :: < E > ( ) , & dispatch_ctx)
650652 . await
651653 {
652- error ! ( error = %err, "event_bus.try_publish.dispatch_failed" ) ;
654+ #[ cfg( feature = "trace" ) ]
655+ error ! ( error = %_err, "event_bus.try_publish.dispatch_failed" ) ;
653656 }
654657 } ) ;
655658 Ok ( ( ) )
@@ -786,5 +789,6 @@ async fn control_loop(inner: std::sync::Weak<Inner>, mut notify_rx: mpsc::Unboun
786789 }
787790 }
788791 }
792+ #[ cfg( feature = "trace" ) ]
789793 warn ! ( "event_bus.control_loop.stopped" ) ;
790794}
0 commit comments