Repository navigation
fix(telemetry): record a LiteLlm streamed answer once, not chunks plus aggregate - #7694
ishan-1010 wants to merge 1 commit into
Conversation
…s aggregate LiteLlm streams chunks without a finish reason and then yields their aggregate with one. record_llm_response kept recording until that finish reason, so gen_ai.output.messages held every chunk and then the whole answer again (a 5-chunk answer was 6 messages, a streamed tool call 4 half-built calls plus the real one). When a complete response with a finish reason follows only partial chunks without one, drop the chunks' output messages and keep the aggregate. Streams whose last chunk carries the finish reason (Gemini) and streams that fail before their aggregate keep their chunks. Fixes google#7630
|
Thanks, Ishan—I’ve attached two supplemental native tests against
The full I’m not claiming a full telemetry-suite pass: the broader run hit a missing SOCKS dependency in the functional tests. The patch only changes tests and was AI-assisted. |
|
Hi Ishan — I’ve now ported the two supplemental tests from the attached patch onto your PR head ( |
|
@surajksharma07 added the v1/stable path to the description as out of scope. it logs 6 @GBX-Max1220 you can open a PR against |
Link to Issue or Description of Change
Problem:
LiteLlm streams chunks without a finish reason and then yields their aggregate with one.
record_llm_responsekeeps recording until a finish reason arrives, sogen_ai.output.messagesheld every chunk and then the whole answer again.Solution:
As suggested in #7630: when a complete response with a finish reason follows only partial chunks without one, drop the chunks' output messages and keep the aggregate. Streams whose last chunk carries the finish reason (Gemini) and streams that fail before their aggregate keep their chunks.
Testing Plan
Unit Tests:
New tests in
tests/unittests/telemetry/test_instrumentation.py:test_aggregate_after_unfinished_chunks_is_recorded_once(fails on main: 3 messages)test_tool_call_aggregate_replaces_its_partial_call_chunks(fails on main: a call witharguments: nullplus the real one)test_stream_cut_off_before_its_aggregate_keeps_its_chunkstest_stream_whose_last_chunk_finishes_keeps_its_chunks(Gemini shape)Manual End-to-End (E2E) Tests:
gen_ai.output.messageson main vs this PR, LiteLlm withStreamingMode.SSE:openai/gpt-oss-20b, text answeropenai/gpt-oss-20b, tool calltool_callwitharguments: nulltool_call({"city": "Oslo"})Same counts in the completion log with
EVENT_ONLY.Checklist
Additional context
Out of scope: with the v1 schema (
ADK_TELEMETRY_SCHEMA_VERSION_OPT_IN=1) or stable semconv,trace_inference_resultemits onegen_ai.choicelog per response, and those are already emitted when the aggregate arrives. On the local SSE server that is 6 logs for a 5-chunk text answer and 5 for a streamed tool call, the same on main and on this branch. That needs a different fix.The silent cut-off from #7630 (a dropped stream is finalized as
stop) is tracked separately in #7693.