@@ -572,6 +572,8 @@ enum CommandState<'a> {
572572 executed_at : & ' a Location < ' a > ,
573573 fingerprint : CommandFingerprint ,
574574 start_time : Instant ,
575+ #[ cfg( feature = "tracing" ) ]
576+ _span_guard : tracing:: span:: EnteredSpan ,
575577 } ,
576578}
577579
@@ -581,6 +583,8 @@ pub struct StreamingCommand {
581583 pub stderr : Option < ChildStderr > ,
582584 fingerprint : CommandFingerprint ,
583585 start_time : Instant ,
586+ #[ cfg( feature = "tracing" ) ]
587+ _span_guard : tracing:: span:: EnteredSpan ,
584588}
585589
586590#[ must_use]
@@ -672,6 +676,9 @@ impl ExecutionContext {
672676 ) -> DeferredCommand < ' a > {
673677 let fingerprint = command. fingerprint ( ) ;
674678
679+ #[ cfg( feature = "tracing" ) ]
680+ let span_guard = trace_cmd ! ( command) ;
681+
675682 if let Some ( cached_output) = self . command_cache . get ( & fingerprint) {
676683 command. mark_as_executed ( ) ;
677684 self . verbose ( || println ! ( "Cache hit: {command:?}" ) ) ;
@@ -692,13 +699,12 @@ impl ExecutionContext {
692699 executed_at,
693700 fingerprint,
694701 start_time : Instant :: now ( ) ,
702+ #[ cfg( feature = "tracing" ) ]
703+ _span_guard : span_guard,
695704 } ,
696705 } ;
697706 }
698707
699- #[ cfg( feature = "tracing" ) ]
700- let _run_span = trace_cmd ! ( command) ;
701-
702708 self . verbose ( || {
703709 println ! ( "running: {command:?} (created at {created_at}, executed at {executed_at})" )
704710 } ) ;
@@ -720,6 +726,8 @@ impl ExecutionContext {
720726 executed_at,
721727 fingerprint,
722728 start_time,
729+ #[ cfg( feature = "tracing" ) ]
730+ _span_guard : span_guard,
723731 } ,
724732 }
725733 }
@@ -773,6 +781,10 @@ impl ExecutionContext {
773781 if !command. run_in_dry_run && self . dry_run ( ) {
774782 return None ;
775783 }
784+
785+ #[ cfg( feature = "tracing" ) ]
786+ let span_guard = trace_cmd ! ( command) ;
787+
776788 let start_time = Instant :: now ( ) ;
777789 let fingerprint = command. fingerprint ( ) ;
778790 let cmd = & mut command. command ;
@@ -786,7 +798,15 @@ impl ExecutionContext {
786798
787799 let stdout = child. stdout . take ( ) ;
788800 let stderr = child. stderr . take ( ) ;
789- Some ( StreamingCommand { child, stdout, stderr, fingerprint, start_time } )
801+ Some ( StreamingCommand {
802+ child,
803+ stdout,
804+ stderr,
805+ fingerprint,
806+ start_time,
807+ #[ cfg( feature = "tracing" ) ]
808+ _span_guard : span_guard,
809+ } )
790810 }
791811}
792812
@@ -820,12 +840,17 @@ impl<'a> DeferredCommand<'a> {
820840 executed_at,
821841 fingerprint,
822842 start_time,
843+ #[ cfg( feature = "tracing") ]
844+ _span_guard,
823845 } => {
824846 let exec_ctx = exec_ctx. as_ref ( ) ;
825847
826848 let output =
827849 Self :: finish_process ( process, command, stdout, stderr, executed_at, exec_ctx) ;
828850
851+ #[ cfg( feature = "tracing" ) ]
852+ drop ( _span_guard) ;
853+
829854 if ( !exec_ctx. dry_run ( ) || command. run_in_dry_run )
830855 && output. status ( ) . is_some ( )
831856 && command. should_cache
0 commit comments