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
chore(email-service): Clean up logs (#984)
Evan Hutnikd345edcc0164
diff --git a/rust/cloud-storage/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs b/rust/cloud-storage/email_service/src/pubsub/inbox_sync/operations/upsert_message.rsindex 023a67a009..db1f564850 100644--- a/rust/cloud-storage/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs+++ b/rust/cloud-storage/email_service/src/pubsub/inbox_sync/operations/upsert_message.rs@@ -228,14 +228,6 @@ async fn handle_attachment_upload(let mut attachments = document_atts;attachments.extend(media_atts);if !attachments.is_empty() {- tracing::info!(- "Uploading attachments ({:?}) to Macro for new email",- attachments- .iter()- .map(|a| a.attachment_db_id)- .collect::<Vec<_>>()- );-let message_ids = attachments.iter().map(|a| a.message_db_id)@@ -315,12 +307,6 @@ async fn handle_contacts_sync(return Ok(());}- tracing::info!(- "Upserting contacts {:?} for new sent message with id {}",- recipient_emails,- provider_message_id- );-// Create users list starting with the sender, then all recipientslet mut users = vec![link.macro_id.to_string()];users.extend(@@ -347,12 +333,6 @@ async fn handle_contacts_sync(})})?;- tracing::info!(- "Successfully upserted contacts {:?} for new sent message with id {}",- recipient_emails,- provider_message_id- );-Ok(())}diff --git a/rust/cloud-storage/email_service/src/pubsub/link_manager/process.rs b/rust/cloud-storage/email_service/src/pubsub/link_manager/process.rsindex 14d6beaff4..74a5d8e8a8 100644--- a/rust/cloud-storage/email_service/src/pubsub/link_manager/process.rs+++ b/rust/cloud-storage/email_service/src/pubsub/link_manager/process.rs@@ -1,5 +1,4 @@use crate::pubsub::link_manager::context::LinkManagerContext;-use crate::pubsub::util::fetch_link;use crate::util::gmail::auth::{fetch_gmail_access_token_from_link, fetch_token_or_delete_on_revocation,};@@ -21,7 +20,14 @@ pub async fn process_message(let notification_data = extract_message(message)?;// Step 2: Fetch the user's link details from the database- let link = fetch_link(&ctx.db, notification_data.link_id).await?;+ let link =+ email_db_client::links::get::fetch_link_by_id(&ctx.db, notification_data.link_id).await?;++ let Some(link) = link else {+ tracing::debug!(link_id=%notification_data.link_id, "Link not found - skipping");+ cleanup_message(&ctx.sqs_worker, message).await?;+ return Ok(());+ };// Step 3: Execute the appropriate operationmatch notification_data.operation {@@ -133,7 +139,7 @@ async fn handle_delete(tracing::warn!(error=?e, link_id=?link.id, "Gmail call to stop watch failed");}} else {- tracing::info!(link_id=?link.id, "Skipping Gmail stop_watch - no access token available");+ tracing::debug!(link_id=?link.id, "Skipping Gmail stop_watch - no access token available");}// remove google fusionauth link with gmail inbox permissionsdiff --git a/rust/cloud-storage/email_service/src/pubsub/scheduled/process.rs b/rust/cloud-storage/email_service/src/pubsub/scheduled/process.rsindex dcfdeaabb0..20515d5f3f 100644--- a/rust/cloud-storage/email_service/src/pubsub/scheduled/process.rs+++ b/rust/cloud-storage/email_service/src/pubsub/scheduled/process.rs@@ -1,5 +1,4 @@use crate::pubsub::scheduled::context::ScheduledContext;-use crate::pubsub::util::fetch_link;use crate::util::gmail::auth::fetch_gmail_access_token_from_link;use crate::util::gmail::send::{cleanup_draft_attachments, fetch_and_attach_draft_attachments, generate_email_threading_headers,@@ -18,7 +17,14 @@ pub async fn process_message(// Parse the incoming messagelet data = extract_scheduled_message(message)?;- let link = fetch_link(&ctx.db, data.link_id).await?;+ let link = email_db_client::links::get::fetch_link_by_id(&ctx.db, data.link_id).await?;++ let Some(link) = link else {+ tracing::debug!(link_id=%data.link_id, "Link not found - skipping");+ cleanup_message(&ctx.sqs_worker, message).await?;+ return Ok(());+ };+let gmail_access_token =fetch_gmail_access_token_from_link(&link, &ctx.redis_client, &ctx.auth_service_client).await?;diff --git a/rust/cloud-storage/email_service/src/pubsub/util.rs b/rust/cloud-storage/email_service/src/pubsub/util.rsindex 9dd2223a69..0d96425e90 100644--- a/rust/cloud-storage/email_service/src/pubsub/util.rs+++ b/rust/cloud-storage/email_service/src/pubsub/util.rs@@ -1,12 +1,9 @@use crate::util::redis::RedisClient;use crate::util::redis::rate_limit::RateLimitArgs;-use anyhow::anyhow;use connection_gateway_client::client::ConnectionGatewayClient;/// shared utils across different pubsub workersuse models_email::email::service::pubsub::{DetailedError, FailureReason, ProcessingError};use models_email::gmail::operations::GmailApiOperation;-use models_email::service::link::Link;-use sqlx::PgPool;use uuid::Uuid;/// Arguments for checking Gmail API rate limits@@ -91,19 +88,3 @@ pub async fn cg_refresh_email(client: &ConnectionGatewayClient, macro_id: &str,.inspect_err(|e| tracing::error!(macro_id = %macro_id, "Failed to refresh email: {e}"));}}--/// Fetches the Link details from the database using the link_id from the notification.-pub async fn fetch_link(db: &PgPool, link_id: Uuid) -> anyhow::Result<Link> {- email_db_client::links::get::fetch_link_by_id(db, link_id)- .await- .map_err(|e| {- let error_message = "Unable to fetch link from DB";- tracing::error!(error = ?e, link_id = %link_id, error_message);- anyhow!(error_message)- })?- .ok_or_else(|| {- let error_message = "Link not found";- tracing::error!(link_id = %link_id, error_message);- anyhow!(error_message)- })-}diff --git a/rust/cloud-storage/email_service/src/util/sync_contacts.rs b/rust/cloud-storage/email_service/src/util/sync_contacts.rsindex b5d288b427..bf467fdfd2 100644--- a/rust/cloud-storage/email_service/src/util/sync_contacts.rs+++ b/rust/cloud-storage/email_service/src/util/sync_contacts.rs@@ -80,38 +80,25 @@ async fn fetch_new_contacts_from_google({Ok(response) => {all_new_contacts.push(response);- tracing::info!(- link_id = %link.id,- "Fetched own contact"- );}Err(e) => {tracing::error!(error = ?e, link_id = %link.id, "Failed to get own contact");}};- let primary_start = Instant::now();match gmail_client.get_contacts(gmail_access_token, link.id, contacts_sync_token.as_deref()).await{Ok(response) => {- let length = response.contacts.len();new_contacts_token = Some(response.next_sync_token);all_new_contacts.extend(response.contacts);- tracing::info!(- duration = ?primary_start.elapsed(),- num_contacts = length,- link_id = %link.id,- "Fetched primary contacts"- );}Err(e) => {- tracing::error!(error = ?e, link_id = %link.id, "Failed to get primary contacts");+ tracing::debug!(error = ?e, link_id = %link.id, "Failed to get primary contacts");}};- let other_start = Instant::now();match gmail_client.get_other_contacts(gmail_access_token,@@ -121,18 +108,11 @@ async fn fetch_new_contacts_from_google(.await{Ok(response) => {- let length = response.contacts.len();new_other_contacts_token = Some(response.next_sync_token);all_new_contacts.extend(response.contacts);- tracing::info!(- duration = ?other_start.elapsed(),- num_contacts = length,- link_id = %link.id,- "Fetched other contacts"- );}Err(e) => {- tracing::error!(error = ?e, link_id = %link.id, "Failed to get other contacts");+ tracing::debug!(error = ?e, link_id = %link.id, "Failed to get other contacts");}};@@ -196,15 +176,11 @@ async fn process_and_store_contacts(return Ok(());}// Async enqueue messages to sfs_uploader worker that populates the sfs_url for the contacts profile images- let sqs_start = Instant::now();- let link_id = link.id;let sqs_client = sqs_client.clone();let contacts_for_sqs = contacts.clone();tokio::spawn(async move {const MAX_CONCURRENT_ENQUEUES: usize = 50;- let mut successful_enqueues = 0;- let mut failed_enqueues = 0;let mut stream = stream::iter(contacts_for_sqs)// only enqueue contacts that have a photo_url@@ -223,20 +199,7 @@ async fn process_and_store_contacts(}).buffer_unordered(MAX_CONCURRENT_ENQUEUES);- while let Some(result) = stream.next().await {- match result {- Ok(_) => successful_enqueues += 1,- Err(_) => failed_enqueues += 1,- }- }-- tracing::info!(- duration = ?sqs_start.elapsed(),- successful_enqueues = successful_enqueues,- failed_enqueues = failed_enqueues,- link_id = %link_id,- "Completed SQS enqueuing"- );+ while stream.next().await.is_some() {}});Ok(())