From eb7580e7a597bff0a1e2f79e0441f7b5e5e72709 Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Wed, 18 Dec 2024 09:09:16 -0800 Subject: [PATCH] Add test --- libs/core/langchain_core/callbacks/manager.py | 1 + .../runnables/test_tracing_interops.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/libs/core/langchain_core/callbacks/manager.py b/libs/core/langchain_core/callbacks/manager.py index 821939d1a609c..cabe04b6a94d1 100644 --- a/libs/core/langchain_core/callbacks/manager.py +++ b/libs/core/langchain_core/callbacks/manager.py @@ -2379,6 +2379,7 @@ def _configure( if run_tree is not None else tracing_context["client"] ), + tags=tracing_tags, ) callback_manager.add_handler(handler, True) except Exception as e: diff --git a/libs/core/tests/unit_tests/runnables/test_tracing_interops.py b/libs/core/tests/unit_tests/runnables/test_tracing_interops.py index af6a5e84ce9ee..0743929f86120 100644 --- a/libs/core/tests/unit_tests/runnables/test_tracing_interops.py +++ b/libs/core/tests/unit_tests/runnables/test_tracing_interops.py @@ -35,6 +35,25 @@ def _get_posts(client: Client) -> list: return posts +def test_tracing_context() -> None: + mock_session = MagicMock() + mock_client_ = Client( + session=mock_session, api_key="test", auto_batch_tracing=False + ) + + @RunnableLambda + def my_function(a: int) -> int: + return a + 1 + + name = uuid.uuid4().hex + project_name = f"Some project {name}" + with tracing_context(project_name=project_name, client=mock_client_, enabled=True): + assert my_function.invoke(1) == 2 + posts = _get_posts(mock_client_) + assert posts + assert all(post["session_name"] == project_name for post in posts) + + def test_config_traceable_handoff() -> None: get_env_var.cache_clear() mock_session = MagicMock()