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
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
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
root_span_attributes(backend, harness, model, effort=None, subagent_effort=None)
¶
Return the synthetic root span attributes for one agent run.
Always sets agent.backend, agent.harness and agent.model;
adds agent.reasoning_effort and agent.subagent_reasoning_effort
when those efforts are in effect, so MLflow and JSONL consumers can see
the effective effort next to the model.
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)
¶
Stitch the run's traces together and append a synthetic root.
All traces in the JSONL belong to one agent run, so they are first merged
into a single trace (see :func:_stitch_run_traces). Then, for each trace
that has child spans but no root span (agent ignored TRACEPARENT,
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
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 | |
main()
¶
Run the OTEL collector server.