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,17 +634,21 @@ async function renderToHTMLOrFlightImpl( ...@@ -634,17 +634,21 @@ async function renderToHTMLOrFlightImpl(
req.on('end', () => { req.on('end', () => {
if ('performance' in globalThis) { if ('performance' in globalThis) {
const metrics = getClientComponentLoaderMetrics({ reset: true }) const metrics = getClientComponentLoaderMetrics({ reset: true })
if (metrics) {
getTracer() getTracer()
.startSpan(NextNodeServerSpan.clientComponentLoading, { .startSpan(NextNodeServerSpan.clientComponentLoading, {
startTime: metrics.clientComponentLoadStart, startTime: metrics.clientComponentLoadStart,
attributes: { attributes: {
'next.clientComponentLoadCount': metrics.clientComponentLoadCount, 'next.clientComponentLoadCount':
metrics.clientComponentLoadCount,
}, },
}) })
.end( .end(
metrics.clientComponentLoadStart + metrics.clientComponentLoadTimes metrics.clientComponentLoadStart +
metrics.clientComponentLoadTimes
) )
} }
}
}) })
} }
......
...@@ -37,7 +37,10 @@ export function wrapClientComponentLoader(ComponentMod: any) { ...@@ -37,7 +37,10 @@ export function wrapClientComponentLoader(ComponentMod: any) {
export function getClientComponentLoaderMetrics( export function getClientComponentLoaderMetrics(
options: { reset?: boolean } = {} options: { reset?: boolean } = {}
) { ) {
const metrics = { const metrics =
clientComponentLoadStart === 0
? undefined
: {
clientComponentLoadStart, clientComponentLoadStart,
clientComponentLoadTimes, clientComponentLoadTimes,
clientComponentLoadCount, clientComponentLoadCount,
......
...@@ -55,6 +55,7 @@ function createWriterFromResponse( ...@@ -55,6 +55,7 @@ function createWriterFromResponse(
process.env.NEXT_OTEL_PERFORMANCE_PREFIX process.env.NEXT_OTEL_PERFORMANCE_PREFIX
) { ) {
const metrics = getClientComponentLoaderMetrics() const metrics = getClientComponentLoaderMetrics()
if (metrics) {
performance.measure( performance.measure(
`${process.env.NEXT_OTEL_PERFORMANCE_PREFIX}:next-client-component-loading`, `${process.env.NEXT_OTEL_PERFORMANCE_PREFIX}:next-client-component-loading`,
{ {
...@@ -65,6 +66,7 @@ function createWriterFromResponse( ...@@ -65,6 +66,7 @@ function createWriterFromResponse(
} }
) )
} }
}
res.flushHeaders() res.flushHeaders()
getTracer().trace( getTracer().trace(
......
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