Improve tracing for nested tool calls and exec processes (#41950)

## Why

Code-mode callbacks can outlive their initial request and run in separate tasks,
so their trace context must be preserved explicitly.

## What changed

- Preserve the execution context for code-mode callbacks and add spans for
  nested tool invocations in the runtime and dispatch broker.
- Propagate each tool invocation span as the parent of its streamed gRPC
  callback, falling back to the outer execution context when needed.
- Add a `codex.exec_server.process` span for each process lifetime, including
  its process ID and completion result, without retaining the request span.

GitOrigin-RevId: a6059e34d895416f5517e51dad6ca0078355adca
This commit is contained in:
Adam Perry @ OpenAI
2026-09-01 01:00:50 +00:00
committed by copyberry
parent bfa9646787
commit 55e5158e18
10 changed files with 61 additions and 4 deletions
@@ -126,6 +126,12 @@ impl GrpcSession {
.collect::<Vec<_>>();
(sequence, execution.traceparent.clone(), subscriptions)
};
// The saved traceparent belongs to the outer execution. Prefer the runtime's
// per-tool span so the callback is nested under its invocation, with the
// execution context as a fallback when no current span context is available.
let traceparent = codex_otel::current_span_w3c_trace_context()
.and_then(|trace| trace.traceparent)
.or(traceparent);
if subscriptions.is_empty() {
return Err("no code-mode tool subscription matches the requested tool".to_string());
}