fix(tracing): don't record an empty streaming model as llm.model_name - #2444
Open
jeremypng wants to merge 2 commits into
Open
fix(tracing): don't record an empty streaming model as llm.model_name#2444jeremypng wants to merge 2 commits into
jeremypng wants to merge 2 commits into
Conversation
On streaming chat completions, convertSSEToJSON took the model from the first SSE chunk only. Azure OpenAI's leading content-filter chunk carries model:"", so the span's llm.model_name was overwritten with an empty string (the request-time value is last-write-lost), breaking cost attribution in OpenInference consumers. Capture the first non-empty model across chunks so a leading empty-model chunk (or any later chunk reporting a different value) can't clobber it — this intentionally differs from the translator's streamingResponseModel, which takes the last non-empty value across the stream. Also guard the attribute write like the Responses API path already does. Signed-off-by: Jeremy Sanders <23668453+jeremypng@users.noreply.github.com>
nacx
enabled auto-merge (squash)
July 30, 2026 11:06
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2444 +/- ##
==========================================
- Coverage 84.87% 84.86% -0.02%
==========================================
Files 154 154
Lines 22419 22423 +4
==========================================
+ Hits 19028 19029 +1
- Misses 2236 2238 +2
- Partials 1155 1156 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On streaming chat completions,
convertSSEToJSONtook the model from the first SSE chunk only. Azure OpenAI's leading content-filter chunk carriesmodel:"", so the span'sllm.model_namewas overwritten with an empty string (the request-time value is last-write-lost), breaking cost attribution in OpenInference consumers.This fixes it by capturing the first non-empty model across all SSE chunks in the stream, so a leading empty-model chunk (or any later chunk reporting a different value) can't clobber it. It also adds the same
resp.Model != ""guard tobuildResponseAttributesthatbuildResponsesResponseAttributesalready has for the Responses API path, so an empty response model can never overwrite the request-timellm.model_nameattribute.This intentionally differs from the translator's
streamingResponseModel(used for metrics), which takes the last non-empty value across the stream. For tracing, taking the first non-empty value is a defensive choice: it means a later, possibly-anomalous chunk (e.g. a routed fallback reporting a different model) can't silently override the model that was already correctly captured earlier in the stream.Two behavioral guarantees after this change:
llm.model_namevalue, on either the streaming or non-streaming Chat Completions path.Related Issues/PRs (if applicable)
Fixes #2443
Special notes for reviewers (if applicable)
internal/tracing/openinference/openai):TestBuildResponseAttributesEmptyModelOmitsModelName(response_attrs_test.go) — an empty response model must not emitllm.model_nameat all.sse_converter_test.go, case "model from first non-empty chunk (Azure content-filter prologue)" — model comes from the first chunk that actually carries one, skipping the empty-model prologue chunk.sse_converter_test.go, case "model retains first non-empty value even if a later chunk differs" — a later chunk reporting a different model does not override the first non-empty value.