tracing/tracing-attributes
Simon THOBY 369b0c5e1d
attributes: support using #[instrument] with async-trait (#711)
## Motivation

As outlined in #399, right now `tracing-futures` (or more precisely, the
code generated by `#[instrument]`) is not working well with async-trait.
What happens is that async-trait rewrites the trait method as a
non-async function, insides of which it pins the async method we want to
instrument, and we end up instrumenting the wrapper instead of the async
fn.

This will allow people to use traits with (seemingly) async functions
along with `#[instrument]`.

## Solution

I decided to follow the discussion at
https://github.com/dtolnay/async-trait/issues/45 and see if I could make
it working. Right now I would describe its state as "works for me, and
*should* work for everyone".

The `instrument` macro will now:

* Rewrite the block when it looks like there is async_trait involved to
  wrap the internal async function instead of the wrapper generated by
  `async-trait` 
* Rewrite '_self' as 'self' when using #[instrument] jointly with 
  `async-trait`

Fixes #399
2020-05-13 13:01:55 -07:00
..

tracing-attributes

Macro attributes for application-level tracing.

Crates.io Documentation Documentation (master) MIT licensed Build Status Discord chat

Documentation | Chat

Overview

tracing is a framework for instrumenting Rust programs to collect structured, event-based diagnostic information. This crate provides the #[instrument] attribute for automatically instrumenting functions using tracing.

Note that this macro is also re-exported by the main tracing crate.

Usage

First, add this to your Cargo.toml:

[dependencies]
tracing-attributes = "0.1.7"

Compiler support: requires rustc 1.39+

This crate provides the #[instrument] attribute for instrumenting a function with a tracing span. For example:

use tracing_attributes::instrument;

#[instrument]
pub fn my_function(my_arg: usize) {
    // ...
}

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Tokio by you, shall be licensed as MIT, without any additional terms or conditions.