middleware.tracing_notebook

Notebook helpers that live-render correlated LangChain turn traces.

Classes

NotebookTraceRenderer

Render trace sink snapshots in a notebook cell.

LiveNotebookTrace

Own a recorder and live-render notebook trace updates.

Module Contents

class middleware.tracing_notebook.NotebookTraceRenderer(sink: middleware.tracing.TraceSink, *, heading: str = 'Trace')

Render trace sink snapshots in a notebook cell.

sink
heading = 'Trace'
refresh() → None

Render the current sink snapshot into the notebook output.

class middleware.tracing_notebook.LiveNotebookTrace(*, heading: str = 'Trace', max_events: int = 500, refresh_interval_seconds: float = 0.25)

Own a recorder and live-render notebook trace updates.

sink
recorder
renderer
refresh_interval_seconds = 0.25
property callbacks: tuple[middleware.tracing.TraceRecorder, Ellipsis]

Return callback handlers suitable for LangChain config injection.

start() → None

Begin periodic notebook refreshes until stopped.

stop() → None

Stop periodic refreshes and flush any remaining trace events.

attach(runnable: Any) → Any

Return a runnable configured with this trace recorder.

refresh() → None

Force a notebook refresh immediately.

dump(path: str | pathlib.Path | os.PathLike[str] | None = None, *, indent: int | None = 2) → str

Persist correlated TurnTrace rows as JSON.

When path is None, returns the transcript as a string and does not write to disk. Otherwise writes UTF-8 JSON and returns the path as a string.