[BUG] Built-in OTel spans remain UNSET when a streaming request ends with an API error

Status Open
Reported on v2.1.211
Maintainer reply None cached
Activity 0 comments · opened Jul 21, 2026

Summary

When a streamed Claude API response terminates with a server error mid-response, Claude Code's built-in OpenTelemetry spans are exported without an error status.

The Agent SDK subsequently yields a terminal result equivalent to:

ResultMessage(
  is_error=True,
  subtype="success",
  result="API Error: Server error mid-response. The response above may be incomplete."
)

However, the corresponding claude_code.llm_request span and its enclosing claude_code.interaction span both have OpenTelemetry status UNSET.

Versions

  • claude-agent-sdk==0.2.120
  • Bundled Claude Code: 2.1.211

Telemetry configuration

The built-in exporter was enabled with:

CLAUDE_CODE_ENABLE_TELEMETRY=1
CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1
ENABLE_BETA_TRACING_DETAILED=1
OTEL_TRACES_EXPORTER=otlp

Steps to reproduce

  1. Enable Claude Code's built-in OTLP trace export.
  2. Run Claude Code through the Python Agent SDK.
  3. Encounter a provider-side failure after streaming has begun, producing the terminal result shown above.
  4. Inspect the exported claude_code.llm_request and claude_code.interaction spans.

The provider failure is transient, so forcing the exact server-side condition may not be deterministic.

Incident context

The observed failure occurred at approximately 15:30 UTC on July 21, 2026. At 15:35 UTC, Anthropic's public status page began reporting elevated errors on several models, affecting the Claude API and Claude Code among other surfaces.

That public incident was likely the trigger for the provider error. This report is specifically about the telemetry behavior during a genuine provider failure: regardless of the underlying outage, the exported request span should record the terminal error.

Actual behavior

  • The SDK reports is_error=True.
  • The terminal result contains an API error.
  • claude_code.llm_request is exported with status UNSET.
  • claude_code.interaction is exported with status UNSET.
  • The Claude Code spans finish immediately before the SDK consumer receives the terminal error result.

Expected behavior

The affected claude_code.llm_request span, and preferably the enclosing interaction span, should be exported with OpenTelemetry status ERROR. A low-cardinality error type or API status attribute would also help classify the failure.

If the terminal error is only known at the end of the stream, the built-in spans may need to remain open until that terminal state has been processed.

Impact

Metrics and alerts derived from the built-in Claude Code spans undercount provider failures because failed requests appear indistinguishable from spans that completed without a recorded error.

View original on GitHub ↗