Skip to content

Commit

Permalink
attributes: permit #[instrument(follows_from = …)] (tokio-rs#2093)
Browse files Browse the repository at this point in the history
This PR extends the `#[instrument]` attribute to accept an optional
`follows_from = …` argument that supplies any number of
`Span::follows_from` relationships to the generated `Span`.

## Motivation

This PR resolves tokio-rs#879.

## Solution

This PR largely follows the implementation strategy articulated by
@hawkw:
tokio-rs#879 (comment)

In that comment, @hawkw suggests taking one of two approaches:
1. each `follows_from` relationship is supplied with a distinct
   `follows_from` argument
2. the `follows_from` argument is provided once, and its value is a
   **list** of indirect causes

I take the second approach, since it is slightly more flexible: it
allows for the number of indirect causes to vary at runtime.

This addition is complemented by changes to `tracing-mock` to permit
making `follows_from` assertions for testing purposes.
  • Loading branch information
jswrenn authored and kaffarell committed May 22, 2024
1 parent 5c7abbb commit b60ba70
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tracing-attributes/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ fn gen_block<B: ToTokens>(
})*
};

let follows_from = args.follows_from.iter();
let follows_from = quote! {
#(for cause in #follows_from {
__tracing_attr_span.follows_from(cause);
})*
};

// generate this inside a closure, so we can return early on errors.
let span = (|| {
// Pull out the arguments-to-be-skipped first, so we can filter results
Expand Down

0 comments on commit b60ba70

Please sign in to comment.