AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

AppRender.Fetch Spans Never Set Span Status To ERROR For Failed (4Xx/5Xx) Responses

Next.js native fetch instrumentation creates AppRender.fetch spans but does not mark them as ERROR when the upstream response status is 4xx/5xx. This causes OTel-compatible APM backends to record failed backend dependencies as successful, misleading monitoring and alerting.

highConfidence 95%Next.jsReact Server ComponentsApp RouterAffected V16.3.0-Canary.53

Origin Analysis

The root cause is a missing call to span.setStatus({ code: SpanStatusCode.ERROR }) in packages/next/src/server/lib/patch-fetch.ts after the response status code attribute is set; the code only records the status as an attribute but never propagates it to the span status.
1. git clone https://github.com/anilparlak/otel-repro && cd otel-repro 2. npm install 3. npm run dev 4. In another terminal: curl http://localhost:3000/ 5. In the dev-server console, observe the 'fetch GET .../api/fail' span: it has status code 0 (UNSET) despite upstream HTTP 503.

Fixing Code Block

Edge Case Audit

Setting all 4xx responses as ERROR may increase error rates in APM dashboards, which could be noisy if 4xx codes are used for expected business logic (e.g., 404 for not-found routes). This change is global and applies to next start and next dev. Rollback: if error rates become too noisy, revert the change or adjust the threshold to only status >= 500. Also ensure the @opentelemetry/api package version supports SpanStatusCode (available since 1.0.0). No concurrency or multi-thread issues are expected as spans are per-request, but be cautious with custom span processors that may override status.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state