-
Notifications
You must be signed in to change notification settings - Fork 726
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
attributes: implement #[instrument(tracing)]
#1819
base: master
Are you sure you want to change the base?
Changes from 8 commits
78b4e37
087e369
fabca1a
aadd850
b7f105e
1684e54
b91ee93
899714d
96f016f
40ad784
f4b31c5
a185b25
a17b04d
3b5d4c3
fc39c55
12b854e
3802e68
72bc05c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//! Ensures that all unqualified uses of `tracing` can be overridden. | ||
//! | ||
//! As compilation fails directly when `tracing` is shadowed, no test functions are run here. | ||
|
||
use ::tracing::instrument; | ||
|
||
/// Shadows the crate `tracing` locally. | ||
#[allow(dead_code)] | ||
mod tracing {} | ||
|
||
#[instrument(tracing = ::tracing)] | ||
pub fn plain() {} | ||
|
||
#[instrument(tracing = ::tracing)] | ||
pub async fn async_fn() {} | ||
|
||
#[derive(Debug)] | ||
pub struct Custom; | ||
|
||
#[instrument(tracing = ::tracing)] | ||
pub fn implicit_field_debug(custom: Custom) {} | ||
|
||
#[instrument(tracing = ::tracing, level = "error")] | ||
pub fn level_error() {} | ||
#[instrument(tracing = ::tracing, level = "warn")] | ||
pub fn level_warn() {} | ||
#[instrument(tracing = ::tracing, level = "info")] | ||
pub fn level_info() {} | ||
#[instrument(tracing = ::tracing, level = "debug")] | ||
pub fn level_debug() {} | ||
#[instrument(tracing = ::tracing, level = "trace")] | ||
pub fn level_trace() {} | ||
|
||
#[instrument(tracing = ::tracing, level = 5)] | ||
pub fn level_5() {} | ||
#[instrument(tracing = ::tracing, level = 4)] | ||
pub fn level_4() {} | ||
#[instrument(tracing = ::tracing, level = 3)] | ||
pub fn level_3() {} | ||
#[instrument(tracing = ::tracing, level = 2)] | ||
pub fn level_2() {} | ||
#[instrument(tracing = ::tracing, level = 1)] | ||
pub fn level_1() {} | ||
|
||
const A_LEVEL: ::tracing::Level = ::tracing::Level::INFO; | ||
#[instrument(tracing = ::tracing, level = A_LEVEL)] | ||
pub fn level_ident() {} | ||
Comment on lines
+34
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ability to specify the level through an integer constant or (I'd still like to keep these tests here regardless of the answer to that question, since they all have distinct code paths.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should probably be documented, but in a follow-up PR. We should probably document it on the |
||
|
||
#[::tracing::instrument(tracing = ::tracing, fields(empty))] | ||
pub fn empty() {} | ||
|
||
#[::tracing::instrument(tracing = ::tracing, ret)] | ||
pub fn ret() {} | ||
|
||
#[instrument(tracing = ::tracing, ret(Debug))] | ||
pub fn ret_debug() {} | ||
|
||
#[instrument(tracing = ::tracing, ret(Display))] | ||
pub fn ret_display() -> &'static str { | ||
"" | ||
} | ||
|
||
#[instrument(tracing = ::tracing, err)] | ||
pub fn err() -> Result<(), &'static str> { | ||
Ok(()) | ||
} | ||
|
||
#[instrument(tracing = ::tracing, err(Debug))] | ||
pub fn err_debug() -> Result<(), &'static str> { | ||
Ok(()) | ||
} | ||
|
||
#[instrument(tracing = ::tracing, err(Display))] | ||
pub fn err_display() -> Result<(), &'static str> { | ||
Ok(()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure if this should go into the doc comment, on second thought. A comment above the
quote!(tracing)
may be more apt.I'd actually like to suggest adding one of those breaking change comments there: A default of
quote!(::tracing)
would avoid collisions with consumer-defined names just about entirely by default, but unfortunately it would also break the "hidden override" that's theoretically available right now.