feat(nextjs): Trace pageloads in App Router #12157
Merged
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.
This PR adds a very basic form of App Router pageload tracing to the Next.js SDK. This will allow us to see server component spans inside the trace, alongside the pageload span.
This works by using the new
experimental.clientTraceMetadata
option added in Next.js 15 (14.3.0-canary.64) which will inject meta tags, containing OTEL trace propagation data. The SDK automatically sets this option when a supporting version is detected.As a side-effect, this allows the SDK to associate errors thrown in server components (server side) with errors captured in error boundaries in the browser.
Example trace:
![Screenshot 2024-05-23 at 11 38 51](https://private-user-images.githubusercontent.com/8118419/333129961-e6accf3c-d29c-4027-99ad-5e12af5ce4e6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk2OTMyNjksIm5iZiI6MTcxOTY5Mjk2OSwicGF0aCI6Ii84MTE4NDE5LzMzMzEyOTk2MS1lNmFjY2YzYy1kMjljLTQwMjctOTlhZC01ZTEyYWY1Y2U0ZTYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjlUMjAyOTI5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MzRhZjQ5NmNmNzgzNmEzNGZjNmRhYmEwYzU5MTY2MDE2N2YwNDM4ODA1MDY4ZDlhZGEyZjYxOWNkMTliMzk0OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.FIc1TxADIAAcR5LEly3sIFqJc7PCYn94bXtLcOnotnw)
What doesn't work yet
This PR does not yet include the functionality to attach serverside spans to the request span of the pageload span. This requires some hack that we can explore in a follow-up PR: #12182