Improve tracing of request error responses.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-07-31 13:30:31 +00:00
parent 6742e1d206
commit e6f1b98d6a
4 changed files with 19 additions and 9 deletions

View File

@@ -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<T> {
/// Request struct body
pub(crate) body: T,
@@ -38,10 +39,7 @@ pub(crate) struct Args<T> {
pub(crate) json_body: Option<CanonicalJsonValue>,
}
impl<T> Args<T>
where
T: IncomingRequest + Send + Sync + 'static,
{
impl<T> Args<T> {
#[inline]
pub(crate) fn sender(&self) -> (&UserId, &DeviceId) {
(self.sender_user(), self.sender_device())
@@ -71,7 +69,7 @@ where
impl<T> Deref for Args<T>
where
T: IncomingRequest + Send + Sync + 'static,
T: Sync,
{
type Target = T;
@@ -80,10 +78,11 @@ where
impl<T> FromRequest<State, Body> for Args<T>
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<Body>,
services: &State,

View File

@@ -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<OwnedServerName>,
pub(super) sender_user: Option<OwnedUserId>,
@@ -51,6 +53,12 @@ pub(super) struct Auth {
pub(super) appservice_info: Option<RegistrationInfo>,
}
#[tracing::instrument(
level = "trace",
skip(services, request, json_body),
ret,
err
)]
pub(super) async fn auth(
services: &Services,
request: &mut Request,

View File

@@ -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<Req>,) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Req::OutgoingResponse, Err>> + Send,
Req: IncomingRequest + Send + Sync + 'static,
Req: IncomingRequest + Debug + Send + Sync + 'static,
Err: IntoResponse + Send,
<Req as IncomingRequest>::OutgoingResponse: Send,
$( $tx: FromRequestParts<State> + Send + Sync + 'static, )*

View File

@@ -19,6 +19,7 @@ use tuwunel_service::Services;
name = "request",
level = "debug",
skip_all,
err(Debug)
fields(
id = %services
.server