From 9582902e7585fc279852bbddf5efd2fa0dddbda8 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Tue, 20 Sep 2022 12:30:08 -0700 Subject: [PATCH] handle `pathname` being passed in object --- packages/nextjs/src/utils/instrumentServer.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/nextjs/src/utils/instrumentServer.ts b/packages/nextjs/src/utils/instrumentServer.ts index d92ed3e14ae7..dbfc0a91d45c 100644 --- a/packages/nextjs/src/utils/instrumentServer.ts +++ b/packages/nextjs/src/utils/instrumentServer.ts @@ -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 { + 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 { 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);