Skip to content

Commit

Permalink
Support parent=false to prune trees (#1429)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Jan 17, 2025
1 parent 2c83ab5 commit 04d87c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
8 changes: 6 additions & 2 deletions python/langsmith/run_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {})}
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
Expand Down
15 changes: 13 additions & 2 deletions python/tests/unit_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 04d87c8

Please sign in to comment.