Skip to main content

Module otel

Module otel 

Source
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_agent span id under the run trace), record a chat/execute_tool child as each completes, then finish to flush the whole trace. Every method is a no-op without the otel feature (or without OTEL_EXPORTER_OTLP_ENDPOINT), so the loop wires it unconditionally with no cfg at 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 without otel.
capture_log
Buffer one log record for OTLP export. A no-op unless arm_logs installed the exporter (and always a no-op without otel).
now_unix_nanos
Current time as unix nanoseconds — a span start/end stamp.
run_begin
Begin the run span. trace_id is the run’s W3C trace id; start_unix_nanos stamps the invoke_agent span start.