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

Trait Bound Tracing Error #2334

Closed
1 task done
kingofdreams777 opened this issue Nov 22, 2023 · 4 comments
Closed
1 task done

Trait Bound Tracing Error #2334

kingofdreams777 opened this issue Nov 22, 2023 · 4 comments

Comments

@kingofdreams777
Copy link

  • I have looked for existing issues (including closed) about this

Bug Report

While using tower_http, tracing, and tracing_subscriber I have found the error

Version

Versions of axum I am using:

├── axum v0.6.20
│   ├── axum-core v0.3.4

Platform

Platform: 6.6.2-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Mon, 20 Nov 2023 23:17:26 +0000 x86_64 GNU/Linux

Crates

Versions of tower and tracing

├── tower-http v0.5.0
│   ├── bitflags v2.4.1
│   ├── bytes v1.5.0
│   ├── futures-util v0.3.29 (*)
│   ├── http v1.0.0
│   │   ├── bytes v1.5.0
│   │   ├── fnv v1.0.7
│   │   └── itoa v1.0.9
│   ├── http-body v1.0.0
│   │   ├── bytes v1.5.0
│   │   └── http v1.0.0 (*)
│   ├── http-body-util v0.1.0
│   │   ├── bytes v1.5.0
│   │   ├── futures-util v0.3.29 (*)
│   │   ├── http v1.0.0 (*)
│   │   ├── http-body v1.0.0 (*)
│   │   └── pin-project-lite v0.2.13
│   ├── pin-project-lite v0.2.13
│   ├── tower-layer v0.3.2
│   ├── tower-service v0.3.2
│   └── tracing v0.1.40 (*)
├── tracing v0.1.40 (*)
├── tracing-subscriber v0.3.18
│   ├── nu-ansi-term v0.46.0
│   │   └── overload v0.1.1
│   ├── sharded-slab v0.1.7
│   │   └── lazy_static v1.4.0
│   ├── smallvec v1.11.2
│   ├── thread_local v1.1.7
│   │   ├── cfg-if v1.0.0
│   │   └── once_cell v1.18.0
│   ├── tracing-core v0.1.32 (*)
│   └── tracing-log v0.2.0
│       ├── log v0.4.20
│       ├── once_cell v1.18.0
│       └── tracing-core v0.1.32 (*)

Description

I tried this code

mod controllers;
mod errors;
mod models;

use std::{net::SocketAddr, sync::Arc};

use axum::{
    routing::{get, post},
    Router,
};
use controllers::{narrator_controller, story_controller};
use models::narrator::{INarrator, Narrator};
use tokio::sync::Mutex;
use tower_http::trace::{self, TraceLayer};
use tracing::Level;

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::DEBUG)
        .compact()
        .init();

    let state = Arc::new(Mutex::new(Narrator::new()));

    let tracing = TraceLayer::new_for_http()
        .make_span_with(trace::DefaultMakeSpan::new().level(Level::INFO))
        .on_response(trace::DefaultOnResponse::new().level(Level::INFO));

    let app = Router::new()
        .route("/", get(|| async { "Hello World!" }))
        .route("/story", post(story_controller::create_story))
        .route(
            "/narrator/stories",
            get(narrator_controller::get_narrator_info),
        )
        .layer(tracing)
        .with_state(state);

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    tracing::info!("listening on {}", addr);

    axum::Server::bind(&addr)
        .serve(app.into_make_service())
        .await
        .unwrap()
}

I expected to see this happen: Able to use TraceLayer with Axum

the trait bound `tower_http::trace::Trace<axum::routing::Route<_>, tower_http::classify::SharedClassifier<tower_http::classify::ServerErrorsAsFailures>>: tower_service::Service<axum::http::Request<_>>` is not satisfied the trait bound `tower_http::trace::Trace<axum::routing::Route<_>, tower_http::classify::SharedClassifier<tower_http::classify::ServerErrorsAsFailures>>: tower_service::Service<axum::http::Request<_>>` is not satisfied

the trait `tower_service::Service<http::request::Request<ReqBody>>` is implemented for `tower_http::trace::Trace<S, M, MakeSpanT, OnRequestT, OnResponseT, OnBodyChunkT, OnEosT, OnFailureT>` 

-->

@davidpdrsn
Copy link
Member

axum does not yet support tower-http 0.5. Follow #1882 for updates

@davidpdrsn davidpdrsn closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2023
@NickAcPT
Copy link

axum does not yet support tower-http 0.5. Follow #1882 for updates

@davidpdrsn sorry to bump a closed issue.
Now with #1882 having been merged and assuming the usage of tower-http 0.5 is more than okay, how would one solve this issue?

@jplatte
Copy link
Member

jplatte commented Nov 25, 2023

If you depend on axum as a git dependency, it should just work. Otherwise, nothing has changed since that PR has not been published in a crates.io release yet. It will be released in v0.7.0.

@NickAcPT
Copy link

NickAcPT commented Nov 25, 2023

If you depend on axum as a git dependency, it should just work. Otherwise, nothing has changed since that PR has not been published in a crates.io release yet. It will be released in v0.7.0.

Thanks for the fast reply haha. I was using axum as a git dependency, but I was having some issues with using a ServiceBuilder to chain the layers. As soon as I put the layers on the Router itself (now that it's no longer generic over the request body type), it suddenly worked

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

4 participants