hyper
hyper copied to clipboard
Make tracing optional
Is your feature request related to a problem? Please describe.
When hyper is used anywhere within the tracing pipeline, e.g. sending data to a tracing server, we can get into an infinite loop, since hyper uses tracing unconditionally. This makes the crate effectively unusable in such scenarios.
Describe the solution you'd like A flag for tracing usage. Ideally, there should be support for users to enable tracing in their code, but disable it in tracing itself.
Describe alternatives you've considered Using another crate.
Additional context Originally found at https://github.com/krojew/tracing-elastic-apm/issues/13
tracing has a feature named max_level_off that effectively disabled all types of logging. The only problem is that it only works globally. In your tracing subscriber, is there a way to filter hyper out from the output?
I feel like we ran into a similar issue in the Tokio Console, where we noticed that using tokio::sync types inside the console subscriber, trying to process tracing results, would cause new events to trigger since we had instrumented those types. I don't recall what the best proposed solution there was. I think it was either:
- trying to make
tracingbetter handle reentrancy - provide an easy way to say something like
tracing::with_no_subscriber(|| do_the_thing()).
@hawkw do you recall? I believe this is a problem that likely exists in many cases, not just hyper.
In this case, this isn't a re-entrancy issue like the tokio::sync issues in tokio-console. The task that calls into hyper is not happening inside of a call into a tracing::Subscriber method, it's happening in a task that's spawned as a result of such a method. So, in this case, it's not really possible for tracing to handle this internally. Instead, the tracing-elastic-apm crate should disable the tracing subscriber when spawning its task that uses hyper, here: https://github.com/krojew/tracing-elastic-apm/blob/36dd07719cfc852037d304c8b042152d064c03ac/src/apm_client.rs#L106
This could be done using tracing's WithSubscriber combinator:
use tracing::instrument::WithSubscriber;
tokio::spawn(async {
/* ... */
}.with_subscriber(tracing::subscriber::NoSubscriber::default())
I agree with @seanmonstar's suggestion
- provide an easy way to say something like
tracing::with_no_subscriber(|| do_the_thing()).
that tracing could probably have an API specifically for disabling the subscriber in a scope, which might make this code a little simpler.
Unfortunately .with_subscriber(NoSubscriber::default()) does not help - there are still spans from hyper being passed to tracing layers.