diff --git a/letta/interfaces/anthropic_streaming_interface.py b/letta/interfaces/anthropic_streaming_interface.py index 9e1328fa..3022a11c 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 aee3584d..710c3ba0 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.")