From 9968f162d6ba64d6115d9c9723dcecfdf65e789f Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 3 Nov 2024 07:07:04 -0500 Subject: [PATCH] Update simplemind/logging.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- simplemind/logging.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/simplemind/logging.py b/simplemind/logging.py index 22600ad..bd2c1cc 100644 --- a/simplemind/logging.py +++ b/simplemind/logging.py @@ -46,14 +46,19 @@ def logger(func: Callable[..., Any]) -> Callable[..., Any]: ) return result - except Exception as e: + if not settings.logging.is_enabled: + return func(*args, **kwargs) + + chunks = [] + try: + is_streaming = "generate_stream_text" in func.__name__ or kwargs.get("stream") logfire.error( "{event}", event="function failed", error=str(e), duration=time.perf_counter() - t1, - streamed_chunks=len(chunks) if is_streaming else None, - partial_streaming_result="".join(chunks)[:2000] if is_streaming else None, + streamed_chunks=len(chunks) if chunks else None, + partial_streaming_result="".join(chunks)[:2000] if chunks else None, ) raise e