Skip to content

Instrument Gemini streaming (streamGenerateContent) calls#55

Open
Matt Perpick (clutchski) wants to merge 2 commits intomainfrom
matt/50
Open

Instrument Gemini streaming (streamGenerateContent) calls#55
Matt Perpick (clutchski) wants to merge 2 commits intomainfrom
matt/50

Conversation

@clutchski
Copy link
Copy Markdown
Contributor

Summary

  • Fix URL routing to match streamGenerateContent endpoints (previously only generateContent was matched)
  • Add SSE streaming response parsing with chunk aggregation into standard Gemini response format
  • Track time_to_first_token metric for both streaming and non-streaming responses
  • Update genai example to use gemini-2.0-flash (replacing deprecated gemini-2.0-flash-exp) and fix missing otel.SetTracerProvider call

Fixes #50

Test plan

  • Added TestContainsGenerateContent — verifies URL routing matches both streaming and non-streaming paths
  • Added TestExtractModelFromPath — verifies model extraction from streaming paths
  • Added TestIsStreamingPath — verifies streaming endpoint detection
  • Added TestStreamingGenerateContent — full integration test with VCR cassette verifying span creation, metadata, output aggregation, token metrics, and time_to_first_token
  • Added time_to_first_token assertion to TestBasicGenerateContent for non-streaming
  • make ci passes (lint + test + build)
  • Ran internal genai example end-to-end and verified all spans (including streaming) appear correctly in Braintrust with proper metrics

🤖 Generated with Claude Code

Matt Perpick (clutchski) and others added 2 commits April 3, 2026 10:31
The genai integration was not tracing streaming API calls at all. The URL
router could not match streamGenerateContent endpoints, and the response
parser only handled single-JSON responses. This adds full streaming
support: SSE chunk parsing, response aggregation, time_to_first_token
metrics, and proper URL routing for both streaming and non-streaming
Gemini endpoints. Also adds time_to_first_token to non-streaming
responses.

Fixes #50

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Shows that both non-streaming and streaming Gemini calls now produce
complete spans with output, token metrics, and time_to_first_token.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@socket-security
Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedgoogle.golang.org/​genai@​v1.30.0 ⏵ v1.52.172 -5100100100100
Addedgo.opentelemetry.io/​otel/​sdk@​v1.43.098100100100100

View full report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BOT ISSUE] Gemini streaming calls (streamGenerateContent) are completely uninstrumented

1 participant