fix: classify 4xx as failure, move trace layer up

This commit is contained in:
əlemi 2024-05-31 18:46:31 +02:00
parent 0097a0533a
commit fffb562ddb
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,3 +1,5 @@
use tower_http::classify::{SharedClassifier, StatusInRangeAsFailures};
pub mod activitypub; pub mod activitypub;
#[cfg(feature = "mastodon")] #[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}; use tower_http::{cors::CorsLayer, trace::TraceLayer};
let router = axum::Router::new() let router = axum::Router::new()
.ap_routes()
.mastodon_routes() // no-op if mastodon feature is disabled
.layer(CorsLayer::permissive()) .layer(CorsLayer::permissive())
.layer( .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<_>| { .make_span_with(|req: &axum::http::Request<_>| {
tracing::span!( tracing::span!(
tracing::Level::INFO, 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); .with_state(ctx);
// run our app with hyper, listening locally on port 3000 // run our app with hyper, listening locally on port 3000