-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
ref(nextjs): Improve app router routing instrumentation accuracy #13695
ref(nextjs): Improve app router routing instrumentation accuracy #13695
Conversation
…router-routing-instrumentation
size-limit report 📦
|
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.
Looks good!
}; | ||
function transactionNameifyRouterArgument(target: string): string { | ||
try { | ||
return new URL(target, 'http://some-random-base.com/').pathname; |
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.
q: Why do we need that exactly? Couldn't we just take the target?
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.
So users could be passing basically any string to router.push()
, including absolute URLs to the current origin. Taking the absolute URLs wouldn't be good, so we somehow need to parse out the path. Parsing urls is really hard so this is the easiest/best way I found.
Improves the Next.js routing instrumentation by patching the Next.js router and instrumenting window popstates.
A few details on this PR that might explain weird-looking logic:
router.back
/router.forward
and thepopstate
event to emit a properly named transaction, becauserouter.back
androuter.forward
aren't passed any useful strings we could use as txn names.router.back
/router.forward
calls and thepopstate
event, we temporarily give the navigation span an invalid name that we use as an indicator to drop if one may leak through.