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( ...@@ -634,16 +634,20 @@ 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 })
getTracer() if (metrics) {
.startSpan(NextNodeServerSpan.clientComponentLoading, { getTracer()
startTime: metrics.clientComponentLoadStart, .startSpan(NextNodeServerSpan.clientComponentLoading, {
attributes: { startTime: metrics.clientComponentLoadStart,
'next.clientComponentLoadCount': metrics.clientComponentLoadCount, attributes: {
}, 'next.clientComponentLoadCount':
}) metrics.clientComponentLoadCount,
.end( },
metrics.clientComponentLoadStart + metrics.clientComponentLoadTimes })
) .end(
metrics.clientComponentLoadStart +
metrics.clientComponentLoadTimes
)
}
} }
}) })
} }
......
...@@ -37,11 +37,14 @@ export function wrapClientComponentLoader(ComponentMod: any) { ...@@ -37,11 +37,14 @@ export function wrapClientComponentLoader(ComponentMod: any) {
export function getClientComponentLoaderMetrics( export function getClientComponentLoaderMetrics(
options: { reset?: boolean } = {} options: { reset?: boolean } = {}
) { ) {
const metrics = { const metrics =
clientComponentLoadStart, clientComponentLoadStart === 0
clientComponentLoadTimes, ? undefined
clientComponentLoadCount, : {
} clientComponentLoadStart,
clientComponentLoadTimes,
clientComponentLoadCount,
}
if (options.reset) { if (options.reset) {
clientComponentLoadStart = 0 clientComponentLoadStart = 0
......
...@@ -55,15 +55,17 @@ function createWriterFromResponse( ...@@ -55,15 +55,17 @@ function createWriterFromResponse(
process.env.NEXT_OTEL_PERFORMANCE_PREFIX process.env.NEXT_OTEL_PERFORMANCE_PREFIX
) { ) {
const metrics = getClientComponentLoaderMetrics() const metrics = getClientComponentLoaderMetrics()
performance.measure( if (metrics) {
`${process.env.NEXT_OTEL_PERFORMANCE_PREFIX}:next-client-component-loading`, performance.measure(
{ `${process.env.NEXT_OTEL_PERFORMANCE_PREFIX}:next-client-component-loading`,
start: metrics.clientComponentLoadStart, {
end: start: metrics.clientComponentLoadStart,
metrics.clientComponentLoadStart + end:
metrics.clientComponentLoadTimes, metrics.clientComponentLoadStart +
} metrics.clientComponentLoadTimes,
) }
)
}
} }
res.flushHeaders() 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