Skip to content

feat(nextjs): Improve server component data #15996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Template({ children }: { children: React.ReactNode }) {
return <div>{children}</div>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test('Will create a transaction with spans for every server component and metada

expect(spanDescriptions).toContainEqual('Layout Server Component (/(nested-layout)/nested-layout)');
expect(spanDescriptions).toContainEqual('Layout Server Component (/(nested-layout))');
expect(spanDescriptions).toContainEqual('Template Server Component (/(nested-layout))');
expect(spanDescriptions).toContainEqual('Page Server Component (/(nested-layout)/nested-layout)');
expect(spanDescriptions).toContainEqual('Page.generateMetadata (/(nested-layout)/nested-layout)');
});
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ test('Should set a "not_found" status on a server component span when notFound()
description: 'Page Server Component (/server-component/not-found)',
op: 'function.nextjs',
status: 'not_found',
data: expect.objectContaining({
'sentry.nextjs.function.type': 'Page',
'sentry.nextjs.function.route': '/server-component/not-found',
}),
}),
);
});
Expand Down Expand Up @@ -107,6 +111,10 @@ test('Should capture an error and transaction for a app router page', async ({ p
description: 'Page Server Component (/server-component/faulty)',
op: 'function.nextjs',
status: 'internal_error',
data: expect.objectContaining({
'sentry.nextjs.function.type': 'Page',
'sentry.nextjs.function.route': '/server-component/faulty',
}),
}),
);

Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { RequestAsyncStorage } from '../config/templates/requestAsyncStorag

export type ServerComponentContext = {
componentRoute: string;
componentType: 'Page' | 'Layout' | 'Head' | 'Not-found' | 'Loading' | 'Unknown';
componentType: 'Page' | 'Layout' | 'Head' | 'Not-found' | 'Loading' | 'Unknown' | 'Template' | 'Default';
headers?: WebFetchHeaders;
};

Expand Down
2 changes: 2 additions & 0 deletions packages/nextjs/src/common/wrapServerComponentWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs',
'sentry.nextjs.function.type': componentType,
'sentry.nextjs.function.route': componentRoute,
},
},
span => {
Expand Down
6 changes: 6 additions & 0 deletions packages/nextjs/src/config/loaders/wrappingLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ export default function wrappingLoader(
case 'loading':
componentType = 'Loading';
break;
case 'template':
componentType = 'Template';
break;
case 'default':
componentType = 'Default';
break;
default:
componentType = 'Unknown';
}
Expand Down
Loading