Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
6fd885cf
Commit
6fd885cf
authored
Mar 17, 2025
by
Evan Kirkiles
Committed by
devjiwonchoi
Aug 29, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not overwrite `next.route` on root span if present
parent
81bd026e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
188 additions
and
2 deletions
+188
-2
tracer.ts
packages/next/src/server/lib/trace/tracer.ts
+1
-1
opentelemetry.test.ts
test/e2e/opentelemetry/instrumentation/opentelemetry.test.ts
+170
-1
getServerSidePropsError.tsx
...mentation/pages/pages/[param]/getServerSidePropsError.tsx
+10
-0
getServerSidePropsNotFound.tsx
...tation/pages/pages/[param]/getServerSidePropsNotFound.tsx
+7
-0
No files found.
packages/next/src/server/lib/trace/tracer.ts
View file @
6fd885cf
...
@@ -456,7 +456,7 @@ class NextTracerImpl implements NextTracer {
...
@@ -456,7 +456,7 @@ class NextTracerImpl implements NextTracer {
public
setRootSpanAttribute
(
key
:
AttributeNames
,
value
:
AttributeValue
)
{
public
setRootSpanAttribute
(
key
:
AttributeNames
,
value
:
AttributeValue
)
{
const
spanId
=
context
.
active
().
getValue
(
rootSpanIdKey
)
as
number
const
spanId
=
context
.
active
().
getValue
(
rootSpanIdKey
)
as
number
const
attributes
=
rootSpanAttributesStore
.
get
(
spanId
)
const
attributes
=
rootSpanAttributesStore
.
get
(
spanId
)
if
(
attributes
)
{
if
(
attributes
&&
!
attributes
.
has
(
key
)
)
{
attributes
.
set
(
key
,
value
)
attributes
.
set
(
key
,
value
)
}
}
}
}
...
...
test/e2e/opentelemetry/instrumentation/opentelemetry.test.ts
View file @
6fd885cf
...
@@ -13,7 +13,7 @@ const EXTERNAL = {
...
@@ -13,7 +13,7 @@ const EXTERNAL = {
const
COLLECTOR_PORT
=
9001
const
COLLECTOR_PORT
=
9001
describe
(
'opentelemetry'
,
()
=>
{
describe
(
'opentelemetry'
,
()
=>
{
const
{
next
,
skipped
,
isNextDev
}
=
nextTestSetup
({
const
{
next
,
skipped
,
isNextDev
,
isNextStart
}
=
nextTestSetup
({
files
:
__dirname
,
files
:
__dirname
,
skipDeployment
:
true
,
skipDeployment
:
true
,
dependencies
:
require
(
'./package.json'
).
dependencies
,
dependencies
:
require
(
'./package.json'
).
dependencies
,
...
@@ -856,6 +856,175 @@ describe('opentelemetry', () => {
...
@@ -856,6 +856,175 @@ describe('opentelemetry', () => {
])
])
})
})
it
(
'should handle getServerSideProps exceptions'
,
async
()
=>
{
await
next
.
fetch
(
'/pages/param/getServerSidePropsError'
,
env
.
fetchInit
)
await
expectTrace
(
getCollector
(),
[
{
name
:
'GET /pages/[param]/getServerSidePropsError'
,
attributes
:
{
'http.method'
:
'GET'
,
'http.route'
:
'/pages/[param]/getServerSidePropsError'
,
'http.status_code'
:
500
,
'http.target'
:
'/pages/param/getServerSidePropsError'
,
'next.route'
:
'/pages/[param]/getServerSidePropsError'
,
'next.span_name'
:
'GET /pages/[param]/getServerSidePropsError'
,
'next.span_type'
:
'BaseServer.handleRequest'
,
},
kind
:
1
,
status
:
{
code
:
0
},
traceId
:
env
.
span
.
traceId
,
parentId
:
env
.
span
.
rootParentId
,
spans
:
[
{
name
:
'getServerSideProps /pages/[param]/getServerSidePropsError'
,
attributes
:
{
'next.route'
:
'/pages/[param]/getServerSidePropsError'
,
'next.span_name'
:
'getServerSideProps /pages/[param]/getServerSidePropsError'
,
'next.span_type'
:
'Render.getServerSideProps'
,
},
kind
:
0
,
status
:
{
code
:
2
,
message
:
'ServerSideProps error'
,
},
events
:
[
{
name
:
'exception'
,
attributes
:
{
'exception.type'
:
'Error'
,
'exception.message'
:
'ServerSideProps error'
,
},
},
],
},
{
name
:
'render route (pages) /_error'
,
attributes
:
{
'next.route'
:
'/_error'
,
'next.span_name'
:
'render route (pages) /_error'
,
'next.span_type'
:
'Render.renderDocument'
,
},
kind
:
0
,
status
:
{
code
:
0
},
},
{
name
:
'resolve page components'
,
attributes
:
{
'next.route'
:
'/pages/[param]/getServerSidePropsError'
,
'next.span_name'
:
'resolve page components'
,
'next.span_type'
:
'NextNodeServer.findPageComponents'
,
},
kind
:
0
,
status
:
{
code
:
0
},
},
...(
isNextStart
?
[
{
name
:
'resolve page components'
,
attributes
:
{
'next.route'
:
'/500'
,
'next.span_name'
:
'resolve page components'
,
'next.span_type'
:
'NextNodeServer.findPageComponents'
,
},
kind
:
0
,
status
:
{
code
:
0
},
},
]
:
[]),
{
name
:
'resolve page components'
,
attributes
:
{
'next.route'
:
'/_error'
,
'next.span_name'
:
'resolve page components'
,
'next.span_type'
:
'NextNodeServer.findPageComponents'
,
},
kind
:
0
,
status
:
{
code
:
0
},
},
],
},
])
})
it
(
'should handle getServerSideProps returning notFound'
,
async
()
=>
{
await
next
.
fetch
(
'/pages/param/getServerSidePropsNotFound'
,
env
.
fetchInit
)
await
expectTrace
(
getCollector
(),
[
{
name
:
'GET /pages/[param]/getServerSidePropsNotFound'
,
attributes
:
{
'http.method'
:
'GET'
,
'http.route'
:
'/pages/[param]/getServerSidePropsNotFound'
,
'http.status_code'
:
404
,
'http.target'
:
'/pages/param/getServerSidePropsNotFound'
,
'next.route'
:
'/pages/[param]/getServerSidePropsNotFound'
,
'next.span_name'
:
'GET /pages/[param]/getServerSidePropsNotFound'
,
'next.span_type'
:
'BaseServer.handleRequest'
,
},
kind
:
1
,
status
:
{
code
:
0
},
traceId
:
env
.
span
.
traceId
,
parentId
:
env
.
span
.
rootParentId
,
spans
:
[
{
name
:
'getServerSideProps /pages/[param]/getServerSidePropsNotFound'
,
attributes
:
{
'next.route'
:
'/pages/[param]/getServerSidePropsNotFound'
,
'next.span_name'
:
'getServerSideProps /pages/[param]/getServerSidePropsNotFound'
,
'next.span_type'
:
'Render.getServerSideProps'
,
},
kind
:
0
,
status
:
{
code
:
0
,
},
},
{
name
:
'render route (app) /404'
,
attributes
:
{
'next.route'
:
'/404'
,
'next.span_name'
:
'render route (app) /404'
,
'next.span_type'
:
'AppRender.getBodyResult'
,
},
kind
:
0
,
status
:
{
code
:
0
},
},
{
name
:
'resolve page components'
,
attributes
:
{
'next.route'
:
'/pages/[param]/getServerSidePropsNotFound'
,
'next.span_name'
:
'resolve page components'
,
'next.span_type'
:
'NextNodeServer.findPageComponents'
,
},
kind
:
0
,
status
:
{
code
:
0
},
},
{
name
:
'resolve page components'
,
attributes
:
{
'next.route'
:
'/_not-found'
,
'next.span_name'
:
'resolve page components'
,
'next.span_type'
:
'NextNodeServer.findPageComponents'
,
},
kind
:
0
,
status
:
{
code
:
0
},
},
],
},
])
})
it
(
'should handle api routes in pages'
,
async
()
=>
{
it
(
'should handle api routes in pages'
,
async
()
=>
{
await
next
.
fetch
(
'/api/pages/param/basic'
,
env
.
fetchInit
)
await
next
.
fetch
(
'/api/pages/param/basic'
,
env
.
fetchInit
)
...
...
test/e2e/opentelemetry/instrumentation/pages/pages/[param]/getServerSidePropsError.tsx
0 → 100644
View file @
6fd885cf
export
default
function
Page
()
{
return
<
div
>
Page
</
div
>
}
export
function
getServerSideProps
()
{
throw
new
Error
(
'ServerSideProps error'
)
return
{
props
:
{},
}
}
test/e2e/opentelemetry/instrumentation/pages/pages/[param]/getServerSidePropsNotFound.tsx
0 → 100644
View file @
6fd885cf
export
default
function
Page
()
{
return
<
div
>
Page
</
div
>
}
export
function
getServerSideProps
()
{
return
{
notFound
:
true
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment