-
Notifications
You must be signed in to change notification settings - Fork 732
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
tracing/log
doesn't work with tokio::spawn
/ .with_current_subscriber()
.
#2913
Comments
Note:
But this is not something I want to enable in the library - IIUC it adds overhead as it generates 2 event for each tracing call. |
Hmm, this is interesting... I think the But I can't seem to find the code that decides whether to log or not @hawkw ? |
The A library should not generally enable the |
With that said, we probably could fix this by having |
What should the library do instead? It seemed reasonable that when spawning a task we want it to use current subscriber, not some default one. |
Those calls were introduced in e557095, with message: ``` Now, when the driver spawns a task to run a new future on it, that future will use the same subscriber as the code that spawned the task in the first place. ``` There is unfortunately no explanation about when it is necessary. I don't see any problems after removing those - logs are still collected correctly using a tracing subscriber. Those calls however have a harmful side-effect: they prevent usage of `log` loggers to listen to driver logs using `log` feature in `tracing` crate. After reporting the problem to `tracing` crate: tokio-rs/tracing#2913 one of maintainers said that using `.with_current_subscriber()` in a library is not necessary in general. As I don't see any issue caused by removing these calls, but their existence cause an issue, they are removed in this commit.
Those calls were introduced in e557095, with message: ``` Now, when the driver spawns a task to run a new future on it, that future will use the same subscriber as the code that spawned the task in the first place. ``` There is unfortunately no explanation about when it is necessary. I don't see any problems after removing those - logs are still collected correctly using a tracing subscriber. Those calls however have a harmful side-effect: they prevent usage of `log` loggers to listen to driver logs using `log` feature in `tracing` crate. After reporting the problem to `tracing` crate: tokio-rs/tracing#2913 one of maintainers said that using `.with_current_subscriber()` in a library is not necessary in general. As I don't see any issue caused by removing these calls, but their existence cause an issue, they are removed in this commit.
Bug Report
Version
└── tracing v0.1.40
├── tracing-attributes v0.1.27 (proc-macro)
└── tracing-core v0.1.32
Platform
Fedora 39
uname -a:
Linux scyllaptop 6.7.9-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Mar 6 19:35:04 UTC 2024 x86_64 GNU/Linux
Description
Let me start by saying that I'm not 100% it's a bug - it may be be lack of knowledge in regards to usage of
tracing
.I'm one of maintainters of a library ( https://github.com/scylladb/scylla-rust-driver ) that uses tokio and tracing.
We call
.with_current_subscriber()
on each future passed totokio::spawn
which according to docs ( https://docs.rs/tracing/latest/tracing/instrument/trait.WithSubscriber.html#method.with_current_subscriber )seems like what we should do as a library.
This works as intended when using tracing subscriber. Example:
Consider a crate with the following
Cargo.toml
(it will be used for another example later, thus unused dependencies):and the following
main.rs
:After
cargo run
traces are printed and logs are not, as expected:Now let's switch tracing subscriber for env_logger. As far as I understand from
tracing
's docs env_logger should print my traces because I enabledlog
feature ontracing
crate.New main.rs:
Output:
As you can see, no traces are printed after the
tokio::spawn
call - interestingly it affects even the tracing call in the same function.It's not the problem with
log
calls - issue persists even if I remove them.This results in our library not being usable with
log
loggers likeenv_logger
even if we enablelog
feature :(The text was updated successfully, but these errors were encountered: