Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(observability): log expected auth, access and client failures below error (#7901)
teof5b3e83beb94
diff --git a/Cargo.lock b/Cargo.lockindex 815ae7bad2..0e85e7ecc9 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4642,7 +4642,6 @@ dependencies = ["tower-http","tracing","tracing-opentelemetry",- "tungstenite 0.28.0","url","utoipa","utoipa-swagger-ui",@@ -11465,6 +11464,7 @@ dependencies = ["tokio","tower 0.5.3","tracing",+ "tracing-subscriber","urlencoding","uuid","workspace-hack",diff --git a/crates/ai_projections/src/inbound/axum_router/upsert_projection.rs b/crates/ai_projections/src/inbound/axum_router/upsert_projection.rsindex b9ce03b0b5..3b00cadc39 100644--- a/crates/ai_projections/src/inbound/axum_router/upsert_projection.rs+++ b/crates/ai_projections/src/inbound/axum_router/upsert_projection.rs@@ -4,6 +4,7 @@use axum::{Json, extract::State};use chrono::{DateTime, Utc};use macro_authorization::{MacroAuthorizationExtractor, MacroAuthorizationService, UserOrInternal};+use tracing::Level;use crate::domain::{ai_projection_service::{AiProjectionService, requires_professional_features},@@ -95,7 +96,7 @@ impl From<UserAiProjection> for ProjectionStateResponse {(status = 500, body = model_error_response::ErrorResponse),),)]-#[tracing::instrument(skip_all, err)]+#[tracing::instrument(skip_all, err(level = Level::WARN))]pub async fn handler<T: AiProjectionService, Auth: MacroAuthorizationService>(State(state): State<AiProjectionRouterState<T, Auth>>,user: MacroAuthorizationExtractor<Auth, UserOrInternal>,diff --git a/crates/email_db_client/src/messages/delete.rs b/crates/email_db_client/src/messages/delete.rsindex c8e4471df7..8281363ccb 100644--- a/crates/email_db_client/src/messages/delete.rs+++ b/crates/email_db_client/src/messages/delete.rs@@ -3,15 +3,25 @@ use models_email::email::service::message;use sqlx::types::Uuid;use sqlx::{Executor, Postgres};-/// Deletes message from the database with transaction handling. Returns an optional db thread id-/// if the thread was deleted+/// Outcome of [`delete_message_with_tx`].+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum MessageDeletion {+ /// The message row was already gone, e.g. removed by a concurrent sync.+ AlreadyDeleted,+ /// The message was deleted. `deleted_thread` holds the thread id when the+ /// message was the thread's last one and the thread was deleted with it.+ Deleted { deleted_thread: Option<Uuid> },+}++/// Deletes message from the database with transaction handling.#[tracing::instrument(skip(tx, message), fields(link_id = %message.link_id), err)]pub async fn delete_message_with_tx(tx: &mut sqlx::PgConnection,message: &message::SimpleMessage,-) -> anyhow::Result<Option<Uuid>> {- // delete the message itself- delete_db_message(&mut *tx, message.db_id).await?;+) -> anyhow::Result<MessageDeletion> {+ if !delete_db_message(&mut *tx, message.db_id).await? {+ return Ok(MessageDeletion::AlreadyDeleted);+ }// if it was the only message in the thread, delete the thread toolet deleted_thread =@@ -33,27 +43,20 @@ pub async fn delete_message_with_tx(threads::update::sync_thread_calendar_flag(&mut *tx, message.thread_db_id).await?;}- if deleted_thread {- Ok(Some(message.thread_db_id))- } else {- Ok(None)- }+ Ok(MessageDeletion::Deleted {+ deleted_thread: deleted_thread.then_some(message.thread_db_id),+ })}+/// Deletes a message row, returning `false` when no message has this id.#[tracing::instrument(skip(executor), err)]-pub async fn delete_db_message<'e, E>(executor: E, message_id: Uuid) -> anyhow::Result<()>+pub async fn delete_db_message<'e, E>(executor: E, message_id: Uuid) -> anyhow::Result<bool>whereE: Executor<'e, Database = Postgres>,{- // Delete the messagelet result = sqlx::query!(r#"DELETE FROM email_messages WHERE id = $1"#, message_id).execute(executor).await?;- // Check if any rows were affected- if result.rows_affected() == 0 {- anyhow::bail!("Message not found with id {}", message_id);- }-- Ok(())+ Ok(result.rows_affected() > 0)}diff --git a/crates/email_db_client/src/messages/test.rs b/crates/email_db_client/src/messages/test.rsindex 51abd125d6..548c0095e7 100644--- a/crates/email_db_client/src/messages/test.rs+++ b/crates/email_db_client/src/messages/test.rs@@ -1,3 +1,4 @@+use crate::messages::delete::MessageDeletion;use crate::messages::get::{draft_exists_with_id, filter_existing_provider_message_ids};use crate::messages::scheduled::get::get_scheduled_db_messages_by_link_id;use macro_db_migrator::MACRO_DB_MIGRATIONS;@@ -358,16 +359,48 @@ async fn delete_message_clears_calendar_flag_when_last_ics_message_removed(.expect("fixture message present");let mut tx = pool.begin().await?;- let deleted_thread = crate::messages::delete::delete_message_with_tx(&mut tx, &message).await?;+ let deletion = crate::messages::delete::delete_message_with_tx(&mut tx, &message).await?;tx.commit().await?;// The thread survives (a second message remains) and the flag flips off// because its attachments cascaded away with the message.- assert!(deleted_thread.is_none());+ assert_eq!(+ deletion,+ MessageDeletion::Deleted {+ deleted_thread: None+ }+ );assert!(!fetch_calendar_flag(&pool, thread_id).await?);Ok(())}+#[sqlx::test(+ migrator = "MACRO_DB_MIGRATIONS",+ fixtures(path = "../../fixtures", scripts("sync_thread_calendar_flag"))+)]+async fn delete_message_reports_already_deleted_message(+ pool: Pool<Postgres>,+) -> anyhow::Result<()> {+ let ics_message_id = Uuid::parse_str("00000000-0000-0000-0000-00000000b501")?;+ let fusionauth_user_id = "00000000-0000-0000-0000-000000000b01";++ let message = crate::messages::get_simple_messages::get_simple_message(+ &pool,+ &ics_message_id,+ fusionauth_user_id,+ )+ .await?+ .expect("fixture message present");++ let mut conn = pool.acquire().await?;+ let first = crate::messages::delete::delete_message_with_tx(&mut conn, &message).await?;+ let second = crate::messages::delete::delete_message_with_tx(&mut conn, &message).await?;++ assert!(matches!(first, MessageDeletion::Deleted { .. }));+ assert_eq!(second, MessageDeletion::AlreadyDeleted);+ Ok(())+}+const READ_STATUS_LINK: &str = "00000000-0000-0000-0000-000000000e11";const READ_STATUS_OTHER_LINK: &str = "00000000-0000-0000-0000-000000000e12";const READ_STATUS_MSG_A: &str = "00000000-0000-0000-0000-00000000e611";diff --git a/crates/email_db_client/src/threads/update/test.rs b/crates/email_db_client/src/threads/update/test.rsindex b770e2d71e..0ecec7da79 100644--- a/crates/email_db_client/src/threads/update/test.rs+++ b/crates/email_db_client/src/threads/update/test.rs@@ -244,8 +244,14 @@ async fn draft_discard_recomputes_thread_metadata(pool: Pool<Postgres>) -> anyho};let mut conn = pool.acquire().await?;- let deleted_thread = crate::messages::delete::delete_message_with_tx(&mut conn, &draft).await?;- assert!(deleted_thread.is_none(), "thread should survive");+ let deletion = crate::messages::delete::delete_message_with_tx(&mut conn, &draft).await?;+ assert_eq!(+ deletion,+ crate::messages::delete::MessageDeletion::Deleted {+ deleted_thread: None+ },+ "thread should survive"+ );// The remaining message is CATEGORY_PROMOTIONS-only: noise, and without// an INBOX label the thread leaves the inbox and has no inbound ts.diff --git a/crates/entity_access/src/domain/service.rs b/crates/entity_access/src/domain/service.rsindex d5c18642d6..816966b117 100644--- a/crates/entity_access/src/domain/service.rs+++ b/crates/entity_access/src/domain/service.rs@@ -17,6 +17,7 @@ use futures::{StreamExt, stream};use macro_user_id::{cowlike::CowLike, lowercased::Lowercase, user_id::MacroUserId, user_id::MacroUserIdStr,};+use tracing::Level;use uuid::Uuid;const MAX_CONCURRENT_BATCH_ACCESS_CHECKS: usize = 8;@@ -306,7 +307,7 @@ impl<R> AccessibleDatabases for EntityAccessServiceImpl<R>whereR: AccessRepository,{- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn accessible_databases(&self,user_id: &MacroUserId<Lowercase<'_>>,@@ -319,7 +320,7 @@ impl<R> AccessibleForms for EntityAccessServiceImpl<R>whereR: AccessRepository,{- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn accessible_forms(&self,user_id: &MacroUserId<Lowercase<'_>>,@@ -332,7 +333,7 @@ impl<R> EntityAccessService for EntityAccessServiceImpl<R>whereR: AccessRepository,{- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn generate_entity_access_receipt<T: RequiredPermission>(&self,user_id: &MacroUserId<Lowercase<'_>>,@@ -510,7 +511,7 @@ wherereceipts}- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn generate_bot_entity_access_receipt<T: RequiredPermission>(&self,bot_id: BotId,@@ -543,7 +544,7 @@ where)}- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn get_access_level(&self,user_id: Option<&MacroUserId<Lowercase<'_>>>,@@ -589,7 +590,7 @@ where}}- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn check_access(&self,user_id: Option<&MacroUserId<Lowercase<'_>>>,@@ -608,7 +609,7 @@ where}}- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn check_public_access(&self,entity_id: &str,@@ -623,7 +624,7 @@ where}}- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn get_entity_permission(&self,user_id: Option<&MacroUserId<Lowercase<'_>>>,@@ -739,7 +740,7 @@ where}}- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn get_crm_entity_permission_with_team(&self,user_id: Option<&MacroUserId<Lowercase<'_>>>,@@ -768,7 +769,7 @@ where))}- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn get_users_by_entity(&self,entity_id: &str,@@ -836,7 +837,7 @@ where}}- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn get_call_channel(&self,call_id: &Uuid,@@ -844,7 +845,7 @@ whereself.repo.get_call_channel(call_id).await}- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn get_call_channel_by_channel_id(&self,channel_id: &Uuid,@@ -852,7 +853,7 @@ whereself.repo.get_call_channel_by_channel_id(channel_id).await}- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn get_user_team(&self,user_id: &MacroUserId<Lowercase<'_>>,diff --git a/crates/entity_access/src/inbound/axum_extractors/agent_session.rs b/crates/entity_access/src/inbound/axum_extractors/agent_session.rsindex d085e061b6..79cc09b0f1 100644--- a/crates/entity_access/src/inbound/axum_extractors/agent_session.rs+++ b/crates/entity_access/src/inbound/axum_extractors/agent_session.rs@@ -16,6 +16,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use super::{ExtractorError, bot::generate_bot_entity_access_receipt};use crate::domain::{@@ -55,7 +56,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);diff --git a/crates/entity_access/src/inbound/axum_extractors/call.rs b/crates/entity_access/src/inbound/axum_extractors/call.rsindex ff2bb4e2df..59d0cc026c 100644--- a/crates/entity_access/src/inbound/axum_extractors/call.rs+++ b/crates/entity_access/src/inbound/axum_extractors/call.rs@@ -18,6 +18,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use uuid::Uuid;use super::{ExtractorError, bot::generate_bot_entity_access_receipt};@@ -70,7 +71,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);@@ -203,7 +204,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);diff --git a/crates/entity_access/src/inbound/axum_extractors/channel.rs b/crates/entity_access/src/inbound/axum_extractors/channel.rsindex 52ce76feb6..b3d734a774 100644--- a/crates/entity_access/src/inbound/axum_extractors/channel.rs+++ b/crates/entity_access/src/inbound/axum_extractors/channel.rs@@ -24,6 +24,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;#[derive(Debug, serde::Deserialize)]struct ChannelAccessParams {channel_id: String,@@ -52,7 +53,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);let authorization =diff --git a/crates/entity_access/src/inbound/axum_extractors/chat.rs b/crates/entity_access/src/inbound/axum_extractors/chat.rsindex 513ebf9fa8..e001ba8b63 100644--- a/crates/entity_access/src/inbound/axum_extractors/chat.rs+++ b/crates/entity_access/src/inbound/axum_extractors/chat.rs@@ -15,6 +15,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use super::{ExtractorError, RequiredPermission, bot::generate_bot_entity_access_receipt};use crate::domain::{@@ -52,7 +53,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);@@ -67,6 +68,7 @@ wherelet chat_context: Extension<ChatBasic> = parts.extract().await+ .inspect_err(|error| tracing::error!(error=?error, "chat context missing")).map_err(|_| ExtractorError::Internal)?;if let Some(MacroAuthorization::Bot(authentication)) = authorization.as_ref() {diff --git a/crates/entity_access/src/inbound/axum_extractors/database.rs b/crates/entity_access/src/inbound/axum_extractors/database.rsindex 3c38526023..7169ee989f 100644--- a/crates/entity_access/src/inbound/axum_extractors/database.rs+++ b/crates/entity_access/src/inbound/axum_extractors/database.rs@@ -16,6 +16,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use super::{ExtractorError, bot::generate_bot_entity_access_receipt};use crate::domain::{@@ -55,7 +56,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);diff --git a/crates/entity_access/src/inbound/axum_extractors/document.rs b/crates/entity_access/src/inbound/axum_extractors/document.rsindex c7ef7ad63b..f1b5612207 100644--- a/crates/entity_access/src/inbound/axum_extractors/document.rs+++ b/crates/entity_access/src/inbound/axum_extractors/document.rs@@ -15,6 +15,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use super::{ExtractorError, RequiredPermission, bot::generate_bot_entity_access_receipt};use crate::domain::{@@ -52,7 +53,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);@@ -66,6 +67,7 @@ wherelet document_context: Extension<DocumentBasic> = parts.extract().await+ .inspect_err(|error| tracing::error!(error=?error, "document context missing")).map_err(|_| ExtractorError::Internal)?;if let Some(MacroAuthorization::Bot(authentication)) = &authorization.authorization {diff --git a/crates/entity_access/src/inbound/axum_extractors/entity_body.rs b/crates/entity_access/src/inbound/axum_extractors/entity_body.rsindex a5dd0ee0ea..982a7991a4 100644--- a/crates/entity_access/src/inbound/axum_extractors/entity_body.rs+++ b/crates/entity_access/src/inbound/axum_extractors/entity_body.rs@@ -14,6 +14,7 @@ use macro_authorization::{OptionalMacroAuthorizationExtractor,};use serde::{Deserialize, de::DeserializeOwned};+use tracing::Level;use super::{ExtractorError, RequiredPermission, bot::generate_bot_entity_access_receipt};use crate::domain::{@@ -54,7 +55,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(req, state))]+ #[tracing::instrument(err(level = Level::INFO), skip(req, state))]async fn from_request(mut req: Request, state: &S) -> Result<Self, Self::Rejection> {let authorization = req.extract_parts_with_state::<OptionalMacroAuthorizationExtractor<Auth, AnyPrincipal>, _>(diff --git a/crates/entity_access/src/inbound/axum_extractors/entity_permission.rs b/crates/entity_access/src/inbound/axum_extractors/entity_permission.rsindex b7c8b2c552..dcc1569bbd 100644--- a/crates/entity_access/src/inbound/axum_extractors/entity_permission.rs+++ b/crates/entity_access/src/inbound/axum_extractors/entity_permission.rs@@ -14,6 +14,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use super::{ExtractorError, bot::generate_bot_entity_access_receipt};use crate::domain::{@@ -52,7 +53,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(parts, state))]+ #[tracing::instrument(err(level = Level::INFO), skip(parts, state))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);diff --git a/crates/entity_access/src/inbound/axum_extractors/foreign_entity.rs b/crates/entity_access/src/inbound/axum_extractors/foreign_entity.rsindex 89619e2263..20ea5f193b 100644--- a/crates/entity_access/src/inbound/axum_extractors/foreign_entity.rs+++ b/crates/entity_access/src/inbound/axum_extractors/foreign_entity.rs@@ -16,6 +16,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use uuid::Uuid;use super::{ExtractorError, RequiredPermission, bot::generate_bot_entity_access_receipt};@@ -52,7 +53,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);diff --git a/crates/entity_access/src/inbound/axum_extractors/form.rs b/crates/entity_access/src/inbound/axum_extractors/form.rsindex 47fbab23a9..df9f20436f 100644--- a/crates/entity_access/src/inbound/axum_extractors/form.rs+++ b/crates/entity_access/src/inbound/axum_extractors/form.rs@@ -17,6 +17,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use super::{ExtractorError, bot::generate_bot_entity_access_receipt};use crate::domain::{@@ -62,7 +63,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &State) -> Result<Self, Self::Rejection> {let service = <Arc<AccessService>>::from_ref(state);diff --git a/crates/entity_access/src/inbound/axum_extractors/history.rs b/crates/entity_access/src/inbound/axum_extractors/history.rsindex effa445ee4..39509645af 100644--- a/crates/entity_access/src/inbound/axum_extractors/history.rs+++ b/crates/entity_access/src/inbound/axum_extractors/history.rs@@ -14,6 +14,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use super::{ExtractorError, RequiredPermission, bot::generate_bot_entity_access_receipt};use crate::domain::{@@ -54,7 +55,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(parts, state))]+ #[tracing::instrument(err(level = Level::INFO), skip(parts, state))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);diff --git a/crates/entity_access/src/inbound/axum_extractors/initiative.rs b/crates/entity_access/src/inbound/axum_extractors/initiative.rsindex 11c2218c3e..63ab36fa81 100644--- a/crates/entity_access/src/inbound/axum_extractors/initiative.rs+++ b/crates/entity_access/src/inbound/axum_extractors/initiative.rs@@ -16,6 +16,7 @@ use macro_authorization::{MacroAuthorizationState, OptionalMacroAuthorizationExtractor,};use macro_user_id::user_id::MacroUserIdStr;+use tracing::Level;use super::{ExtractorError, RequiredPermission, bot::generate_bot_entity_access_receipt};use crate::domain::{@@ -76,7 +77,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);diff --git a/crates/entity_access/src/inbound/axum_extractors/pin.rs b/crates/entity_access/src/inbound/axum_extractors/pin.rsindex d597d2155f..bb8341a127 100644--- a/crates/entity_access/src/inbound/axum_extractors/pin.rs+++ b/crates/entity_access/src/inbound/axum_extractors/pin.rs@@ -15,6 +15,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use super::{ExtractorError, RequiredPermission, bot::generate_bot_entity_access_receipt};use crate::domain::{@@ -63,7 +64,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(req, state))]+ #[tracing::instrument(err(level = Level::INFO), skip(req, state))]async fn from_request(mut req: Request, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);diff --git a/crates/entity_access/src/inbound/axum_extractors/project.rs b/crates/entity_access/src/inbound/axum_extractors/project.rsindex 777b8f3953..8d8da4d0a0 100644--- a/crates/entity_access/src/inbound/axum_extractors/project.rs+++ b/crates/entity_access/src/inbound/axum_extractors/project.rs@@ -17,6 +17,7 @@ use macro_authorization::{};use macro_user_id::user_id::MacroUserIdStr;use serde::de::DeserializeOwned;+use tracing::Level;use super::{ExtractorError, RequiredPermission, bot::generate_bot_entity_access_receipt};use crate::domain::{@@ -54,7 +55,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);@@ -68,6 +69,7 @@ wherelet project_context: Extension<BasicProject> = parts.extract().await+ .inspect_err(|error| tracing::error!(error=?error, "project context missing")).map_err(|_| ExtractorError::Internal)?;if matches!(diff --git a/crates/entity_access/src/inbound/axum_extractors/reminder.rs b/crates/entity_access/src/inbound/axum_extractors/reminder.rsindex 491b98b4bb..9a6d1fab93 100644--- a/crates/entity_access/src/inbound/axum_extractors/reminder.rs+++ b/crates/entity_access/src/inbound/axum_extractors/reminder.rs@@ -11,6 +11,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use uuid::Uuid;use super::{ExtractorError, RequiredPermission};@@ -52,7 +53,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(parts, state))]+ #[tracing::instrument(err(level = Level::INFO), skip(parts, state))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);diff --git a/crates/entity_access/src/inbound/axum_extractors/scheduled_action.rs b/crates/entity_access/src/inbound/axum_extractors/scheduled_action.rsindex 958895e4aa..ed765e441e 100644--- a/crates/entity_access/src/inbound/axum_extractors/scheduled_action.rs+++ b/crates/entity_access/src/inbound/axum_extractors/scheduled_action.rs@@ -17,6 +17,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use uuid::Uuid;use super::{ExtractorError, bot::generate_bot_entity_access_receipt};@@ -49,7 +50,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);diff --git a/crates/entity_access/src/inbound/axum_extractors/team.rs b/crates/entity_access/src/inbound/axum_extractors/team.rsindex 73b33fe4b8..631c8fb7d3 100644--- a/crates/entity_access/src/inbound/axum_extractors/team.rs+++ b/crates/entity_access/src/inbound/axum_extractors/team.rs@@ -29,6 +29,7 @@ use macro_authorization::{MacroAuthorizationService, MacroAuthorizationState,};use macro_user_id::user_id::MacroUserIdStr;+use tracing::Level;enum TeamAccessOutcome<T: RequiredPermission> {Qualifying(EntityAccessReceipt<T>),@@ -201,7 +202,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);let authorization: MacroAuthorizationExtractor<Auth, AnyPrincipal> = parts@@ -243,7 +244,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);let authorization: MacroAuthorizationExtractor<Auth, AnyPrincipal> = partsdiff --git a/crates/entity_access/src/inbound/axum_extractors/thread.rs b/crates/entity_access/src/inbound/axum_extractors/thread.rsindex 41c967f9fd..6205390023 100644--- a/crates/entity_access/src/inbound/axum_extractors/thread.rs+++ b/crates/entity_access/src/inbound/axum_extractors/thread.rs@@ -16,6 +16,7 @@ use macro_authorization::{AnyPrincipal, MacroAuthorization, MacroAuthorizationService, MacroAuthorizationState,OptionalMacroAuthorizationExtractor,};+use tracing::Level;use super::{ExtractorError, RequiredPermission, bot::generate_bot_entity_access_receipt};use crate::domain::{@@ -49,7 +50,7 @@ where{type Rejection = ExtractorError;- #[tracing::instrument(err, skip(state, parts))]+ #[tracing::instrument(err(level = Level::INFO), skip(state, parts))]async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {let service = <Arc<Svc>>::from_ref(state);diff --git a/crates/entity_access/src/outbound/pg_access_repo.rs b/crates/entity_access/src/outbound/pg_access_repo.rsindex 4e3079f8ae..c0ce729105 100644--- a/crates/entity_access/src/outbound/pg_access_repo.rs+++ b/crates/entity_access/src/outbound/pg_access_repo.rs@@ -234,6 +234,7 @@ impl AccessRepository for PgAccessRepository {Ok(queries::call_access::get_call_access(&self.pool, &call_uuid, &source_ids).await?)}+ #[tracing::instrument(err, skip(self))]async fn get_agent_session_parent(&self,agent_session_id: &str,@@ -265,6 +266,7 @@ impl AccessRepository for PgAccessRepository {.transpose()}+ #[tracing::instrument(err, skip(self))]async fn agent_session_exists(&self, agent_session_id: &str) -> Result<bool, AccessError> {let session = agent_session_id.parse::<Uuid>()@@ -277,6 +279,7 @@ impl AccessRepository for PgAccessRepository {.await?)}+ #[tracing::instrument(err, skip(self, user_id))]async fn get_agent_session_access(&self,agent_session_id: &str,@@ -296,6 +299,7 @@ impl AccessRepository for PgAccessRepository {.await?)}+ #[tracing::instrument(err, skip(self, user_id))]async fn get_initiative_access(&self,initiative_id: &str,@@ -315,6 +319,7 @@ impl AccessRepository for PgAccessRepository {.await?)}+ #[tracing::instrument(err, skip(self, user_id))]async fn get_pipeline_access(&self,id: &str,@@ -329,6 +334,7 @@ impl AccessRepository for PgAccessRepository {Ok(queries::pipeline_access::get_pipeline_access(&self.pool, id, &sources).await?)}+ #[tracing::instrument(err, skip(self, user_id))]async fn list_pipeline_access(&self,user_id: &MacroUserId<Lowercase<'_>>,@@ -436,6 +442,7 @@ impl AccessRepository for PgAccessRepository {)}+ #[tracing::instrument(err, skip(self, user_id))]async fn get_scheduled_action_access(&self,scheduled_action_id: &str,@@ -457,6 +464,7 @@ impl AccessRepository for PgAccessRepository {)}+ #[tracing::instrument(err, skip(self, user_id))]async fn accessible_scheduled_action_ids(&self,user_id: &MacroUserId<Lowercase<'_>>,diff --git a/crates/macro_authorization/Cargo.toml b/crates/macro_authorization/Cargo.tomlindex 74931c6f77..3ce3ef0420 100644--- a/crates/macro_authorization/Cargo.toml+++ b/crates/macro_authorization/Cargo.toml@@ -48,4 +48,5 @@ serde_json = { workspace = true }serde_urlencoded = { workspace = true }tokio = { workspace = true, features = ["macros", "rt"] }tower = { workspace = true, features = ["util"] }+tracing-subscriber = { workspace = true }urlencoding = { workspace = true }diff --git a/crates/macro_authorization/src/domain/service.rs b/crates/macro_authorization/src/domain/service.rsindex 8fe1aa230b..50fe900495 100644--- a/crates/macro_authorization/src/domain/service.rs+++ b/crates/macro_authorization/src/domain/service.rs@@ -6,6 +6,7 @@ use std::{future::Future, pin::Pin, sync::Arc};use constant_time_eq::constant_time_eq;use model_user::UserContext;use rootcause::Report;+use tracing::Level;use super::{models::{@@ -155,7 +156,7 @@ where}#[tracing::instrument(- err,+ err(level = Level::DEBUG),skip_all,fields(bot_id = tracing::field::Empty,@@ -194,7 +195,7 @@ where}#[tracing::instrument(- err,+ err(level = Level::DEBUG),skip_all,fields(user_id = tracing::field::Empty))]@@ -212,7 +213,7 @@ where}#[tracing::instrument(- err,+ err(level = Level::DEBUG),skip_all,fields(harness_id = tracing::field::Empty,diff --git a/crates/macro_authorization/src/domain/user_api_key_authorizer.rs b/crates/macro_authorization/src/domain/user_api_key_authorizer.rsindex 1ee2a8a0c1..7b825716f3 100644--- a/crates/macro_authorization/src/domain/user_api_key_authorizer.rs+++ b/crates/macro_authorization/src/domain/user_api_key_authorizer.rs@@ -5,6 +5,7 @@ mod test;use model_user::UserContext;use rootcause::Report;+use tracing::Level;use super::{models::{MacroAuthorizationError, ResolvedApiKeyUser},@@ -28,7 +29,7 @@ impl<R> UserApiKeyAuthorizer for UserApiKeyAuthorizerService<R>whereR: UserApiKeyAuthorizationRepo,{- #[tracing::instrument(err, skip_all)]+ #[tracing::instrument(err(level = Level::DEBUG), skip_all)]async fn authorize_user_api_key(&self,api_key: &str,diff --git a/crates/macro_authorization/src/inbound/axum.rs b/crates/macro_authorization/src/inbound/axum.rsindex 2993cf14ad..4caaedab60 100644--- a/crates/macro_authorization/src/inbound/axum.rs+++ b/crates/macro_authorization/src/inbound/axum.rs@@ -22,8 +22,9 @@ use harness_id::HarnessId;use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};use model_error_response::ErrorResponse;use model_user::UserContext;+use rootcause::Report;-use crate::{MacroAuthorization, MacroUserAuthentication};+use crate::{MacroAuthorization, MacroAuthorizationError, MacroUserAuthentication};pub use bot::{BOT_FOR_FUSIONAUTH_USER_ID_HEADER, BOT_FOR_MACRO_USER_ID_HEADER,@@ -147,6 +148,24 @@ pub(super) fn authenticated_user(})}+/// Logs a failed authorization at a level matching its cause: rejected+/// credentials are routine client traffic, while an unavailable dependency is+/// a server fault.+pub(super) fn log_authorization_failure(+ error: &Report<MacroAuthorizationError>,+ message: &'static str,+) {+ match error.current_context() {+ MacroAuthorizationError::CredentialsExpired => tracing::info!(error=?error, "{message}"),+ MacroAuthorizationError::InvalidCredentials+ | MacroAuthorizationError::ActingUserNotAuthorized+ | MacroAuthorizationError::BotScopeNotAuthorized => {+ tracing::warn!(error=?error, "{message}")+ }+ MacroAuthorizationError::Unavailable => tracing::error!(error=?error, "{message}"),+ }+}+pub(super) fn rejection(message: &'static str) -> MacroAuthorizationRejection {status_rejection(StatusCode::UNAUTHORIZED, message)}diff --git a/crates/macro_authorization/src/inbound/axum/bot.rs b/crates/macro_authorization/src/inbound/axum/bot.rsindex aa49dc49ae..46db809199 100644--- a/crates/macro_authorization/src/inbound/axum/bot.rs+++ b/crates/macro_authorization/src/inbound/axum/bot.rs@@ -9,7 +9,10 @@ use crate::{MacroAuthorizationService,};-use super::{MacroAuthorizationRejection, MacroAuthorizationState, rejection, status_rejection};+use super::{+ MacroAuthorizationRejection, MacroAuthorizationState, log_authorization_failure, rejection,+ status_rejection,+};/// Header carrying a bot authentication token.pub const BOT_TOKEN_HEADER: &str = "x-macro-bot-token";@@ -129,6 +132,6 @@ fn bot_authorization_rejection(status_rejection(StatusCode::INTERNAL_SERVER_ERROR, "internal server error")}};- tracing::error!(error=?error, "bot authorization failed");+ log_authorization_failure(&error, "bot authorization failed");rejection}diff --git a/crates/macro_authorization/src/inbound/axum/harness.rs b/crates/macro_authorization/src/inbound/axum/harness.rsindex be3f57ba1d..2086beb61f 100644--- a/crates/macro_authorization/src/inbound/axum/harness.rs+++ b/crates/macro_authorization/src/inbound/axum/harness.rs@@ -6,7 +6,10 @@ use rootcause::Report;use crate::{HarnessAuthentication, MacroAuthorizationError, MacroAuthorizationService};-use super::{MacroAuthorizationRejection, MacroAuthorizationState, rejection, status_rejection};+use super::{+ MacroAuthorizationRejection, MacroAuthorizationState, log_authorization_failure, rejection,+ status_rejection,+};/// Header carrying a harness authentication token.pub const HARNESS_TOKEN_HEADER: &str = "x-macro-harness-token";@@ -75,6 +78,6 @@ fn harness_authorization_rejection(status_rejection(StatusCode::INTERNAL_SERVER_ERROR, "internal server error")}};- tracing::error!(error=?error, "harness authorization failed");+ log_authorization_failure(&error, "harness authorization failed");rejection}diff --git a/crates/macro_authorization/src/inbound/axum/internal.rs b/crates/macro_authorization/src/inbound/axum/internal.rsindex fef1a12d84..ec146a4196 100644--- a/crates/macro_authorization/src/inbound/axum/internal.rs+++ b/crates/macro_authorization/src/inbound/axum/internal.rs@@ -8,7 +8,10 @@ use crate::{InternalIdentityClaims, MacroAuthorization, MacroAuthorizationError, MacroAuthorizationService,};-use super::{MacroAuthorizationRejection, MacroAuthorizationState, authenticated_user, rejection};+use super::{+ MacroAuthorizationRejection, MacroAuthorizationState, authenticated_user,+ log_authorization_failure, rejection,+};/// Header carrying the shared key for standard internal service authorization.pub const INTERNAL_API_KEY_HEADER: &str = "x-internal-auth-key";@@ -103,6 +106,6 @@ fn header_string(headers: &HeaderMap, name: Option<&str>) -> Option<String> {fn internal_authorization_rejection(error: Report<MacroAuthorizationError>,) -> MacroAuthorizationRejection {- tracing::error!(error=?error.current_context(), "internal authorization failed");+ log_authorization_failure(&error, "internal authorization failed");rejection("unauthorized")}diff --git a/crates/macro_authorization/src/inbound/axum/test.rs b/crates/macro_authorization/src/inbound/axum/test.rsindex 743ea63d3e..061fdcfbda 100644--- a/crates/macro_authorization/src/inbound/axum/test.rs+++ b/crates/macro_authorization/src/inbound/axum/test.rs@@ -734,6 +734,71 @@ async fn user_rejects_missing_and_invalid_user_credentials() {);}+/// Records the level of every event emitted while installed.+#[derive(Clone, Default)]+struct EventLevels(Arc<Mutex<Vec<tracing::Level>>>);++impl<S: tracing::Subscriber> tracing_subscriber::Layer<S> for EventLevels {+ fn on_event(+ &self,+ event: &tracing::Event<'_>,+ _context: tracing_subscriber::layer::Context<'_, S>,+ ) {+ self.0+ .lock()+ .expect("levels lock poisoned")+ .push(*event.metadata().level());+ }+}++#[tokio::test]+async fn authorization_failures_log_at_the_level_of_their_cause() {+ use tracing::Level;+ use tracing_subscriber::layer::SubscriberExt;++ async fn check(request: Request<Body>, expected: Level) {+ let (router, _service) = test_router();+ let levels = EventLevels::default();+ let _guard =+ tracing::subscriber::set_default(tracing_subscriber::registry().with(levels.clone()));++ send(&router, request).await;++ assert_eq!(*levels.0.lock().expect("levels lock poisoned"), [expected]);+ }++ check(+ empty_body(request("/user").header("authorization", "Bearer expired")),+ Level::INFO,+ )+ .await;+ check(+ empty_body(request("/user").header("authorization", "Bearer invalid")),+ Level::WARN,+ )+ .await;+ check(+ empty_body(request("/internal").header(INTERNAL_API_KEY_HEADER, "invalid")),+ Level::WARN,+ )+ .await;+ check(+ empty_body(bot_request("/bot", "bot-forbidden")),+ Level::WARN,+ )+ .await;+ check(+ empty_body(bot_request("/bot", "bot-unavailable")),+ Level::ERROR,+ )+ .await;+ check(+ empty_body(user_api_key_request("/required", "mak_unavailable")),+ Level::ERROR,+ )+ .await;+}+#[tokio::test]async fn required_extracts_valid_bearer_and_preserves_organization() {let (router, service) = test_router();diff --git a/crates/macro_authorization/src/inbound/axum/user.rs b/crates/macro_authorization/src/inbound/axum/user.rsindex 6b15268029..65720d1ea1 100644--- a/crates/macro_authorization/src/inbound/axum/user.rs+++ b/crates/macro_authorization/src/inbound/axum/user.rs@@ -12,7 +12,10 @@ use serde::Deserialize;use crate::{MacroAuthorizationError, MacroAuthorizationService, MacroUserAuthentication};-use super::{MacroAuthorizationRejection, MacroAuthorizationState, authenticated_user, rejection};+use super::{+ MacroAuthorizationRejection, MacroAuthorizationState, authenticated_user,+ log_authorization_failure, rejection,+};#[cfg(feature = "local_auth")]maybe_env_vars! {@@ -149,6 +152,6 @@ fn authorization_rejection(error: Report<MacroAuthorizationError>) -> MacroAutho| MacroAuthorizationError::BotScopeNotAuthorized| MacroAuthorizationError::Unavailable => "unauthorized",};- tracing::error!(error=?error, "credential authorization failed");+ log_authorization_failure(&error, "credential authorization failed");rejection(message)}diff --git a/crates/macro_authorization/src/inbound/axum/user_api_key.rs b/crates/macro_authorization/src/inbound/axum/user_api_key.rsindex 291a102f29..35c556a1df 100644--- a/crates/macro_authorization/src/inbound/axum/user_api_key.rs+++ b/crates/macro_authorization/src/inbound/axum/user_api_key.rs@@ -7,8 +7,8 @@ use rootcause::Report;use crate::{MacroAuthorizationError, MacroAuthorizationService, MacroUserAuthentication};use super::{- MacroAuthorizationRejection, MacroAuthorizationState, authenticated_user, rejection,- status_rejection,+ MacroAuthorizationRejection, MacroAuthorizationState, authenticated_user,+ log_authorization_failure, rejection, status_rejection,};/// Header carrying a user API key.@@ -57,6 +57,6 @@ fn user_api_key_authorization_rejection(status_rejection(StatusCode::INTERNAL_SERVER_ERROR, "internal server error")}};- tracing::error!(error=?error, "user api key authorization failed");+ log_authorization_failure(&error, "user api key authorization failed");rejection}diff --git a/crates/macro_authorization/src/outbound/macro_auth.rs b/crates/macro_authorization/src/outbound/macro_auth.rsindex 8390c3ad7a..107d11c5a9 100644--- a/crates/macro_authorization/src/outbound/macro_auth.rs+++ b/crates/macro_authorization/src/outbound/macro_auth.rs@@ -6,6 +6,7 @@ use ::macro_auth::{middleware::decode_jwt::{self, JwtToken, JwtValidationArgs},};use rootcause::Report;+use tracing::Level;use crate::domain::{models::{MacroAuthorizationError, ValidatedIdentity},@@ -32,7 +33,7 @@ impl MacroAuthJwtValidator {}impl JwtValidator for MacroAuthJwtValidator {- #[tracing::instrument(err, skip(self, jwt))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self, jwt))]fn validate(&self, jwt: &str) -> Result<ValidatedIdentity, Report<MacroAuthorizationError>> {decode_jwt::handler(&self.jwt_validation_args, jwt).map(identity_from_token)diff --git a/crates/models_pagination/src/axum.rs b/crates/models_pagination/src/axum.rsindex d6b87fe496..d3ed27a037 100644--- a/crates/models_pagination/src/axum.rs+++ b/crates/models_pagination/src/axum.rs@@ -7,6 +7,7 @@ use model_error_response::ErrorResponse;use serde::Deserialize;use serde::de::DeserializeOwned;use thiserror::Error;+use tracing::Level;/// Extension trait adding `into_query` to `Option<CursorWithValAndFilter<...>>`/// for convenient conversion from an optional extracted cursor to a pagination query.@@ -109,7 +110,7 @@ where{type Rejection = CursorExtractErr;- #[tracing::instrument(err, skip(parts, state))]+ #[tracing::instrument(err(level = Level::WARN), skip(parts, state))]async fn from_request_parts(parts: &mut Parts,state: &S,@@ -154,7 +155,7 @@ where{type Rejection = CursorExtractErr;- #[tracing::instrument(err, skip(parts, state))]+ #[tracing::instrument(err(level = Level::WARN), skip(parts, state))]async fn from_request_parts(parts: &mut Parts,state: &S,diff --git a/crates/unfurl/src/domain/service.rs b/crates/unfurl/src/domain/service.rsindex 5fb06b1ef8..0d731c2efb 100644--- a/crates/unfurl/src/domain/service.rs+++ b/crates/unfurl/src/domain/service.rs@@ -1,6 +1,8 @@//! Service implementation that drives the [`UnfurlFetcher`] port and turns//! its raw meta-tag output into a [`GetUnfurlResponse`].+use tracing::Level;+use crate::domain::{favicon::append_optimistic_favico,models::{GetUnfurlResponse, UnfurlErr},@@ -28,7 +30,7 @@ whereF: UnfurlFetcher,anyhow::Error: From<F::Err>,{- #[tracing::instrument(err, skip(self))]+ #[tracing::instrument(err(level = Level::DEBUG), skip(self))]async fn unfurl(&self, url: &str) -> Result<GetUnfurlResponse, UnfurlErr> {let tags = self.fetcherdiff --git a/crates/unfurl/src/outbound/reqwest_fetcher.rs b/crates/unfurl/src/outbound/reqwest_fetcher.rsindex 8e1398d38c..99afad840d 100644--- a/crates/unfurl/src/outbound/reqwest_fetcher.rs+++ b/crates/unfurl/src/outbound/reqwest_fetcher.rs@@ -6,6 +6,7 @@ use std::sync::Arc;use futures::StreamExt;use scraper::{Html, Selector};use thiserror::Error;+use tracing::Level;use url::Url;use super::http_safety::{@@ -82,7 +83,7 @@ enum UnfurlFetchError {Parse(anyhow::Error),}-#[tracing::instrument(err(Debug), skip(client))]+#[tracing::instrument(err(Debug, level = Level::DEBUG), skip(client))]async fn extract_meta_tags(client: &reqwest::Client,raw_url: &str,diff --git a/services/authentication_service/src/api/jwt/refresh.rs b/services/authentication_service/src/api/jwt/refresh.rsindex f8965e2538..645bedfa2d 100644--- a/services/authentication_service/src/api/jwt/refresh.rs+++ b/services/authentication_service/src/api/jwt/refresh.rs@@ -81,7 +81,7 @@ pub async fn handler(// We only want to refresh the token if it's expiredMacroAuthError::JwtExpired => {}_ => {- tracing::error!(error=?e, token=?token_context.access_token, "unable to decode jwt");+ tracing::error!(error=?e, "unable to decode jwt");return Err(RefreshError::Unauthorized);}},diff --git a/services/connection_gateway/Cargo.toml b/services/connection_gateway/Cargo.tomlindex 78ef93496e..7bfa664736 100644--- a/services/connection_gateway/Cargo.toml+++ b/services/connection_gateway/Cargo.toml@@ -83,7 +83,6 @@ tower = { workspace = true }tower-http = { workspace = true }tracing = { workspace = true, features = ["attributes"] }tracing-opentelemetry = { workspace = true }-tungstenite = { workspace = true }url = { workspace = true }utoipa = { workspace = true, features = ["axum_extras"] }utoipa-swagger-ui = { workspace = true, features = ["axum"] }diff --git a/services/connection_gateway/src/api/connection/messages.rs b/services/connection_gateway/src/api/connection/messages.rsindex 11404e09c3..2de7340358 100644--- a/services/connection_gateway/src/api/connection/messages.rs+++ b/services/connection_gateway/src/api/connection/messages.rs@@ -12,9 +12,7 @@ use axum::extract::ws::{Message, WebSocket};use cowlike::CowLike;use futures::{StreamExt, stream::SplitStream};use macro_user_id::user_id::MacroUserIdStr;-use std::error::Error;use tokio::sync::mpsc::Sender;-use tungstenite::error::{Error as TungsteniteError, ProtocolError};pub async fn handle_websocket_stream(connection_context: ConnectionContext<'_>,@@ -25,35 +23,18 @@ pub async fn handle_websocket_stream(match msg {Ok(msg) => {if let Err(e) = handle_message(connection_context, msg, &sender).await {- tracing::error!(error=?e, "error handling message");+ tracing::warn!(error=?e, "error handling message");}}+ // A read error means the client went away without a close frame+ // (connection reset, broken pipe, no closing handshake).Err(err) => {- match err- .source()- .and_then(|e| e.downcast_ref::<TungsteniteError>())- {- // benign disconnect – ignore- Some(TungsteniteError::Protocol(- ProtocolError::ResetWithoutClosingHandshake,- )) => {}- Some(e) => {- tracing::error!(- error = ?e,- connection_id = %connection_context.connection_id,- user_id = %connection_context.user_context.user_id,- "web-socket closed with tungstenite error",- );- }- None => {- tracing::error!(- error = ?err,- connection_id = %connection_context.connection_id,- user_id = %connection_context.user_context.user_id,- "web-socket closed with non-tungstenite error",- );- }- }+ tracing::info!(+ error = ?err,+ connection_id = %connection_context.connection_id,+ user_id = %connection_context.user_context.user_id,+ "web-socket closed with error",+ );break;}};@@ -71,6 +52,7 @@ pub async fn handle_message() -> Result<()> {let text_message = match message {Message::Text(text) => Some(text),+ Message::Ping(_) | Message::Pong(_) => return Ok(()),Message::Close(_) => {tracing::debug!("websocket connection closed naturally");return Ok(());diff --git a/services/email_service/src/api/email/drafts/delete.rs b/services/email_service/src/api/email/drafts/delete.rsindex 14bdf941e5..9996a1ce59 100644--- a/services/email_service/src/api/email/drafts/delete.rs+++ b/services/email_service/src/api/email/drafts/delete.rs@@ -96,7 +96,7 @@ pub async fn handler(.await;match result {- Ok(_deleted_thread) => {+ Ok(_) => {tx.commit().await?;// cleanup attachments in the backgrounddiff --git a/services/email_service/src/pubsub/inbox_sync/operations/delete_message.rs b/services/email_service/src/pubsub/inbox_sync/operations/delete_message.rsindex 9021ae4933..1f97e06bea 100644--- a/services/email_service/src/pubsub/inbox_sync/operations/delete_message.rs+++ b/services/email_service/src/pubsub/inbox_sync/operations/delete_message.rs@@ -4,12 +4,12 @@ use crate::pubsub::util::{publish_email_event,};use email::domain::events::{EmailMacroEvent, MessageDeletedMetadata};+use email_db_client::messages::delete::MessageDeletion;use models_email::api::refresh::RefreshEmailEvent;use models_email::email::service::link;use models_email::gmail::inbox_sync::DeleteMessagePayload;use models_email::service::pubsub::{DetailedError, FailureReason, ProcessingError};use std::result;-use uuid::Uuid;// delete user's message from the db#[tracing::instrument(skip(ctx))]@@ -106,11 +106,19 @@ pub async fn delete_message(source: e.context("Failed to delete message with transaction".to_string()),})})?;- Ok::<Option<Uuid>, ProcessingError>(result)+ Ok::<MessageDeletion, ProcessingError>(result)}.await;- complete_transaction_with_processing_error(tx, result).await?;+ let deletion = complete_transaction_with_processing_error(tx, result).await?;+ if deletion == MessageDeletion::AlreadyDeleted {+ tracing::debug!(+ message_id = %message.db_id,+ link_id = %link.id,+ "Message already deleted by a concurrent operation"+ );+ return Ok(());+ }publish_email_event(&ctx.macro_event_broker,diff --git a/services/unfurl_service/src/api/proxy.rs b/services/unfurl_service/src/api/proxy.rsindex 918a605321..37647b6c84 100644--- a/services/unfurl_service/src/api/proxy.rs+++ b/services/unfurl_service/src/api/proxy.rs@@ -5,6 +5,7 @@ use axum::http::{HeaderMap, HeaderName, Request};use axum::response::Response;use axum::routing::get;use serde::Deserialize;+use tracing::Level;use utoipa::{self, ToSchema};use crate::http_safety::{@@ -25,7 +26,7 @@ pub struct ProxyParams {path="/proxy",params(("url" = String, Query, description = "The url to proxy from")),)]-#[tracing::instrument(err(Debug), skip(http_client, request))]+#[tracing::instrument(err(Debug, level = Level::WARN), skip(http_client, request))]pub async fn proxy_request_handler(Query(params): Query<ProxyParams>,State(http_client): State<SsrfSafeHttpClient>,diff --git a/services/unfurl_service/src/unfurl.rs b/services/unfurl_service/src/unfurl.rsindex c988a19c10..d3c7e2c58d 100644--- a/services/unfurl_service/src/unfurl.rs+++ b/services/unfurl_service/src/unfurl.rs@@ -2,6 +2,7 @@ use anyhow::Error;use futures::StreamExt;use scraper::{Html, Selector};use std::collections::HashMap;+use tracing::Level;use url::Url;use crate::http_safety::{@@ -113,7 +114,7 @@ impl From<FetchError> for UnfurlFetchError {}}-#[tracing::instrument(err(Debug), skip(client))]+#[tracing::instrument(err(Debug, level = Level::DEBUG), skip(client))]pub async fn extract_meta_tags_prod(client: &reqwest::Client,raw_url: &str,