-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat(nextjs): Connect server component transactions if there is no incoming trace #9845
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e1841f2
ref(nextjs): Simplify `wrapServerComponentWithSentry`
lforst 49d6e4c
feat(nextjs): Connect server component transactions if there is no in…
lforst 6dd49dd
.
lforst 9ecaa10
Merge remote-tracking branch 'origin/develop' into lforst-refactor-wr…
lforst 9e8e0aa
Set status to ok on redirect
lforst e44f1ed
Merge branch 'lforst-refactor-wrap-servercomponents' into lforst-conn…
lforst 2619bbd
Merge remote-tracking branch 'origin/develop' into lforst-connect-ser…
lforst 3618f73
Connect generation functions
lforst 5696faa
Merge remote-tracking branch 'origin/develop' into lforst-connect-ser…
lforst 1ae5c14
Add comment explaining.
lforst 9b871f3
Add e2e test
lforst edcda0d
Pr feedback
lforst File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
packages/e2e-tests/test-applications/nextjs-app-dir/app/(nested-layout)/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PropsWithChildren } from 'react'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Layout({ children }: PropsWithChildren<{}>) { | ||
return ( | ||
<div> | ||
<p>Layout</p> | ||
{children} | ||
</div> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
...s/e2e-tests/test-applications/nextjs-app-dir/app/(nested-layout)/nested-layout/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PropsWithChildren } from 'react'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Layout({ children }: PropsWithChildren<{}>) { | ||
return ( | ||
<div> | ||
<p>Layout</p> | ||
{children} | ||
</div> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
...ges/e2e-tests/test-applications/nextjs-app-dir/app/(nested-layout)/nested-layout/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Page() { | ||
return <p>Hello World!</p>; | ||
} | ||
|
||
export async function generateMetadata() { | ||
return { | ||
title: 'I am generated metadata', | ||
}; | ||
} |
50 changes: 50 additions & 0 deletions
50
.../e2e-tests/test-applications/nextjs-app-dir/tests/connected-servercomponent-trace.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForTransaction } from '../event-proxy-server'; | ||
|
||
test('Will capture a connected trace for all server components and generation functions when visiting a page', async ({ | ||
page, | ||
}) => { | ||
const someConnectedEvent = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { | ||
return ( | ||
transactionEvent?.transaction === 'Layout Server Component (/(nested-layout)/nested-layout)' || | ||
transactionEvent?.transaction === 'Layout Server Component (/(nested-layout))' || | ||
transactionEvent?.transaction === 'Page Server Component (/(nested-layout)/nested-layout)' || | ||
transactionEvent?.transaction === 'Page.generateMetadata (/(nested-layout)/nested-layout)' | ||
); | ||
}); | ||
|
||
const layout1Transaction = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { | ||
return ( | ||
transactionEvent?.transaction === 'Layout Server Component (/(nested-layout)/nested-layout)' && | ||
(await someConnectedEvent).contexts?.trace?.trace_id === transactionEvent.contexts?.trace?.trace_id | ||
); | ||
}); | ||
|
||
const layout2Transaction = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { | ||
return ( | ||
transactionEvent?.transaction === 'Layout Server Component (/(nested-layout))' && | ||
(await someConnectedEvent).contexts?.trace?.trace_id === transactionEvent.contexts?.trace?.trace_id | ||
); | ||
}); | ||
|
||
const pageTransaction = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { | ||
return ( | ||
transactionEvent?.transaction === 'Page Server Component (/(nested-layout)/nested-layout)' && | ||
(await someConnectedEvent).contexts?.trace?.trace_id === transactionEvent.contexts?.trace?.trace_id | ||
); | ||
}); | ||
|
||
const generateMetadataTransaction = waitForTransaction('nextjs-13-app-dir', async transactionEvent => { | ||
return ( | ||
transactionEvent?.transaction === 'Page.generateMetadata (/(nested-layout)/nested-layout)' && | ||
(await someConnectedEvent).contexts?.trace?.trace_id === transactionEvent.contexts?.trace?.trace_id | ||
); | ||
}); | ||
|
||
await page.goto('/nested-layout'); | ||
|
||
expect(await layout1Transaction).toBeDefined(); | ||
expect(await layout2Transaction).toBeDefined(); | ||
expect(await pageTransaction).toBeDefined(); | ||
expect(await generateMetadataTransaction).toBeDefined(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { PropagationContext } from '@sentry/types'; | ||
|
||
const commonMap = new WeakMap<object, PropagationContext>(); | ||
|
||
/** | ||
* Takes a shared (garbage collectable) object between resources, e.g. a headers object shared between Next.js server components and returns a common propagation context. | ||
*/ | ||
export function commonObjectToPropagationContext( | ||
commonObject: unknown, | ||
propagationContext: PropagationContext, | ||
): PropagationContext { | ||
if (typeof commonObject === 'object' && commonObject) { | ||
const memoPropagationContext = commonMap.get(commonObject); | ||
if (memoPropagationContext) { | ||
return memoPropagationContext; | ||
} else { | ||
commonMap.set(commonObject, propagationContext); | ||
return propagationContext; | ||
} | ||
} else { | ||
return propagationContext; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sneaking this in. This is actually a bug because routing groups should part of the txn name. I added this when I didn't fully understand the app router yet.