diff --git a/langfuse/_client/observe.py b/langfuse/_client/observe.py index 6252c5383..c648a0a62 100644 --- a/langfuse/_client/observe.py +++ b/langfuse/_client/observe.py @@ -327,7 +327,7 @@ async def async_wrapper(*args: Tuple[Any], **kwargs: Dict[str, Any]) -> Any: langfuse_span_or_generation.update(output=result) return result - except Exception as e: + except (Exception, asyncio.CancelledError) as e: langfuse_span_or_generation.update( level="ERROR", status_message=str(e) or type(e).__name__ ) @@ -445,7 +445,7 @@ def sync_wrapper(*args: Any, **kwargs: Any) -> Any: langfuse_span_or_generation.update(output=result) return result - except Exception as e: + except (Exception, asyncio.CancelledError) as e: langfuse_span_or_generation.update( level="ERROR", status_message=str(e) or type(e).__name__ ) @@ -586,7 +586,7 @@ def __next__(self) -> Any: raise # Re-raise StopIteration - except Exception as e: + except (Exception, asyncio.CancelledError) as e: self.span.update( level="ERROR", status_message=str(e) or type(e).__name__ ).end() @@ -653,7 +653,7 @@ async def __anext__(self) -> Any: self.span.update(output=output).end() raise # Re-raise StopAsyncIteration - except Exception as e: + except (Exception, asyncio.CancelledError) as e: self.span.update( level="ERROR", status_message=str(e) or type(e).__name__ ).end()