@@ -75,8 +75,15 @@ use syn::{
75
75
/// Instruments a function to create and enter a `tracing` [span] every time
76
76
/// the function is called.
77
77
///
78
- /// The generated span's name will be the name of the function, and any
79
- /// arguments to that function will be recorded as fields using `fmt::Debug`.
78
+ /// The generated span's name will be the name of the function. Any arguments
79
+ /// to that function will be recorded as fields using [`fmt::Debug`]. To skip
80
+ /// recording a function's or method's argument, pass the argument's name
81
+ /// to the `skip` argument on the `#[instrument]` macro. For example,
82
+ /// `skip` can be used when an argument to an instrumented function does
83
+ /// not implement [`fmt::Debug`], or to exclude an argument with a verbose
84
+ /// or costly Debug implementation. Note that:
85
+ /// - multiple argument names can be passed to `skip`.
86
+ /// - arguments passed to `skip` do _not_ need to implement `fmt::Debug`.
80
87
///
81
88
/// # Examples
82
89
/// Instrumenting a function:
@@ -110,14 +117,24 @@ use syn::{
110
117
/// # fn main() {}
111
118
/// ```
112
119
///
113
- /// When the `async-await` feature flag is enabled, `async fn`s may also be
114
- /// instrumented:
120
+ /// To skip recording an argument, pass the argument's name to the `skip`:
115
121
///
116
- /// ```compile_fail
117
- /// // this currently only compiles on nightly.
118
- /// #![feature(async-await)]
122
+ /// ```
119
123
/// # use tracing_attributes::instrument;
124
+ /// struct NonDebug;
125
+ ///
126
+ /// #[instrument(skip(non_debug))]
127
+ /// fn my_function(arg: usize, non_debug: NonDebug) {
128
+ /// // ...
129
+ /// }
130
+ /// # fn main() {}
131
+ /// ```
132
+ ///
133
+ /// If `tracing_futures` is specified as a dependency in `Cargo.toml`,
134
+ /// `async fn`s may also be instrumented:
120
135
///
136
+ /// ```
137
+ /// # use tracing_attributes::instrument;
121
138
/// #[instrument]
122
139
/// pub async fn my_function() -> Result<(), ()> {
123
140
/// // ...
@@ -126,13 +143,9 @@ use syn::{
126
143
/// # fn main() {}
127
144
/// ```
128
145
///
129
- /// # Notes
130
- /// - All argument types must implement `fmt::Debug`
131
- /// - When using `#[instrument]` on an `async fn`, the `tracing_futures` must
132
- /// also be specified as a dependency in `Cargo.toml`.
133
- ///
134
146
/// [span]: https://docs.rs/tracing/0.1.5/tracing/span/index.html
135
147
/// [`tracing`]: https://github.com/tokio-rs/tracing
148
+ /// [`fmt::Debug`]: https://doc.rust-lang.org/std/fmt/trait.Debug.html
136
149
#[ proc_macro_attribute]
137
150
pub fn instrument ( args : TokenStream , item : TokenStream ) -> TokenStream {
138
151
let input: ItemFn = syn:: parse_macro_input!( item as ItemFn ) ;
0 commit comments