Legion. OpenTelemetry
(Legion v0.7.0)
View Source
Turns Legion's work into OpenTelemetry traces: an invoke_agent <agent>
span per turn, an execute_tool sandbox span per code evaluation, and
ReqLLM's chat spans, which Legion attaches under its own handler. See the
Observability guide for the trace shape and vendor setup.
Legion only depends on opentelemetry_api, optionally; without it
attach/1 returns {:error, :opentelemetry_unavailable}. Options can also
be set in config :legion, Legion.OpenTelemetry; options given to
attach/1 win.
Message content is recorded by default
Unlike ReqLLM.OpenTelemetry, Legion defaults to content: :attributes,
so prompts, replies, generated code, tool results and error messages
reach the tracing backend. Attach with content: :none to keep them out.
That covers every ReqLLM call in the app: while attached, Legion sets
payloads: :raw in config :req_llm, telemetry:, unless you set
:payloads there, so your other handlers of ReqLLM's telemetry events
receive raw prompts and replies too. detach/0 puts your setting back. A
call that passes its own telemetry: option needs payloads: :raw in
it, since ReqLLM then reads that option instead of the config.
Options
:adapter- aLegion.OpenTelemetry.Adapter, or:braintrust,:datadog,:otel. Defaults toLegion.OpenTelemetry.Adapter.OTel.Legion.OpenTelemetry.Exporteralways exports to the vendor adapter named in config.:vendor- the vendor adapter's own settings, such as its API key. Only read from config, since the exporter starts beforeattach/1runs.:content-:attributes(default) records message content,:noneleaves it out, and a failed span's status then names only itserror.type.:max_attribute_bytes- longest content attribute on Legion's own spans, cut on a UTF-8 boundary. Defaults to100_000, above the 40 KB an agent shows the model per message by default.:iteration_spans-trueadds aniteration Nspan per executor iteration. Defaults tofalse.:conversation_traces-trueputs an agent's turns in one trace under aconversation <agent>root span. Defaults tofalse.:req_llm- extra options forReqLLM.OpenTelemetry.attach/2, orfalsefor hosts that attach it themselves. A host's own attach or:adapterthere getschatspans' error text and server-side tool arguments unfiltered, whatever:contentsays.
Example
# application.ex
:ok = Legion.OpenTelemetry.attach()
Summary
Functions
Attaches the OpenTelemetry integration. See the module docs for options.
Returns the active configuration, or nil when not attached.
Detaches the integration.
Returns the handler id Legion attaches ReqLLM.OpenTelemetry under.
Functions
Attaches the OpenTelemetry integration. See the module docs for options.
Safe to call again: the new options replace the earlier attachment. Raises on unknown options, and on an incomplete vendor setup in config (naming the option, never its value).
Returns the active configuration, or nil when not attached.
Detaches the integration.
Returns the handler id Legion attaches ReqLLM.OpenTelemetry under.