diff --git a/src/main.rs b/src/main.rs index 90eb18b0..8b4c0a86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,11 +38,12 @@ use tokio::{ use tower::ServiceBuilder; use tower_http::{ catch_panic::CatchPanicLayer, + classify::ServerErrorsFailureClass, cors::{self, CorsLayer}, - trace::{DefaultOnFailure, TraceLayer}, + trace::TraceLayer, ServiceBuilderExt as _, }; -use tracing::{debug, error, info, warn, Level}; +use tracing::{debug, error, info, warn, Span}; use tracing_subscriber::{prelude::*, reload, EnvFilter, Registry}; use utils::error::{Error, Result}; @@ -303,7 +304,9 @@ async fn build(server: &Server) -> io::Result) - .on_failure(DefaultOnFailure::new().level(Level::INFO)), + .on_failure(|error: ServerErrorsFailureClass, latency: Duration, _span: &Span| { + debug_info!("response failed: {error:?}, latency: {latency:?}"); + }), ) .layer(axum::middleware::from_fn(request_handler)) .layer(cors_layer(server)) @@ -424,14 +427,16 @@ fn compression_layer(server: &Server) -> tower_http::compression::CompressionLay compression_layer } -fn tracing_span(request: &http::Request) -> tracing::Span { - let path = if let Some(path) = request.extensions().get::() { - path.as_str() - } else { - request.uri().path() - }; +fn tracing_span(request: &http::Request) -> Span { + let path = request.extensions().get::(); + let uri = &request.uri().to_string(); - tracing::info_span!("handle", %path) + if let Some(path) = path { + let path = path.as_str(); + tracing::info_span!("handle", %path, %uri) + } else { + tracing::info_span!("handle", %uri) + } } /// Non-async initializations