Skip to content

Commit 1a17399

Browse files
author
Stephen Cefali
authored
fix(react-router-v3): makes normalizeTransactionName take a callback function (#2946)
1 parent 0ee0799 commit 1a17399

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

packages/react/src/reactrouterv3.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ export function reactRouterV3Instrumentation(
4444

4545
// Have to use global.location because history.location might not be defined.
4646
if (startTransactionOnPageLoad && global && global.location) {
47-
prevName = normalizeTransactionName(routes, (global.location as unknown) as Location, match);
48-
49-
activeTransaction = startTransaction({
50-
name: prevName,
51-
op: 'pageload',
52-
tags: {
53-
'routing.instrumentation': 'react-router-v3',
54-
},
47+
normalizeTransactionName(routes, (global.location as unknown) as Location, match, (localName: string) => {
48+
prevName = localName;
49+
activeTransaction = startTransaction({
50+
name: prevName,
51+
op: 'pageload',
52+
tags: {
53+
'routing.instrumentation': 'react-router-v3',
54+
},
55+
});
5556
});
5657
}
5758

@@ -65,11 +66,13 @@ export function reactRouterV3Instrumentation(
6566
if (prevName) {
6667
tags.from = prevName;
6768
}
68-
prevName = normalizeTransactionName(routes, location, match);
69-
activeTransaction = startTransaction({
70-
name: prevName,
71-
op: 'navigation',
72-
tags,
69+
normalizeTransactionName(routes, location, match, (localName: string) => {
70+
prevName = localName;
71+
activeTransaction = startTransaction({
72+
name: prevName,
73+
op: 'navigation',
74+
tags,
75+
});
7376
});
7477
}
7578
});
@@ -80,7 +83,12 @@ export function reactRouterV3Instrumentation(
8083
/**
8184
* Normalize transaction names using `Router.match`
8285
*/
83-
function normalizeTransactionName(appRoutes: Route[], location: Location, match: Match): string {
86+
function normalizeTransactionName(
87+
appRoutes: Route[],
88+
location: Location,
89+
match: Match,
90+
callback: (pathname: string) => void,
91+
): void {
8492
let name = location.pathname;
8593
match(
8694
{
@@ -89,19 +97,18 @@ function normalizeTransactionName(appRoutes: Route[], location: Location, match:
8997
},
9098
(error, _redirectLocation, renderProps) => {
9199
if (error || !renderProps) {
92-
return name;
100+
return callback(name);
93101
}
94102

95103
const routePath = getRouteStringFromRoutes(renderProps.routes || []);
96104
if (routePath.length === 0 || routePath === '/*') {
97-
return name;
105+
return callback(name);
98106
}
99107

100108
name = routePath;
101-
return name;
109+
return callback(name);
102110
},
103111
);
104-
return name;
105112
}
106113

107114
/**

0 commit comments

Comments
 (0)