-
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
tracing::instrument decorator should require a level argument. #1070
Comments
IIRC, when the macro was initially prototyped, it defaulted to the TRACE level, and then folks asked to change it to INFO. I think that having a default level was probably a mistake --- no matter what the default is, I think it's going to surprise someone. I'm +1 on removing the default in I think it would be nice to be able to use the attributes without required arguments, though, so maybe we should consider introducing leveled shorthand attributes (similar to the Of course, we can add leveled shorthand macros separately from removing the default level, so figuring out the right naming isn't a blocker. |
As a side note, removing the default level should be pretty simple, so if anyone is interested in helping contribute to 0.2, I'd be happy to provide guidance. |
I found myself kind of wishing I could specify level on a per-field basis in the |
Hey @hawkw, I would love to take up this issue. I have added a compile error in case of no level specified in the instrument attribute. Let me know if I should take up shorthands alongside this change. Also, Can you direct me to all the places where I need to update documentation and examples? |
This commit removes the default level for the #[instrument] attribute macro, forcing user to explicitly specify the logging level. Fixes tokio-rs#1070 Signed-off-by: psinghal20 <psinghal20@gmail.com>
I really don't understand how something that literally trace a function call on a crate named tracing default to info level. I agree with remove the default. And I agree about having alias.
We could rename to
or short instrument
for completeness:
|
Feature Request
Crates
tracing::instrument
Motivation
The
tracing::instrument
proc macro is incredibly useful, and the docs encourage users to use it, as well as set a level. Not all users read documentation, so many use defaults. (Like me)By default, they seem to decorate at all logging levels, which can impact performance for users in unexpected ways.
We met this problem in Vector recently, we merged vectordotdev/vector#4485 which introduced
tracing::instrument
on some hot paths, and, since we didn't pick a level, this lead to a 5x slowdown of the overall code along many of our topologies. We only caught it after during testing with bench users. (Our recent CI migration had benching out of commission, we're feeling that bad right now!)Proposal
I propose
#[tracing::instrument(level = "something")]
be the required minimal syntax. This forces users to understand the performance characteristics of the tool and make a deliberate choice.Alternatives
We could choose a default level, but someone will always complain.
We could not change. There is no harm in this.
We could update the docs to better highlight this issue. (This should probably be done regardless)
The text was updated successfully, but these errors were encountered: