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(ai): Improve logging in stream + ai crate (#1771)
Eric Hayes36a49d557442
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex 747c8b08ba..7f58c30e4e 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -138,6 +138,7 @@ dependencies = ["serde","serde_json","thiserror 2.0.17",+ "tracing","utoipa",]diff --git a/rust/cloud-storage/ai/src/tool/tool_loop/chat.rs b/rust/cloud-storage/ai/src/tool/tool_loop/chat.rsindex 8c5d39135f..e1cb12ce01 100644--- a/rust/cloud-storage/ai/src/tool/tool_loop/chat.rs+++ b/rust/cloud-storage/ai/src/tool/tool_loop/chat.rs@@ -57,6 +57,7 @@ where}}+ #[tracing::instrument(skip(self, request_context), err)]pub async fn send_message(&mut self,request: ChatCompletionRequest,@@ -82,6 +83,7 @@ wheremessages.0}+ #[tracing::instrument(err, skip_all)]async fn make_chat_completion_stream(&mut self,request_context: RequestContext,@@ -378,6 +380,7 @@ whereBox::pin(stream)}+ #[tracing::instrument(err, skip(self))]async fn make_openai_chat_completion_stream(&mut self,) -> Result<ExtendedOpenAIStream<I::ResponseExtension>> {diff --git a/rust/cloud-storage/ai_toolset/Cargo.toml b/rust/cloud-storage/ai_toolset/Cargo.tomlindex 39cb20ca81..5bae0c795f 100644--- a/rust/cloud-storage/ai_toolset/Cargo.toml+++ b/rust/cloud-storage/ai_toolset/Cargo.toml@@ -16,3 +16,4 @@ anyhow = { workspace = true }macro_user_id = { path = "../macro_user_id" }axum = { workspace = true }axum-macros = { workspace = true }+tracing = { workspace = true }diff --git a/rust/cloud-storage/ai_toolset/src/toolset/tool_object/tool_async.rs b/rust/cloud-storage/ai_toolset/src/toolset/tool_object/tool_async.rsindex 1913385c18..14db8d89ad 100644--- a/rust/cloud-storage/ai_toolset/src/toolset/tool_object/tool_async.rs+++ b/rust/cloud-storage/ai_toolset/src/toolset/tool_object/tool_async.rs@@ -54,6 +54,7 @@ whereT: AsyncTool<ToolContext> + Send + Sync,T::Output: Serialize,{+ #[tracing::instrument(err, skip_all)]async fn call(&self,context: ToolSetContext,@@ -94,6 +95,7 @@ whereParentContext: Send + Sync,SubContext: FromRef<ParentContext> + Send + Sync,{+ #[tracing::instrument(err, skip_all)]async fn call(&self,context: ParentContext,@@ -119,6 +121,7 @@ pub type AsyncToolObject<ToolSetContext> = ToolObject<AsyncDeserializer<ToolSetCimpl<ToolSetContext> ToolObject<AsyncDeserializer<ToolSetContext>> {/// Attempts to deserialize JSON input into a callable async tool instance.+ #[tracing::instrument(err, skip(self))]pub fn try_deserialize(&self,data: &serde_json::Value,diff --git a/rust/cloud-storage/ai_toolset/src/toolset/types.rs b/rust/cloud-storage/ai_toolset/src/toolset/types.rsindex 5a48f5bd06..134df637a7 100644--- a/rust/cloud-storage/ai_toolset/src/toolset/types.rs+++ b/rust/cloud-storage/ai_toolset/src/toolset/types.rs@@ -124,6 +124,7 @@ where/// was added.////// Returns an error if the tool is not found or if deserialization fails.+ #[tracing::instrument(err, skip(self, context, request_context))]pub async fn try_tool_call(&self,context: ToolSetContext,diff --git a/rust/cloud-storage/stream/src/outbound/redis_pg/queries/mod.rs b/rust/cloud-storage/stream/src/outbound/redis_pg/queries/mod.rsindex 42a64d29ee..6da0d3bed5 100644--- a/rust/cloud-storage/stream/src/outbound/redis_pg/queries/mod.rs+++ b/rust/cloud-storage/stream/src/outbound/redis_pg/queries/mod.rs@@ -5,6 +5,7 @@ use crate::domain::StreamId;use sqlx::PgPool;/// Insert a new active stream entry, ignoring conflicts.+#[tracing::instrument(err, skip(pool))]pub(crate) async fn insert_active_stream(pool: &PgPool,stream_id: &StreamId,@@ -20,6 +21,7 @@ pub(crate) async fn insert_active_stream(}/// Delete an active stream entry.+#[tracing::instrument(err, skip(pool))]pub(crate) async fn delete_active_stream(pool: &PgPool,stream_id: &StreamId,diff --git a/rust/cloud-storage/stream/src/outbound/redis_pg/repo.rs b/rust/cloud-storage/stream/src/outbound/redis_pg/repo.rsindex 7d8dcd6109..0118d38a50 100644--- a/rust/cloud-storage/stream/src/outbound/redis_pg/repo.rs+++ b/rust/cloud-storage/stream/src/outbound/redis_pg/repo.rs@@ -119,6 +119,7 @@ impl RedisPostgresStreamRepo {/// Delete stream data from redis and postgres./// Internal / testing only. Streams are cleaned using TTL for prod.#[allow(unused)]+ #[tracing::instrument(err, skip(self))]pub async fn cleanup_stream(&self, id: &StreamId) -> Result<()> {let mut conn = self.redis_client.get_multiplexed_async_connection().await?;let _: () = conn@@ -134,6 +135,7 @@ impl RedisPostgresStreamRepo {Ok(())}+ #[tracing::instrument(skip(conn, item), err)]async fn publish_item(conn: &mut redis::aio::MultiplexedConnection,id: &StreamId,@@ -149,6 +151,7 @@ impl RedisPostgresStreamRepo {#[async_trait]impl StreamRepo for RedisPostgresStreamRepo {/// Create and append to stream or append to an existing stream.+ #[tracing::instrument(err, skip(self, payload))]async fn append(&self, id: &StreamId, payload: serde_json::Value) -> Result<ItemId> {let mut conn = self.redis_client.get_multiplexed_async_connection().await?;@@ -183,6 +186,7 @@ impl StreamRepo for RedisPostgresStreamRepo {Ok(item_id)}+ #[tracing::instrument(skip(self), err)]async fn stream_from_beginning(&self, id: &StreamId) -> Result<ItemStream> {// Use no response timeout for blocking XREAD — the default 500ms from redis 1.0// kills the connection before the block period expires.@@ -249,6 +253,7 @@ impl StreamRepo for RedisPostgresStreamRepo {Ok(Box::pin(stream))}+ #[tracing::instrument(err, skip(self))]async fn close(&self, id: &StreamId) -> Result<()> {let mut conn = self.redis_client.get_multiplexed_async_connection().await?;Self::publish_item(&mut conn, id, &StoredStreamItem::End).await?;@@ -273,6 +278,7 @@ impl StreamRepo for RedisPostgresStreamRepo {Ok(())}+ #[tracing::instrument(err, skip(self))]async fn active_streams(&self, entity_id: &str) -> Result<Vec<StreamId>> {super::queries::get_active_stream_keys(&self.pg_pool, entity_id).await