Commit 6fd885cf authored by Evan Kirkiles's avatar Evan Kirkiles Committed by devjiwonchoi

Do not overwrite `next.route` on root span if present

parent 81bd026e
......@@ -456,7 +456,7 @@ class NextTracerImpl implements NextTracer {
public setRootSpanAttribute(key: AttributeNames, value: AttributeValue) {
const spanId = context.active().getValue(rootSpanIdKey) as number
const attributes = rootSpanAttributesStore.get(spanId)
if (attributes) {
if (attributes && !attributes.has(key)) {
attributes.set(key, value)
}
}
......
......@@ -13,7 +13,7 @@ const EXTERNAL = {
const COLLECTOR_PORT = 9001
describe('opentelemetry', () => {
const { next, skipped, isNextDev } = nextTestSetup({
const { next, skipped, isNextDev, isNextStart } = nextTestSetup({
files: __dirname,
skipDeployment: true,
dependencies: require('./package.json').dependencies,
......@@ -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 () => {
await next.fetch('/api/pages/param/basic', env.fetchInit)
......
export default function Page() {
return <div>Page</div>
}
export function getServerSideProps() {
throw new Error('ServerSideProps error')
return {
props: {},
}
}
export default function Page() {
return <div>Page</div>
}
export function getServerSideProps() {
return { notFound: true }
}
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