Skip to content
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: update docs for instrument #2908

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 24 additions & 4 deletions tracing-attributes/src/lib.rs
Expand Up @@ -109,12 +109,18 @@ mod expand;
///
/// Additional fields (key-value pairs with arbitrary data) can be passed to
/// to the generated span through the `fields` argument on the
/// `#[instrument]` macro. Strings, integers or boolean literals are accepted values
/// for each field. The name of the field must be a single valid Rust
/// identifier, nested (dotted) field names are not supported.
/// `#[instrument]` macro. Strings, integers or boolean literals are accepted
/// values for each field. The name of the field may be a nested (dotted) field
/// name.
///
/// When an additional field does not include a value and does not shadow a
/// function argument name, [`Empty`](tracing-core::field::Empty) will be
/// inserted and this field can be recorded later with
/// [`Span::record`](tracing::Span::record).
///
/// Note that overlap between the names of fields and (non-skipped) arguments
/// will result in a compile error.
/// will result in recording the value provided in the attribute and ignoring
/// the value passed as a function argument.
///
/// # Examples
/// Instrumenting a function:
Expand Down Expand Up @@ -220,6 +226,20 @@ mod expand;
/// }
/// ```
///
/// To add additional context not known at the time of the function call, add a
/// field without a value.
///
/// ```
/// # use tracing::Span;
/// # use tracing_attributes::instrument;
/// #[instrument(fields(foo="bar", id))]
/// fn my_function(arg: usize) {
/// // ...
/// Span::current().record("id", 1);
/// // ...
/// }
/// ```
///
/// Adding the `ret` argument to `#[instrument]` will emit an event with the function's
/// return value when the function returns:
///
Expand Down