context.py — langchain Source File
Architecture documentation for context.py, a python file in the langchain codebase. 10 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 7a327b28_f017_60c5_fd1c_4ad57fb697d1["context.py"] 69e1d8cc_6173_dcd0_bfdf_2132d8e1ce56["contextlib"] 7a327b28_f017_60c5_fd1c_4ad57fb697d1 --> 69e1d8cc_6173_dcd0_bfdf_2132d8e1ce56 e7c46dc4_ca3a_87ac_156f_0aa3d9b9d3f4["contextvars"] 7a327b28_f017_60c5_fd1c_4ad57fb697d1 --> e7c46dc4_ca3a_87ac_156f_0aa3d9b9d3f4 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 7a327b28_f017_60c5_fd1c_4ad57fb697d1 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 8dfa0cac_d802_3ccd_f710_43a5e70da3a5["uuid"] 7a327b28_f017_60c5_fd1c_4ad57fb697d1 --> 8dfa0cac_d802_3ccd_f710_43a5e70da3a5 023156c8_e306_6129_d953_9f1dac71e6fd["langsmith"] 7a327b28_f017_60c5_fd1c_4ad57fb697d1 --> 023156c8_e306_6129_d953_9f1dac71e6fd ec9bee24_c773_b0b6_adc6_6ee890d32c05["langchain_core.tracers.langchain"] 7a327b28_f017_60c5_fd1c_4ad57fb697d1 --> ec9bee24_c773_b0b6_adc6_6ee890d32c05 b2f3f5a5_2c04_3f89_138f_ced45a8e8edd["langchain_core.tracers.run_collector"] 7a327b28_f017_60c5_fd1c_4ad57fb697d1 --> b2f3f5a5_2c04_3f89_138f_ced45a8e8edd cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] 7a327b28_f017_60c5_fd1c_4ad57fb697d1 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 7e64d143_ea36_1c73_4897_1d0ae1757b5b["langchain_core.callbacks.base"] 7a327b28_f017_60c5_fd1c_4ad57fb697d1 --> 7e64d143_ea36_1c73_4897_1d0ae1757b5b e8ec017e_6c91_4b34_675f_2a96c5aa9be6["langchain_core.callbacks.manager"] 7a327b28_f017_60c5_fd1c_4ad57fb697d1 --> e8ec017e_6c91_4b34_675f_2a96c5aa9be6 style 7a327b28_f017_60c5_fd1c_4ad57fb697d1 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Context management for tracers."""
from __future__ import annotations
from contextlib import contextmanager
from contextvars import ContextVar
from typing import (
TYPE_CHECKING,
Any,
Literal,
cast,
)
from uuid import UUID
from langsmith import run_helpers as ls_rh
from langsmith import utils as ls_utils
from langchain_core.tracers.langchain import LangChainTracer
from langchain_core.tracers.run_collector import RunCollectorCallbackHandler
if TYPE_CHECKING:
from collections.abc import Generator
from langsmith import Client as LangSmithClient
from langchain_core.callbacks.base import BaseCallbackHandler, Callbacks
from langchain_core.callbacks.manager import AsyncCallbackManager, CallbackManager
# for backwards partial compatibility if this is imported by users but unused
tracing_callback_var: Any = None
tracing_v2_callback_var: ContextVar[LangChainTracer | None] = ContextVar(
"tracing_callback_v2", default=None
)
run_collector_var: ContextVar[RunCollectorCallbackHandler | None] = ContextVar(
"run_collector", default=None
)
@contextmanager
def tracing_v2_enabled(
project_name: str | None = None,
*,
example_id: str | UUID | None = None,
tags: list[str] | None = None,
client: LangSmithClient | None = None,
) -> Generator[LangChainTracer, None, None]:
"""Instruct LangChain to log all runs in context to LangSmith.
Args:
project_name: The name of the project.
Defaults to `'default'`.
example_id: The ID of the example.
tags: The tags to add to the run.
client: The client of the langsmith.
Yields:
The LangChain tracer.
Example:
// ... (146 more lines)
Domain
Subdomains
Functions
Dependencies
- collections.abc
- contextlib
- contextvars
- langchain_core.callbacks.base
- langchain_core.callbacks.manager
- langchain_core.tracers.langchain
- langchain_core.tracers.run_collector
- langsmith
- typing
- uuid
Source
Frequently Asked Questions
What does context.py do?
context.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 context.py?
context.py defines 7 function(s): _get_trace_callbacks, _get_tracer_project, _tracing_v2_is_enabled, collect_runs, collections, register_configure_hook, tracing_v2_enabled.
What does context.py depend on?
context.py imports 10 module(s): collections.abc, contextlib, contextvars, langchain_core.callbacks.base, langchain_core.callbacks.manager, langchain_core.tracers.langchain, langchain_core.tracers.run_collector, langsmith, and 2 more.
Where is context.py in the architecture?
context.py is located at libs/core/langchain_core/tracers/context.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/langchain_core/tracers).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free