diff --git a/Cargo.lock b/Cargo.lock index 059dd40..a4f1fbd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,6 +110,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + [[package]] name = "bytes" version = "1.6.1" @@ -711,6 +717,23 @@ dependencies = [ "tower-service", ] +[[package]] +name = "tower-http" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" +dependencies = [ + "bitflags", + "bytes", + "http", + "http-body", + "http-body-util", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower-layer" version = "0.3.2" @@ -809,6 +832,7 @@ dependencies = [ "axum", "serde", "tokio", + "tower-http", "tracing", "tracing-subscriber", ] diff --git a/Cargo.toml b/Cargo.toml index 5e24b37..7be4ace 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ include = [ axum = { version = "0.7.5", default-features = false, features = ["tokio", "http1", "http2", "json"] } serde = { version = "1.0.204", features = ["derive"] } tokio = { version = "1.38.0", default-features = false, features = ["macros", "process", "rt", "rt-multi-thread"] } +tower-http = { version = "0.5.2", default-features = false, features = ["trace"] } # default attributes, std, tracing-attributes tracing = { version = "0.1.40", default-features = false, features = ["attributes", "std", "tracing-attributes", "async-await"] } # default alloc, ansi, fmt, nu-ansi-term, registry, sharded-slab, smallvec, std, thread_local, tracing-log diff --git a/src/main.rs b/src/main.rs index e246346..f679429 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use axum::routing::get; use axum::Json; use axum::Router; use serde::Serialize; +use tower_http::trace::TraceLayer; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; @@ -16,7 +17,9 @@ async fn main() -> Result<(), Box> { ) .with(tracing_subscriber::fmt::layer()) .init(); - let app = Router::new().route("/health", get(health)); + let app = Router::new() + .route("/health", get(health)) + .layer(TraceLayer::new_for_http()); let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?; tracing::info!("listening on {}", listener.local_addr().unwrap());