diff --git a/python/langsmith/run_helpers.py b/python/langsmith/run_helpers.py index 0e0d1fd4f..b9942a174 100644 --- a/python/langsmith/run_helpers.py +++ b/python/langsmith/run_helpers.py @@ -102,7 +102,7 @@ def tracing_context( project_name: Optional[str] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None, - parent: Optional[Union[run_trees.RunTree, Mapping, str]] = None, + parent: Optional[Union[run_trees.RunTree, Mapping, str, Literal[False]]] = None, enabled: Optional[Union[bool, Literal["local"]]] = None, client: Optional[ls_client.Client] = None, **kwargs: Any, @@ -129,7 +129,11 @@ def tracing_context( DeprecationWarning, ) current_context = get_tracing_context() - parent_run = _get_parent_run({"parent": parent or kwargs.get("parent_run")}) + parent_run = ( + _get_parent_run({"parent": parent or kwargs.get("parent_run")}) + if parent is not False + else None + ) if parent_run is not None: tags = sorted(set(tags or []) | set(parent_run.tags or [])) metadata = {**parent_run.metadata, **(metadata or {})} diff --git a/python/pyproject.toml b/python/pyproject.toml index e02abadd9..e05b7a5c4 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langsmith" -version = "0.2.10" +version = "0.2.11" description = "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform." authors = ["LangChain "] license = "MIT" diff --git a/python/tests/unit_tests/test_utils.py b/python/tests/unit_tests/test_utils.py index 857e55e7f..a0ea16db4 100644 --- a/python/tests/unit_tests/test_utils.py +++ b/python/tests/unit_tests/test_utils.py @@ -18,7 +18,7 @@ import langsmith.utils as ls_utils from langsmith import Client, traceable -from langsmith.run_helpers import tracing_context +from langsmith.run_helpers import get_current_run_tree, tracing_context class LangSmithProjectNameTest(unittest.TestCase): @@ -107,10 +107,21 @@ def test_tracing_enabled(): assert not ls_utils.tracing_is_enabled() @traceable - def child_function(): + def grandchild_function(): assert ls_utils.tracing_is_enabled() + rt = get_current_run_tree() + assert rt + assert rt.parent_run_id is None + assert "." not in rt.dotted_order + assert rt.parent_run is None return 1 + @traceable + def child_function(): + assert ls_utils.tracing_is_enabled() + with tracing_context(parent=False): + return grandchild_function() + @traceable def untraced_child_function(): assert not ls_utils.tracing_is_enabled()