-
-
Notifications
You must be signed in to change notification settings - Fork 4k
/
apm.tsx
48 lines (40 loc) · 1.27 KB
/
apm.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import * as Router from 'react-router';
import {createMemoryHistory} from 'history';
import * as Sentry from '@sentry/react';
import getRouteStringFromRoutes from 'app/utils/getRouteStringFromRoutes';
const createLocation = createMemoryHistory().createLocation;
/**
* Sets the transaction name
*/
export function setTransactionName(name: string) {
Sentry.configureScope(scope => {
scope.setTransaction(name);
scope.setTag('ui.route', name);
});
}
export function normalizeTransactionName(
appRoutes: Router.PlainRoute[],
location: Location
): string {
const defaultName = location.pathname;
// For JavaScript transactions, translate the transaction name if it exists and doesn't start with /
// using the app's react-router routes. If the transaction name doesn't exist, use the window.location.pathname
// as the fallback.
Router.match(
{
routes: appRoutes,
location: createLocation(location.pathname),
},
(error, _redirectLocation, renderProps) => {
if (error) {
return defaultName;
}
const routePath = getRouteStringFromRoutes(renderProps?.routes ?? []);
if (routePath.length === 0 || routePath === '/*') {
return defaultName;
}
return routePath;
}
);
return defaultName;
}