-
Notifications
You must be signed in to change notification settings - Fork 734
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
Allow disabling logging feature #1190
Allow disabling logging feature #1190
Conversation
c2bcb6e
to
ffce665
Compare
It was renamed everywhere in tokio-rs#1015, but until tokio-rs#1190 it wasn't possible to enter this macro branch. Now it fails with the following: ``` Compiling tracing v0.2.0 (/Users/ivan/projects/tracing/tracing) error[E0433]: failed to resolve: maybe a missing crate `dispatcher`? --> /Users/ivan/projects/tracing/tracing/src/macros.rs:2351:21 | 2351 | if !$crate::dispatcher::has_been_set() { | ^^^^^^^^^^ maybe a missing crate `dispatcher`? ```
The timings are more different if I run the same traced code twice and measure more precisely, but it's still better. fn trace_timings() {
let now = std::time::Instant::now();
let before_span_created = now.elapsed().as_nanos();
let span = tracing::span!(tracing::Level::TRACE, "setup");
let after_span_created = now.elapsed().as_nanos();
let entered = span.enter();
let after_span_entered = now.elapsed().as_nanos();
drop(entered);
let after_span_entered_dropped = now.elapsed().as_nanos();
drop(span);
let after_span_dropped = now.elapsed().as_nanos();
eprintln!("before span created ns = {:6}", before_span_created);
eprintln!("after span created ns = {:6}", after_span_created);
eprintln!("after enter ns = {:6}", after_span_entered);
eprintln!("after entered drop ns = {:6}", after_span_entered_dropped);
eprintln!("after span drop ns = {:6}", after_span_dropped);
}
|
Logging macro `if_log_enabled` checks both `log` and `always-log` crate features to select which macro version to use. Unfortunately, `log` feature cannot be set by crate consumers in either existing form or if added to `Cargo.toml`, probably because of a name clash with `log` crate: ```diff $ git diff Cargo.toml diff --git a/tracing/Cargo.toml b/tracing/Cargo.toml index 37bb61f..e030d27 100644 --- a/tracing/Cargo.toml +++ b/tracing/Cargo.toml @@ -63,7 +63,7 @@ release_max_level_trace = [] async-await = [] std = ["tracing-core/std"] +log = ["log"] log-always = ["log"] attributes = ["tracing-attributes"] ``` ``` Caused by: optional dependency `log` is not included in any feature Make sure that `dep:log` is included in one of features in the [features] table. ``` I'm renaming `log` feature to `logging` to work around that. There's a slight improvement in throughput with logging disabled: ``` global/collector/span_no_fields time: [7.9682 ns 7.9704 ns 7.9729 ns] change: [-13.902% -13.812% -13.720%] (p = 0.00 < 0.05) Performance has improved. ```
ffce665
to
2d54456
Compare
Please disregard my ramblings about the timings, these are from a non-release build. Actual difference from the benchmark:
I amended the commit to reflect that. #1191 should probably be merged before this. |
It was renamed everywhere in #1015, but until #1190 it wasn't possible to enter this macro branch. Now it fails with the following: ``` Compiling tracing v0.2.0 (/Users/ivan/projects/tracing/tracing) error[E0433]: failed to resolve: maybe a missing crate `dispatcher`? --> /Users/ivan/projects/tracing/tracing/src/macros.rs:2351:21 | 2351 | if !$crate::dispatcher::has_been_set() { | ^^^^^^^^^^ maybe a missing crate `dispatcher`? ``` Co-authored-by: Eliza Weisman <eliza@buoyant.io>
I'm not sure if this is the case. It should be possible to enable or disable the optional dependency as though it were a crate feature, without adding it to the Something like this should work, and I'm pretty sure it's been used successfully in the past. [dependencies.tracing]
version = "0.1"
features = ["log"] Does this no longer work? |
Not sure how I messed up my local setup, but it does indeed work as intended. |
Logging macro
if_log_enabled
checks bothlog
andalways-log
crate features to select which macro version to use. Unfortunately,log
feature cannot be set by crate consumers in either existing form or if added toCargo.toml
, probably because of a name clash withlog
crate:I'm renaming
log
feature tologging
to work around that.With the following code:
Typical timings with logging feature enabled (but not logging anything):
Typical timings with logging disabled (this PR):