MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / withSentryRouting

Function withSentryRouting

packages/react/src/reactrouter.tsx:224–252  ·  view source on GitHub ↗
(Route: R)

Source from the content-addressed store, hash-verified

222
223/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
224export function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {
225 const componentDisplayName = Route.displayName || Route.name;
226
227 const WrappedRoute: React.FC<P> = (props: P) => {
228 if (props?.computedMatch?.isExact) {
229 const route = props.computedMatch.path;
230 const activeRootSpan = getActiveRootSpan();
231
232 getCurrentScope().setTransactionName(route);
233
234 if (activeRootSpan) {
235 activeRootSpan.updateName(route);
236 activeRootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
237 }
238 }
239
240 // @ts-expect-error Setting more specific React Component typing for `R` generic above
241 // will break advanced type inference done by react router params:
242 // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
243 return <Route {...props} />;
244 };
245
246 WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;
247 hoistNonReactStatics(WrappedRoute, Route);
248 // @ts-expect-error Setting more specific React Component typing for `R` generic above
249 // will break advanced type inference done by react router params:
250 // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
251 return WrappedRoute;
252}
253/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
254
255function getActiveRootSpan(): Span | undefined {

Callers 2

Calls 1

hoistNonReactStaticsFunction · 0.90

Tested by

no test coverage detected