Maps an online-eval Nous.Eval.Sample to OpenTelemetry spans following the
GenAI semantic conventions (pinned to semconv 1.37.0, see
semconv_version/0).
What is mapped
- each agent run → an
"invoke_agent <agent_name>"span (kind:internal) whose span id is the run'sagent_run_id; a sub-agent run is parented to theexecute_toolspan that spawned it, else to its parent run - each model request → a
"chat <model_name>"span (kind:client) with the request/response model, token usage and finish reasons - each tool call → an
"execute_tool <tool_name>"span with the tool name, call id, outcome and approval; a call that spawned a sub-agent run also carriesgen_ai.transfer.target.name - guard, loop-guard and hook events → span events
nous.<guard>.<event>on the enclosing run span, with skeleton attributes only (verdict, severity, action, surface, tier, hook name, tool call id) - each score and scorer error → a
"gen_ai.evaluation.result"event on the root run span
Content
This mapping only ever sees redacted samples: the online pipeline removes
(redact: :drop_content) or rewrites content keys before a sample reaches
an exporter. Even so, content attributes (gen_ai.input.messages,
gen_ai.output.messages, gen_ai.tool.call.arguments,
gen_ai.tool.call.result) and score explanations are emitted only with
export_content: true (default false), as JSON of the already-redacted
value. Under redact: :drop_content they never appear, since the content
keys are absent. No other content key (reason, error, details, …) is
ever exported; a failed run reports only its error_kind.
OpenTelemetry API
spans/2 is pure and needs no dependency. export/2 calls the
OpenTelemetry Erlang API only when it is loaded (:otel_tracer), and
returns {:error, :opentelemetry_not_loaded} otherwise. Nous does not
depend on OpenTelemetry.
Summary
Functions
Exports sample through the OpenTelemetry API when it is loaded.
A 1-arity exporter for the online exporter: option.
The GenAI semantic-conventions version this mapping follows.
The spans for sample, parents before children.
Types
@type span() :: %{ name: String.t(), trace_id: String.t(), span_id: String.t(), parent_span_id: String.t() | nil, kind: :internal | :client, start_time: integer(), end_time: integer(), attributes: attributes(), events: [span_event()], status: :unset | :ok | :error }
@type span_event() :: %{name: String.t(), time: integer(), attributes: attributes()}
Functions
@spec export(Nous.Eval.Sample.t(), keyword()) :: :ok | {:error, :opentelemetry_not_loaded}
Exports sample through the OpenTelemetry API when it is loaded.
Takes the same options as spans/2.
@spec exporter(keyword()) :: (Nous.Eval.Sample.t() -> :ok | {:error, :opentelemetry_not_loaded})
A 1-arity exporter for the online exporter: option.
@spec semconv_version() :: String.t()
The GenAI semantic-conventions version this mapping follows.
@spec spans(Nous.Eval.Sample.t(), keyword()) :: [span()]
The spans for sample, parents before children.
Options:
:export_content- emit content attributes and score explanations (defaultfalse)
Total: malformed events are skipped. A sample without a valid 32-hex
trace_id yields [].