Skip to content

Commit 5d0d9dc

Browse files
committed
add transaction name source values
1 parent ae086f9 commit 5d0d9dc

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

packages/nextjs/src/performance/client.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ export function nextRouterInstrumentation(
3535
// route name. Setting the transaction name after the transaction is started could lead
3636
// to possible race conditions with the router, so this approach was taken.
3737
if (startTransactionOnPageLoad) {
38-
prevTransactionName = Router.route !== null ? stripUrlQueryAndFragment(Router.route) : global.location.pathname;
38+
const pathIsRoute = Router.route !== null;
39+
40+
prevTransactionName = pathIsRoute ? stripUrlQueryAndFragment(Router.route) : global.location.pathname;
3941
activeTransaction = startTransactionCb({
4042
name: prevTransactionName,
4143
op: 'pageload',
4244
tags: DEFAULT_TAGS,
45+
metadata: {
46+
source: pathIsRoute ? 'route' : 'url',
47+
},
4348
});
4449
}
4550

@@ -105,6 +110,7 @@ function changeStateWrapper(originalChangeStateWrapper: RouterChangeState): Wrap
105110
name: prevTransactionName,
106111
op: 'navigation',
107112
tags,
113+
metadata: { source: 'route' },
108114
});
109115
}
110116
return originalChangeStateWrapper.call(this, method, url, as, options, ...args);

packages/nextjs/src/utils/instrumentServer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,14 @@ function makeWrappedReqHandler(origReqHandler: ReqHandler): WrappedReqHandler {
269269
{
270270
name: `${namePrefix}${reqPath}`,
271271
op: 'http.server',
272-
metadata: { requestPath: reqPath, baggage },
272+
metadata: {
273+
baggage,
274+
requestPath: reqPath,
275+
// TODO: Investigate if there's a way to tell if this is a dynamic route, so that we can make this more
276+
// like `source: isDynamicRoute? 'url' : 'route'`
277+
// TODO: What happens when `withSentry` is used also? Which values of `name` and `source` win?
278+
source: 'url',
279+
},
273280
...traceparentData,
274281
},
275282
// Extra context passed to the `tracesSampler` (Note: We're combining `nextReq` and `req` this way in order
@@ -326,6 +333,7 @@ function makeWrappedMethodForGettingParameterizedPath(
326333
if (transaction && transaction.metadata.requestPath) {
327334
const origPath = transaction.metadata.requestPath;
328335
transaction.name = transaction.name.replace(origPath, parameterizedPath);
336+
transaction.setMetadata({ source: 'route' });
329337
}
330338

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

packages/nextjs/src/utils/withSentry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
6060
// Replace with placeholder
6161
if (req.query) {
6262
// TODO get this from next if possible, to avoid accidentally replacing non-dynamic parts of the path if
63-
// they match dynamic parts
63+
// they happen to match the values of any of the dynamic parts
6464
for (const [key, value] of Object.entries(req.query)) {
6565
reqPath = reqPath.replace(`${value}`, `[${key}]`);
6666
}
@@ -72,7 +72,7 @@ export const withSentry = (origHandler: NextApiHandler): WrappedNextApiHandler =
7272
name: `${reqMethod}${reqPath}`,
7373
op: 'http.server',
7474
...traceparentData,
75-
metadata: { baggage },
75+
metadata: { baggage, source: 'route' },
7676
},
7777
// extra context passed to the `tracesSampler`
7878
{ request: req },

0 commit comments

Comments
 (0)