Skip to content
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): Mark clientside prefetch request spans with http.request.prefetch: true attribute #15980

Merged
merged 17 commits into from
Apr 7, 2025

Conversation

lforst
Copy link
Member

@lforst lforst commented Apr 4, 2025

Adds a http.request.prefetch: true attribute to Next.js clientside requests if they're prefetching other pages.

Copy link
Contributor

github-actions bot commented Apr 4, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.26 KB - -
@sentry/browser - with treeshaking flags 23.09 KB - -
@sentry/browser (incl. Tracing) 36.91 KB - -
@sentry/browser (incl. Tracing, Replay) 74.11 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.48 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 78.77 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 90.58 KB - -
@sentry/browser (incl. Feedback) 39.65 KB - -
@sentry/browser (incl. sendFeedback) 27.87 KB - -
@sentry/browser (incl. FeedbackAsync) 32.65 KB - -
@sentry/react 25.06 KB - -
@sentry/react (incl. Tracing) 38.83 KB - -
@sentry/vue 27.47 KB - -
@sentry/vue (incl. Tracing) 38.64 KB - -
@sentry/svelte 23.29 KB - -
CDN Bundle 24.5 KB - -
CDN Bundle (incl. Tracing) 36.94 KB - -
CDN Bundle (incl. Tracing, Replay) 71.99 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 77.15 KB - -
CDN Bundle - uncompressed 71.45 KB - -
CDN Bundle (incl. Tracing) - uncompressed 109.21 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 220.5 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 233.03 KB - -
@sentry/nextjs (client) 40.35 KB +0.13% +53 B 🔺
@sentry/sveltekit (client) 37.35 KB - -
@sentry/node 142.92 KB - -
@sentry/node - without tracing 96.13 KB -0.01% -1 B 🔽
@sentry/aws-serverless 120.47 KB - -

View base workflow run

Comment on lines 20 to 22
if (headers?.get('next-router-prefetch')) {
span?.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'http.client.prefetch');
}
Copy link
Member

@Lms24 Lms24 Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Have we checked if this change plays well with the product? Specifically I'm thinking of the "Network Requests" insights module
image

wondering if http.client.prefetch spans would still count towards the http.client request spans tracked in this module.

Also, might be worth adding the op to dev docs, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point getsentry/sentry-docs#13239

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on an internal discussion we have agreed to instead add a http.request.prefetch: true attribute to the requests.

@lforst lforst changed the title feat(nextjs): Mark clientside prefetch request spans with http.client.prefetch op feat(nextjs): Mark clientside prefetch request spans with http.request.prefetch: true attribute Apr 7, 2025
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I think this is a great improvement and something we can implement in other meta frameworks as well in the future

@@ -12,6 +12,16 @@ export function browserTracingIntegration(
...options,
instrumentNavigation: false,
instrumentPageLoad: false,
onRequestSpanStart(...args) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: do we care about cases where users register their own browserTracingIntegration()? As in should we merge a possible custom implementation with our logic? Not sure what our general approach to this is so feel free to declare undefined behaviour :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think user's would be always importing this browserTracingIntegration (the Next.js one) so the behavior should already be merged (see line 23). Unless I am misunderstanding.

Base automatically changed from lforst-request-span-hook to develop April 7, 2025 09:05
@lforst lforst merged commit 4d0c270 into develop Apr 7, 2025
128 of 129 checks passed
@lforst lforst deleted the lforst-nextjs-client-prefetch-op branch April 7, 2025 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants