Unverified Commit 00f300a0 authored by Dima Voytenko's avatar Dima Voytenko Committed by GitHub

Telemetry: ensure the ClientComponentLoad metric is only reported when available (#62459)

parent dcf8f041
......@@ -634,16 +634,20 @@ async function renderToHTMLOrFlightImpl(
req.on('end', () => {
if ('performance' in globalThis) {
const metrics = getClientComponentLoaderMetrics({ reset: true })
getTracer()
.startSpan(NextNodeServerSpan.clientComponentLoading, {
startTime: metrics.clientComponentLoadStart,
attributes: {
'next.clientComponentLoadCount': metrics.clientComponentLoadCount,
},
})
.end(
metrics.clientComponentLoadStart + metrics.clientComponentLoadTimes
)
if (metrics) {
getTracer()
.startSpan(NextNodeServerSpan.clientComponentLoading, {
startTime: metrics.clientComponentLoadStart,
attributes: {
'next.clientComponentLoadCount':
metrics.clientComponentLoadCount,
},
})
.end(
metrics.clientComponentLoadStart +
metrics.clientComponentLoadTimes
)
}
}
})
}
......
......@@ -37,11 +37,14 @@ export function wrapClientComponentLoader(ComponentMod: any) {
export function getClientComponentLoaderMetrics(
options: { reset?: boolean } = {}
) {
const metrics = {
clientComponentLoadStart,
clientComponentLoadTimes,
clientComponentLoadCount,
}
const metrics =
clientComponentLoadStart === 0
? undefined
: {
clientComponentLoadStart,
clientComponentLoadTimes,
clientComponentLoadCount,
}
if (options.reset) {
clientComponentLoadStart = 0
......
......@@ -55,15 +55,17 @@ function createWriterFromResponse(
process.env.NEXT_OTEL_PERFORMANCE_PREFIX
) {
const metrics = getClientComponentLoaderMetrics()
performance.measure(
`${process.env.NEXT_OTEL_PERFORMANCE_PREFIX}:next-client-component-loading`,
{
start: metrics.clientComponentLoadStart,
end:
metrics.clientComponentLoadStart +
metrics.clientComponentLoadTimes,
}
)
if (metrics) {
performance.measure(
`${process.env.NEXT_OTEL_PERFORMANCE_PREFIX}:next-client-component-loading`,
{
start: metrics.clientComponentLoadStart,
end:
metrics.clientComponentLoadStart +
metrics.clientComponentLoadTimes,
}
)
}
}
res.flushHeaders()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment