Skip to content

feat: add Gemini SSE streaming response parsing#2530

Open
NameHaibinZhang wants to merge 2 commits into
open-telemetry:mainfrom
NameHaibinZhang:feat/gemini-streaming
Open

feat: add Gemini SSE streaming response parsing#2530
NameHaibinZhang wants to merge 2 commits into
open-telemetry:mainfrom
NameHaibinZhang:feat/gemini-streaming

Conversation

@NameHaibinZhang

@NameHaibinZhang NameHaibinZhang commented Jun 29, 2026

Copy link
Copy Markdown
Member

#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:

  • 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

Summary

Describe the change briefly.

Validation

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
@NameHaibinZhang NameHaibinZhang requested a review from a team as a code owner June 29, 2026 01:36
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.42105% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.35%. Comparing base (b9fe20e) to head (37a29b6).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
pkg/ebpf/common/http/gemini_stream.go 68.90% 32 Missing and 5 partials ⚠️
pkg/ebpf/common/http/gemini.go 64.28% 4 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
integration-test 51.43% <0.00%> (+0.56%) ⬆️
integration-test-arm 26.98% <0.00%> (+0.69%) ⬆️
integration-test-vm-5.15-lts ?
integration-test-vm-6.18-lts ?
k8s-integration-test 35.78% <0.00%> (-0.40%) ⬇️
oats-test 35.29% <2.88%> (-0.29%) ⬇️
unittests 63.71% <87.50%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mariomac mariomac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for your contribution

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a GeminiResponse.
  • Updated GeminiSpan() to dispatch between JSON and SSE responses using looksLikeJSON().
  • 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).

Comment thread pkg/ebpf/common/http/gemini_stream.go Outdated
Comment thread pkg/ebpf/common/http/gemini_stream.go Outdated

@MrAlias MrAlias left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/ebpf/common/http/gemini_stream.go Outdated
Comment thread pkg/ebpf/common/http/gemini_stream.go
Comment thread pkg/ebpf/common/http/gemini_stream.go Outdated
Comment thread pkg/ebpf/common/http/gemini_stream.go Outdated
Comment thread pkg/ebpf/common/http/gemini_stream_test.go
- 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

@NameHaibinZhang NameHaibinZhang left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@NameHaibinZhang NameHaibinZhang requested a review from MrAlias June 30, 2026 02:43
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.

4 participants