Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

feat: log stream cancellation to sentry (#3759)

cthomas7d33254f5f3f
diff --git a/letta/interfaces/anthropic_streaming_interface.py b/letta/interfaces/anthropic_streaming_interface.py
index 9e1328fae..3022a11c5 100644
--- a/letta/interfaces/anthropic_streaming_interface.py
+++ b/letta/interfaces/anthropic_streaming_interface.py
@@ -389,13 +389,24 @@ class AnthropicStreamingInterface:
self.anthropic_mode = None
except asyncio.CancelledError as e:
- logger.info("Cancelled stream %s", e)
- yield LettaStopReason(stop_reason=StopReasonType.cancelled)
- raise
+ import traceback
+
+ logger.error("Cancelled stream %s: %s", e, traceback.format_exc())
+ ttft_span.add_event(
+ name="stop_reason",
+ attributes={"stop_reason": StopReasonType.cancelled.value, "error": str(e), "stacktrace": traceback.format_exc()},
+ )
+ raise e
except Exception as e:
- logger.error("Error processing stream: %s", e)
+ import traceback
+
+ logger.error("Error processing stream: %s", e, traceback.format_exc())
+ ttft_span.add_event(
+ name="stop_reason",
+ attributes={"stop_reason": StopReasonType.error.value, "error": str(e), "stacktrace": traceback.format_exc()},
+ )
yield LettaStopReason(stop_reason=StopReasonType.error)
- raise
+ raise e
finally:
logger.info("AnthropicStreamingInterface: Stream processing complete.")
diff --git a/letta/interfaces/openai_streaming_interface.py b/letta/interfaces/openai_streaming_interface.py
index aee3584d3..710c3ba0d 100644
--- a/letta/interfaces/openai_streaming_interface.py
+++ b/letta/interfaces/openai_streaming_interface.py
@@ -389,12 +389,23 @@ class OpenAIStreamingInterface:
yield tool_call_msg
self.function_id_buffer = None
except asyncio.CancelledError as e:
- logger.info("Cancelled stream %s", e)
- yield LettaStopReason(stop_reason=StopReasonType.cancelled)
- raise
+ import traceback
+
+ logger.error("Cancelled stream %s: %s", e, traceback.format_exc())
+ ttft_span.add_event(
+ name="stop_reason",
+ attributes={"stop_reason": StopReasonType.cancelled.value, "error": str(e), "stacktrace": traceback.format_exc()},
+ )
+ raise e
except Exception as e:
- logger.error("Error processing stream: %s", e)
+ import traceback
+
+ logger.error("Error processing stream: %s", e, traceback.format_exc())
+ ttft_span.add_event(
+ name="stop_reason",
+ attributes={"stop_reason": StopReasonType.error.value, "error": str(e), "stacktrace": traceback.format_exc()},
+ )
yield LettaStopReason(stop_reason=StopReasonType.error)
- raise
+ raise e
finally:
logger.info("OpenAIStreamingInterface: Stream processing complete.")