feat(openai): record streaming errors on responses API span#119
Draft
Matt Perpick (clutchski) wants to merge 1 commit intomainfrom
Draft
feat(openai): record streaming errors on responses API span#119Matt Perpick (clutchski) wants to merge 1 commit intomainfrom
Matt Perpick (clutchski) wants to merge 1 commit intomainfrom
Conversation
When the OpenAI Responses API delivers a mid-stream error (e.g. `context_length_exceeded` as a `type: error` SSE event on an HTTP 200 response), the tracer previously produced a span with no output, no metrics, and no error — indistinguishable from a successful empty call. - `parseStreamingResponse` now captures `type: error` events and returns them from `TagSpan`. Streams that end without `response.completed` and without an error event are left alone (can't distinguish truncation from a clean client-side close). - `Middleware` now calls `span.RecordError` + `span.SetStatus(codes.Error, ...)` when `TagSpan` returns a non-nil error, matching the transport-error path. Fixes #113 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
type: errorevents (e.g.context_length_exceeded) in the Responses API tracer and surface them fromTagSpanTagSpanreturns an error, matching the existing transport-error pathresponses-streaming-errorexample that intentionally overflows the context windowFixes #113
Test plan
parseStreamingResponsereturns an error and captures the envelope when atype: errorevent is delivered (TestResponsesStreamingErrorEvent)response.completedbut no error event is NOT surfaced as an OTel error (TestResponsesStreamingEndsWithoutCompleted) — avoids false positives on client-side closecodes.Errorstatus and anexceptionevent (TestResponsesStreamingErrorEventEndToEnd)span.RecordError+span.SetStatusare called whenTagSpanreturns an error (TestMiddlewarePropagatesTagSpanError)make lintclean, all./trace/...tests pass🤖 Generated with Claude Code