From d0f2a5469f0be2b986bca3027660cd9e35d1d914 Mon Sep 17 00:00:00 2001 From: Hassieb Pakzad <68423100+hassiebp@users.noreply.github.com> Date: Thu, 2 Jan 2025 14:42:56 +0100 Subject: [PATCH 1/2] fix(dataset+decorator): item observer with top-level generation --- langfuse/decorators/langfuse_decorator.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/langfuse/decorators/langfuse_decorator.py b/langfuse/decorators/langfuse_decorator.py index 984cd5b32..137ba84b7 100644 --- a/langfuse/decorators/langfuse_decorator.py +++ b/langfuse/decorators/langfuse_decorator.py @@ -364,7 +364,9 @@ def _prepare_call( # Create wrapper trace if generation is top-level # Do not add wrapper trace to stack, as it does not have a corresponding end that will pop it off again trace = self.client_instance.trace( - id=id, name=name, start_time=start_time + id=_root_trace_id_context.get() or id, + name=name, + start_time=start_time, ) self._set_root_trace_id(trace.id) From 07b0870a7f12a3f8cfcc9f7db460924a97d98813 Mon Sep 17 00:00:00 2001 From: Hassieb Pakzad <68423100+hassiebp@users.noreply.github.com> Date: Thu, 2 Jan 2025 15:06:55 +0100 Subject: [PATCH 2/2] fix test --- tests/test_singleton.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_singleton.py b/tests/test_singleton.py index cf77c4b1d..c54c86f79 100644 --- a/tests/test_singleton.py +++ b/tests/test_singleton.py @@ -1,6 +1,8 @@ -import pytest import threading from unittest.mock import patch + +import pytest + from langfuse.utils.langfuse_singleton import LangfuseSingleton @@ -64,4 +66,4 @@ def test_reset_functionality(mock_langfuse): assert instance._langfuse is None - mock_langfuse.return_value.flush.assert_called_once() + mock_langfuse.return_value.shutdown.assert_called_once()