Home / File/ test_tracing_interops.py — langchain Source File

test_tracing_interops.py — langchain Source File

Architecture documentation for test_tracing_interops.py, a python file in the langchain codebase. 14 imports, 0 dependents.

File python CoreAbstractions Serialization 14 imports 8 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  9e4cc504_a234_ce9c_259e_c1569860bb81["test_tracing_interops.py"]
  7025b240_fdc3_cf68_b72f_f41dac94566b["json"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> 7025b240_fdc3_cf68_b72f_f41dac94566b
  d76a28c2_c3ab_00a8_5208_77807a49449d["sys"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> d76a28c2_c3ab_00a8_5208_77807a49449d
  8dfa0cac_d802_3ccd_f710_43a5e70da3a5["uuid"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> 8dfa0cac_d802_3ccd_f710_43a5e70da3a5
  614e7b9f_ed51_0780_749c_ff40b74963fc["inspect"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> 614e7b9f_ed51_0780_749c_ff40b74963fc
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  525a7d6f_f455_56e3_854a_c8a7da4a1417["unittest.mock"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> 525a7d6f_f455_56e3_854a_c8a7da4a1417
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  023156c8_e306_6129_d953_9f1dac71e6fd["langsmith"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> 023156c8_e306_6129_d953_9f1dac71e6fd
  ae8a5181_678b_4c6a_5dab_f5850ee1ed20["langsmith.run_helpers"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> ae8a5181_678b_4c6a_5dab_f5850ee1ed20
  567c6247_ac0d_f2ef_8bc0_4138f59d02a9["langsmith.utils"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> 567c6247_ac0d_f2ef_8bc0_4138f59d02a9
  c764ccae_0d75_abec_7c23_6d5d1949a7ba["langchain_core.runnables.base"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> c764ccae_0d75_abec_7c23_6d5d1949a7ba
  ec9bee24_c773_b0b6_adc6_6ee890d32c05["langchain_core.tracers.langchain"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> ec9bee24_c773_b0b6_adc6_6ee890d32c05
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  f3bc7443_c889_119d_0744_aacc3620d8d2["langchain_core.callbacks"]
  9e4cc504_a234_ce9c_259e_c1569860bb81 --> f3bc7443_c889_119d_0744_aacc3620d8d2
  style 9e4cc504_a234_ce9c_259e_c1569860bb81 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

import json
import sys
import uuid
from inspect import isasyncgenfunction
from typing import TYPE_CHECKING, Any, Literal
from unittest.mock import MagicMock, patch

import pytest
from langsmith import Client, RunTree, get_current_run_tree, traceable
from langsmith.run_helpers import tracing_context
from langsmith.utils import get_env_var

from langchain_core.runnables.base import RunnableLambda, RunnableParallel
from langchain_core.tracers.langchain import LangChainTracer

if TYPE_CHECKING:
    from collections.abc import AsyncGenerator, Callable, Coroutine, Generator

    from langchain_core.callbacks import BaseCallbackHandler


def _get_posts(client: Client) -> list[dict[str, Any]]:
    mock_calls = client.session.request.mock_calls  # type: ignore[attr-defined]
    posts = []
    for call in mock_calls:
        if call.args:
            if call.args[0] != "POST":
                continue
            assert call.args[0] == "POST"
            assert call.args[1].startswith("https://api.smith.langchain.com")
            body = json.loads(call.kwargs["data"])
            if "post" in body:
                # Batch request
                assert body["post"]
                posts.extend(body["post"])
            else:
                posts.append(body)
    return posts


def _create_tracer_with_mocked_client(
    project_name: str | None = None,
    tags: list[str] | None = None,
) -> LangChainTracer:
    mock_session = MagicMock()
    mock_client_ = Client(
        session=mock_session, api_key="test", auto_batch_tracing=False
    )
    return LangChainTracer(client=mock_client_, project_name=project_name, tags=tags)


def test_tracing_context() -> None:
    mock_session = MagicMock()
    mock_client_ = Client(
        session=mock_session, api_key="test", auto_batch_tracing=False
    )

    @RunnableLambda
// ... (451 more lines)

Subdomains

Dependencies

  • collections.abc
  • inspect
  • json
  • langchain_core.callbacks
  • langchain_core.runnables.base
  • langchain_core.tracers.langchain
  • langsmith
  • langsmith.run_helpers
  • langsmith.utils
  • pytest
  • sys
  • typing
  • unittest.mock
  • uuid

Frequently Asked Questions

What does test_tracing_interops.py do?
test_tracing_interops.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in test_tracing_interops.py?
test_tracing_interops.py defines 8 function(s): _create_tracer_with_mocked_client, _get_posts, collections, test_config_traceable_async_handoff, test_config_traceable_handoff, test_tracing_context, test_tracing_enable_disable, test_tree_is_constructed.
What does test_tracing_interops.py depend on?
test_tracing_interops.py imports 14 module(s): collections.abc, inspect, json, langchain_core.callbacks, langchain_core.runnables.base, langchain_core.tracers.langchain, langsmith, langsmith.run_helpers, and 6 more.
Where is test_tracing_interops.py in the architecture?
test_tracing_interops.py is located at libs/core/tests/unit_tests/runnables/test_tracing_interops.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/tests/unit_tests/runnables).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free