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(connection-gateway): replace timing logs with spans (#5424)
teoac9f60a93eff
diff --git a/services/connection_gateway/src/api/message/mod.rs b/services/connection_gateway/src/api/message/mod.rsindex 88abc2f12a..9763352c65 100644--- a/services/connection_gateway/src/api/message/mod.rs+++ b/services/connection_gateway/src/api/message/mod.rs@@ -15,7 +15,6 @@ use connection_gateway_models::{use futures::future::try_join_all;use macro_authorization::{InternalOnly, MacroAuthorizationExtractor};use model_entity::Entity;-use std::time::Instant;pub fn router<S>(state: AppState) -> Router<S>where@@ -93,14 +92,17 @@ pub async fn send_message_handler((status = 500, description = "Internal server error", body = String),))]-#[tracing::instrument(skip(_internal_authorization, ctx))]+#[tracing::instrument(+ name = "send_messages",+ skip_all,+ fields(batch_kind = "shared", message_count = body.entities.len()),+ err(Debug)+)]pub async fn batch_send_message_handler(_internal_authorization: MacroAuthorizationExtractor<AuthorizationService, InternalOnly>,State(ctx): State<AppState>,Json(body): Json<BatchSendMessageBody<'static>>,) -> Result<(StatusCode, JsonResponse<SendMessageResponse>), (StatusCode, String)> {- let now = Instant::now();-let redis_connection = ctx.context.redis_connection.clone();let all_receipts = try_join_all(body.entities.iter().map(|entity| {@@ -116,16 +118,16 @@ pub async fn batch_send_message_handler()})).await- .map_err(|e| {- tracing::error!(error=?e, "unable to send message");+ .inspect_err(|error| {+ tracing::error!(error = ?error, "unable to send message");+ })+ .map_err(|_| {(StatusCode::INTERNAL_SERVER_ERROR,"unable to send message".to_string(),)})?;- tracing::trace!("batch send message took {:?}", now.elapsed());-Ok((StatusCode::OK,JsonResponse(SendMessageResponse {@@ -144,15 +146,18 @@ pub async fn batch_send_message_handler((status = 500, description = "Internal server error", body = String),))]-#[tracing::instrument(skip(_internal_authorization, ctx))]+#[tracing::instrument(+ name = "send_messages",+ skip_all,+ fields(batch_kind = "unique", message_count = body.messages.len()),+ err(Debug)+)]#[axum::debug_handler(state = AppState)]pub async fn batch_send_unique_messages_handler(_internal_authorization: MacroAuthorizationExtractor<AuthorizationService, InternalOnly>,State(ctx): State<AppState>,Json(body): Json<BatchSendUniqueMessagesBody>,) -> Result<(StatusCode, JsonResponse<SendMessageResponse>), (StatusCode, String)> {- let now = Instant::now();-let redis_connection = ctx.context.redis_connection.clone();let all_receipts = try_join_all(body.messages.iter().map(|message| {@@ -168,16 +173,16 @@ pub async fn batch_send_unique_messages_handler()})).await- .map_err(|e| {- tracing::error!(error=?e, "unable to send message");+ .inspect_err(|error| {+ tracing::error!(error = ?error, "unable to send message");+ })+ .map_err(|_| {(StatusCode::INTERNAL_SERVER_ERROR,"unable to send message".to_string(),)})?;- tracing::trace!("batch send unique message took {:?}", now.elapsed());-Ok((StatusCode::OK,JsonResponse(SendMessageResponse {diff --git a/services/connection_gateway/src/service/sender.rs b/services/connection_gateway/src/service/sender.rsindex 7cfaeb3c95..9ec9f96573 100644--- a/services/connection_gateway/src/service/sender.rs+++ b/services/connection_gateway/src/service/sender.rs@@ -18,7 +18,7 @@ pub struct Delivery {pub active: bool,}-#[tracing::instrument(skip(ctx, redis_connection))]+#[tracing::instrument(skip(ctx, redis_connection), err)]pub async fn send_message_to_entity<Ctx>(ctx: Ctx,entity: &Entity<'_>,@@ -45,26 +45,48 @@ wheretracing::trace!("sending message to {} connections", connections.len());- let instant = Instant::now();-let local_connections: Vec<&StoredConnectionEntity> = connections.iter()- .filter(|c| {+ .filter(|connection| {api_context.connection_manager- .has_connection(&c.connection_id)+ .has_connection(&connection.connection_id)}).collect();let remote_connections: Vec<&StoredConnectionEntity> = connections.iter()- .filter(|c| {+ .filter(|connection| {!api_context.connection_manager- .has_connection(&c.connection_id)+ .has_connection(&connection.connection_id)}).collect();+ Ok(send_messages_to_connections(+ api_context,+ local_connections,+ remote_connections,+ message,+ redis_connection,+ )+ .await)+}++#[tracing::instrument(+ skip_all,+ fields(+ local_connection_count = local_connections.len(),+ remote_connection_count = remote_connections.len(),+ )+)]+async fn send_messages_to_connections(+ api_context: &ApiContext,+ local_connections: Vec<&StoredConnectionEntity>,+ remote_connections: Vec<&StoredConnectionEntity>,+ message: Message,+ redis_connection: MultiplexedConnection,+) -> Vec<MessageReceipt> {let local_send_futures = local_connections.into_iter().map(|connection| {let message = message.clone();@@ -145,7 +167,5 @@ where}}- tracing::trace!("sent message to connections in {:?}", instant.elapsed());-- Ok(receipts.into_values().collect())+ receipts.into_values().collect()}