next.js
4f13405b - fix: otel error spans from streamed responses (#86955)

Commit
41 days ago
fix: otel error spans from streamed responses (#86955) When an error is thrown inside a Suspense boundary during streaming SSR, the error was not being captured in the "render route (app)" span. This happened because `getTracer().wrap()` ends the span as soon as the stream is created and returned, but errors inside Suspense boundaries occur asynchronously during stream consumption. This PR changes the span management from using `wrap()` to manually calling `startSpan()` and tracking the span lifecycle. The span now stays open until `allReady` resolves or rejects. A new `withSpan()` helper was added to the tracer to properly activate the span context so child spans are parented. Error handlers now accept an optional `spanToRecordOn` parameter to record exceptions on the correct span rather than relying solely on the active scope span. Fixes #86517
Author
Parents
Loading