Skip to content

[bot] OpenAI Realtime API (WebSocket) not instrumented #130

Description

@braintrust-bot

Gap description

The openai-java SDK v2.15.0+ exposes a WebSocket-based Realtime API under client.beta().realtime(). The current instrumentation in openai_2_15_0 works by wrapping the SDK's HttpClient interface (execute / executeAsync), which only intercepts HTTP/HTTPS requests. WebSocket connections are established through a separate code path and are never passed through TracingHttpClient, so no span is created for any Realtime API session.

Affected surface

SDK API surface Transport
com.openai:openai-java:2.15.0+ client.beta().realtime() WebSocket (WSS)

Why it matters

Realtime API sessions carry voice and text generation work that is billable and latency-sensitive — exactly the kind of LLM execution Braintrust is designed to observe. Without instrumentation, users see a complete blind spot for this API even when all other OpenAI calls are traced.

Analogous gap already tracked

Issue #120 tracks the same problem for the Google GenAI Live (streaming) API, which also uses a persistent bidirectional connection that bypasses the HTTP-layer hook.

Suggested approach

  1. Identify the WebSocket-abstraction interface in openai-java (likely WebSocket or a RealtimeClient).
  2. Use ByteBuddy to intercept session open/message/close events, or wrap the WebSocket factory the same way TracingHttpClient wraps HttpClient.
  3. Accumulate audio/text deltas and emit a span on session close with braintrust.input_json / braintrust.output_json and token metrics where available.

Notes

  • This gap exists only in the openai_2_15_0 module; no other provider currently wraps a WebSocket transport.
  • If the upstream SDK does not yet expose a stable hook point, a note in the docs would at minimum set user expectations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions