Home / Class/ RootListenersTracer Class — langchain Architecture

RootListenersTracer Class — langchain Architecture

Architecture documentation for the RootListenersTracer class in root_listeners.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  89d8d69c_785e_e71a_498a_04879f19121c["RootListenersTracer"]
  0f6b3261_31fa_c34e_ca33_cb141bdf78ff["BaseTracer"]
  89d8d69c_785e_e71a_498a_04879f19121c -->|extends| 0f6b3261_31fa_c34e_ca33_cb141bdf78ff
  cc8ba568_e178_2f0e_b70b_f9448e561f12["root_listeners.py"]
  89d8d69c_785e_e71a_498a_04879f19121c -->|defined in| cc8ba568_e178_2f0e_b70b_f9448e561f12
  2ed41984_febf_cafa_0c33_3fbd9df6f45a["__init__()"]
  89d8d69c_785e_e71a_498a_04879f19121c -->|method| 2ed41984_febf_cafa_0c33_3fbd9df6f45a
  077f1108_9fc4_2757_cc3f_591c9bdc255e["_persist_run()"]
  89d8d69c_785e_e71a_498a_04879f19121c -->|method| 077f1108_9fc4_2757_cc3f_591c9bdc255e
  6ba5dd85_d522_bdcf_17b7_eaaa793df704["_on_run_create()"]
  89d8d69c_785e_e71a_498a_04879f19121c -->|method| 6ba5dd85_d522_bdcf_17b7_eaaa793df704
  4a7513c5_6cf9_561d_93c4_5c59b36c9b9e["_on_run_update()"]
  89d8d69c_785e_e71a_498a_04879f19121c -->|method| 4a7513c5_6cf9_561d_93c4_5c59b36c9b9e

Relationship Graph

Source Code

libs/core/langchain_core/tracers/root_listeners.py lines 23–75

class RootListenersTracer(BaseTracer):
    """Tracer that calls listeners on run start, end, and error."""

    log_missing_parent = False
    """Whether to log a warning if the parent is missing."""

    def __init__(
        self,
        *,
        config: RunnableConfig,
        on_start: Listener | None,
        on_end: Listener | None,
        on_error: Listener | None,
    ) -> None:
        """Initialize the tracer.

        Args:
            config: The runnable config.
            on_start: The listener to call on run start.
            on_end: The listener to call on run end.
            on_error: The listener to call on run error
        """
        super().__init__(_schema_format="original+chat")

        self.config = config
        self._arg_on_start = on_start
        self._arg_on_end = on_end
        self._arg_on_error = on_error
        self.root_id: UUID | None = None

    def _persist_run(self, run: Run) -> None:
        # This is a legacy method only called once for an entire run tree
        # therefore not useful here
        pass

    def _on_run_create(self, run: Run) -> None:
        if self.root_id is not None:
            return

        self.root_id = run.id

        if self._arg_on_start is not None:
            call_func_with_variable_args(self._arg_on_start, run, self.config)

    def _on_run_update(self, run: Run) -> None:
        if run.id != self.root_id:
            return

        if run.error is None:
            if self._arg_on_end is not None:
                call_func_with_variable_args(self._arg_on_end, run, self.config)
        elif self._arg_on_error is not None:
            call_func_with_variable_args(self._arg_on_error, run, self.config)

Extends

Frequently Asked Questions

What is the RootListenersTracer class?
RootListenersTracer is a class in the langchain codebase, defined in libs/core/langchain_core/tracers/root_listeners.py.
Where is RootListenersTracer defined?
RootListenersTracer is defined in libs/core/langchain_core/tracers/root_listeners.py at line 23.
What does RootListenersTracer extend?
RootListenersTracer extends BaseTracer.

Analyze Your Own Codebase

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

Try Supermodel Free