Repository navigation
Open Telemetry and NextJS Partial Prefetching #7384
|
Hey everyone, We have a NextJS app deployed into Azure App service and using azure/monitor-opentelemetry package. We have recently tried to enable partial prefetching in Next, but anytime we do we get the following errors From various trial and error, we think we have isolated it to this dependency, and in particular this line: Should this be something we expect to happen and have to make the tradeoff between telemetry and partial prefetching, does it seem more like an issue with Next, or is it maybe something for this repo? Thank you! |
Replies: 2 comments 1 reply
|
Short version: this is expected when OTel metric recording happens inside a route that Next.js is trying to prerender. The line you linked is the SDK passing this._writableMetricStorage.record(value, attributes, context, Date.now());Do not patch that to The practical fixes are:
import { connection } from 'next/server'
async function RequestTelemetry() {
await connection() // this subtree is request-time, not prerendered
myCounter.add(1, { route: 'home' })
return null
}Then render
So: the dependency is doing the right thing by supplying a wall-clock timestamp. The fix is to ensure metric recording happens at request time or on the client, or to mark that subtree/route dynamic. If you can share where in your app the counter/histogram is recorded (Server Component vs route handler vs shared singleton), I can point to the exact boundary to move. |
|
@Sion-Coop - did this clear up the |
Short version: this is expected when OTel metric recording happens inside a route that Next.js is trying to prerender. The line you linked is the SDK passing
Date.now()as the measurement timestamp to the metric storage. That timestamp is part of the OTel data model, so Next.js is flagging your render as dynamic - it is not evidence that telemetry and partial prefetching can never coexist.Do not patch that to
performance.now():performance.now()is a monotonic offset, not epoch milliseconds, so it would break metric timestamps and aggregation. If you only need a duration, measure it withperformance.now()in your…