Skip to content

Commit c7ced68

Browse files
authored
fix(react/v7): Fix react router v4/v5 span names (#11940)
Fixes #11938
1 parent 280a49e commit c7ced68

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/react/src/reactrouter.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,14 @@ function computeRootMatch(pathname: string): Match {
263263
export function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {
264264
const componentDisplayName = (Route as any).displayName || (Route as any).name;
265265

266-
const activeRootSpan = getActiveRootSpan();
267-
268266
const WrappedRoute: React.FC<P> = (props: P) => {
269-
if (activeRootSpan && props && props.computedMatch && props.computedMatch.isExact) {
270-
activeRootSpan.updateName(props.computedMatch.path);
271-
activeRootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
267+
if (props && props.computedMatch && props.computedMatch.isExact) {
268+
const route = props.computedMatch.path;
269+
const activeRootSpan = getActiveRootSpan();
270+
if (activeRootSpan) {
271+
activeRootSpan.updateName(route);
272+
activeRootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
273+
}
272274
}
273275

274276
// @ts-expect-error Setting more specific React Component typing for `R` generic above

0 commit comments

Comments
 (0)