Skip to content
Please note that GitHub no longer supports Internet Explorer.

We recommend upgrading to the latest Microsoft Edge, Google Chrome, or Firefox.

Learn more
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

#[instrument] codegen does not work with async_trait async fns #399

Open
pkinsky opened this issue Oct 23, 2019 · 1 comment
Open

#[instrument] codegen does not work with async_trait async fns #399

pkinsky opened this issue Oct 23, 2019 · 1 comment

Comments

@pkinsky
Copy link
Contributor

@pkinsky pkinsky commented Oct 23, 2019

Bug Report

async_trait (as re-exported by tonic) and instrument do not work as expected together. Instrumented async trait fns enter then immediately exit and drop their span, while top-level async functions work as expected.

Minimal reproduction with checked-in expanded macro-generated code at https://github.com/pkinsky/tracing-async-trait-bug-repro

This is a cross-project bug, let me know if it's best posted elsewhere.

Version

│   │   │   │   └── tracing v0.1.9
│   │   │   │       ├── tracing-attributes v0.1.4
│   │   │   │       └── tracing-core v0.1.7
│   │   │   │   └── tracing v0.1.9 (*)
│   │   │   └── tracing-core v0.1.7 (*)
│   │   │   └── tracing v0.1.9 (*)
│   │   └── tracing v0.1.9 (*)
│   └── tracing v0.1.9 (*)
├── tracing v0.1.9 (*)
├── tracing-attributes v0.1.4 (*)
├── tracing-core v0.1.7 (*)
├── tracing-futures v0.1.0
│   └── tracing v0.1.9 (*)
└── tracing-subscriber v0.1.5
    ├── tracing-core v0.1.7 (*)
    └── tracing-log v0.1.0
        └── tracing-core v0.1.7 (*)
    └── tracing-log v0.1.0 (*)

Platform

Linux pk-thinkpad 4.15.0-54-generic #58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Crates

tracing-attributes, tracing-futures

Description

code output by #[instrument] macro for async trait functions does not use expected code gen pathway for async trait fns.

for

#[tonic::async_trait]
pub trait Foo
where
    Self: std::marker::Send,
{
    async fn foo(&self) -> ();
}

struct FooImpl;

#[tonic::async_trait]
impl Foo for FooImpl {
    #[instrument]
    async fn foo(&self) {}
}

#[instrument]
async fn top_level() {}

the resulting generated code uses the expected future instrumentation pathway for top_level

    tracing_futures::Instrument::instrument(async move  { { } },
                                            __tracing_attr_span).await

but for the async trait fn foo it generates

    fn foo<'life0, 'async_trait>(&'life0 self)
     ->
         ::core::pin::Pin<Box<dyn ::core::future::Future<Output = ()> +
                              ::core::marker::Send + 'async_trait>> where
     'life0: 'async_trait, Self: 'async_trait {
        let __tracing_attr_span = { omitted };
        let __tracing_attr_guard = __tracing_attr_span.enter();
        {
            #[allow(clippy :: used_underscore_binding)]
            async fn __foo(_self: &FooImpl) { }
            Box::pin(__foo::<>(self))
        }
    }
@pkinsky pkinsky changed the title #[instrument] codegen does not work with tonic::async_trait async fns #[instrument] codegen does not work with async_trait async fns Oct 23, 2019
@xd009642

This comment has been minimized.

Copy link

@xd009642 xd009642 commented Nov 29, 2019

I'd be willing to help with this as it's an issue I've came up against. I may need some help though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.