Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-router-v3): makes normalizeTransactionName take a callback function #2946

Merged
merged 2 commits into from
Sep 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions packages/react/src/reactrouterv3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ export function reactRouterV3Instrumentation(

// Have to use global.location because history.location might not be defined.
if (startTransactionOnPageLoad && global && global.location) {
prevName = normalizeTransactionName(routes, (global.location as unknown) as Location, match);

activeTransaction = startTransaction({
name: prevName,
op: 'pageload',
tags: {
'routing.instrumentation': 'react-router-v3',
},
normalizeTransactionName(routes, (global.location as unknown) as Location, match, (localName: string) => {
prevName = localName;
activeTransaction = startTransaction({
name: prevName,
op: 'pageload',
tags: {
'routing.instrumentation': 'react-router-v3',
},
});
});
}

Expand All @@ -65,11 +66,13 @@ export function reactRouterV3Instrumentation(
if (prevName) {
tags.from = prevName;
}
prevName = normalizeTransactionName(routes, location, match);
activeTransaction = startTransaction({
name: prevName,
op: 'navigation',
tags,
normalizeTransactionName(routes, location, match, (localName: string) => {
prevName = localName;
activeTransaction = startTransaction({
name: prevName,
op: 'navigation',
tags,
});
});
}
});
Expand All @@ -80,7 +83,12 @@ export function reactRouterV3Instrumentation(
/**
* Normalize transaction names using `Router.match`
*/
function normalizeTransactionName(appRoutes: Route[], location: Location, match: Match): string {
function normalizeTransactionName(
appRoutes: Route[],
location: Location,
match: Match,
callback: (pathname: string) => void,
): void {
let name = location.pathname;
match(
{
Expand All @@ -89,19 +97,18 @@ function normalizeTransactionName(appRoutes: Route[], location: Location, match:
},
(error, _redirectLocation, renderProps) => {
if (error || !renderProps) {
return name;
return callback(name);
}

const routePath = getRouteStringFromRoutes(renderProps.routes || []);
if (routePath.length === 0 || routePath === '/*') {
return name;
return callback(name);
}

name = routePath;
return name;
return callback(name);
},
);
return name;
}

/**
Expand Down