mirror of
https://github.com/openai/codex.git
synced 2026-10-19 17:28:46 +00:00
Trace startup prewarm tasks (#33155)
## What changed Instrument the spawned WebSocket startup prewarm task with a `startup_prewarm` trace span. Set its OpenTelemetry name and attach the session's `thread.id` so prewarm work can be associated with its session. GitOrigin-RevId: f2d642d145686b883cd82be8a594bd2383470651
This commit is contained in:
committed by
copyberry
parent
e0a3641e6c
commit
2012d87211
@@ -5,8 +5,10 @@ use std::time::Instant;
|
||||
use tokio::task::JoinHandle;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tokio_util::task::AbortOnDropHandle;
|
||||
use tracing::Instrument;
|
||||
use tracing::info;
|
||||
use tracing::instrument;
|
||||
use tracing::trace_span;
|
||||
use tracing::warn;
|
||||
|
||||
use crate::client::ModelClientSession;
|
||||
@@ -198,22 +200,30 @@ impl Session {
|
||||
let websocket_connect_timeout = self.provider().await.websocket_connect_timeout();
|
||||
let started_at = Instant::now();
|
||||
let startup_prewarm_session = Arc::clone(self);
|
||||
let startup_prewarm = tokio::spawn(async move {
|
||||
let result =
|
||||
schedule_startup_prewarm_inner(startup_prewarm_session, base_instructions).await;
|
||||
let status = if result.is_ok() { "ready" } else { "failed" };
|
||||
session_telemetry.record_startup_phase(
|
||||
"startup_prewarm_total",
|
||||
started_at.elapsed(),
|
||||
Some(status),
|
||||
);
|
||||
session_telemetry.record_duration(
|
||||
STARTUP_PREWARM_DURATION_METRIC,
|
||||
started_at.elapsed(),
|
||||
&[("status", status)],
|
||||
);
|
||||
result
|
||||
});
|
||||
let startup_prewarm = tokio::spawn(
|
||||
async move {
|
||||
let result =
|
||||
schedule_startup_prewarm_inner(startup_prewarm_session, base_instructions)
|
||||
.await;
|
||||
let status = if result.is_ok() { "ready" } else { "failed" };
|
||||
session_telemetry.record_startup_phase(
|
||||
"startup_prewarm_total",
|
||||
started_at.elapsed(),
|
||||
Some(status),
|
||||
);
|
||||
session_telemetry.record_duration(
|
||||
STARTUP_PREWARM_DURATION_METRIC,
|
||||
started_at.elapsed(),
|
||||
&[("status", status)],
|
||||
);
|
||||
result
|
||||
}
|
||||
.instrument(trace_span!(
|
||||
"startup_prewarm",
|
||||
otel.name = "startup_prewarm",
|
||||
thread.id = %self.thread_id(),
|
||||
)),
|
||||
);
|
||||
self.set_session_startup_prewarm(SessionStartupPrewarmHandle::new(
|
||||
startup_prewarm,
|
||||
started_at,
|
||||
|
||||
Reference in New Issue
Block a user