Skip to content

feat(openai): record streaming errors on responses API span#119

Draft
Matt Perpick (clutchski) wants to merge 1 commit intomainfrom
matt/113
Draft

feat(openai): record streaming errors on responses API span#119
Matt Perpick (clutchski) wants to merge 1 commit intomainfrom
matt/113

Conversation

@clutchski
Copy link
Copy Markdown
Contributor

Summary

  • Capture mid-stream type: error events (e.g. context_length_exceeded) in the Responses API tracer and surface them from TagSpan
  • Middleware now marks the span with OTel error status + exception event when TagSpan returns an error, matching the existing transport-error path
  • Adds a responses-streaming-error example that intentionally overflows the context window

Fixes #113

Test plan

  • Unit test: parseStreamingResponse returns an error and captures the envelope when a type: error event is delivered (TestResponsesStreamingErrorEvent)
  • Unit test: stream that ends without response.completed but no error event is NOT surfaced as an OTel error (TestResponsesStreamingEndsWithoutCompleted) — avoids false positives on client-side close
  • End-to-end test: full middleware + openai client streaming path produces a span with codes.Error status and an exception event (TestResponsesStreamingErrorEventEndToEnd)
  • Middleware test: span.RecordError + span.SetStatus are called when TagSpan returns an error (TestMiddlewarePropagatesTagSpanError)
  • make lint clean, all ./trace/... tests pass

🤖 Generated with Claude Code

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>
@clutchski Matt Perpick (clutchski) marked this pull request as draft April 24, 2026 18:28
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.

feat: record streaming errors on span for Responses API tracer

1 participant