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

tracing::instrument doesn't work in async_trait #3179

Open
smichxq opened this issue Dec 29, 2024 · 0 comments
Open

tracing::instrument doesn't work in async_trait #3179

smichxq opened this issue Dec 29, 2024 · 0 comments

Comments

@smichxq
Copy link

smichxq commented Dec 29, 2024

Feature Request

Crates

async-trait = {version = "0.1.81", eatures = ["full"]}
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
sqlx = { version = "0.8.0" , features = ["mysql","runtime-tokio-rustls"]}

Motivation

#[async_trait]
pub trait CacheImp<T1, T2> {

    #[instrument(skip(pool))]
    async fn init(pool: &Pool<MySql>) -> Result<Self, CustomerErr> where Self: Sized;
}

in "#[instrument(skip(pool))]" told me:

mismatched types
expected struct Pin<Box<(dyn futures::Future<Output = Result<Self, CustomerErr>> + std::marker::Send + 'async_trait)>>
found unit type ()

if trait has many impl , i need write a lot #[instrument(skip(pool))]

i think the compiler won't forward attributes from a trait function declaration to all implementations, maybe macros don't have enough context to do that?

Are there other ways to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant