From e6f1b98d6a8169085a39cd8ca547d96f2ecb4bb8 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 31 Jul 2025 13:30:31 +0000 Subject: [PATCH] Improve tracing of request error responses. Signed-off-by: Jason Volk --- src/api/router/args.rs | 13 ++++++------- src/api/router/auth.rs | 10 +++++++++- src/api/router/handler.rs | 4 +++- src/router/request.rs | 1 + 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/api/router/args.rs b/src/api/router/args.rs index 6e4edbe9..8cad31a1 100644 --- a/src/api/router/args.rs +++ b/src/api/router/args.rs @@ -1,4 +1,4 @@ -use std::{mem, ops::Deref}; +use std::{fmt::Debug, mem, ops::Deref}; use axum::{body::Body, extract::FromRequest}; use bytes::{BufMut, Bytes, BytesMut}; @@ -13,6 +13,7 @@ use super::{auth, auth::Auth, request, request::Request}; use crate::State; /// Extractor for Ruma request structs +#[derive(Debug)] pub(crate) struct Args { /// Request struct body pub(crate) body: T, @@ -38,10 +39,7 @@ pub(crate) struct Args { pub(crate) json_body: Option, } -impl Args -where - T: IncomingRequest + Send + Sync + 'static, -{ +impl Args { #[inline] pub(crate) fn sender(&self) -> (&UserId, &DeviceId) { (self.sender_user(), self.sender_device()) @@ -71,7 +69,7 @@ where impl Deref for Args where - T: IncomingRequest + Send + Sync + 'static, + T: Sync, { type Target = T; @@ -80,10 +78,11 @@ where impl FromRequest for Args where - T: IncomingRequest + Send + Sync + 'static, + T: IncomingRequest + Debug + Send + Sync + 'static, { type Rejection = Error; + #[tracing::instrument(name = "ar", level = "debug", skip(services), ret, err)] async fn from_request( request: hyper::Request, services: &State, diff --git a/src/api/router/auth.rs b/src/api/router/auth.rs index 2553d44e..104acbea 100644 --- a/src/api/router/auth.rs +++ b/src/api/router/auth.rs @@ -1,3 +1,5 @@ +use std::{fmt::Debug, time::SystemTime}; + use axum::RequestPartsExt; use axum_extra::{ TypedHeader, @@ -43,7 +45,7 @@ enum Token { None, } -#[derive(Default)] +#[derive(Debug, Default)] pub(super) struct Auth { pub(super) origin: Option, pub(super) sender_user: Option, @@ -51,6 +53,12 @@ pub(super) struct Auth { pub(super) appservice_info: Option, } +#[tracing::instrument( + level = "trace", + skip(services, request, json_body), + ret, + err +)] pub(super) async fn auth( services: &Services, request: &mut Request, diff --git a/src/api/router/handler.rs b/src/api/router/handler.rs index d7846b83..9f1a38c4 100644 --- a/src/api/router/handler.rs +++ b/src/api/router/handler.rs @@ -1,3 +1,5 @@ +use std::fmt::Debug; + use axum::{ Router, extract::FromRequestParts, @@ -38,7 +40,7 @@ macro_rules! ruma_handler { where Fun: Fn($($tx,)* Ruma,) -> Fut + Send + Sync + 'static, Fut: Future> + Send, - Req: IncomingRequest + Send + Sync + 'static, + Req: IncomingRequest + Debug + Send + Sync + 'static, Err: IntoResponse + Send, ::OutgoingResponse: Send, $( $tx: FromRequestParts + Send + Sync + 'static, )* diff --git a/src/router/request.rs b/src/router/request.rs index f3c1e8be..224c4eb8 100644 --- a/src/router/request.rs +++ b/src/router/request.rs @@ -19,6 +19,7 @@ use tuwunel_service::Services; name = "request", level = "debug", skip_all, + err(Debug) fields( id = %services .server