Propagate trace context through gRPC code mode (#41017)

## What changed

- Inject W3C `traceparent` metadata into code-mode session and execution requests.
- Carry each execution's trace context on streamed tool callbacks so callback and nested-tool spans remain connected across the gRPC boundary.
- Preserve the relevant spans when execution, callback, and dispatch work moves into spawned tasks.

GitOrigin-RevId: 6482963cb9b2e2f0ea27f1345bba208b70a80d0b
This commit is contained in:
yqz-openai authored and copyberry committed 2026-08-27 01:55:53 +00:00
1 parent 7c3747941a
commit eed1dee69e
13 files changed
+191 -76

No files matched your search

@@ -14,6 +14,7 @@ use serde_json::Value as JsonValue;
use tokio::sync::oneshot;
use tokio::sync::watch;
use tokio_util::sync::CancellationToken;
use tracing::Instrument;
use super::ExecContext;
use super::PUBLIC_TOOL_NAME;
@@ -133,6 +134,7 @@ impl CodeModeDispatchBroker {
invocation,
cancellation_token,
response_tx,
span,
} => {
let cell_id = invocation.cell_id.clone();
if !wait_until_cell_ready_for_dispatch(
@@ -147,8 +149,9 @@ impl CodeModeDispatchBroker {
}
let host = Arc::clone(&host);
tokio::spawn(async move {
let invocation =
host.invoke_tool(invocation, cancellation_token.clone());
let invocation = host
.invoke_tool(invocation, cancellation_token.clone())
.instrument(span);
tokio::pin!(invocation);
let response = tokio::select! {
biased;
@@ -236,6 +239,7 @@ impl CodeModeSessionDelegate for CodeModeDispatchBroker {
invocation,
cancellation_token: cancellation_token.clone(),
response_tx,
span: tracing::Span::current(),
})
.await
.map_err(|_| "code mode nested tool dispatcher is unavailable".to_string())?;
@@ -291,6 +295,7 @@ enum DispatchMessage {
invocation: CodeModeNestedToolCall,
cancellation_token: CancellationToken,
response_tx: oneshot::Sender<Result<JsonValue, String>>,
span: tracing::Span,
},
Notify {
call_id: String,