Skip to content

Commit

Permalink
add transaction name source values
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Jul 8, 2022
1 parent 6d98f68 commit 19d72d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/nextjs/src/performance/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ export function nextRouterInstrumentation(
// route name. Setting the transaction name after the transaction is started could lead
// to possible race conditions with the router, so this approach was taken.
if (startTransactionOnPageLoad) {
prevTransactionName = Router.route !== null ? stripUrlQueryAndFragment(Router.route) : global.location.pathname;
const pathIsRoute = Router.route !== null;

prevTransactionName = pathIsRoute ? stripUrlQueryAndFragment(Router.route) : global.location.pathname;
activeTransaction = startTransactionCb({
name: prevTransactionName,
op: 'pageload',
tags: DEFAULT_TAGS,
metadata: {
source: pathIsRoute ? 'route' : 'url',
},
});
}

Expand Down Expand Up @@ -105,6 +110,7 @@ function changeStateWrapper(originalChangeStateWrapper: RouterChangeState): Wrap
name: prevTransactionName,
op: 'navigation',
tags,
metadata: { source: 'route' },
});
}
return originalChangeStateWrapper.call(this, method, url, as, options, ...args);
Expand Down
10 changes: 9 additions & 1 deletion packages/nextjs/src/utils/instrumentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,14 @@ function makeWrappedReqHandler(origReqHandler: ReqHandler): WrappedReqHandler {
{
name: `${namePrefix}${reqPath}`,
op: 'http.server',
metadata: { requestPath: reqPath, baggage },
metadata: {
baggage,
requestPath: reqPath,
// TODO: Investigate if there's a way to tell if this is a dynamic route, so that we can make this more
// like `source: isDynamicRoute? 'url' : 'route'`
// TODO: What happens when `withSentry` is used also? Which values of `name` and `source` win?
source: 'url',
},
...traceparentData,
},
// Extra context passed to the `tracesSampler` (Note: We're combining `nextReq` and `req` this way in order
Expand Down Expand Up @@ -326,6 +333,7 @@ function makeWrappedMethodForGettingParameterizedPath(
if (transaction && transaction.metadata.requestPath) {
const origPath = transaction.metadata.requestPath;
transaction.name = transaction.name.replace(origPath, parameterizedPath);
transaction.setMetadata({ source: 'route' });
}

return origMethod.call(this, parameterizedPath, ...args);
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/utils/withSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
// Replace with placeholder
if (req.query) {
// TODO get this from next if possible, to avoid accidentally replacing non-dynamic parts of the path if
// they match dynamic parts
// they happen to match the values of any of the dynamic parts
for (const [key, value] of Object.entries(req.query)) {
reqPath = reqPath.replace(`${value}`, `[${key}]`);
}
Expand All @@ -72,7 +72,7 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
name: `${reqMethod}${reqPath}`,
op: 'http.server',
...traceparentData,
metadata: { baggage },
metadata: { baggage, source: 'route' },
},
// extra context passed to the `tracesSampler`
{ request: req },
Expand Down

0 comments on commit 19d72d5

Please sign in to comment.