feat: add Gemini SSE streaming response parsing#2530
Conversation
Implement parseGeminiStream() to handle Server-Sent Events responses from Gemini's streamGenerateContent endpoint. This adds streaming support comparable to what exists for OpenAI and Anthropic providers. Changes: - New gemini_stream.go with SSE parsing and text/functionCall aggregation - Modified GeminiSpan() to dispatch between JSON and SSE responses - Comprehensive test coverage for streaming scenarios
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2530 +/- ##
==========================================
+ Coverage 69.07% 69.35% +0.27%
==========================================
Files 348 349 +1
Lines 47314 47509 +195
==========================================
+ Hits 32683 32950 +267
+ Misses 12582 12503 -79
- Partials 2049 2056 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mariomac
left a comment
There was a problem hiding this comment.
Looks good! Thanks for your contribution
There was a problem hiding this comment.
Pull request overview
Adds Gemini SSE (Server-Sent Events) streaming response parsing so Gemini spans can normalize output similarly to existing OpenAI/Anthropic streaming support.
Changes:
- Added
parseGeminiStream()and helpers to aggregate streamed text and function-call tool names into aGeminiResponse. - Updated
GeminiSpan()to dispatch between JSON and SSE responses usinglooksLikeJSON(). - Added unit tests covering Gemini streaming parsing and span extraction for stream responses.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/ebpf/common/http/gemini.go | Switches Gemini response parsing between JSON and SSE; wires tool-call extraction for both cases. |
| pkg/ebpf/common/http/gemini_stream.go | Implements SSE parsing + aggregation into a synthetic GeminiResponse plus tool calls. |
| pkg/ebpf/common/http/gemini_test.go | Adds a GeminiSpan streaming-response test to validate end-to-end extraction. |
| pkg/ebpf/common/http/gemini_stream_test.go | Adds focused unit tests for parseGeminiStream() (text aggregation, tool calls, empty/truncated streams). |
MrAlias
left a comment
There was a problem hiding this comment.
Thanks for adding Gemini streaming support. The overall integration direction matches what we do for the other GenAI providers, but the stream parser is currently a bit too lossy for Gemini's response shape. I think we should tighten the parser and add coverage for those cases before merging.
- Support per-candidate-index aggregation for multi-candidate streams - Preserve function call arguments (raw JSON) in streamed parts output - Accept usage metadata when any token field is non-zero, not just total - Handle both 'data: ' and 'data:' SSE prefixes with extractSSEData helper - Add tests for multi-candidate, function-call args, partial usage, SSE framing
#2394
#1854
Implement parseGeminiStream() to handle Server-Sent Events responses from Gemini's streamGenerateContent endpoint. This adds streaming support comparable to what exists for OpenAI and Anthropic providers.
Changes:
Summary
Describe the change briefly.
Validation