From fffb562ddbe12638c7e7ab4bd09cd6388322952f Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 31 May 2024 18:46:31 +0200 Subject: [PATCH] fix: classify 4xx as failure, move trace layer up --- upub/routes/src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/upub/routes/src/lib.rs b/upub/routes/src/lib.rs index c62454d9..333bf833 100644 --- a/upub/routes/src/lib.rs +++ b/upub/routes/src/lib.rs @@ -1,3 +1,5 @@ +use tower_http::classify::{SharedClassifier, StatusInRangeAsFailures}; + pub mod activitypub; #[cfg(feature = "mastodon")] @@ -23,11 +25,11 @@ pub async fn serve(ctx: upub::Context, bind: String) -> upub::Result<()> { use tower_http::{cors::CorsLayer, trace::TraceLayer}; let router = axum::Router::new() - .ap_routes() - .mastodon_routes() // no-op if mastodon feature is disabled .layer(CorsLayer::permissive()) .layer( - TraceLayer::new_for_http() + // TODO 4xx errors aren't really failures but since upub is in development it's useful to log + // these too, in case something's broken + TraceLayer::new(SharedClassifier::new(StatusInRangeAsFailures::new(300..=u16::MAX))) .make_span_with(|req: &axum::http::Request<_>| { tracing::span!( tracing::Level::INFO, @@ -37,6 +39,8 @@ pub async fn serve(ctx: upub::Context, bind: String) -> upub::Result<()> { ) }) ) + .ap_routes() + .mastodon_routes() // no-op if mastodon feature is disabled .with_state(ctx); // run our app with hyper, listening locally on port 3000