Skip to content

Commit 9582902

Browse files
committed
handle pathname being passed in object
1 parent 204af14 commit 9582902

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packages/nextjs/src/utils/instrumentServer.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,23 @@ function makeWrappedMethodForGettingParameterizedPath(
317317
origMethod: ApiPageEnsurer | PageComponentFinder,
318318
): WrappedApiPageEnsurer | WrappedPageComponentFinder {
319319
// eslint-disable-next-line @typescript-eslint/no-explicit-any
320-
const wrappedMethod = async function (this: Server, parameterizedPath: string, ...args: any[]): Promise<any> {
320+
const wrappedMethod = async function (
321+
this: Server,
322+
parameterizedPath:
323+
| string // `ensureAPIPage`, `findPageComponents` before nextjs 12.2.6
324+
| { pathname: string }, // `findPageComponents` from nextjs 12.2.6 onward
325+
...args: any[]
326+
): Promise<any> {
321327
const transaction = getActiveTransaction();
322328

323329
// replace specific URL with parameterized version
324330
if (transaction && transaction.metadata.requestPath) {
325331
const origPath = transaction.metadata.requestPath;
326-
const newName = transaction.name.replace(origPath, parameterizedPath);
327-
transaction.setName(newName, 'route');
332+
const newPath = typeof parameterizedPath === 'string' ? parameterizedPath : parameterizedPath.pathname;
333+
if (newPath) {
334+
const newName = transaction.name.replace(origPath, newPath);
335+
transaction.setName(newName, 'route');
336+
}
328337
}
329338

330339
return origMethod.call(this, parameterizedPath, ...args);

0 commit comments

Comments
 (0)