Unverified Commit 0c1741c4 authored by Dima Voytenko's avatar Dima Voytenko Committed by GitHub

Telemetry code load (#60594)

The following spans are either added or displayed by default:

* `NextNodeServer.findPageComponents` - page components
resolution/require
* `NextNodeServer.getLayoutOrPageModule` - load modules (webpack or
turbopack)
parent b805180f
...@@ -337,3 +337,27 @@ Attributes: ...@@ -337,3 +337,27 @@ Attributes:
- `next.span_name` - `next.span_name`
- `next.span_type` - `next.span_type`
- `next.page` - `next.page`
### `resolve page components`
- `next.span_type`: `NextNodeServer.findPageComponents`.
This span represents the process of resolving page components for a specific page.
Attributes:
- `next.span_name`
- `next.span_type`
- `next.route`
### `resolve segment modules`
- `next.span_type`: `NextNodeServer.getLayoutOrPageModule`.
This span represents loading of code modules for a layout or a page.
Attributes:
- `next.span_name`
- `next.span_type`
- `next.segment`
...@@ -11,6 +11,8 @@ import { getLayerAssets } from './get-layer-assets' ...@@ -11,6 +11,8 @@ import { getLayerAssets } from './get-layer-assets'
import { hasLoadingComponentInTree } from './has-loading-component-in-tree' import { hasLoadingComponentInTree } from './has-loading-component-in-tree'
import { validateRevalidate } from '../lib/patch-fetch' import { validateRevalidate } from '../lib/patch-fetch'
import { PARALLEL_ROUTE_DEFAULT_PATH } from '../../client/components/parallel-route-default' import { PARALLEL_ROUTE_DEFAULT_PATH } from '../../client/components/parallel-route-default'
import { getTracer } from '../lib/trace/tracer'
import { NextNodeServerSpan } from '../lib/trace/constants'
type ComponentTree = { type ComponentTree = {
seedData: CacheNodeSeedData seedData: CacheNodeSeedData
...@@ -131,7 +133,17 @@ export async function createComponentTree({ ...@@ -131,7 +133,17 @@ export async function createComponentTree({
const isLayout = typeof layout !== 'undefined' const isLayout = typeof layout !== 'undefined'
const isPage = typeof page !== 'undefined' const isPage = typeof page !== 'undefined'
const [layoutOrPageMod] = await getLayoutOrPageModule(tree) const [layoutOrPageMod] = await getTracer().trace(
NextNodeServerSpan.getLayoutOrPageModule,
{
hideSpan: !(isLayout || isPage),
spanName: 'resolve segment modules',
attributes: {
'next.segment': segment,
},
},
() => getLayoutOrPageModule(tree)
)
/** /**
* Checks if the current segment is a root layout. * Checks if the current segment is a root layout.
......
...@@ -38,6 +38,7 @@ enum NextServerSpan { ...@@ -38,6 +38,7 @@ enum NextServerSpan {
enum NextNodeServerSpan { enum NextNodeServerSpan {
compression = 'NextNodeServer.compression', compression = 'NextNodeServer.compression',
getBuildId = 'NextNodeServer.getBuildId', getBuildId = 'NextNodeServer.getBuildId',
getLayoutOrPageModule = 'NextNodeServer.getLayoutOrPageModule',
generateStaticRoutes = 'NextNodeServer.generateStaticRoutes', generateStaticRoutes = 'NextNodeServer.generateStaticRoutes',
generateFsStaticRoutes = 'NextNodeServer.generateFsStaticRoutes', generateFsStaticRoutes = 'NextNodeServer.generateFsStaticRoutes',
generatePublicRoutes = 'NextNodeServer.generatePublicRoutes', generatePublicRoutes = 'NextNodeServer.generatePublicRoutes',
...@@ -127,6 +128,8 @@ export const NextVanillaSpanAllowlist = [ ...@@ -127,6 +128,8 @@ export const NextVanillaSpanAllowlist = [
AppRouteRouteHandlersSpan.runHandler, AppRouteRouteHandlersSpan.runHandler,
ResolveMetadataSpan.generateMetadata, ResolveMetadataSpan.generateMetadata,
ResolveMetadataSpan.generateViewport, ResolveMetadataSpan.generateViewport,
NextNodeServerSpan.findPageComponents,
NextNodeServerSpan.getLayoutOrPageModule,
] ]
export { export {
......
...@@ -141,6 +141,7 @@ interface NextTracer { ...@@ -141,6 +141,7 @@ interface NextTracer {
type NextAttributeNames = type NextAttributeNames =
| 'next.route' | 'next.route'
| 'next.page' | 'next.page'
| 'next.segment'
| 'next.span_name' | 'next.span_name'
| 'next.span_type' | 'next.span_type'
type OTELAttributeNames = `http.${string}` | `net.${string}` type OTELAttributeNames = `http.${string}` | `net.${string}`
......
...@@ -658,7 +658,7 @@ export default class NextNodeServer extends BaseServer { ...@@ -658,7 +658,7 @@ export default class NextNodeServer extends BaseServer {
return getTracer().trace( return getTracer().trace(
NextNodeServerSpan.findPageComponents, NextNodeServerSpan.findPageComponents,
{ {
spanName: `resolving page into components`, spanName: 'resolve page components',
attributes: { attributes: {
'next.route': isAppPath ? normalizeAppPath(page) : page, 'next.route': isAppPath ? normalizeAppPath(page) : page,
}, },
......
...@@ -114,8 +114,8 @@ createNextDescribe( ...@@ -114,8 +114,8 @@ createNextDescribe(
const numberOfRootTraces = const numberOfRootTraces =
env.span.rootParentId === undefined ? 1 : 0 env.span.rootParentId === undefined ? 1 : 0
const traces = await getSanitizedTraces(numberOfRootTraces) const traces = await getSanitizedTraces(numberOfRootTraces)
if (traces.length < 5) { if (traces.length < 8) {
return `not enough traces, expected 5, but got ${traces.length}` return `not enough traces, expected 8, but got ${traces.length}`
} }
expect(traces).toMatchInlineSnapshot(` expect(traces).toMatchInlineSnapshot(`
[ [
...@@ -171,6 +171,48 @@ createNextDescribe( ...@@ -171,6 +171,48 @@ createNextDescribe(
}, },
"traceId": "${env.span.traceId}", "traceId": "${env.span.traceId}",
}, },
{
"attributes": {
"next.route": "/app/[param]/rsc-fetch",
"next.span_name": "resolve page components",
"next.span_type": "NextNodeServer.findPageComponents",
},
"kind": 0,
"name": "resolve page components",
"parentId": "[parent-id]",
"status": {
"code": 0,
},
"traceId": "${env.span.traceId}",
},
{
"attributes": {
"next.segment": "[param]",
"next.span_name": "resolve segment modules",
"next.span_type": "NextNodeServer.getLayoutOrPageModule",
},
"kind": 0,
"name": "resolve segment modules",
"parentId": "[parent-id]",
"status": {
"code": 0,
},
"traceId": "${env.span.traceId}",
},
{
"attributes": {
"next.segment": "__PAGE__",
"next.span_name": "resolve segment modules",
"next.span_type": "NextNodeServer.getLayoutOrPageModule",
},
"kind": 0,
"name": "resolve segment modules",
"parentId": "[parent-id]",
"status": {
"code": 0,
},
"traceId": "${env.span.traceId}",
},
{ {
"attributes": { "attributes": {
"next.page": "/app/[param]/layout", "next.page": "/app/[param]/layout",
...@@ -212,8 +254,8 @@ createNextDescribe( ...@@ -212,8 +254,8 @@ createNextDescribe(
const numberOfRootTraces = const numberOfRootTraces =
env.span.rootParentId === undefined ? 1 : 0 env.span.rootParentId === undefined ? 1 : 0
const traces = await getSanitizedTraces(numberOfRootTraces) const traces = await getSanitizedTraces(numberOfRootTraces)
if (traces.length < 2) { if (traces.length < 3) {
return `not enough traces, expected 2, but got ${traces.length}` return `not enough traces, expected 3, but got ${traces.length}`
} }
expect(traces).toMatchInlineSnapshot(` expect(traces).toMatchInlineSnapshot(`
[ [
...@@ -253,6 +295,20 @@ createNextDescribe( ...@@ -253,6 +295,20 @@ createNextDescribe(
}, },
"traceId": "${env.span.traceId}", "traceId": "${env.span.traceId}",
}, },
{
"attributes": {
"next.route": "/api/app/[param]/data",
"next.span_name": "resolve page components",
"next.span_type": "NextNodeServer.findPageComponents",
},
"kind": 0,
"name": "resolve page components",
"parentId": "[parent-id]",
"status": {
"code": 0,
},
"traceId": "${env.span.traceId}",
},
] ]
`) `)
return 'success' return 'success'
...@@ -268,8 +324,8 @@ createNextDescribe( ...@@ -268,8 +324,8 @@ createNextDescribe(
const numberOfRootTraces = const numberOfRootTraces =
env.span.rootParentId === undefined ? 1 : 0 env.span.rootParentId === undefined ? 1 : 0
const traces = await getSanitizedTraces(numberOfRootTraces) const traces = await getSanitizedTraces(numberOfRootTraces)
if (traces.length < 3) { if (traces.length < 4) {
return `not enough traces, expected 3, but got ${traces.length}` return `not enough traces, expected 4, but got ${traces.length}`
} }
expect(traces).toMatchInlineSnapshot(` expect(traces).toMatchInlineSnapshot(`
[ [
...@@ -295,6 +351,20 @@ createNextDescribe( ...@@ -295,6 +351,20 @@ createNextDescribe(
}, },
"traceId": "${env.span.traceId}", "traceId": "${env.span.traceId}",
}, },
{
"attributes": {
"next.route": "/pages/[param]/getServerSideProps",
"next.span_name": "resolve page components",
"next.span_type": "NextNodeServer.findPageComponents",
},
"kind": 0,
"name": "resolve page components",
"parentId": "[parent-id]",
"status": {
"code": 0,
},
"traceId": "${env.span.traceId}",
},
{ {
"attributes": { "attributes": {
"next.route": "/pages/[param]/getServerSideProps", "next.route": "/pages/[param]/getServerSideProps",
...@@ -337,8 +407,8 @@ createNextDescribe( ...@@ -337,8 +407,8 @@ createNextDescribe(
const numberOfRootTraces = const numberOfRootTraces =
env.span.rootParentId === undefined ? 1 : 0 env.span.rootParentId === undefined ? 1 : 0
const traces = await getSanitizedTraces(numberOfRootTraces) const traces = await getSanitizedTraces(numberOfRootTraces)
if (traces.length < 3) { if (traces.length < 4) {
return `not enough traces, expected 3, but got ${traces.length}` return `not enough traces, expected 4, but got ${traces.length}`
} }
expect(traces).toMatchInlineSnapshot(` expect(traces).toMatchInlineSnapshot(`
[ [
...@@ -364,6 +434,20 @@ createNextDescribe( ...@@ -364,6 +434,20 @@ createNextDescribe(
}, },
"traceId": "${env.span.traceId}", "traceId": "${env.span.traceId}",
}, },
{
"attributes": {
"next.route": "/pages/[param]/getStaticProps${v}",
"next.span_name": "resolve page components",
"next.span_type": "NextNodeServer.findPageComponents",
},
"kind": 0,
"name": "resolve page components",
"parentId": "[parent-id]",
"status": {
"code": 0,
},
"traceId": "${env.span.traceId}",
},
{ {
"attributes": { "attributes": {
"next.route": "/pages/[param]/getStaticProps${v}", "next.route": "/pages/[param]/getStaticProps${v}",
...@@ -578,6 +662,48 @@ createNextDescribe( ...@@ -578,6 +662,48 @@ createNextDescribe(
}, },
"traceId": "[trace-id]", "traceId": "[trace-id]",
}, },
{
"attributes": {
"next.route": "/app/[param]/rsc-fetch",
"next.span_name": "resolve page components",
"next.span_type": "NextNodeServer.findPageComponents",
},
"kind": 0,
"name": "resolve page components",
"parentId": "[parent-id]",
"status": {
"code": 0,
},
"traceId": "[trace-id]",
},
{
"attributes": {
"next.segment": "[param]",
"next.span_name": "resolve segment modules",
"next.span_type": "NextNodeServer.getLayoutOrPageModule",
},
"kind": 0,
"name": "resolve segment modules",
"parentId": "[parent-id]",
"status": {
"code": 0,
},
"traceId": "[trace-id]",
},
{
"attributes": {
"next.segment": "__PAGE__",
"next.span_name": "resolve segment modules",
"next.span_type": "NextNodeServer.getLayoutOrPageModule",
},
"kind": 0,
"name": "resolve segment modules",
"parentId": "[parent-id]",
"status": {
"code": 0,
},
"traceId": "[trace-id]",
},
{ {
"attributes": { "attributes": {
"next.page": "/app/[param]/layout", "next.page": "/app/[param]/layout",
......
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