Skip to content

Commit cf435e7

Browse files
authored
chore: Added tracing span for build script execution (#16053)
### What does this PR try to resolve? While reading up on how Cargo's build script implementation I noticed we do not have any tracking for it build script execution. This PR adds a span for build script execution giving better visualization for `CARGO_LOG_PROFILE`. Example output: <img width="2325" height="1109" alt="image" src="https://github.com/user-attachments/assets/945c1a14-90a6-4520-b27b-6e94f8619099" /> NOTE: The `cmd.to_string()` is only executed when the tracing level is DEBUG so it should not be executed under normal conditions.
2 parents 0b3a76f + 5efcc2a commit cf435e7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,9 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
564564
let timestamp = paths::set_invocation_time(&script_run_dir)?;
565565
let prefix = format!("[{} {}] ", id.name(), id.version());
566566
let mut log_messages_in_case_of_panic = Vec::new();
567-
let output = cmd
568-
.exec_with_streaming(
567+
let span = tracing::debug_span!("build_script", process = cmd.to_string());
568+
let output = span.in_scope(|| {
569+
cmd.exec_with_streaming(
569570
&mut |stdout| {
570571
if let Some(error) = stdout.strip_prefix(CARGO_ERROR_SYNTAX) {
571572
log_messages_in_case_of_panic.push((Severity::Error, error.to_owned()));
@@ -612,7 +613,8 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
612613
}
613614

614615
build_error_context
615-
});
616+
})
617+
});
616618

617619
// If the build failed
618620
if let Err(error) = output {

0 commit comments

Comments
 (0)