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

Fix @Vercel/Otel Fetch Instrumentation Loss On HMR By Moving OriginalFetch Capture After Instrumentation

In Next.js dev mode with Turbopack, HMR resets global fetch to a pre-instrumentation reference, stripping the OpenTelemetry wrapper and causing trace headers to be lost on subsequent requests.

highConfidence 95%Next.jsApp RouterRoute HandlersHydrationAffected V15.5.15Affected V16.0.11Affected V16.1.7Affected V16.2.3

Origin Analysis

router-server.ts captures originalFetch before ensureInstrumentationRegistered() runs, so resetFetch() restores the raw fetch on HMR, removing the OTel wrapper added by @vercel/otel.
1. Clone repro repo and install dependencies. 2. Start downstream logging server and Next.js dev server. 3. Open the page and observe traceparent header present. 4. Edit app/page.tsx to trigger HMR. 5. Refresh page; traceparent header is missing from downstream.

Fixing Code Block

Edge Case Audit

This change may still lose userland fetch wrappers that are installed after instrumentation but before the first HMR event, because originalFetch only captures the state at that point. For full compatibility with the original #68193 goal, consider modifying resetFetch to call an unpatch function that knows the previous fetch function instead of blindly restoring a stale reference. Rollback is safe by reverting this change, but test with custom fetch patching and ensure OTel wrapper is not double-applied (should be idempotent).

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