Open lforst opened 4 months ago
I created a Next.js test application based on this PR where I excluded our HTTP integration. I tried different scenarios (httpIntegration
added/excluded in SDK, Next.js version in test app, manually adding startSpan
to client function or server route handler).
I will differentiate between up until Next.js v14.0.1-canary.0 and from v14.0.1-canary.1 ongoing, because that made the biggest difference in the outcome.
As it is about checking the spans created by route handlers, most of the logic and console.log
s where happening in packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts
. In the test application, I fetched GET /api/delayed-res/3
(route handler) with a button click in a client component.
When fetching, the rootSpan
is defined and looks something like this:
{
"span_id": "073d3f27a455bf13",
"trace_id": "85d3b8afd4e840cf9d2f79e496508240",
"data": {
"next.span_name": "GET /api/delayed-res/3",
"next.span_type": "BaseServer.handleRequest",
"http.method": "GET",
"http.target": "/api/delayed-res/3",
"sentry.sample_rate": 1,
"sentry.parentIsRemote": true
},
"description": "GET /api/delayed-res/3",
"parent_span_id": "a763e5c6d28d2bc7",
"start_timestamp": 1712306141.038
}
The traces show up correctly (except for the parameter) in Spotlight.
With a startSpan
wrapper on the route handler:
Without a startSpan
wrapper:
When including the httpIntegration
, the spans are not sampled (just like how it is after v14.0.1-canary.1) and the root span also looks like how it looks there.
When fetching, rootSpan
is defined and looks like this:
{
"span_id": "e450a61e70c6d723",
"trace_id": "aa4b89228bce4a5481bb73f672ea3342"
}
Spotlight does not show any traces coming in. Wrapping the route handler code in a startSpan
doesn't show traces either.
Only when adding startSpan
around the client function which fetches the server route, the spans pop up in Spotlight. BUT they are missing the parent and the three requests seem to have the same trace ID.
Just a collection of things I noticed when trying out the Next.js SDK with our newest OTEL implementation. This list is WIP:
Findings:
Sentry.init()
.@vercel/otel
package has support for Edge runtime fetch instrumentation. We need to try this out.Problems:
forceTransaction: true
for our own spans.instrument.ts
to init the SDK will destroy parent-child relationships between Next.js spans and Sentry SDK spans. No friggin idea what is going on here.instrumentation.ts
waitUntil
coming in Next.js which could solve this. Right now I don't have an idea on how to fix this. I tried adding a SIGTERM handler, I tried adding a custom spanprocessor that flushes. Nothing works.--turbo
flag: https://github.com/vercel/next.js/issues/64022