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

fix(nextjs): Handle pathname being passed in object in instrumentServer #5782

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/nextjs/src/utils/instrumentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,23 @@ function makeWrappedMethodForGettingParameterizedPath(
origMethod: ApiPageEnsurer | PageComponentFinder,
): WrappedApiPageEnsurer | WrappedPageComponentFinder {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const wrappedMethod = async function (this: Server, parameterizedPath: string, ...args: any[]): Promise<any> {
const wrappedMethod = async function (
this: Server,
parameterizedPath:
| string // `ensureAPIPage`, `findPageComponents` before nextjs 12.2.6
| { pathname: string }, // `findPageComponents` from nextjs 12.2.6 onward
...args: any[]
): Promise<any> {
const transaction = getActiveTransaction();

// replace specific URL with parameterized version
if (transaction && transaction.metadata.requestPath) {
const origPath = transaction.metadata.requestPath;
const newName = transaction.name.replace(origPath, parameterizedPath);
transaction.setName(newName, 'route');
const newPath = typeof parameterizedPath === 'string' ? parameterizedPath : parameterizedPath.pathname;
if (newPath) {
const newName = transaction.name.replace(origPath, newPath);
transaction.setName(newName, 'route');
}
}

return origMethod.call(this, parameterizedPath, ...args);
Expand Down