Legion. Telemetry
(Legion v0.4.0)
View Source
Telemetry integration for Legion agents.
Legion emits the following telemetry events:
Agent Lifecycle Events
[:legion, :agent, :started]— agent process finishedinit/1- Measurements:
%{system_time: integer} - Metadata:
%{agent: module, run_id: reference, parent_run_id: reference} parent_run_idis only present when the agent was started inside another agent's run. Not emitted ifinit/1itself crashes (e.g. while building the system prompt) — in that case:stoppedis not emitted either, since GenServer does not callterminate/2on init failure.
- Measurements:
[:legion, :agent, :stopped]— agent process terminated viaterminate/2- Measurements:
%{system_time: integer} - Metadata:
%{agent: module, run_id: reference}(plusparent_run_idwhen the parent's run is still on the process Vault)
- Measurements:
Agent Message Events (spans)
[:legion, :agent, :message, :start | :stop | :exception]— agent handling a message- Metadata includes:
agent,run_id,message - Stop adds:
iterations(count of assistant turns in this message),status(:okor:cancel),result(the value returned, or the cancellation reason such as:reached_max_iterations), andbindings(the variable bindings carried out of the turn)
- Metadata includes:
Iteration Events (spans)
[:legion, :iteration, :start | :stop | :exception]- Metadata includes:
agent,run_id,iteration - Stop adds:
action
- Metadata includes:
LLM Request Events (spans)
[:legion, :llm, :request, :start | :stop | :exception]- Metadata includes:
agent,run_id,model,message_count,iteration
- Metadata includes:
Sandbox Eval Events (spans)
[:legion, :sandbox, :eval, :start | :stop | :exception]- Metadata includes:
agent,run_id,code - Stop adds:
success,resultorerror
- Metadata includes:
Default Logger
A default logger is provided that outputs human-readable telemetry to Logger.
Attach it with Legion.Telemetry.attach_default_logger/1.
Summary
Functions
Attaches a default logger for Legion telemetry events.
Detaches the default logger.
Emits a single telemetry event. Injects run_id from the process dictionary.
Wraps a function with :start / :stop / :exception telemetry events.
Functions
Attaches a default logger for Legion telemetry events.
Options
:level— log level, defaults to:info:events—:allor a list of event categories (:agent,:message,:iteration,:llm,:sandbox). Defaults to:all.
Detaches the default logger.
Emits a single telemetry event. Injects run_id from the process dictionary.
Wraps a function with :start / :stop / :exception telemetry events.
The function should return {result, extra_stop_metadata}.
run_id is automatically injected from the process dictionary.