LangEx.Telemetry.Runs (LangEx v0.11.3)

Copy Markdown View Source

Run-tree correlation for telemetry spans.

Wraps :telemetry.span/3 so that every span carries a :run_id and a :parent_run_id in its metadata. Nested spans (graph invoke → step → node → LLM call / checkpoint) form a tree that can be reconstructed from the emitted events, which is the foundation for tracing UIs and the OpenTelemetry bridge.

The current run id lives in the process dictionary. Node tasks run in separate processes, so the executor captures the parent's run id before spawning and seeds it with inherit_run_id/1 inside the task.

Summary

Functions

Returns the run id of the currently executing span, if any.

Adopts a run id captured in a parent process (for spawned tasks).

Emits a :telemetry.span/3 with :run_id/:parent_run_id correlation merged into both start and stop metadata.

Functions

current_run_id()

@spec current_run_id() :: String.t() | nil

Returns the run id of the currently executing span, if any.

inherit_run_id(run_id)

@spec inherit_run_id(String.t() | nil) :: :ok

Adopts a run id captured in a parent process (for spawned tasks).

span(event, metadata, fun)

@spec span([atom(), ...], map(), (-> {term(), map()})) :: term()

Emits a :telemetry.span/3 with :run_id/:parent_run_id correlation merged into both start and stop metadata.