mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Preserve trace context during WebSocket startup prewarm (#62103)
## What changed - Inject the current span's W3C trace headers into WebSocket handshakes. - Promote `startup_prewarm` to an info span and fall back to the current span when it is disabled, preserving trace context in the spawned task. ## Testing Add a regression test for `traceparent` and `tracestate` propagation through the handshake, prewarm request, and subsequent turn on the same connection. Verify that prewarm uses the startup trace while the turn uses its own trace, with the prewarm span both enabled and filtered out. GitOrigin-RevId: 1e196e132a1991206469060ab80a474857fa7909
This commit is contained in:
@@ -14,8 +14,8 @@ use tokio_util::sync::CancellationToken;
|
||||
use tokio_util::task::AbortOnDropHandle;
|
||||
use tracing::Instrument;
|
||||
use tracing::info;
|
||||
use tracing::info_span;
|
||||
use tracing::instrument;
|
||||
use tracing::trace_span;
|
||||
use tracing::warn;
|
||||
|
||||
use crate::client::ModelClientSession;
|
||||
@@ -262,6 +262,13 @@ impl Session {
|
||||
let started_at = Instant::now();
|
||||
let startup_prewarm_session = Arc::clone(self);
|
||||
let input_label = input.as_str();
|
||||
let prewarm_span = info_span!(
|
||||
"startup_prewarm",
|
||||
otel.name = "startup_prewarm",
|
||||
thread.id = %self.thread_id(),
|
||||
prewarm.input = input_label,
|
||||
)
|
||||
.or_current();
|
||||
let startup_prewarm = tokio::spawn(
|
||||
async move {
|
||||
let result = schedule_startup_prewarm_inner(startup_prewarm_session, input).await;
|
||||
@@ -278,12 +285,7 @@ impl Session {
|
||||
);
|
||||
result
|
||||
}
|
||||
.instrument(trace_span!(
|
||||
"startup_prewarm",
|
||||
otel.name = "startup_prewarm",
|
||||
thread.id = %self.thread_id(),
|
||||
prewarm.input = input_label,
|
||||
)),
|
||||
.instrument(prewarm_span),
|
||||
);
|
||||
state.set_session_startup_prewarm(SessionStartupPrewarmHandle::new(
|
||||
startup_prewarm,
|
||||
|
||||
Reference in New Issue
Block a user