OTEL Collector¶
otel
¶
OTLP HTTP/JSON receiver and token/cost summary.
Lightweight collector that accepts OTLP exports for metrics and logs, tracks token usage over a sliding window, and prints a summary.
start_collector(run_dir, bind_addr='127.0.0.1')
¶
Start the OTEL collector as a subprocess. Returns (proc, port).
Source code in src/agentic_ci/otel.py
stop_collector(proc)
¶
parse_metrics(records)
¶
Parse OTLP JSONL records into structured token/cost data.
Source code in src/agentic_ci/otel.py
print_summary(log_file)
¶
Print a human-readable token/cost summary from an OTEL JSONL log.
Source code in src/agentic_ci/otel.py
generate_trace_context()
¶
Generate W3C Trace Context components for orchestrator-owned root spans.
Returns (trace_id, span_id, traceparent) where traceparent is a valid W3C traceparent header value. If the agent's OTEL SDK picks up the TRACEPARENT env var, its spans become children of this root span.
Source code in src/agentic_ci/otel.py
inject_root_spans(log_file, start_ns, end_ns, exit_code, fallback_trace_id=None, fallback_span_id=None, attributes=None)
¶
Scan JSONL for traces missing root spans and append synthetic roots.
For each trace that has child spans but no root span (container crash, OOM, timeout), a synthetic root span is appended to the JSONL file. If no spans exist at all and fallback_trace_id is provided, a standalone root span is created so MLflow always has at least one complete trace. When fallback_span_id is set, the fallback root reuses that span ID so children that were parented via TRACEPARENT stay connected.
Returns the number of synthetic root spans injected.
Source code in src/agentic_ci/otel.py
main()
¶
Run the OTEL collector server.