Skip to content

Commit d4f71a3

Browse files
committed
ref(react): Add source to react-router-v3
1 parent 1cfcb0d commit d4f71a3

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

packages/react/src/reactrouterv3.ts

+25-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Primitive, Transaction, TransactionContext } from '@sentry/types';
1+
import { Primitive, Transaction, TransactionContext, TransactionSource } from '@sentry/types';
22
import { getGlobalObject } from '@sentry/utils';
33

44
import { Location, ReactRouterInstrumentation } from './types';
@@ -44,16 +44,24 @@ export function reactRouterV3Instrumentation(
4444

4545
// Have to use global.location because history.location might not be defined.
4646
if (startTransactionOnPageLoad && global && global.location) {
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-
});
56-
});
47+
normalizeTransactionName(
48+
routes,
49+
global.location as unknown as Location,
50+
match,
51+
(localName: string, source: TransactionSource = 'url') => {
52+
prevName = localName;
53+
activeTransaction = startTransaction({
54+
name: prevName,
55+
op: 'pageload',
56+
tags: {
57+
'routing.instrumentation': 'react-router-v3',
58+
},
59+
});
60+
if (activeTransaction) {
61+
activeTransaction.setMetadata({ source });
62+
}
63+
},
64+
);
5765
}
5866

5967
if (startTransactionOnLocationChange && history.listen) {
@@ -68,13 +76,16 @@ export function reactRouterV3Instrumentation(
6876
if (prevName) {
6977
tags.from = prevName;
7078
}
71-
normalizeTransactionName(routes, location, match, (localName: string) => {
79+
normalizeTransactionName(routes, location, match, (localName: string, source: TransactionSource = 'url') => {
7280
prevName = localName;
7381
activeTransaction = startTransaction({
7482
name: prevName,
7583
op: 'navigation',
7684
tags,
7785
});
86+
if (activeTransaction) {
87+
activeTransaction.setMetadata({ source });
88+
}
7889
});
7990
}
8091
});
@@ -89,7 +100,7 @@ function normalizeTransactionName(
89100
appRoutes: Route[],
90101
location: Location,
91102
match: Match,
92-
callback: (pathname: string) => void,
103+
callback: (pathname: string, source?: TransactionSource) => void,
93104
): void {
94105
let name = location.pathname;
95106
match(
@@ -108,7 +119,7 @@ function normalizeTransactionName(
108119
}
109120

110121
name = routePath;
111-
return callback(name);
122+
return callback(name, 'route');
112123
},
113124
);
114125
}

0 commit comments

Comments
 (0)