Skip to content

[BOT ISSUE] Google GenAI (Gemini) streaming calls are not instrumented #61

@braintrust-bot

Description

@braintrust-bot

Summary

The Google GenAI instrumentation wraps ApiClient.request() and ApiClient.asyncRequest() for synchronous and asynchronous non-streaming calls, but does not override any streaming methods. Calls to client.models.generateContentStream() and similar streaming APIs bypass the instrumentation entirely, producing no spans, no output capture, and no token usage metrics.

What is missing

BraintrustApiClient.java overrides 4 methods:

  • request(String, String, String, Optional) (line 186)
  • request(String, String, byte[], Optional) (line 210)
  • asyncRequest(String, String, String, Optional) (line 239)
  • asyncRequest(String, String, byte[], Optional) (line 277)

The upstream ApiClient class in the Google GenAI SDK also has streaming request methods (used internally by generateContentStream) that are not overridden. This means streaming Gemini calls — a common pattern for chat applications — are completely invisible to Braintrust tracing.

For comparison, both the OpenAI and Anthropic instrumentations in this repo handle streaming via SSE detection and chunk accumulation in their respective TracingHttpClient implementations.

Upstream sources

Braintrust docs status

  • not_found — braintrust.dev/docs does not reference Google GenAI streaming instrumentation for Java. The Java SDK docs page redirects to the GitHub repo.

Local files inspected

  • braintrust-sdk/instrumentation/genai_1_18_0/src/main/java/com/google/genai/BraintrustApiClient.java — lines 186–312 (only non-streaming request/asyncRequest overridden; no streaming method override)
  • braintrust-sdk/instrumentation/genai_1_18_0/src/main/java/com/google/genai/BraintrustInstrumentation.java — wraps ApiClient in Client and service fields, no streaming awareness
  • braintrust-sdk/instrumentation/genai_1_18_0/src/main/java/dev/braintrust/instrumentation/genai/v1_18_0/BraintrustGenAI.java — thin wrapper, delegates to BraintrustInstrumentation
  • braintrust-sdk/instrumentation/genai_1_18_0/src/test/java/dev/braintrust/instrumentation/genai/v1_18_0/BraintrustGenAITest.java — only tests sync and async non-streaming; no streaming tests exist

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions