From 328be9467717bbc5bcc36669223ead67d878f8c5 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 3 Nov 2024 07:17:44 -0500 Subject: [PATCH] Revert "Merge pull request #35 from barisozmen/logger-for-streaming" This reverts commit d7f8418f238a6db8703cfde57f939f2e0901dc1b, reversing changes made to cb73621e39f211ef6e5e8cb668edf6c6386e2266. --- simplemind/logging.py | 54 +++++++++---------------------------------- 1 file changed, 11 insertions(+), 43 deletions(-) diff --git a/simplemind/logging.py b/simplemind/logging.py index bd2c1cc..06defc3 100644 --- a/simplemind/logging.py +++ b/simplemind/logging.py @@ -15,51 +15,19 @@ def logger(func: Callable[..., Any]) -> Callable[..., Any]: if not settings.logging.is_enabled: return func(*args, **kwargs) - # See logfire manual tracing docs: https://logfire.pydantic.dev/docs/guides/onboarding-checklist/add-manual-tracing/#exceptions - with logfire.span("{event}", event="function called", function=func.__name__, args=args, kwargs=kwargs): - - t1 = time.perf_counter() + logfire.info(f"Calling {func.__name__} with args: {args}, kwargs: {kwargs}") + t1 = time.perf_counter() - try: - is_streaming = "generate_stream_text" in func.__name__ or kwargs.get("stream") - if is_streaming: - chunks = [] - for chunk in func(*args, **kwargs): - chunks.append(chunk) - yield chunk - result = "".join(chunks) - # note: no need to log the function name here, as it's already in the span - logfire.info( - "{event}", - event="function completed", - result=result[:2000], - chunk_count=len(chunks), - duration=time.perf_counter() - t1 - ) - else: - result = func(*args, **kwargs) - logfire.info( - "{event}", - event="function completed", - result=str(result)[:2000], - duration=time.perf_counter() - t1 - ) - return result + try: + result = func(*args, **kwargs) + t2 = time.perf_counter() + logfire.info(f"{func.__name__} returned: {result} in {t2-t1} seconds") - if not settings.logging.is_enabled: - return func(*args, **kwargs) + return result - 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 chunks else None, - partial_streaming_result="".join(chunks)[:2000] if chunks else None, - ) - raise e + except Exception as e: + t2 = time.perf_counter() + logfire.error(f"Error in {func.__name__}: {e} in {t2-t1} seconds") + raise e return wrapper