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:
Tom
2026-11-17 19:24:17 +00:00
committed by copyberry
parent 7fb2cd20c8
commit 7457b7268f
3 changed files with 134 additions and 7 deletions
+9 -7
View File
@@ -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,