Skip to content

@traceable with langsmith_extra={"parent": ...} and tracing off sends its child runs but not itself #117

Open

Description

With LANGSMITH_TRACING unset, a @traceable called with langsmith_extra={"parent": ...} doesn't send its own run, which is what test_client_not_passed_when_traceable_parent expects. Nested @traceable and trace() calls are still sent, though, with a parent_run_id that never reaches LangSmith:

import os

for var in ("LANGSMITH_TRACING", "LANGSMITH_TRACING_V2", "LANGCHAIN_TRACING", "LANGCHAIN_TRACING_V2"):
    os.environ.pop(var, None)

from langsmith import Client, traceable
from langsmith.run_trees import RunTree


class RecordingClient(Client):
    def __init__(self):
        super().__init__(api_url="http://localhost:1984", api_key="fake", auto_batch_tracing=False)
        self.created = []

    def create_run(self, name, inputs, run_type, **kwargs):
        self.created.append(name)

    def update_run(self, run_id, **kwargs):
        pass


client = RecordingClient()


@traceable(client=client)
def child(x):
    return x


@traceable(client=client)
def handler(x):
    return child(x)


handler(1, langsmith_extra={"parent": RunTree(name="upstream", inputs={}, client=client)})
print("sent:", client.created)
sent: ['child']

_setup_run skips the post when tracing_is_enabled() is false (run_helpers.py:1801) but still makes the run current (:1828). tracing_is_enabled() returns True whenever a current run exists (utils.py:133), so the children get sent. This regressed in 0.1.145 with langchain-ai/langsmith-sdk#1224; 0.1.144 sent both.

The parent and its children should get the same answer: either both skipped, as the existing test implies, or both sent.

langsmith 0.16.0 (main 1b8dd10), Python 3.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions