Skip to content

Inherit tracing spans, if the program uses tracing #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 1, 2025

Conversation

delan
Copy link
Contributor

@delan delan commented Jul 31, 2025

some programs use tracing, a log-compatible logging framework. tracing allows programs to prefix log messages with additional context via span!() or #[instrument], but StderrThread spawns a new thread to read command output, so this context is lost.

this patch adds an optional feature “tracing” with an optional dependency on tracing. when enabled, StderrThread::new() propagates the current span (if any) from the calling thread to the new thread. as a result, any context added by the calling thread is preserved in the info logs generated by stderr.

@delan
Copy link
Contributor Author

delan commented Jul 31, 2025

with the following patch to make tracing optional in the tracing example:

diff --git a/Cargo.toml b/Cargo.toml
index 1d250f3..54b2872 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,4 +33,4 @@ tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }

 [[example]]
 name = "tracing"
-required-features = ["tracing"]
+# required-features = ["tracing"]
image

@tao-guo tao-guo merged commit f0c102c into rust-shell-script:master Aug 1, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants