@@ -593,6 +593,8 @@ enum CommandState<'a> {
593593 executed_at : & ' a Location < ' a > ,
594594 fingerprint : CommandFingerprint ,
595595 start_time : Instant ,
596+ #[ cfg( feature = "tracing" ) ]
597+ _span_guard : tracing:: span:: EnteredSpan ,
596598 } ,
597599}
598600
@@ -602,6 +604,8 @@ pub struct StreamingCommand {
602604 pub stderr : Option < ChildStderr > ,
603605 fingerprint : CommandFingerprint ,
604606 start_time : Instant ,
607+ #[ cfg( feature = "tracing" ) ]
608+ _span_guard : tracing:: span:: EnteredSpan ,
605609}
606610
607611#[ must_use]
@@ -693,6 +697,9 @@ impl ExecutionContext {
693697 ) -> DeferredCommand < ' a > {
694698 let fingerprint = command. fingerprint ( ) ;
695699
700+ #[ cfg( feature = "tracing" ) ]
701+ let span_guard = trace_cmd ! ( command) ;
702+
696703 if let Some ( cached_output) = self . command_cache . get ( & fingerprint) {
697704 command. mark_as_executed ( ) ;
698705 self . verbose ( || println ! ( "Cache hit: {command:?}" ) ) ;
@@ -713,13 +720,12 @@ impl ExecutionContext {
713720 executed_at,
714721 fingerprint,
715722 start_time : Instant :: now ( ) ,
723+ #[ cfg( feature = "tracing" ) ]
724+ _span_guard : span_guard,
716725 } ,
717726 } ;
718727 }
719728
720- #[ cfg( feature = "tracing" ) ]
721- let _run_span = trace_cmd ! ( command) ;
722-
723729 self . verbose ( || {
724730 println ! ( "running: {command:?} (created at {created_at}, executed at {executed_at})" )
725731 } ) ;
@@ -741,6 +747,8 @@ impl ExecutionContext {
741747 executed_at,
742748 fingerprint,
743749 start_time,
750+ #[ cfg( feature = "tracing" ) ]
751+ _span_guard : span_guard,
744752 } ,
745753 }
746754 }
@@ -794,6 +802,10 @@ impl ExecutionContext {
794802 if !command. run_in_dry_run && self . dry_run ( ) {
795803 return None ;
796804 }
805+
806+ #[ cfg( feature = "tracing" ) ]
807+ let span_guard = trace_cmd ! ( command) ;
808+
797809 let start_time = Instant :: now ( ) ;
798810 let fingerprint = command. fingerprint ( ) ;
799811 let cmd = & mut command. command ;
@@ -807,7 +819,15 @@ impl ExecutionContext {
807819
808820 let stdout = child. stdout . take ( ) ;
809821 let stderr = child. stderr . take ( ) ;
810- Some ( StreamingCommand { child, stdout, stderr, fingerprint, start_time } )
822+ Some ( StreamingCommand {
823+ child,
824+ stdout,
825+ stderr,
826+ fingerprint,
827+ start_time,
828+ #[ cfg( feature = "tracing" ) ]
829+ _span_guard : span_guard,
830+ } )
811831 }
812832}
813833
@@ -841,12 +861,17 @@ impl<'a> DeferredCommand<'a> {
841861 executed_at,
842862 fingerprint,
843863 start_time,
864+ #[ cfg( feature = "tracing") ]
865+ _span_guard,
844866 } => {
845867 let exec_ctx = exec_ctx. as_ref ( ) ;
846868
847869 let output =
848870 Self :: finish_process ( process, command, stdout, stderr, executed_at, exec_ctx) ;
849871
872+ #[ cfg( feature = "tracing" ) ]
873+ drop ( _span_guard) ;
874+
850875 if ( !exec_ctx. dry_run ( ) || command. run_in_dry_run )
851876 && output. status ( ) . is_some ( )
852877 && command. should_cache
0 commit comments