mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Reuse decoded WebSocket event kinds in telemetry (#59769)
## Why WebSocket telemetry reparses text frames to extract event kinds that the transport already decodes. ## What changed Pass decoded event kinds to telemetry and report receive failures separately. Keep JSON parsing for timing metrics and as a fallback when stream event decoding fails. Remove the `tokio-tungstenite` dependency from `codex-otel` and restrict it to tests in `codex-core`. Limit wrapped error parsing to error events or failed stream decoding, preserving HTTP error forwarding when unrelated stream fields are malformed. ## Testing Update runtime summary coverage to include receive failures and extend the WebSocket error forwarding test with a malformed stream field. GitOrigin-RevId: e1f9d200fd6d30ec124a2354bdbc01f3082ddde3
This commit is contained in:
@@ -11,8 +11,6 @@ use std::future::Future;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::time::Instant;
|
||||
use tokio_tungstenite::tungstenite::Error;
|
||||
use tokio_tungstenite::tungstenite::Message;
|
||||
|
||||
/// Generic telemetry.
|
||||
pub trait SseTelemetry: Send + Sync {
|
||||
@@ -33,13 +31,15 @@ pub trait SseTelemetry: Send + Sync {
|
||||
|
||||
/// Telemetry for Responses WebSocket transport.
|
||||
pub trait WebsocketTelemetry: Send + Sync {
|
||||
/// Reports how long it took to send the request and whether the send failed.
|
||||
fn on_ws_request(&self, duration: Duration, error: Option<&ApiError>, connection_reused: bool);
|
||||
|
||||
fn on_ws_event(
|
||||
&self,
|
||||
result: &Result<Option<Result<Message, Error>>, ApiError>,
|
||||
duration: Duration,
|
||||
);
|
||||
/// Reports the poll duration for timeouts, stream errors, end of stream,
|
||||
/// and binary, close, or raw frames.
|
||||
fn on_ws_receive_failure(&self, duration: Duration);
|
||||
|
||||
/// Reports each text frame and its poll duration. `kind` is `None` if decoding the stream event failed.
|
||||
fn on_ws_text_event(&self, text: &str, kind: Option<&str>, duration: Duration);
|
||||
}
|
||||
|
||||
pub(crate) trait WithStatus {
|
||||
|
||||
Reference in New Issue
Block a user