LogStreamCallbackHandler Class — langchain Architecture
Architecture documentation for the LogStreamCallbackHandler class in log_stream.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 78fc514f_5439_00c6_7e00_021af9ce4e07["LogStreamCallbackHandler"] 0f6b3261_31fa_c34e_ca33_cb141bdf78ff["BaseTracer"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|extends| 0f6b3261_31fa_c34e_ca33_cb141bdf78ff f3c4d153_ffb6_fec0_fa1f_e6051f9d0ac9["_StreamingCallbackHandler"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|extends| f3c4d153_ffb6_fec0_fa1f_e6051f9d0ac9 b114f430_2bfc_a8db_3787_d43839f4ce3a["ChatGenerationChunk"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|extends| b114f430_2bfc_a8db_3787_d43839f4ce3a bd3b753a_7a64_0c77_8d7a_afcce4658003["log_stream.py"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|defined in| bd3b753a_7a64_0c77_8d7a_afcce4658003 07946e14_8733_b693_5370_577c13824076["__init__()"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|method| 07946e14_8733_b693_5370_577c13824076 a986d859_d327_e601_1941_4c1297b63217["__aiter__()"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|method| a986d859_d327_e601_1941_4c1297b63217 c5f1fbd2_23b6_75cb_1f29_b9e028c332a0["send()"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|method| c5f1fbd2_23b6_75cb_1f29_b9e028c332a0 c52d25da_e50c_d411_085c_c87f3733b1c6["tap_output_aiter()"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|method| c52d25da_e50c_d411_085c_c87f3733b1c6 a4facac0_e177_a5c6_18cb_41e1fabc5bc2["tap_output_iter()"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|method| a4facac0_e177_a5c6_18cb_41e1fabc5bc2 98bcd7e4_7b8f_2694_2f03_85ddc533e9b2["include_run()"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|method| 98bcd7e4_7b8f_2694_2f03_85ddc533e9b2 fc4b4dc7_3d7d_5534_372c_af9075528bd5["_persist_run()"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|method| fc4b4dc7_3d7d_5534_372c_af9075528bd5 79906bae_a315_8c6a_0f74_2bca8c58615c["_on_run_create()"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|method| 79906bae_a315_8c6a_0f74_2bca8c58615c dd086141_42ce_3053_f911_051099488c1c["_on_run_update()"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|method| dd086141_42ce_3053_f911_051099488c1c 8261c1a6_4dc8_1ce7_5560_5ac4b395ac72["_on_llm_new_token()"] 78fc514f_5439_00c6_7e00_021af9ce4e07 -->|method| 8261c1a6_4dc8_1ce7_5560_5ac4b395ac72
Relationship Graph
Source Code
libs/core/langchain_core/tracers/log_stream.py lines 232–561
class LogStreamCallbackHandler(BaseTracer, _StreamingCallbackHandler):
"""Tracer that streams run logs to a stream."""
def __init__(
self,
*,
auto_close: bool = True,
include_names: Sequence[str] | None = None,
include_types: Sequence[str] | None = None,
include_tags: Sequence[str] | None = None,
exclude_names: Sequence[str] | None = None,
exclude_types: Sequence[str] | None = None,
exclude_tags: Sequence[str] | None = None,
# Schema format is for internal use only.
_schema_format: Literal["original", "streaming_events"] = "streaming_events",
) -> None:
"""A tracer that streams run logs to a stream.
Args:
auto_close: Whether to close the stream when the root run finishes.
include_names: Only include runs from `Runnable` objects with matching
names.
include_types: Only include runs from `Runnable` objects with matching
types.
include_tags: Only include runs from `Runnable` objects with matching tags.
exclude_names: Exclude runs from `Runnable` objects with matching names.
exclude_types: Exclude runs from `Runnable` objects with matching types.
exclude_tags: Exclude runs from `Runnable` objects with matching tags.
_schema_format: Primarily changes how the inputs and outputs are handled.
**For internal use only. This API will change.**
- `'original'` is the format used by all current tracers. This format is
slightly inconsistent with respect to inputs and outputs.
- 'streaming_events' is used for supporting streaming events, for
internal usage. It will likely change in the future, or deprecated
entirely in favor of a dedicated async tracer for streaming events.
Raises:
ValueError: If an invalid schema format is provided (internal use only).
"""
if _schema_format not in {"original", "streaming_events"}:
msg = (
f"Invalid schema format: {_schema_format}. "
f"Expected one of 'original', 'streaming_events'."
)
raise ValueError(msg)
super().__init__(_schema_format=_schema_format)
self.auto_close = auto_close
self.include_names = include_names
self.include_types = include_types
self.include_tags = include_tags
self.exclude_names = exclude_names
self.exclude_types = exclude_types
self.exclude_tags = exclude_tags
try:
loop = asyncio.get_event_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
memory_stream = _MemoryStream[RunLogPatch](loop)
self.lock = threading.Lock()
self.send_stream = memory_stream.get_send_stream()
self.receive_stream = memory_stream.get_receive_stream()
self._key_map_by_run_id: dict[UUID, str] = {}
self._counter_map_by_name: dict[str, int] = defaultdict(int)
self.root_id: UUID | None = None
def __aiter__(self) -> AsyncIterator[RunLogPatch]:
"""Iterate over the stream of run logs.
Returns:
An async iterator over the run log patches.
"""
return self.receive_stream.__aiter__()
def send(self, *ops: dict[str, Any]) -> bool:
"""Send a patch to the stream, return `False` if the stream is closed.
Args:
Source
Frequently Asked Questions
What is the LogStreamCallbackHandler class?
LogStreamCallbackHandler is a class in the langchain codebase, defined in libs/core/langchain_core/tracers/log_stream.py.
Where is LogStreamCallbackHandler defined?
LogStreamCallbackHandler is defined in libs/core/langchain_core/tracers/log_stream.py at line 232.
What does LogStreamCallbackHandler extend?
LogStreamCallbackHandler extends BaseTracer, _StreamingCallbackHandler, ChatGenerationChunk.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free