Expand description
OTLP span export with the GenAI semantic conventions. [feature: otel]
Hand-rolled OTLP-over-HTTP/JSON — no opentelemetry crate, no protobuf.
It reuses what agentd already has: the W3C trace/span ids on every run
(crate::obs::trace), serde_json, and the hand-rolled HTTP client
(crate::net::http). So --features otel stays dependency-free.
Off the default path: RunSpan is a no-op handle unless built
--features otel (so loop call sites stay clean and the default build pays
nothing). With the feature, a run records a chat span per model call and an
execute_tool span per tool call, then flushes the whole trace — the
invoke_agent run span (GenAI semconv) plus those children, one OTLP batch —
to OTEL_EXPORTER_OTLP_ENDPOINT when it finishes. Best-effort: an export
failure is logged-and-dropped; telemetry never fails a run.
Structs§
- RunSpan
- A run’s span recorder. Begin it once (mints the
invoke_agentspan id under the run trace), record achat/execute_toolchild as each completes, thenfinishto flush the whole trace. Every method is a no-op without theotelfeature (or withoutOTEL_EXPORTER_OTLP_ENDPOINT), so the loop wires it unconditionally with nocfgat the call sites.
Functions§
- arm_
logs - Arm the OTLP logs exporter: a bounded buffer drained by a background
thread to
<endpoint>/v1/logs. Idempotent; a no-op withoutotel. - capture_
log - Buffer one log record for OTLP export. A no-op unless
arm_logsinstalled the exporter (and always a no-op withoutotel). - now_
unix_ nanos - Current time as unix nanoseconds — a span start/end stamp.
- run_
begin - Begin the run span.
trace_idis the run’s W3C trace id;start_unix_nanosstamps theinvoke_agentspan start.