Skip to content

Commit c7fd524

Browse files
committed
fix: OTel root span should indicate error status on exceptions
1 parent 2c9fe23 commit c7fd524

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default async function Page() {
2+
throw new Error('Error')
3+
}

test/e2e/opentelemetry/instrumentation/opentelemetry.test.ts

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,132 @@ describe('opentelemetry', () => {
529529
},
530530
])
531531
})
532+
533+
it('should handle error in RSC', async () => {
534+
await next.fetch('/app/param/rsc-fetch/error', env.fetchInit)
535+
536+
await expectTrace(getCollector(), [
537+
{
538+
name: 'GET /app/[param]/rsc-fetch/error',
539+
attributes: {
540+
'http.method': 'GET',
541+
'http.route': '/app/[param]/rsc-fetch/error',
542+
'http.status_code': 500,
543+
'http.target': '/app/param/rsc-fetch/error',
544+
'next.route': '/app/[param]/rsc-fetch/error',
545+
'next.rsc': false,
546+
'next.span_name': 'GET /app/[param]/rsc-fetch/error',
547+
'next.span_type': 'BaseServer.handleRequest',
548+
},
549+
kind: 1,
550+
status: { code: 2 },
551+
traceId: env.span.traceId,
552+
parentId: env.span.rootParentId,
553+
spans: [
554+
{
555+
name: 'render route (app) /app/[param]/rsc-fetch/error',
556+
attributes: {
557+
'next.route': '/app/[param]/rsc-fetch/error',
558+
'next.span_name':
559+
'render route (app) /app/[param]/rsc-fetch/error',
560+
'next.span_type': 'AppRender.getBodyResult',
561+
},
562+
kind: 0,
563+
status: { code: 2 },
564+
spans: [
565+
{
566+
name: 'build component tree',
567+
attributes: {
568+
'next.span_name': 'build component tree',
569+
'next.span_type':
570+
'NextNodeServer.createComponentTree',
571+
},
572+
kind: 0,
573+
status: { code: 0 },
574+
spans: [
575+
{
576+
name: 'resolve segment modules',
577+
attributes: {
578+
'next.segment': '__PAGE__',
579+
'next.span_name': 'resolve segment modules',
580+
'next.span_type':
581+
'NextNodeServer.getLayoutOrPageModule',
582+
},
583+
kind: 0,
584+
status: { code: 0 },
585+
},
586+
{
587+
name: 'resolve segment modules',
588+
attributes: {
589+
'next.segment': '[param]',
590+
'next.span_name': 'resolve segment modules',
591+
'next.span_type':
592+
'NextNodeServer.getLayoutOrPageModule',
593+
},
594+
kind: 0,
595+
status: { code: 0 },
596+
},
597+
],
598+
},
599+
{
600+
name: 'generateMetadata /app/[param]/layout',
601+
attributes: {
602+
'next.page': '/app/[param]/layout',
603+
'next.span_name':
604+
'generateMetadata /app/[param]/layout',
605+
'next.span_type': 'ResolveMetadata.generateMetadata',
606+
},
607+
kind: 0,
608+
status: { code: 0 },
609+
},
610+
{
611+
name: 'generateMetadata /app/[param]/layout',
612+
attributes: {
613+
'next.page': '/app/[param]/layout',
614+
'next.span_name':
615+
'generateMetadata /app/[param]/layout',
616+
'next.span_type': 'ResolveMetadata.generateMetadata',
617+
},
618+
kind: 0,
619+
status: { code: 0 },
620+
},
621+
{
622+
attributes: {
623+
'next.clientComponentLoadCount': 8,
624+
'next.span_type':
625+
'NextNodeServer.clientComponentLoading',
626+
},
627+
kind: 0,
628+
name: 'NextNodeServer.clientComponentLoading',
629+
status: {
630+
code: 0,
631+
},
632+
},
633+
{
634+
name: 'start response',
635+
attributes: {
636+
'next.span_name': 'start response',
637+
'next.span_type': 'NextNodeServer.startResponse',
638+
},
639+
kind: 0,
640+
status: { code: 0 },
641+
},
642+
],
643+
},
644+
{
645+
name: 'resolve page components',
646+
attributes: {
647+
'next.route': '/app/[param]/rsc-fetch/error',
648+
'next.span_name': 'resolve page components',
649+
'next.span_type': 'NextNodeServer.findPageComponents',
650+
},
651+
kind: 0,
652+
status: { code: 0 },
653+
},
654+
],
655+
},
656+
])
657+
})
532658
})
533659

534660
describe('pages', () => {

0 commit comments

Comments
 (0)