[codex] add otel tracing (#7844)

This commit is contained in:
Anton Panasenko
2025-12-12 17:07:17 -08:00
committed by GitHub
parent 596fcd040f
commit ad7b9d63c3
39 changed files with 958 additions and 315 deletions

View File

@@ -5,6 +5,9 @@ use tokio::sync::RwLock;
use tokio_util::either::Either;
use tokio_util::sync::CancellationToken;
use tokio_util::task::AbortOnDropHandle;
use tracing::Instrument;
use tracing::info_span;
use tracing::instrument;
use crate::codex::Session;
use crate::codex::TurnContext;
@@ -42,6 +45,7 @@ impl ToolCallRuntime {
}
}
#[instrument(skip_all, fields(call = ?call))]
pub(crate) fn handle_tool_call(
&self,
call: ToolCall,
@@ -56,11 +60,20 @@ impl ToolCallRuntime {
let lock = Arc::clone(&self.parallel_execution);
let started = Instant::now();
let dispatch_span = info_span!(
"dispatch_tool_call",
otel.name = call.tool_name.as_str(),
tool_name = call.tool_name.as_str(),
call_id = call.call_id.as_str(),
aborted = false,
);
let handle: AbortOnDropHandle<Result<ResponseInputItem, FunctionCallError>> =
AbortOnDropHandle::new(tokio::spawn(async move {
tokio::select! {
_ = cancellation_token.cancelled() => {
let secs = started.elapsed().as_secs_f32().max(0.1);
dispatch_span.record("aborted", true);
Ok(Self::aborted_response(&call, secs))
},
res = async {
@@ -72,6 +85,7 @@ impl ToolCallRuntime {
router
.dispatch_tool_call(session, turn, tracker, call.clone())
.instrument(dispatch_span.clone())
.await
} => res,
}
@@ -87,6 +101,7 @@ impl ToolCallRuntime {
))),
}
}
.in_current_span()
}
}