Skip to content

Commit

Permalink
fix(react/v7): Fix react router v4/v5 span names (#11940)
Browse files Browse the repository at this point in the history
Fixes #11938
  • Loading branch information
mydea committed May 7, 2024
1 parent 280a49e commit c7ced68
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/react/src/reactrouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,14 @@ function computeRootMatch(pathname: string): Match {
export function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {
const componentDisplayName = (Route as any).displayName || (Route as any).name;

const activeRootSpan = getActiveRootSpan();

const WrappedRoute: React.FC<P> = (props: P) => {
if (activeRootSpan && props && props.computedMatch && props.computedMatch.isExact) {
activeRootSpan.updateName(props.computedMatch.path);
activeRootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
if (props && props.computedMatch && props.computedMatch.isExact) {
const route = props.computedMatch.path;
const activeRootSpan = getActiveRootSpan();
if (activeRootSpan) {
activeRootSpan.updateName(route);
activeRootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
}
}

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

0 comments on commit c7ced68

Please sign in to comment.