@sentry/react 10.53.1 → 10.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/constants.js +3 -5
- package/build/cjs/constants.js.map +1 -1
- package/build/cjs/debug-build.js +0 -5
- package/build/cjs/debug-build.js.map +1 -1
- package/build/cjs/error.js +12 -72
- package/build/cjs/error.js.map +1 -1
- package/build/cjs/errorboundary.js +22 -77
- package/build/cjs/errorboundary.js.map +1 -1
- package/build/cjs/hoist-non-react-statics.js +16 -84
- package/build/cjs/hoist-non-react-statics.js.map +1 -1
- package/build/cjs/isSyntheticEvent.js +10 -0
- package/build/cjs/isSyntheticEvent.js.map +1 -0
- package/build/cjs/profiler.js +35 -110
- package/build/cjs/profiler.js.map +1 -1
- package/build/cjs/reactrouter-compat-utils/instrumentation.js +219 -690
- package/build/cjs/reactrouter-compat-utils/instrumentation.js.map +1 -1
- package/build/cjs/reactrouter-compat-utils/lazy-routes.js +24 -85
- package/build/cjs/reactrouter-compat-utils/lazy-routes.js.map +1 -1
- package/build/cjs/reactrouter-compat-utils/route-manifest.js +17 -95
- package/build/cjs/reactrouter-compat-utils/route-manifest.js.map +1 -1
- package/build/cjs/reactrouter-compat-utils/utils.js +48 -190
- package/build/cjs/reactrouter-compat-utils/utils.js.map +1 -1
- package/build/cjs/reactrouter.js +33 -113
- package/build/cjs/reactrouter.js.map +1 -1
- package/build/cjs/reactrouterv3.js +27 -59
- package/build/cjs/reactrouterv3.js.map +1 -1
- package/build/cjs/reactrouterv6.js +8 -41
- package/build/cjs/reactrouterv6.js.map +1 -1
- package/build/cjs/reactrouterv7.js +8 -41
- package/build/cjs/reactrouterv7.js.map +1 -1
- package/build/cjs/redux.js +60 -88
- package/build/cjs/redux.js.map +1 -1
- package/build/cjs/sdk.js +13 -8
- package/build/cjs/sdk.js.map +1 -1
- package/build/cjs/tanstackrouter.js +24 -64
- package/build/cjs/tanstackrouter.js.map +1 -1
- package/build/esm/constants.js +3 -5
- package/build/esm/constants.js.map +1 -1
- package/build/esm/debug-build.js +0 -5
- package/build/esm/debug-build.js.map +1 -1
- package/build/esm/error.js +12 -72
- package/build/esm/error.js.map +1 -1
- package/build/esm/errorboundary.js +22 -77
- package/build/esm/errorboundary.js.map +1 -1
- package/build/esm/hoist-non-react-statics.js +16 -84
- package/build/esm/hoist-non-react-statics.js.map +1 -1
- package/build/esm/isSyntheticEvent.js +8 -0
- package/build/esm/isSyntheticEvent.js.map +1 -0
- package/build/esm/package.json +1 -1
- package/build/esm/profiler.js +35 -110
- package/build/esm/profiler.js.map +1 -1
- package/build/esm/reactrouter-compat-utils/instrumentation.js +219 -690
- package/build/esm/reactrouter-compat-utils/instrumentation.js.map +1 -1
- package/build/esm/reactrouter-compat-utils/lazy-routes.js +24 -85
- package/build/esm/reactrouter-compat-utils/lazy-routes.js.map +1 -1
- package/build/esm/reactrouter-compat-utils/route-manifest.js +17 -95
- package/build/esm/reactrouter-compat-utils/route-manifest.js.map +1 -1
- package/build/esm/reactrouter-compat-utils/utils.js +48 -190
- package/build/esm/reactrouter-compat-utils/utils.js.map +1 -1
- package/build/esm/reactrouter.js +33 -113
- package/build/esm/reactrouter.js.map +1 -1
- package/build/esm/reactrouterv3.js +27 -59
- package/build/esm/reactrouterv3.js.map +1 -1
- package/build/esm/reactrouterv6.js +8 -41
- package/build/esm/reactrouterv6.js.map +1 -1
- package/build/esm/reactrouterv7.js +8 -41
- package/build/esm/reactrouterv7.js.map +1 -1
- package/build/esm/redux.js +60 -88
- package/build/esm/redux.js.map +1 -1
- package/build/esm/sdk.js +15 -10
- package/build/esm/sdk.js.map +1 -1
- package/build/esm/tanstackrouter.js +24 -64
- package/build/esm/tanstackrouter.js.map +1 -1
- package/build/types/isSyntheticEvent.d.ts +10 -0
- package/build/types/isSyntheticEvent.d.ts.map +1 -0
- package/build/types/sdk.d.ts.map +1 -1
- package/build/types-ts3.8/isSyntheticEvent.d.ts +10 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/reactrouter-compat-utils/utils.ts"],"sourcesContent":["import type { Span, TransactionSource } from '@sentry/core/browser';\nimport { debug, getActiveSpan, getRootSpan, spanToJSON } from '@sentry/core/browser';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { Location, MatchRoutes, RouteMatch, RouteObject } from '../types';\nimport { matchRouteManifest, stripBasenameFromPathname } from './route-manifest';\n\n// Global variables that these utilities depend on\nlet _matchRoutes: MatchRoutes;\nlet _stripBasename: boolean = false;\n\n// Navigation context stack for nested/concurrent patchRoutesOnNavigation calls.\n// Required because window.location hasn't updated yet when handlers are invoked.\ninterface NavigationContext {\n token: object;\n targetPath: string | undefined;\n span: Span | undefined;\n}\n\nconst _navigationContextStack: NavigationContext[] = [];\nconst MAX_CONTEXT_STACK_SIZE = 10;\n\n/**\n * Pushes a navigation context and returns a unique token for cleanup.\n * The token uses object identity for uniqueness (no counter needed).\n */\nexport function setNavigationContext(targetPath: string | undefined, span: Span | undefined): object {\n const token = {};\n // Prevent unbounded stack growth - oldest (likely stale) contexts are evicted first\n if (_navigationContextStack.length >= MAX_CONTEXT_STACK_SIZE) {\n DEBUG_BUILD && debug.warn('[React Router] Navigation context stack overflow - removing oldest context');\n _navigationContextStack.shift();\n }\n _navigationContextStack.push({ token, targetPath, span });\n return token;\n}\n\n/**\n * Clears the navigation context if it's on top of the stack (LIFO).\n * If our context is not on top (out-of-order completion), we leave it -\n * it will be cleaned up by overflow protection when the stack fills up.\n */\nexport function clearNavigationContext(token: object): void {\n const top = _navigationContextStack[_navigationContextStack.length - 1];\n if (top?.token === token) {\n _navigationContextStack.pop();\n }\n}\n\n/** Gets the current (most recent) navigation context if inside a patchRoutesOnNavigation call. */\nexport function getNavigationContext(): NavigationContext | null {\n const length = _navigationContextStack.length;\n // The `?? null` converts undefined (from array access) to null to match return type\n return length > 0 ? (_navigationContextStack[length - 1] ?? null) : null;\n}\n\n/**\n * Initialize function to set dependencies that the router utilities need.\n * Must be called before using any of the exported utility functions.\n */\nexport function initializeRouterUtils(matchRoutes: MatchRoutes, stripBasename: boolean = false): void {\n _matchRoutes = matchRoutes;\n _stripBasename = stripBasename;\n}\n\n// Helper functions\nfunction pickPath(match: RouteMatch): string {\n return trimWildcard(match.route.path || '');\n}\n\nfunction pickSplat(match: RouteMatch): string {\n return match.params['*'] || '';\n}\n\nfunction trimWildcard(path: string): string {\n return path[path.length - 1] === '*' ? path.slice(0, -1) : path;\n}\n\nfunction trimSlash(path: string): string {\n return path[path.length - 1] === '/' ? path.slice(0, -1) : path;\n}\n\n/**\n * Checks if a path ends with a wildcard character (*).\n */\nexport function pathEndsWithWildcard(path: string): boolean {\n return path.endsWith('*');\n}\n\n/** Checks if transaction name has wildcard (/* or ends with *). */\nexport function transactionNameHasWildcard(name: string): boolean {\n return name.includes('/*') || name.endsWith('*');\n}\n\n/**\n * Checks if a path is a wildcard and has child routes.\n */\nexport function pathIsWildcardAndHasChildren(path: string, branch: RouteMatch<string>): boolean {\n return (pathEndsWithWildcard(path) && !!branch.route.children?.length) || false;\n}\n\n/** Check if route is in descendant route (<Routes> within <Routes>) */\nexport function routeIsDescendant(route: RouteObject): boolean {\n return !!(!route.children && route.element && route.path?.endsWith('/*'));\n}\n\nfunction sendIndexPath(pathBuilder: string, pathname: string, basename: string): [string, TransactionSource] {\n const reconstructedPath =\n pathBuilder && pathBuilder.length > 0\n ? pathBuilder\n : _stripBasename\n ? stripBasenameFromPathname(pathname, basename)\n : pathname;\n\n let formattedPath =\n // If the path ends with a wildcard suffix, remove both the slash and the asterisk\n reconstructedPath.slice(-2) === '/*' ? reconstructedPath.slice(0, -2) : reconstructedPath;\n\n // If the path ends with a slash, remove it (but keep single '/')\n if (formattedPath.length > 1 && formattedPath[formattedPath.length - 1] === '/') {\n formattedPath = formattedPath.slice(0, -1);\n }\n\n return [formattedPath, 'route'];\n}\n\n/**\n * Returns the number of URL segments in the given URL string.\n * Splits at '/' or '\\/' to handle regex URLs correctly.\n *\n * @param url - The URL string to segment.\n * @returns The number of segments in the URL.\n */\nexport function getNumberOfUrlSegments(url: string): number {\n // split at '/' or at '\\/' to split regex urls correctly\n return url.split(/\\\\?\\//).filter(s => s.length > 0 && s !== ',').length;\n}\n\n// Exported utility functions\n\n/**\n * Ensures a path string starts with a forward slash.\n */\nexport function prefixWithSlash(path: string): string {\n return path[0] === '/' ? path : `/${path}`;\n}\n\n/**\n * Rebuilds the route path from all available routes by matching against the current location.\n */\nexport function rebuildRoutePathFromAllRoutes(allRoutes: RouteObject[], location: Location): string {\n const matchedRoutes = _matchRoutes(allRoutes, location) as RouteMatch[];\n\n if (!matchedRoutes || matchedRoutes.length === 0) {\n return '';\n }\n\n for (const match of matchedRoutes) {\n if (match.route.path && match.route.path !== '*') {\n const path = pickPath(match);\n const strippedPath = stripBasenameFromPathname(location.pathname, prefixWithSlash(match.pathnameBase));\n\n if (location.pathname === strippedPath) {\n return trimSlash(strippedPath);\n }\n\n return trimSlash(\n trimSlash(path || '') +\n prefixWithSlash(\n rebuildRoutePathFromAllRoutes(\n allRoutes.filter(route => route !== match.route),\n {\n pathname: strippedPath,\n },\n ),\n ),\n );\n }\n }\n\n return '';\n}\n\n/**\n * Checks if the current location is inside a descendant route (route with splat parameter).\n */\nexport function locationIsInsideDescendantRoute(location: Location, routes: RouteObject[]): boolean {\n const matchedRoutes = _matchRoutes(routes, location) as RouteMatch[];\n\n if (matchedRoutes) {\n for (const match of matchedRoutes) {\n if (routeIsDescendant(match.route) && pickSplat(match)) {\n return true;\n }\n }\n }\n\n return false;\n}\n\n/**\n * Returns a fallback transaction name from location pathname.\n */\nfunction getFallbackTransactionName(location: Location, basename: string): string {\n return _stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname || '';\n}\n\n/**\n * Gets a normalized route name and transaction source from the current routes and location.\n */\nexport function getNormalizedName(\n routes: RouteObject[],\n location: Location,\n branches: RouteMatch[],\n basename: string = '',\n): [string, TransactionSource] {\n if (!routes || routes.length === 0) {\n return [_stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname, 'url'];\n }\n\n if (!branches) {\n return [getFallbackTransactionName(location, basename), 'url'];\n }\n\n let pathBuilder = '';\n\n for (const branch of branches) {\n const route = branch.route;\n if (!route) {\n continue;\n }\n\n // Early return for index routes\n if (route.index) {\n return sendIndexPath(pathBuilder, branch.pathname, basename);\n }\n\n const path = route.path;\n if (!path || pathIsWildcardAndHasChildren(path, branch)) {\n continue;\n }\n\n // Build the route path\n const newPath = path[0] === '/' || pathBuilder[pathBuilder.length - 1] === '/' ? path : `/${path}`;\n pathBuilder = trimSlash(pathBuilder) + prefixWithSlash(newPath);\n\n // Check if this path matches the current location\n if (trimSlash(location.pathname) !== trimSlash(basename + branch.pathname)) {\n continue;\n }\n\n // Check if this is a parameterized route like /stores/:storeId/products/:productId\n if (\n getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&\n !pathEndsWithWildcard(pathBuilder)\n ) {\n return [(_stripBasename ? '' : basename) + newPath, 'route'];\n }\n\n // Handle wildcard routes with children - strip trailing wildcard\n if (pathIsWildcardAndHasChildren(pathBuilder, branch)) {\n pathBuilder = pathBuilder.slice(0, -1);\n }\n\n return [(_stripBasename ? '' : basename) + pathBuilder, 'route'];\n }\n\n // Fallback when no matching route found\n return [getFallbackTransactionName(location, basename), 'url'];\n}\n\n/**\n * Shared helper function to resolve route name and source\n */\nexport function resolveRouteNameAndSource(\n location: Location,\n routes: RouteObject[],\n allRoutes: RouteObject[],\n branches: RouteMatch[],\n basename: string = '',\n lazyRouteManifest?: string[],\n enableAsyncRouteHandlers?: boolean,\n): [string, TransactionSource] {\n // When lazy route manifest is provided, use it as the primary source for transaction names\n if (enableAsyncRouteHandlers && lazyRouteManifest && lazyRouteManifest.length > 0) {\n const manifestMatch = matchRouteManifest(location.pathname, lazyRouteManifest, basename);\n if (manifestMatch) {\n return [(_stripBasename ? '' : basename) + manifestMatch, 'route'];\n }\n }\n\n // Fall back to React Router route matching\n let name: string | undefined;\n let source: TransactionSource = 'url';\n\n const isInDescendantRoute = locationIsInsideDescendantRoute(location, allRoutes);\n\n if (isInDescendantRoute) {\n name = prefixWithSlash(rebuildRoutePathFromAllRoutes(allRoutes, location));\n source = 'route';\n }\n\n if (!isInDescendantRoute || !name) {\n [name, source] = getNormalizedName(routes, location, branches, basename);\n }\n\n return [name || location.pathname, source];\n}\n\n/**\n * Gets the active root span if it's a pageload or navigation span.\n */\nexport function getActiveRootSpan(): Span | undefined {\n const span = getActiveSpan();\n const rootSpan = span ? getRootSpan(span) : undefined;\n\n if (!rootSpan) {\n return undefined;\n }\n\n const op = spanToJSON(rootSpan).op;\n\n // Only use this root span if it is a pageload or navigation span\n return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;\n}\n"],"names":[],"mappings":";;;;AAMA;AACA,IAAI,YAAY;AAChB,IAAI,cAAc,GAAY,KAAK;;AAEnC;AACA;;AAOA,MAAM,uBAAuB,GAAwB,EAAE;AACvD,MAAM,sBAAA,GAAyB,EAAE;;AAEjC;AACA;AACA;AACA;AACO,SAAS,oBAAoB,CAAC,UAAU,EAAsB,IAAI,EAA4B;AACrG,EAAE,MAAM,KAAA,GAAQ,EAAE;AAClB;AACA,EAAE,IAAI,uBAAuB,CAAC,MAAA,IAAU,sBAAsB,EAAE;AAChE,IAAI,eAAe,KAAK,CAAC,IAAI,CAAC,4EAA4E,CAAC;AAC3G,IAAI,uBAAuB,CAAC,KAAK,EAAE;AACnC,EAAE;AACF,EAAE,uBAAuB,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,IAAA,EAAM,CAAC;AAC3D,EAAE,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,sBAAsB,CAAC,KAAK,EAAgB;AAC5D,EAAE,MAAM,GAAA,GAAM,uBAAuB,CAAC,uBAAuB,CAAC,MAAA,GAAS,CAAC,CAAC;AACzE,EAAE,IAAI,GAAG,EA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AA,IAAA,GAAA,WAAA,CAAA,IAAA,CAAA,GAAA,SAAA;;AAEA,EAAA,IAAA,CAAA,QAAA,EAAA;AACA,IAAA,OAAA,SAAA;AACA,EAAA;;AAEA,EAAA,MAAA,EAAA,GAAA,UAAA,CAAA,QAAA,CAAA,CAAA,EAAA;;AAEA;AACA,EAAA,OAAA,EAAA,KAAA,YAAA,IAAA,EAAA,KAAA,UAAA,GAAA,QAAA,GAAA,SAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/reactrouter-compat-utils/utils.ts"],"sourcesContent":["import type { Span, TransactionSource } from '@sentry/core/browser';\nimport { debug, getActiveSpan, getRootSpan, spanToJSON } from '@sentry/core/browser';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { Location, MatchRoutes, RouteMatch, RouteObject } from '../types';\nimport { matchRouteManifest, stripBasenameFromPathname } from './route-manifest';\n\n// Global variables that these utilities depend on\nlet _matchRoutes: MatchRoutes;\nlet _stripBasename: boolean = false;\n\n// Navigation context stack for nested/concurrent patchRoutesOnNavigation calls.\n// Required because window.location hasn't updated yet when handlers are invoked.\ninterface NavigationContext {\n token: object;\n targetPath: string | undefined;\n span: Span | undefined;\n}\n\nconst _navigationContextStack: NavigationContext[] = [];\nconst MAX_CONTEXT_STACK_SIZE = 10;\n\n/**\n * Pushes a navigation context and returns a unique token for cleanup.\n * The token uses object identity for uniqueness (no counter needed).\n */\nexport function setNavigationContext(targetPath: string | undefined, span: Span | undefined): object {\n const token = {};\n // Prevent unbounded stack growth - oldest (likely stale) contexts are evicted first\n if (_navigationContextStack.length >= MAX_CONTEXT_STACK_SIZE) {\n DEBUG_BUILD && debug.warn('[React Router] Navigation context stack overflow - removing oldest context');\n _navigationContextStack.shift();\n }\n _navigationContextStack.push({ token, targetPath, span });\n return token;\n}\n\n/**\n * Clears the navigation context if it's on top of the stack (LIFO).\n * If our context is not on top (out-of-order completion), we leave it -\n * it will be cleaned up by overflow protection when the stack fills up.\n */\nexport function clearNavigationContext(token: object): void {\n const top = _navigationContextStack[_navigationContextStack.length - 1];\n if (top?.token === token) {\n _navigationContextStack.pop();\n }\n}\n\n/** Gets the current (most recent) navigation context if inside a patchRoutesOnNavigation call. */\nexport function getNavigationContext(): NavigationContext | null {\n const length = _navigationContextStack.length;\n // The `?? null` converts undefined (from array access) to null to match return type\n return length > 0 ? (_navigationContextStack[length - 1] ?? null) : null;\n}\n\n/**\n * Initialize function to set dependencies that the router utilities need.\n * Must be called before using any of the exported utility functions.\n */\nexport function initializeRouterUtils(matchRoutes: MatchRoutes, stripBasename: boolean = false): void {\n _matchRoutes = matchRoutes;\n _stripBasename = stripBasename;\n}\n\n// Helper functions\nfunction pickPath(match: RouteMatch): string {\n return trimWildcard(match.route.path || '');\n}\n\nfunction pickSplat(match: RouteMatch): string {\n return match.params['*'] || '';\n}\n\nfunction trimWildcard(path: string): string {\n return path[path.length - 1] === '*' ? path.slice(0, -1) : path;\n}\n\nfunction trimSlash(path: string): string {\n return path[path.length - 1] === '/' ? path.slice(0, -1) : path;\n}\n\n/**\n * Checks if a path ends with a wildcard character (*).\n */\nexport function pathEndsWithWildcard(path: string): boolean {\n return path.endsWith('*');\n}\n\n/** Checks if transaction name has wildcard (/* or ends with *). */\nexport function transactionNameHasWildcard(name: string): boolean {\n return name.includes('/*') || name.endsWith('*');\n}\n\n/**\n * Checks if a path is a wildcard and has child routes.\n */\nexport function pathIsWildcardAndHasChildren(path: string, branch: RouteMatch<string>): boolean {\n return (pathEndsWithWildcard(path) && !!branch.route.children?.length) || false;\n}\n\n/** Check if route is in descendant route (<Routes> within <Routes>) */\nexport function routeIsDescendant(route: RouteObject): boolean {\n return !!(!route.children && route.element && route.path?.endsWith('/*'));\n}\n\nfunction sendIndexPath(pathBuilder: string, pathname: string, basename: string): [string, TransactionSource] {\n const reconstructedPath =\n pathBuilder && pathBuilder.length > 0\n ? pathBuilder\n : _stripBasename\n ? stripBasenameFromPathname(pathname, basename)\n : pathname;\n\n let formattedPath =\n // If the path ends with a wildcard suffix, remove both the slash and the asterisk\n reconstructedPath.slice(-2) === '/*' ? reconstructedPath.slice(0, -2) : reconstructedPath;\n\n // If the path ends with a slash, remove it (but keep single '/')\n if (formattedPath.length > 1 && formattedPath[formattedPath.length - 1] === '/') {\n formattedPath = formattedPath.slice(0, -1);\n }\n\n return [formattedPath, 'route'];\n}\n\n/**\n * Returns the number of URL segments in the given URL string.\n * Splits at '/' or '\\/' to handle regex URLs correctly.\n *\n * @param url - The URL string to segment.\n * @returns The number of segments in the URL.\n */\nexport function getNumberOfUrlSegments(url: string): number {\n // split at '/' or at '\\/' to split regex urls correctly\n return url.split(/\\\\?\\//).filter(s => s.length > 0 && s !== ',').length;\n}\n\n// Exported utility functions\n\n/**\n * Ensures a path string starts with a forward slash.\n */\nexport function prefixWithSlash(path: string): string {\n return path[0] === '/' ? path : `/${path}`;\n}\n\n/**\n * Rebuilds the route path from all available routes by matching against the current location.\n */\nexport function rebuildRoutePathFromAllRoutes(allRoutes: RouteObject[], location: Location): string {\n const matchedRoutes = _matchRoutes(allRoutes, location) as RouteMatch[];\n\n if (!matchedRoutes || matchedRoutes.length === 0) {\n return '';\n }\n\n for (const match of matchedRoutes) {\n if (match.route.path && match.route.path !== '*') {\n const path = pickPath(match);\n const strippedPath = stripBasenameFromPathname(location.pathname, prefixWithSlash(match.pathnameBase));\n\n if (location.pathname === strippedPath) {\n return trimSlash(strippedPath);\n }\n\n return trimSlash(\n trimSlash(path || '') +\n prefixWithSlash(\n rebuildRoutePathFromAllRoutes(\n allRoutes.filter(route => route !== match.route),\n {\n pathname: strippedPath,\n },\n ),\n ),\n );\n }\n }\n\n return '';\n}\n\n/**\n * Checks if the current location is inside a descendant route (route with splat parameter).\n */\nexport function locationIsInsideDescendantRoute(location: Location, routes: RouteObject[]): boolean {\n const matchedRoutes = _matchRoutes(routes, location) as RouteMatch[];\n\n if (matchedRoutes) {\n for (const match of matchedRoutes) {\n if (routeIsDescendant(match.route) && pickSplat(match)) {\n return true;\n }\n }\n }\n\n return false;\n}\n\n/**\n * Returns a fallback transaction name from location pathname.\n */\nfunction getFallbackTransactionName(location: Location, basename: string): string {\n return _stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname || '';\n}\n\n/**\n * Gets a normalized route name and transaction source from the current routes and location.\n */\nexport function getNormalizedName(\n routes: RouteObject[],\n location: Location,\n branches: RouteMatch[],\n basename: string = '',\n): [string, TransactionSource] {\n if (!routes || routes.length === 0) {\n return [_stripBasename ? stripBasenameFromPathname(location.pathname, basename) : location.pathname, 'url'];\n }\n\n if (!branches) {\n return [getFallbackTransactionName(location, basename), 'url'];\n }\n\n let pathBuilder = '';\n\n for (const branch of branches) {\n const route = branch.route;\n if (!route) {\n continue;\n }\n\n // Early return for index routes\n if (route.index) {\n return sendIndexPath(pathBuilder, branch.pathname, basename);\n }\n\n const path = route.path;\n if (!path || pathIsWildcardAndHasChildren(path, branch)) {\n continue;\n }\n\n // Build the route path\n const newPath = path[0] === '/' || pathBuilder[pathBuilder.length - 1] === '/' ? path : `/${path}`;\n pathBuilder = trimSlash(pathBuilder) + prefixWithSlash(newPath);\n\n // Check if this path matches the current location\n if (trimSlash(location.pathname) !== trimSlash(basename + branch.pathname)) {\n continue;\n }\n\n // Check if this is a parameterized route like /stores/:storeId/products/:productId\n if (\n getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&\n !pathEndsWithWildcard(pathBuilder)\n ) {\n return [(_stripBasename ? '' : basename) + newPath, 'route'];\n }\n\n // Handle wildcard routes with children - strip trailing wildcard\n if (pathIsWildcardAndHasChildren(pathBuilder, branch)) {\n pathBuilder = pathBuilder.slice(0, -1);\n }\n\n return [(_stripBasename ? '' : basename) + pathBuilder, 'route'];\n }\n\n // Fallback when no matching route found\n return [getFallbackTransactionName(location, basename), 'url'];\n}\n\n/**\n * Shared helper function to resolve route name and source\n */\nexport function resolveRouteNameAndSource(\n location: Location,\n routes: RouteObject[],\n allRoutes: RouteObject[],\n branches: RouteMatch[],\n basename: string = '',\n lazyRouteManifest?: string[],\n enableAsyncRouteHandlers?: boolean,\n): [string, TransactionSource] {\n // When lazy route manifest is provided, use it as the primary source for transaction names\n if (enableAsyncRouteHandlers && lazyRouteManifest && lazyRouteManifest.length > 0) {\n const manifestMatch = matchRouteManifest(location.pathname, lazyRouteManifest, basename);\n if (manifestMatch) {\n return [(_stripBasename ? '' : basename) + manifestMatch, 'route'];\n }\n }\n\n // Fall back to React Router route matching\n let name: string | undefined;\n let source: TransactionSource = 'url';\n\n const isInDescendantRoute = locationIsInsideDescendantRoute(location, allRoutes);\n\n if (isInDescendantRoute) {\n name = prefixWithSlash(rebuildRoutePathFromAllRoutes(allRoutes, location));\n source = 'route';\n }\n\n if (!isInDescendantRoute || !name) {\n [name, source] = getNormalizedName(routes, location, branches, basename);\n }\n\n return [name || location.pathname, source];\n}\n\n/**\n * Gets the active root span if it's a pageload or navigation span.\n */\nexport function getActiveRootSpan(): Span | undefined {\n const span = getActiveSpan();\n const rootSpan = span ? getRootSpan(span) : undefined;\n\n if (!rootSpan) {\n return undefined;\n }\n\n const op = spanToJSON(rootSpan).op;\n\n // Only use this root span if it is a pageload or navigation span\n return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;\n}\n"],"names":[],"mappings":";;;;AAOA,IAAI,YAAA;AACJ,IAAI,cAAA,GAA0B,KAAA;AAU9B,MAAM,0BAA+C,EAAC;AACtD,MAAM,sBAAA,GAAyB,EAAA;AAMxB,SAAS,oBAAA,CAAqB,YAAgC,IAAA,EAAgC;AACnG,EAAA,MAAM,QAAQ,EAAC;AAEf,EAAA,IAAI,uBAAA,CAAwB,UAAU,sBAAA,EAAwB;AAC5D,IAAA,WAAA,IAAe,KAAA,CAAM,KAAK,4EAA4E,CAAA;AACtG,IAAA,uBAAA,CAAwB,KAAA,EAAM;AAAA,EAChC;AACA,EAAA,uBAAA,CAAwB,IAAA,CAAK,EAAE,KAAA,EAAO,UAAA,EAAY,MAAM,CAAA;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Ae;AACjB,MAAA,OAAO,CAAA,CAAE,cAAA,GAAiB,EAAA,GAAK,QAAA,IAAY,eAAe,OAAO,CAAA;AAAA,IACnE;AAAA,EACF;AAGA,EAAA,IAAI,IAAA;AACJ,EAAA,IAAI,MAAA,GAA4B,KAAA;AAEhC,EAAA,MAAM,mBAAA,GAAsB,+BAAA,CAAgC,QAAA,EAAU,SAAS,CAAA;AAE/E,EAAA,IAAI,mBAAA,EAAqB;AACvB,IAAA,IAAA,GAAO,eAAA,CAAgB,6BAAA,CAA8B,SAAA,EAAW,QAAQ,CAAC,CAAA;AACzE,IAAA,MAAA,GAAS,OAAA;AAAA,EACX;AAEA,EAAA,IAAI,CAAC,mBAAA,IAAuB,CAAC,IAAA,EAAM;AACjC,IAAA,CAAC,MAAM,MAAM,CAAA,GAAI,kBAAkB,MAAA,EAAQ,QAAA,EAAU,UAAU,QAAQ,CAAA;AAAA,EACzE;AAEA,EAAA,OAAO,CAAC,IAAA,IAAQ,QAAA,CAAS,QAAA,EAAU,MAAM,CAAA;AAC3C;AAKO,SAAS,iBAAA,GAAsC;AACpD,EAAA,MAAM,OAAO,aAAA,EAAc;AAC3B,EAAA,MAAM,QAAA,GAAW,IAAA,GAAO,WAAA,CAAY,IAAI,CAAA,GAAI,MAAA;AAE5C,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,EAAA,GAAK,UAAA,CAAW,QAAQ,CAAA,CAAE,EAAA;AAGhC,EAAA,OAAO,EAAA,KAAO,YAAA,IAAgB,EAAA,KAAO,UAAA,GAAa,QAAA,GAAW,MAAA;AAC/D;;;;"}
|
package/build/esm/reactrouter.js
CHANGED
|
@@ -3,117 +3,74 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEM
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { hoistNonReactStatics } from './hoist-non-react-statics.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
// react-router typings.
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A browser tracing integration that uses React Router v4 to instrument navigations.
|
|
11
|
-
* Expects `history` (and optionally `routes` and `matchPath`) to be passed as options.
|
|
12
|
-
*/
|
|
13
|
-
function reactRouterV4BrowserTracingIntegration(
|
|
14
|
-
options,
|
|
15
|
-
) {
|
|
6
|
+
function reactRouterV4BrowserTracingIntegration(options) {
|
|
16
7
|
const integration = browserTracingIntegration({
|
|
17
8
|
...options,
|
|
18
9
|
instrumentPageLoad: false,
|
|
19
|
-
instrumentNavigation: false
|
|
10
|
+
instrumentNavigation: false
|
|
20
11
|
});
|
|
21
|
-
|
|
22
12
|
const { history, routes, matchPath, instrumentPageLoad = true, instrumentNavigation = true } = options;
|
|
23
|
-
|
|
24
13
|
return {
|
|
25
14
|
...integration,
|
|
26
15
|
afterAllSetup(client) {
|
|
27
16
|
integration.afterAllSetup(client);
|
|
28
|
-
|
|
29
17
|
instrumentReactRouter(
|
|
30
18
|
client,
|
|
31
19
|
instrumentPageLoad,
|
|
32
20
|
instrumentNavigation,
|
|
33
21
|
history,
|
|
34
|
-
|
|
22
|
+
"reactrouter_v4",
|
|
35
23
|
routes,
|
|
36
|
-
matchPath
|
|
24
|
+
matchPath
|
|
37
25
|
);
|
|
38
|
-
}
|
|
26
|
+
}
|
|
39
27
|
};
|
|
40
28
|
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* A browser tracing integration that uses React Router v5 to instrument navigations.
|
|
44
|
-
* Expects `history` (and optionally `routes` and `matchPath`) to be passed as options.
|
|
45
|
-
*/
|
|
46
|
-
function reactRouterV5BrowserTracingIntegration(
|
|
47
|
-
options,
|
|
48
|
-
) {
|
|
29
|
+
function reactRouterV5BrowserTracingIntegration(options) {
|
|
49
30
|
const integration = browserTracingIntegration({
|
|
50
31
|
...options,
|
|
51
32
|
instrumentPageLoad: false,
|
|
52
|
-
instrumentNavigation: false
|
|
33
|
+
instrumentNavigation: false
|
|
53
34
|
});
|
|
54
|
-
|
|
55
35
|
const { history, routes, matchPath, instrumentPageLoad = true, instrumentNavigation = true } = options;
|
|
56
|
-
|
|
57
36
|
return {
|
|
58
37
|
...integration,
|
|
59
38
|
afterAllSetup(client) {
|
|
60
39
|
integration.afterAllSetup(client);
|
|
61
|
-
|
|
62
40
|
instrumentReactRouter(
|
|
63
41
|
client,
|
|
64
42
|
instrumentPageLoad,
|
|
65
43
|
instrumentNavigation,
|
|
66
44
|
history,
|
|
67
|
-
|
|
45
|
+
"reactrouter_v5",
|
|
68
46
|
routes,
|
|
69
|
-
matchPath
|
|
47
|
+
matchPath
|
|
70
48
|
);
|
|
71
|
-
}
|
|
49
|
+
}
|
|
72
50
|
};
|
|
73
51
|
}
|
|
74
|
-
|
|
75
|
-
function instrumentReactRouter(
|
|
76
|
-
client,
|
|
77
|
-
instrumentPageLoad,
|
|
78
|
-
instrumentNavigation,
|
|
79
|
-
history,
|
|
80
|
-
instrumentationName,
|
|
81
|
-
allRoutes = [],
|
|
82
|
-
matchPath,
|
|
83
|
-
) {
|
|
52
|
+
function instrumentReactRouter(client, instrumentPageLoad, instrumentNavigation, history, instrumentationName, allRoutes = [], matchPath) {
|
|
84
53
|
function getInitPathName() {
|
|
85
54
|
if (history.location) {
|
|
86
55
|
return history.location.pathname;
|
|
87
56
|
}
|
|
88
|
-
|
|
89
57
|
if (WINDOW.location) {
|
|
90
58
|
return WINDOW.location.pathname;
|
|
91
59
|
}
|
|
92
|
-
|
|
93
|
-
return undefined;
|
|
60
|
+
return void 0;
|
|
94
61
|
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Normalizes a transaction name. Returns the new name as well as the
|
|
98
|
-
* source of the transaction.
|
|
99
|
-
*
|
|
100
|
-
* @param pathname The initial pathname we normalize
|
|
101
|
-
*/
|
|
102
62
|
function normalizeTransactionName(pathname) {
|
|
103
63
|
if (allRoutes.length === 0 || !matchPath) {
|
|
104
|
-
return [pathname,
|
|
64
|
+
return [pathname, "url"];
|
|
105
65
|
}
|
|
106
|
-
|
|
107
66
|
const branches = matchRoutes(allRoutes, pathname, matchPath);
|
|
108
67
|
for (const branch of branches) {
|
|
109
68
|
if (branch.match.isExact) {
|
|
110
|
-
return [branch.match.path,
|
|
69
|
+
return [branch.match.path, "route"];
|
|
111
70
|
}
|
|
112
71
|
}
|
|
113
|
-
|
|
114
|
-
return [pathname, 'url'];
|
|
72
|
+
return [pathname, "url"];
|
|
115
73
|
}
|
|
116
|
-
|
|
117
74
|
if (instrumentPageLoad) {
|
|
118
75
|
const initPathName = getInitPathName();
|
|
119
76
|
if (initPathName) {
|
|
@@ -121,111 +78,74 @@ function instrumentReactRouter(
|
|
|
121
78
|
startBrowserTracingPageLoadSpan(client, {
|
|
122
79
|
name,
|
|
123
80
|
attributes: {
|
|
124
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]:
|
|
81
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: "pageload",
|
|
125
82
|
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: `auto.pageload.react.${instrumentationName}`,
|
|
126
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source
|
|
127
|
-
}
|
|
83
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source
|
|
84
|
+
}
|
|
128
85
|
});
|
|
129
86
|
}
|
|
130
87
|
}
|
|
131
|
-
|
|
132
88
|
if (instrumentNavigation && history.listen) {
|
|
133
89
|
history.listen((location, action) => {
|
|
134
|
-
if (action && (action ===
|
|
90
|
+
if (action && (action === "PUSH" || action === "POP")) {
|
|
135
91
|
const [name, source] = normalizeTransactionName(location.pathname);
|
|
136
92
|
startBrowserTracingNavigationSpan(client, {
|
|
137
93
|
name,
|
|
138
94
|
attributes: {
|
|
139
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]:
|
|
95
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
|
|
140
96
|
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: `auto.navigation.react.${instrumentationName}`,
|
|
141
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source
|
|
142
|
-
}
|
|
97
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source
|
|
98
|
+
}
|
|
143
99
|
});
|
|
144
100
|
}
|
|
145
101
|
});
|
|
146
102
|
}
|
|
147
103
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
routes,
|
|
155
|
-
pathname,
|
|
156
|
-
matchPath,
|
|
157
|
-
branch = [],
|
|
158
|
-
) {
|
|
159
|
-
routes.some(route => {
|
|
160
|
-
const match = route.path
|
|
161
|
-
? matchPath(pathname, route)
|
|
162
|
-
: branch.length
|
|
163
|
-
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
164
|
-
branch[branch.length - 1].match // use parent match
|
|
165
|
-
: computeRootMatch(pathname); // use default "root" match
|
|
166
|
-
|
|
104
|
+
function matchRoutes(routes, pathname, matchPath, branch = []) {
|
|
105
|
+
routes.some((route) => {
|
|
106
|
+
const match = route.path ? matchPath(pathname, route) : branch.length ? (
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
108
|
+
branch[branch.length - 1].match
|
|
109
|
+
) : computeRootMatch(pathname);
|
|
167
110
|
if (match) {
|
|
168
111
|
branch.push({ route, match });
|
|
169
|
-
|
|
170
112
|
if (route.routes) {
|
|
171
113
|
matchRoutes(route.routes, pathname, matchPath, branch);
|
|
172
114
|
}
|
|
173
115
|
}
|
|
174
|
-
|
|
175
116
|
return !!match;
|
|
176
117
|
});
|
|
177
|
-
|
|
178
118
|
return branch;
|
|
179
119
|
}
|
|
180
|
-
|
|
181
120
|
function computeRootMatch(pathname) {
|
|
182
|
-
return { path:
|
|
121
|
+
return { path: "/", url: "/", params: {}, isExact: pathname === "/" };
|
|
183
122
|
}
|
|
184
|
-
|
|
185
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
|
|
186
123
|
function withSentryRouting(Route) {
|
|
187
124
|
const componentDisplayName = Route.displayName || Route.name;
|
|
188
|
-
|
|
189
125
|
const WrappedRoute = (props) => {
|
|
190
126
|
if (props?.computedMatch?.isExact) {
|
|
191
127
|
const route = props.computedMatch.path;
|
|
192
128
|
const activeRootSpan = getActiveRootSpan();
|
|
193
|
-
|
|
194
129
|
getCurrentScope().setTransactionName(route);
|
|
195
|
-
|
|
196
130
|
if (activeRootSpan) {
|
|
197
131
|
activeRootSpan.updateName(route);
|
|
198
|
-
activeRootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
|
|
132
|
+
activeRootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, "route");
|
|
199
133
|
}
|
|
200
134
|
}
|
|
201
|
-
|
|
202
|
-
// @ts-expect-error Setting more specific React Component typing for `R` generic above
|
|
203
|
-
// will break advanced type inference done by react router params:
|
|
204
|
-
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
|
|
205
|
-
return React.createElement(Route, { ...props,} );
|
|
135
|
+
return /* @__PURE__ */ React.createElement(Route, { ...props });
|
|
206
136
|
};
|
|
207
|
-
|
|
208
137
|
WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;
|
|
209
138
|
hoistNonReactStatics(WrappedRoute, Route);
|
|
210
|
-
// @ts-expect-error Setting more specific React Component typing for `R` generic above
|
|
211
|
-
// will break advanced type inference done by react router params:
|
|
212
|
-
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
|
|
213
139
|
return WrappedRoute;
|
|
214
140
|
}
|
|
215
|
-
/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
|
|
216
|
-
|
|
217
141
|
function getActiveRootSpan() {
|
|
218
142
|
const span = getActiveSpan();
|
|
219
143
|
const rootSpan = span && getRootSpan(span);
|
|
220
|
-
|
|
221
144
|
if (!rootSpan) {
|
|
222
|
-
return
|
|
145
|
+
return void 0;
|
|
223
146
|
}
|
|
224
|
-
|
|
225
147
|
const op = spanToJSON(rootSpan).op;
|
|
226
|
-
|
|
227
|
-
// Only use this root span if it is a pageload or navigation span
|
|
228
|
-
return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;
|
|
148
|
+
return op === "navigation" || op === "pageload" ? rootSpan : void 0;
|
|
229
149
|
}
|
|
230
150
|
|
|
231
151
|
export { reactRouterV4BrowserTracingIntegration, reactRouterV5BrowserTracingIntegration, withSentryRouting };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouter.js","sources":["../../src/reactrouter.tsx"],"sourcesContent":["import {\n browserTracingIntegration,\n startBrowserTracingNavigationSpan,\n startBrowserTracingPageLoadSpan,\n WINDOW,\n} from '@sentry/browser';\nimport type { Client, Integration, Span, TransactionSource } from '@sentry/core';\nimport {\n getActiveSpan,\n getCurrentScope,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n} from '@sentry/core';\nimport type { ReactElement } from 'react';\nimport * as React from 'react';\nimport { hoistNonReactStatics } from './hoist-non-react-statics';\nimport type { Action, Location } from './types';\n\n// We need to disable eslint no-explicit-any because any is required for the\n// react-router typings.\ntype Match = { path: string; url: string; params: Record<string, any>; isExact: boolean }; // eslint-disable-line @typescript-eslint/no-explicit-any\n\nexport type RouterHistory = {\n location?: Location;\n listen?(cb: (location: Location, action: Action) => void): void;\n} & Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n\nexport type RouteConfig = {\n [propName: string]: unknown;\n path?: string | string[];\n exact?: boolean;\n component?: ReactElement;\n routes?: RouteConfig[];\n};\n\nexport type MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null; // eslint-disable-line @typescript-eslint/no-explicit-any\n\ninterface ReactRouterOptions {\n history: RouterHistory;\n routes?: RouteConfig[];\n matchPath?: MatchPath;\n}\n\n/**\n * A browser tracing integration that uses React Router v4 to instrument navigations.\n * Expects `history` (and optionally `routes` and `matchPath`) to be passed as options.\n */\nexport function reactRouterV4BrowserTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0] & ReactRouterOptions,\n): Integration {\n const integration = browserTracingIntegration({\n ...options,\n instrumentPageLoad: false,\n instrumentNavigation: false,\n });\n\n const { history, routes, matchPath, instrumentPageLoad = true, instrumentNavigation = true } = options;\n\n return {\n ...integration,\n afterAllSetup(client) {\n integration.afterAllSetup(client);\n\n instrumentReactRouter(\n client,\n instrumentPageLoad,\n instrumentNavigation,\n history,\n 'reactrouter_v4',\n routes,\n matchPath,\n );\n },\n };\n}\n\n/**\n * A browser tracing integration that uses React Router v5 to instrument navigations.\n * Expects `history` (and optionally `routes` and `matchPath`) to be passed as options.\n */\nexport function reactRouterV5BrowserTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0] & ReactRouterOptions,\n): Integration {\n const integration = browserTracingIntegration({\n ...options,\n instrumentPageLoad: false,\n instrumentNavigation: false,\n });\n\n const { history, routes, matchPath, instrumentPageLoad = true, instrumentNavigation = true } = options;\n\n return {\n ...integration,\n afterAllSetup(client) {\n integration.afterAllSetup(client);\n\n instrumentReactRouter(\n client,\n instrumentPageLoad,\n instrumentNavigation,\n history,\n 'reactrouter_v5',\n routes,\n matchPath,\n );\n },\n };\n}\n\nfunction instrumentReactRouter(\n client: Client,\n instrumentPageLoad: boolean,\n instrumentNavigation: boolean,\n history: RouterHistory,\n instrumentationName: string,\n allRoutes: RouteConfig[] = [],\n matchPath?: MatchPath,\n): void {\n function getInitPathName(): string | undefined {\n if (history.location) {\n return history.location.pathname;\n }\n\n if (WINDOW.location) {\n return WINDOW.location.pathname;\n }\n\n return undefined;\n }\n\n /**\n * Normalizes a transaction name. Returns the new name as well as the\n * source of the transaction.\n *\n * @param pathname The initial pathname we normalize\n */\n function normalizeTransactionName(pathname: string): [string, TransactionSource] {\n if (allRoutes.length === 0 || !matchPath) {\n return [pathname, 'url'];\n }\n\n const branches = matchRoutes(allRoutes, pathname, matchPath);\n for (const branch of branches) {\n if (branch.match.isExact) {\n return [branch.match.path, 'route'];\n }\n }\n\n return [pathname, 'url'];\n }\n\n if (instrumentPageLoad) {\n const initPathName = getInitPathName();\n if (initPathName) {\n const [name, source] = normalizeTransactionName(initPathName);\n startBrowserTracingPageLoadSpan(client, {\n name,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: `auto.pageload.react.${instrumentationName}`,\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n },\n });\n }\n }\n\n if (instrumentNavigation && history.listen) {\n history.listen((location, action) => {\n if (action && (action === 'PUSH' || action === 'POP')) {\n const [name, source] = normalizeTransactionName(location.pathname);\n startBrowserTracingNavigationSpan(client, {\n name,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: `auto.navigation.react.${instrumentationName}`,\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n },\n });\n }\n });\n }\n}\n\n/**\n * Matches a set of routes to a pathname\n * Based on implementation from\n */\nfunction matchRoutes(\n routes: RouteConfig[],\n pathname: string,\n matchPath: MatchPath,\n branch: Array<{ route: RouteConfig; match: Match }> = [],\n): Array<{ route: RouteConfig; match: Match }> {\n routes.some(route => {\n const match = route.path\n ? matchPath(pathname, route)\n : branch.length\n ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n branch[branch.length - 1]!.match // use parent match\n : computeRootMatch(pathname); // use default \"root\" match\n\n if (match) {\n branch.push({ route, match });\n\n if (route.routes) {\n matchRoutes(route.routes, pathname, matchPath, branch);\n }\n }\n\n return !!match;\n });\n\n return branch;\n}\n\nfunction computeRootMatch(pathname: string): Match {\n return { path: '/', url: '/', params: {}, isExact: pathname === '/' };\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\nexport function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {\n const componentDisplayName = Route.displayName || Route.name;\n\n const WrappedRoute: React.FC<P> = (props: P) => {\n if (props?.computedMatch?.isExact) {\n const route = props.computedMatch.path;\n const activeRootSpan = getActiveRootSpan();\n\n getCurrentScope().setTransactionName(route);\n\n if (activeRootSpan) {\n activeRootSpan.updateName(route);\n activeRootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');\n }\n }\n\n // @ts-expect-error Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return <Route {...props} />;\n };\n\n WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;\n hoistNonReactStatics(WrappedRoute, Route);\n // @ts-expect-error Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return WrappedRoute;\n}\n/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\n\nfunction getActiveRootSpan(): Span | undefined {\n const span = getActiveSpan();\n const rootSpan = span && getRootSpan(span);\n\n if (!rootSpan) {\n return undefined;\n }\n\n const op = spanToJSON(rootSpan).op;\n\n // Only use this root span if it is a pageload or navigation span\n return op === 'navigation' || op === 'pageload' ? rootSp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MAAA;AACA,IAAA;;AAEA;AACA;AACA;AACA,IAAA,OAAA,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,GAAA,KAAA,EAAA,EAAA;AACA,EAAA,CAAA;;AAEA,EAAA,YAAA,CAAA,WAAA,GAAA,CAAA,YAAA,EAAA,oBAAA,CAAA,CAAA,CAAA;AACA,EAAA,oBAAA,CAAA,YAAA,EAAA,KAAA,CAAA;AACA;AACA;AACA;AACA,EAAA,OAAA,YAAA;AACA;AACA;;AAEA,SAAA,iBAAA,GAAA;AACA,EAAA,MAAA,IAAA,GAAA,aAAA,EAAA;AACA,EAAA,MAAA,QAAA,GAAA,IAAA,IAAA,WAAA,CAAA,IAAA,CAAA;;AAEA,EAAA,IAAA,CAAA,QAAA,EAAA;AACA,IAAA,OAAA,SAAA;AACA,EAAA;;AAEA,EAAA,MAAA,EAAA,GAAA,UAAA,CAAA,QAAA,CAAA,CAAA,EAAA;;AAEA;AACA,EAAA,OAAA,EAAA,KAAA,YAAA,IAAA,EAAA,KAAA,UAAA,GAAA,QAAA,GAAA,SAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"reactrouter.js","sources":["../../src/reactrouter.tsx"],"sourcesContent":["import {\n browserTracingIntegration,\n startBrowserTracingNavigationSpan,\n startBrowserTracingPageLoadSpan,\n WINDOW,\n} from '@sentry/browser';\nimport type { Client, Integration, Span, TransactionSource } from '@sentry/core';\nimport {\n getActiveSpan,\n getCurrentScope,\n getRootSpan,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n} from '@sentry/core';\nimport type { ReactElement } from 'react';\nimport * as React from 'react';\nimport { hoistNonReactStatics } from './hoist-non-react-statics';\nimport type { Action, Location } from './types';\n\n// We need to disable eslint no-explicit-any because any is required for the\n// react-router typings.\ntype Match = { path: string; url: string; params: Record<string, any>; isExact: boolean }; // eslint-disable-line @typescript-eslint/no-explicit-any\n\nexport type RouterHistory = {\n location?: Location;\n listen?(cb: (location: Location, action: Action) => void): void;\n} & Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n\nexport type RouteConfig = {\n [propName: string]: unknown;\n path?: string | string[];\n exact?: boolean;\n component?: ReactElement;\n routes?: RouteConfig[];\n};\n\nexport type MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null; // eslint-disable-line @typescript-eslint/no-explicit-any\n\ninterface ReactRouterOptions {\n history: RouterHistory;\n routes?: RouteConfig[];\n matchPath?: MatchPath;\n}\n\n/**\n * A browser tracing integration that uses React Router v4 to instrument navigations.\n * Expects `history` (and optionally `routes` and `matchPath`) to be passed as options.\n */\nexport function reactRouterV4BrowserTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0] & ReactRouterOptions,\n): Integration {\n const integration = browserTracingIntegration({\n ...options,\n instrumentPageLoad: false,\n instrumentNavigation: false,\n });\n\n const { history, routes, matchPath, instrumentPageLoad = true, instrumentNavigation = true } = options;\n\n return {\n ...integration,\n afterAllSetup(client) {\n integration.afterAllSetup(client);\n\n instrumentReactRouter(\n client,\n instrumentPageLoad,\n instrumentNavigation,\n history,\n 'reactrouter_v4',\n routes,\n matchPath,\n );\n },\n };\n}\n\n/**\n * A browser tracing integration that uses React Router v5 to instrument navigations.\n * Expects `history` (and optionally `routes` and `matchPath`) to be passed as options.\n */\nexport function reactRouterV5BrowserTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0] & ReactRouterOptions,\n): Integration {\n const integration = browserTracingIntegration({\n ...options,\n instrumentPageLoad: false,\n instrumentNavigation: false,\n });\n\n const { history, routes, matchPath, instrumentPageLoad = true, instrumentNavigation = true } = options;\n\n return {\n ...integration,\n afterAllSetup(client) {\n integration.afterAllSetup(client);\n\n instrumentReactRouter(\n client,\n instrumentPageLoad,\n instrumentNavigation,\n history,\n 'reactrouter_v5',\n routes,\n matchPath,\n );\n },\n };\n}\n\nfunction instrumentReactRouter(\n client: Client,\n instrumentPageLoad: boolean,\n instrumentNavigation: boolean,\n history: RouterHistory,\n instrumentationName: string,\n allRoutes: RouteConfig[] = [],\n matchPath?: MatchPath,\n): void {\n function getInitPathName(): string | undefined {\n if (history.location) {\n return history.location.pathname;\n }\n\n if (WINDOW.location) {\n return WINDOW.location.pathname;\n }\n\n return undefined;\n }\n\n /**\n * Normalizes a transaction name. Returns the new name as well as the\n * source of the transaction.\n *\n * @param pathname The initial pathname we normalize\n */\n function normalizeTransactionName(pathname: string): [string, TransactionSource] {\n if (allRoutes.length === 0 || !matchPath) {\n return [pathname, 'url'];\n }\n\n const branches = matchRoutes(allRoutes, pathname, matchPath);\n for (const branch of branches) {\n if (branch.match.isExact) {\n return [branch.match.path, 'route'];\n }\n }\n\n return [pathname, 'url'];\n }\n\n if (instrumentPageLoad) {\n const initPathName = getInitPathName();\n if (initPathName) {\n const [name, source] = normalizeTransactionName(initPathName);\n startBrowserTracingPageLoadSpan(client, {\n name,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: `auto.pageload.react.${instrumentationName}`,\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n },\n });\n }\n }\n\n if (instrumentNavigation && history.listen) {\n history.listen((location, action) => {\n if (action && (action === 'PUSH' || action === 'POP')) {\n const [name, source] = normalizeTransactionName(location.pathname);\n startBrowserTracingNavigationSpan(client, {\n name,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: `auto.navigation.react.${instrumentationName}`,\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n },\n });\n }\n });\n }\n}\n\n/**\n * Matches a set of routes to a pathname\n * Based on implementation from\n */\nfunction matchRoutes(\n routes: RouteConfig[],\n pathname: string,\n matchPath: MatchPath,\n branch: Array<{ route: RouteConfig; match: Match }> = [],\n): Array<{ route: RouteConfig; match: Match }> {\n routes.some(route => {\n const match = route.path\n ? matchPath(pathname, route)\n : branch.length\n ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n branch[branch.length - 1]!.match // use parent match\n : computeRootMatch(pathname); // use default \"root\" match\n\n if (match) {\n branch.push({ route, match });\n\n if (route.routes) {\n matchRoutes(route.routes, pathname, matchPath, branch);\n }\n }\n\n return !!match;\n });\n\n return branch;\n}\n\nfunction computeRootMatch(pathname: string): Match {\n return { path: '/', url: '/', params: {}, isExact: pathname === '/' };\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\nexport function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {\n const componentDisplayName = Route.displayName || Route.name;\n\n const WrappedRoute: React.FC<P> = (props: P) => {\n if (props?.computedMatch?.isExact) {\n const route = props.computedMatch.path;\n const activeRootSpan = getActiveRootSpan();\n\n getCurrentScope().setTransactionName(route);\n\n if (activeRootSpan) {\n activeRootSpan.updateName(route);\n activeRootSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');\n }\n }\n\n // @ts-expect-error Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return <Route {...props} />;\n };\n\n WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;\n hoistNonReactStatics(WrappedRoute, Route);\n // @ts-expect-error Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return WrappedRoute;\n}\n/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\n\nfunction getActiveRootSpan(): Span | undefined {\n const span = getActiveSpan();\n const rootSpan = span && getRootSpan(span);\n\n if (!rootSpan) {\n return undefined;\n }\n\n const op = spanToJSON(rootSpan).op;\n\n // Only use this root span if it is a pageload or navigation span\n return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;\n}\n"],"names":[],"mappings":";;;;;AAkDO,SAAS,uCACd,OAAA,EACa;AACb,EAAA,MAAM,cAAc,yBAAA,CAA0B;AAAA,IAC5C,GAAG,OAAA;AAAA,IACH,kBAAA,EAAoB,KAAA;AAAA,IACpB,oBAAA,EAAsB;AAAA,GACvB,CAAA;AAED,EAAA,MAAM,EAAE,SAAS,MAAA,EAAQ,SAAA,EAAW,qBAAqB,IAAA,EAAM,oBAAA,GAAuB,MAAK,GAAI,OAAA;AAE/F,EAAA,OAAO;AAAA,IACL,GAAG,WAAA;AAAA,IACH,cAAc,MAAA,EAAQ;AACpB,MAAA,WAAA,CAAY,cAAc,MAAM,CAAA;AAEhC,MAAA,qBAAA;AAAA,QACE,MAAA;AAAA,QACA,kBAAA;AAAA,QACA,oBAAA;AAAA,QACA,OAAA;AAAA,QACA,gBAAA;AAAA,QACA,MAAA;AAAA,QACA;AAAA,OACF;AAAA,IACF;AAAA,GACF;AACF;AAMO,SAAS,uCACd,OAAA,EACa;AACb,EAAA,MAAM,cAAc,yBAAA,CAA0B;AAAA,IAC5C,GAAG,OAAA;AAAA,IACH,kBAAA,EAAoB,KAAA;AAAA,IACpB,oBAAA,EAAsB;AAAA,GACvB,CAAA;AAED,EAAA,MAAM,EAAE,SAAS,MAAA,EAAQ,SAAA,EAAW,qBAAqB,IAAA,EAAM,oBAAA,GAAuB,MAAK,GAAI,OAAA;AAE/F,EAAA,OAAO;AAAA,IACL,GAAG,WAAA;AAAA,IACH,cAAc,MAAA,EAAQ;AACpB,MAAA,WAAA,CAAY,cAAc,MAAM,CAAA;AAEhC,MAAA,qBAAA;AAAA,QACE,MAAA;AAAA,QACA,kBAAA;AAAA,QACA,oBAAA;AAAA,QACA,OAAA;AAAA,Q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I,CAAC,QAAA,EAAU;AACb,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,EAAA,GAAK,UAAA,CAAW,QAAQ,CAAA,CAAE,EAAA;AAGhC,EAAA,OAAO,EAAA,KAAO,YAAA,IAAgB,EAAA,KAAO,UAAA,GAAa,QAAA,GAAW,MAAA;AAC/D;;;;"}
|
|
@@ -1,127 +1,95 @@
|
|
|
1
1
|
import { browserTracingIntegration, WINDOW, startBrowserTracingPageLoadSpan, startBrowserTracingNavigationSpan } from '@sentry/browser';
|
|
2
2
|
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core/browser';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
// these types are required for correct functionality.
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A browser tracing integration that uses React Router v3 to instrument navigations.
|
|
9
|
-
* Expects `history` (and optionally `routes` and `matchPath`) to be passed as options.
|
|
10
|
-
*/
|
|
11
|
-
function reactRouterV3BrowserTracingIntegration(
|
|
12
|
-
options,
|
|
13
|
-
) {
|
|
4
|
+
function reactRouterV3BrowserTracingIntegration(options) {
|
|
14
5
|
const integration = browserTracingIntegration({
|
|
15
6
|
...options,
|
|
16
7
|
instrumentPageLoad: false,
|
|
17
|
-
instrumentNavigation: false
|
|
8
|
+
instrumentNavigation: false
|
|
18
9
|
});
|
|
19
|
-
|
|
20
10
|
const { history, routes, match, instrumentPageLoad = true, instrumentNavigation = true } = options;
|
|
21
|
-
|
|
22
11
|
return {
|
|
23
12
|
...integration,
|
|
24
13
|
afterAllSetup(client) {
|
|
25
14
|
integration.afterAllSetup(client);
|
|
26
|
-
|
|
27
15
|
if (instrumentPageLoad && WINDOW.location) {
|
|
28
16
|
normalizeTransactionName(
|
|
29
17
|
routes,
|
|
30
|
-
WINDOW.location
|
|
18
|
+
WINDOW.location,
|
|
31
19
|
match,
|
|
32
|
-
(localName, source =
|
|
20
|
+
(localName, source = "url") => {
|
|
33
21
|
startBrowserTracingPageLoadSpan(client, {
|
|
34
22
|
name: localName,
|
|
35
23
|
attributes: {
|
|
36
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]:
|
|
37
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]:
|
|
38
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source
|
|
39
|
-
}
|
|
24
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: "pageload",
|
|
25
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.pageload.react.reactrouter_v3",
|
|
26
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source
|
|
27
|
+
}
|
|
40
28
|
});
|
|
41
|
-
}
|
|
29
|
+
}
|
|
42
30
|
);
|
|
43
31
|
}
|
|
44
|
-
|
|
45
32
|
if (instrumentNavigation && history.listen) {
|
|
46
|
-
history.listen(location => {
|
|
47
|
-
if (location.action ===
|
|
33
|
+
history.listen((location) => {
|
|
34
|
+
if (location.action === "PUSH" || location.action === "POP") {
|
|
48
35
|
normalizeTransactionName(
|
|
49
36
|
routes,
|
|
50
37
|
location,
|
|
51
38
|
match,
|
|
52
|
-
(localName, source =
|
|
39
|
+
(localName, source = "url") => {
|
|
53
40
|
startBrowserTracingNavigationSpan(client, {
|
|
54
41
|
name: localName,
|
|
55
42
|
attributes: {
|
|
56
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]:
|
|
57
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]:
|
|
58
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source
|
|
59
|
-
}
|
|
43
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
|
|
44
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react.reactrouter_v3",
|
|
45
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source
|
|
46
|
+
}
|
|
60
47
|
});
|
|
61
|
-
}
|
|
48
|
+
}
|
|
62
49
|
);
|
|
63
50
|
}
|
|
64
51
|
});
|
|
65
52
|
}
|
|
66
|
-
}
|
|
53
|
+
}
|
|
67
54
|
};
|
|
68
55
|
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Normalize transaction names using `Router.match`
|
|
72
|
-
*/
|
|
73
|
-
function normalizeTransactionName(
|
|
74
|
-
appRoutes,
|
|
75
|
-
location,
|
|
76
|
-
match,
|
|
77
|
-
callback,
|
|
78
|
-
) {
|
|
56
|
+
function normalizeTransactionName(appRoutes, location, match, callback) {
|
|
79
57
|
let name = location.pathname;
|
|
80
58
|
match(
|
|
81
59
|
{
|
|
82
60
|
location,
|
|
83
|
-
routes: appRoutes
|
|
61
|
+
routes: appRoutes
|
|
84
62
|
},
|
|
85
63
|
(error, _redirectLocation, renderProps) => {
|
|
86
64
|
if (error || !renderProps) {
|
|
87
65
|
return callback(name);
|
|
88
66
|
}
|
|
89
|
-
|
|
90
67
|
const routePath = getRouteStringFromRoutes(renderProps.routes || []);
|
|
91
|
-
if (routePath.length === 0 || routePath ===
|
|
68
|
+
if (routePath.length === 0 || routePath === "/*") {
|
|
92
69
|
return callback(name);
|
|
93
70
|
}
|
|
94
|
-
|
|
95
71
|
name = routePath;
|
|
96
|
-
return callback(name,
|
|
97
|
-
}
|
|
72
|
+
return callback(name, "route");
|
|
73
|
+
}
|
|
98
74
|
);
|
|
99
75
|
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Generate route name from array of routes
|
|
103
|
-
*/
|
|
104
76
|
function getRouteStringFromRoutes(routes) {
|
|
105
77
|
if (!Array.isArray(routes) || routes.length === 0) {
|
|
106
|
-
return
|
|
78
|
+
return "";
|
|
107
79
|
}
|
|
108
|
-
|
|
109
80
|
const routesWithPaths = routes.filter((route) => !!route.path);
|
|
110
|
-
|
|
111
81
|
let index = -1;
|
|
112
82
|
for (let x = routesWithPaths.length - 1; x >= 0; x--) {
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
114
83
|
const route = routesWithPaths[x];
|
|
115
|
-
if (route.path?.startsWith(
|
|
84
|
+
if (route.path?.startsWith("/")) {
|
|
116
85
|
index = x;
|
|
117
86
|
break;
|
|
118
87
|
}
|
|
119
88
|
}
|
|
120
|
-
|
|
121
89
|
return routesWithPaths.slice(index).reduce((acc, { path }) => {
|
|
122
|
-
const pathSegment = acc ===
|
|
90
|
+
const pathSegment = acc === "/" || acc === "" ? path : `/${path}`;
|
|
123
91
|
return `${acc}${pathSegment}`;
|
|
124
|
-
},
|
|
92
|
+
}, "");
|
|
125
93
|
}
|
|
126
94
|
|
|
127
95
|
export { reactRouterV3BrowserTracingIntegration };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouterv3.js","sources":["../../src/reactrouterv3.ts"],"sourcesContent":["import {\n browserTracingIntegration,\n startBrowserTracingNavigationSpan,\n startBrowserTracingPageLoadSpan,\n WINDOW,\n} from '@sentry/browser';\nimport type { Integration, TransactionSource } from '@sentry/core/browser';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n} from '@sentry/core/browser';\nimport type { Location } from './types';\n\n// Many of the types below had to be mocked out to prevent typescript issues\n// these types are required for correct functionality.\n\ntype HistoryV3 = {\n location?: Location;\n listen?(cb: (location: Location) => void): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport type Route = { path?: string; childRoutes?: Route[] };\n\nexport type Match = (\n props: { location: Location; routes: Route[] },\n cb: (error?: Error, _redirectLocation?: Location, renderProps?: { routes?: Route[] }) => void,\n) => void;\n\ntype ReactRouterV3TransactionSource = Extract<TransactionSource, 'url' | 'route'>;\n\ninterface ReactRouterOptions {\n history: HistoryV3;\n routes: Route[];\n match: Match;\n}\n\n/**\n * A browser tracing integration that uses React Router v3 to instrument navigations.\n * Expects `history` (and optionally `routes` and `matchPath`) to be passed as options.\n */\nexport function reactRouterV3BrowserTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0] & ReactRouterOptions,\n): Integration {\n const integration = browserTracingIntegration({\n ...options,\n instrumentPageLoad: false,\n instrumentNavigation: false,\n });\n\n const { history, routes, match, instrumentPageLoad = true, instrumentNavigation = true } = options;\n\n return {\n ...integration,\n afterAllSetup(client) {\n integration.afterAllSetup(client);\n\n if (instrumentPageLoad && WINDOW.location) {\n normalizeTransactionName(\n routes,\n WINDOW.location as unknown as Location,\n match,\n (localName: string, source: ReactRouterV3TransactionSource = 'url') => {\n startBrowserTracingPageLoadSpan(client, {\n name: localName,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react.reactrouter_v3',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n },\n });\n },\n );\n }\n\n if (instrumentNavigation && history.listen) {\n history.listen(location => {\n if (location.action === 'PUSH' || location.action === 'POP') {\n normalizeTransactionName(\n routes,\n location,\n match,\n (localName: string, source: TransactionSource = 'url') => {\n startBrowserTracingNavigationSpan(client, {\n name: localName,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.reactrouter_v3',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n },\n });\n },\n );\n }\n });\n }\n },\n };\n}\n\n/**\n * Normalize transaction names using `Router.match`\n */\nfunction normalizeTransactionName(\n appRoutes: Route[],\n location: Location,\n match: Match,\n callback: (pathname: string, source?: ReactRouterV3TransactionSource) => void,\n): void {\n let name = location.pathname;\n match(\n {\n location,\n routes: appRoutes,\n },\n (error, _redirectLocation, renderProps) => {\n if (error || !renderProps) {\n return callback(name);\n }\n\n const routePath = getRouteStringFromRoutes(renderProps.routes || []);\n if (routePath.length === 0 || routePath === '/*') {\n return callback(name);\n }\n\n name = routePath;\n return callback(name, 'route');\n },\n );\n}\n\n/**\n * Generate route name from array of routes\n */\nfunction getRouteStringFromRoutes(routes: Route[]): string {\n if (!Array.isArray(routes) || routes.length === 0) {\n return '';\n }\n\n const routesWithPaths: Route[] = routes.filter((route: Route) => !!route.path);\n\n let index = -1;\n for (let x = routesWithPaths.length - 1; x >= 0; x--) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const route = routesWithPaths[x]!;\n if (route.path?.startsWith('/')) {\n index = x;\n break;\n }\n }\n\n return routesWithPaths.slice(index).reduce((acc, { path }) => {\n const pathSegment = acc === '/' || acc === '' ? path : `/${path}`;\n return `${acc}${pathSegment}`;\n }, '');\n}\n"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"reactrouterv3.js","sources":["../../src/reactrouterv3.ts"],"sourcesContent":["import {\n browserTracingIntegration,\n startBrowserTracingNavigationSpan,\n startBrowserTracingPageLoadSpan,\n WINDOW,\n} from '@sentry/browser';\nimport type { Integration, TransactionSource } from '@sentry/core/browser';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n} from '@sentry/core/browser';\nimport type { Location } from './types';\n\n// Many of the types below had to be mocked out to prevent typescript issues\n// these types are required for correct functionality.\n\ntype HistoryV3 = {\n location?: Location;\n listen?(cb: (location: Location) => void): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport type Route = { path?: string; childRoutes?: Route[] };\n\nexport type Match = (\n props: { location: Location; routes: Route[] },\n cb: (error?: Error, _redirectLocation?: Location, renderProps?: { routes?: Route[] }) => void,\n) => void;\n\ntype ReactRouterV3TransactionSource = Extract<TransactionSource, 'url' | 'route'>;\n\ninterface ReactRouterOptions {\n history: HistoryV3;\n routes: Route[];\n match: Match;\n}\n\n/**\n * A browser tracing integration that uses React Router v3 to instrument navigations.\n * Expects `history` (and optionally `routes` and `matchPath`) to be passed as options.\n */\nexport function reactRouterV3BrowserTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0] & ReactRouterOptions,\n): Integration {\n const integration = browserTracingIntegration({\n ...options,\n instrumentPageLoad: false,\n instrumentNavigation: false,\n });\n\n const { history, routes, match, instrumentPageLoad = true, instrumentNavigation = true } = options;\n\n return {\n ...integration,\n afterAllSetup(client) {\n integration.afterAllSetup(client);\n\n if (instrumentPageLoad && WINDOW.location) {\n normalizeTransactionName(\n routes,\n WINDOW.location as unknown as Location,\n match,\n (localName: string, source: ReactRouterV3TransactionSource = 'url') => {\n startBrowserTracingPageLoadSpan(client, {\n name: localName,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react.reactrouter_v3',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n },\n });\n },\n );\n }\n\n if (instrumentNavigation && history.listen) {\n history.listen(location => {\n if (location.action === 'PUSH' || location.action === 'POP') {\n normalizeTransactionName(\n routes,\n location,\n match,\n (localName: string, source: TransactionSource = 'url') => {\n startBrowserTracingNavigationSpan(client, {\n name: localName,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.reactrouter_v3',\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n },\n });\n },\n );\n }\n });\n }\n },\n };\n}\n\n/**\n * Normalize transaction names using `Router.match`\n */\nfunction normalizeTransactionName(\n appRoutes: Route[],\n location: Location,\n match: Match,\n callback: (pathname: string, source?: ReactRouterV3TransactionSource) => void,\n): void {\n let name = location.pathname;\n match(\n {\n location,\n routes: appRoutes,\n },\n (error, _redirectLocation, renderProps) => {\n if (error || !renderProps) {\n return callback(name);\n }\n\n const routePath = getRouteStringFromRoutes(renderProps.routes || []);\n if (routePath.length === 0 || routePath === '/*') {\n return callback(name);\n }\n\n name = routePath;\n return callback(name, 'route');\n },\n );\n}\n\n/**\n * Generate route name from array of routes\n */\nfunction getRouteStringFromRoutes(routes: Route[]): string {\n if (!Array.isArray(routes) || routes.length === 0) {\n return '';\n }\n\n const routesWithPaths: Route[] = routes.filter((route: Route) => !!route.path);\n\n let index = -1;\n for (let x = routesWithPaths.length - 1; x >= 0; x--) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const route = routesWithPaths[x]!;\n if (route.path?.startsWith('/')) {\n index = x;\n break;\n }\n }\n\n return routesWithPaths.slice(index).reduce((acc, { path }) => {\n const pathSegment = acc === '/' || acc === '' ? path : `/${path}`;\n return `${acc}${pathSegment}`;\n }, '');\n}\n"],"names":[],"mappings":";;;AA0CO,SAAS,uCACd,OAAA,EACa;AACb,EAAA,MAAM,cAAc,yBAAA,CAA0B;AAAA,IAC5C,GAAG,OAAA;AAAA,IACH,kBAAA,EAAoB,KAAA;AAAA,IACpB,oBAAA,EAAsB;AAAA,GACvB,CAAA;AAED,EAAA,MAAM,EAAE,SAAS,MAAA,EAAQ,KAAA,EAAO,qBAAqB,IAAA,EAAM,oBAAA,GAAuB,MAAK,GAAI,OAAA;AAE3F,EAAA,OAAO;AAAA,IACL,GAAG,WAAA;AAAA,IACH,cAAc,MAAA,EAAQ;AACpB,MAAA,WAAA,CAAY,cAAc,MAAM,CAAA;AAEhC,MAAA,IAAI,kBAAA,IAAsB,OAAO,QAAA,EAAU;AACzC,QAAA,wBAAA;AAAA,UACE,MAAA;AAAA,UACA,MAAA,CAAO,QAAA;AAAA,UACP,KAAA;AAAA,UACA,CAAC,SAAA,EAAmB,MAAA,GAAyC,KAAA,KAAU;AACrE,YAAA,+BAAA,CAAgC,MAAA,EAAQ;AA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