-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(nextjs): Add URL to tags of server components and generation functions issues #16500
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
Conversation
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.
LGTM! Could you also add a test case for a generation function in of the e2e tests?
|
||
const spanData = spanToJSON(rootSpan); | ||
|
||
if (spanData.data && 'http.target' in spanData.data) { |
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.
l: this can be simplified to:
if (typeof spanData.data['http.target'] === 'string') {
pathname = spanData.data['http.target'];
}
spanData.data
should never be empty I believe, and we can just check for stringiness and then avoid the typecase below :)
|
||
const spanData = spanToJSON(rootSpan); | ||
|
||
if (spanData.data && 'http.target' in spanData.data) { |
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.
same here as above :)
* @param params - Optional route parameters to replace in the template | ||
* @param headersDict - Optional headers containing protocol and host information | ||
* @param pathname - Optional pathname coming from parent span "http.target" | ||
* @returns A sanitized URL string |
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.
l: I would always mention here if things are only exported for tests, for clarity. In this file, I believe only getSanitizedRequestUrl
is actually used, all the other exports are for tests only right? By mentioning this with each export is is easier to follow why things are exported (vs. "hey can I un-export this because it is not actually used anyhwere?")
Next.js’s uses an internal AsyncLocalStorage (ALS) to share minimal request context—it deliberately does not populate the full Request object or URL in ALS, so only headers (Referer, x-forwarded-host, x-forwarded-proto) are available at runtime in Server Components.
To still capture a usable URL for metadata we use a three-step best-effort fallback:
Referer
header Use it as the fully qualified URL if present (note: this could be omitted by the browser).closes: https://linear.app/getsentry/issue/JS-487/capture-requesturl-for-nextjs-server-spans