Skip to content

Commit 58bb0bf

Browse files
committed
add tags to track the transaction rename
1 parent 92fa48e commit 58bb0bf

File tree

1 file changed

+44
-37
lines changed
  • src/sentry/static/sentry/app/utils

1 file changed

+44
-37
lines changed

src/sentry/static/sentry/app/utils/apm.tsx

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Sentry from '@sentry/browser';
22
import * as Router from 'react-router';
33
import {createMemoryHistory} from 'history';
4+
import set from 'lodash/set';
45

56
import getRouteStringFromRoutes from 'app/utils/getRouteStringFromRoutes';
67

@@ -20,49 +21,55 @@ export async function normalizeTransactionName(
2021
appRoutes: Router.PlainRoute[],
2122
event: Sentry.Event
2223
): Promise<Sentry.Event> {
23-
if (event.type === 'transaction') {
24-
// For JavaScript transactions, translate the transaction name if it exists and doesn't start with /
25-
// using the app's react-router routes. If the transaction name doesn't exist, use the window.location.pathname
26-
// as the fallback.
24+
if (event.type !== 'transaction') {
25+
return event;
26+
}
2727

28-
let prevTransactionName = event.transaction;
28+
// For JavaScript transactions, translate the transaction name if it exists and doesn't start with /
29+
// using the app's react-router routes. If the transaction name doesn't exist, use the window.location.pathname
30+
// as the fallback.
2931

30-
if (typeof prevTransactionName === 'string') {
31-
if (prevTransactionName.startsWith('/')) {
32-
return event;
33-
}
34-
} else {
35-
prevTransactionName = window.location.pathname;
32+
let prevTransactionName = event.transaction;
33+
34+
if (typeof prevTransactionName === 'string') {
35+
if (prevTransactionName.startsWith('/')) {
36+
return event;
3637
}
3738

38-
const transactionName: string | undefined = await new Promise(function(resolve) {
39-
Router.match(
40-
{
41-
routes: appRoutes,
42-
location: createLocation(prevTransactionName),
43-
},
44-
(error, _redirectLocation, renderProps) => {
45-
if (error) {
46-
return resolve(undefined);
47-
}
48-
49-
const routePath = getRouteStringFromRoutes(renderProps.routes ?? []);
50-
return resolve(routePath);
39+
set(event, ['tags', 'transaction.rename.source'], 'existing transaction name');
40+
} else {
41+
set(event, ['tags', 'transaction.rename.source'], 'window.location.pathname');
42+
43+
prevTransactionName = window.location.pathname;
44+
}
45+
46+
const transactionName: string | undefined = await new Promise(function(resolve) {
47+
Router.match(
48+
{
49+
routes: appRoutes,
50+
location: createLocation(prevTransactionName),
51+
},
52+
(error, _redirectLocation, renderProps) => {
53+
if (error) {
54+
set(event, ['tags', 'transaction.rename.react-router-match'], 'error');
55+
return resolve(undefined);
5156
}
52-
);
53-
});
54-
55-
if (typeof transactionName === 'string' && transactionName.length) {
56-
event.transaction = transactionName;
57-
58-
if (event.tags) {
59-
event.tags['ui.route'] = transactionName;
60-
} else {
61-
event.tags = {
62-
'ui.route': transactionName,
63-
};
57+
58+
set(event, ['tags', 'transaction.rename.react-router-match'], 'success');
59+
60+
const routePath = getRouteStringFromRoutes(renderProps.routes ?? []);
61+
return resolve(routePath);
6462
}
65-
}
63+
);
64+
});
65+
66+
if (typeof transactionName === 'string' && transactionName.length) {
67+
event.transaction = transactionName;
68+
69+
set(event, ['tags', 'transaction.rename.before'], prevTransactionName);
70+
set(event, ['tags', 'transaction.rename.after'], transactionName);
71+
72+
set(event, ['tags', 'ui.route'], transactionName);
6673
}
6774

6875
return event;

0 commit comments

Comments
 (0)