From 876cf19327bd8bdd4449f818cce44559c4d3a9ff Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 31 May 2024 14:43:48 +0200 Subject: [PATCH] chore: instrument inbox/outbox this is where side effects happen, so better keep them under control also trying out tracing, i should redo how i trace stuff in upub... --- upub/core/src/server/auth.rs | 5 +++-- upub/routes/src/activitypub/inbox.rs | 1 + upub/routes/src/activitypub/user/outbox.rs | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/upub/core/src/server/auth.rs b/upub/core/src/server/auth.rs index 1516bbc0..226dd964 100644 --- a/upub/core/src/server/auth.rs +++ b/upub/core/src/server/auth.rs @@ -10,6 +10,7 @@ use super::{fetcher::Fetcher, httpsign::HttpSignature}; pub enum Identity { Anonymous, Remote { + user: String, domain: String, internal: i64, }, @@ -124,11 +125,11 @@ where .verify(&user.public_key) { Ok(true) => { - // TODO can we avoid this extra db rountrip made on each server fetch? + let user = user.id; let domain = Context::server(&user_id); // TODO this will fail because we never fetch and insert into instance oops let internal = model::instance::Entity::domain_to_internal(&domain, ctx.db()).await?; - identity = Identity::Remote { domain, internal }; + identity = Identity::Remote { user, domain, internal }; }, Ok(false) => tracing::warn!("invalid signature: {http_signature:?}"), Err(e) => tracing::error!("error verifying signature: {e}"), diff --git a/upub/routes/src/activitypub/inbox.rs b/upub/routes/src/activitypub/inbox.rs index f3365f38..26135795 100644 --- a/upub/routes/src/activitypub/inbox.rs +++ b/upub/routes/src/activitypub/inbox.rs @@ -38,6 +38,7 @@ macro_rules! pretty_json { } +#[tracing::instrument(level = "info", skip(ctx), fields(activity = %activity))] pub async fn post( State(ctx): State, AuthIdentity(auth): AuthIdentity, diff --git a/upub/routes/src/activitypub/user/outbox.rs b/upub/routes/src/activitypub/user/outbox.rs index 62b3d6eb..9719eda7 100644 --- a/upub/routes/src/activitypub/user/outbox.rs +++ b/upub/routes/src/activitypub/user/outbox.rs @@ -37,6 +37,7 @@ pub async fn page( .await } +#[tracing::instrument(level = "info", skip(ctx), fields(activity = %activity))] pub async fn post( State(ctx): State, Path(id): Path,