@depup/sentry__react 10.44.0-depup.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/LICENSE +21 -0
- package/README.md +25 -0
- package/build/cjs/constants.js +12 -0
- package/build/cjs/constants.js.map +1 -0
- package/build/cjs/debug-build.js +11 -0
- package/build/cjs/debug-build.js.map +1 -0
- package/build/cjs/error.js +113 -0
- package/build/cjs/error.js.map +1 -0
- package/build/cjs/errorboundary.js +170 -0
- package/build/cjs/errorboundary.js.map +1 -0
- package/build/cjs/hoist-non-react-statics.js +159 -0
- package/build/cjs/hoist-non-react-statics.js.map +1 -0
- package/build/cjs/index.js +51 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/profiler.js +226 -0
- package/build/cjs/profiler.js.map +1 -0
- package/build/cjs/reactrouter-compat-utils/instrumentation.js +1295 -0
- package/build/cjs/reactrouter-compat-utils/instrumentation.js.map +1 -0
- package/build/cjs/reactrouter-compat-utils/lazy-routes.js +160 -0
- package/build/cjs/reactrouter-compat-utils/lazy-routes.js.map +1 -0
- package/build/cjs/reactrouter-compat-utils/route-manifest.js +194 -0
- package/build/cjs/reactrouter-compat-utils/route-manifest.js.map +1 -0
- package/build/cjs/reactrouter-compat-utils/utils.js +336 -0
- package/build/cjs/reactrouter-compat-utils/utils.js.map +1 -0
- package/build/cjs/reactrouter.js +236 -0
- package/build/cjs/reactrouter.js.map +1 -0
- package/build/cjs/reactrouterv3.js +130 -0
- package/build/cjs/reactrouterv3.js.map +1 -0
- package/build/cjs/reactrouterv6.js +61 -0
- package/build/cjs/reactrouterv6.js.map +1 -0
- package/build/cjs/reactrouterv7.js +61 -0
- package/build/cjs/reactrouterv7.js.map +1 -0
- package/build/cjs/redux.js +106 -0
- package/build/cjs/redux.js.map +1 -0
- package/build/cjs/sdk.js +21 -0
- package/build/cjs/sdk.js.map +1 -0
- package/build/cjs/tanstackrouter.js +134 -0
- package/build/cjs/tanstackrouter.js.map +1 -0
- package/build/esm/constants.js +8 -0
- package/build/esm/constants.js.map +1 -0
- package/build/esm/debug-build.js +9 -0
- package/build/esm/debug-build.js.map +1 -0
- package/build/esm/error.js +108 -0
- package/build/esm/error.js.map +1 -0
- package/build/esm/errorboundary.js +166 -0
- package/build/esm/errorboundary.js.map +1 -0
- package/build/esm/hoist-non-react-statics.js +157 -0
- package/build/esm/hoist-non-react-statics.js.map +1 -0
- package/build/esm/index.js +12 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/package.json +1 -0
- package/build/esm/profiler.js +221 -0
- package/build/esm/profiler.js.map +1 -0
- package/build/esm/reactrouter-compat-utils/instrumentation.js +1281 -0
- package/build/esm/reactrouter-compat-utils/instrumentation.js.map +1 -0
- package/build/esm/reactrouter-compat-utils/lazy-routes.js +156 -0
- package/build/esm/reactrouter-compat-utils/lazy-routes.js.map +1 -0
- package/build/esm/reactrouter-compat-utils/route-manifest.js +191 -0
- package/build/esm/reactrouter-compat-utils/route-manifest.js.map +1 -0
- package/build/esm/reactrouter-compat-utils/utils.js +320 -0
- package/build/esm/reactrouter-compat-utils/utils.js.map +1 -0
- package/build/esm/reactrouter.js +232 -0
- package/build/esm/reactrouter.js.map +1 -0
- package/build/esm/reactrouterv3.js +128 -0
- package/build/esm/reactrouterv3.js.map +1 -0
- package/build/esm/reactrouterv6.js +55 -0
- package/build/esm/reactrouterv6.js.map +1 -0
- package/build/esm/reactrouterv7.js +55 -0
- package/build/esm/reactrouterv7.js.map +1 -0
- package/build/esm/redux.js +104 -0
- package/build/esm/redux.js.map +1 -0
- package/build/esm/sdk.js +19 -0
- package/build/esm/sdk.js.map +1 -0
- package/build/esm/tanstackrouter.js +132 -0
- package/build/esm/tanstackrouter.js.map +1 -0
- package/build/types/constants.d.ts +4 -0
- package/build/types/constants.d.ts.map +1 -0
- package/build/types/debug-build.d.ts +7 -0
- package/build/types/debug-build.d.ts.map +1 -0
- package/build/types/error.d.ts +41 -0
- package/build/types/error.d.ts.map +1 -0
- package/build/types/errorboundary.d.ts +87 -0
- package/build/types/errorboundary.d.ts.map +1 -0
- package/build/types/hoist-non-react-statics.d.ts +21 -0
- package/build/types/hoist-non-react-statics.d.ts.map +1 -0
- package/build/types/index.d.ts +13 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/profiler.d.ts +56 -0
- package/build/types/profiler.d.ts.map +1 -0
- package/build/types/reactrouter-compat-utils/index.d.ts +5 -0
- package/build/types/reactrouter-compat-utils/index.d.ts.map +1 -0
- package/build/types/reactrouter-compat-utils/instrumentation.d.ts +117 -0
- package/build/types/reactrouter-compat-utils/instrumentation.d.ts.map +1 -0
- package/build/types/reactrouter-compat-utils/lazy-routes.d.ts +18 -0
- package/build/types/reactrouter-compat-utils/lazy-routes.d.ts.map +1 -0
- package/build/types/reactrouter-compat-utils/route-manifest.d.ts +13 -0
- package/build/types/reactrouter-compat-utils/route-manifest.d.ts.map +1 -0
- package/build/types/reactrouter-compat-utils/utils.d.ts +71 -0
- package/build/types/reactrouter-compat-utils/utils.d.ts.map +1 -0
- package/build/types/reactrouter.d.ts +41 -0
- package/build/types/reactrouter.d.ts.map +1 -0
- package/build/types/reactrouterv3.d.ts +29 -0
- package/build/types/reactrouterv3.d.ts.map +1 -0
- package/build/types/reactrouterv6.d.ts +32 -0
- package/build/types/reactrouterv6.d.ts.map +1 -0
- package/build/types/reactrouterv7.d.ts +32 -0
- package/build/types/reactrouterv7.d.ts.map +1 -0
- package/build/types/redux.d.ts +38 -0
- package/build/types/redux.d.ts.map +1 -0
- package/build/types/sdk.d.ts +7 -0
- package/build/types/sdk.d.ts.map +1 -0
- package/build/types/tanstackrouter.d.ts +13 -0
- package/build/types/tanstackrouter.d.ts.map +1 -0
- package/build/types/types.d.ts +163 -0
- package/build/types/types.d.ts.map +1 -0
- package/build/types/vendor/tanstackrouter-types.d.ts +36 -0
- package/build/types/vendor/tanstackrouter-types.d.ts.map +1 -0
- package/build/types-ts3.8/constants.d.ts +4 -0
- package/build/types-ts3.8/debug-build.d.ts +7 -0
- package/build/types-ts3.8/error.d.ts +41 -0
- package/build/types-ts3.8/errorboundary.d.ts +87 -0
- package/build/types-ts3.8/hoist-non-react-statics.d.ts +21 -0
- package/build/types-ts3.8/index.d.ts +13 -0
- package/build/types-ts3.8/profiler.d.ts +56 -0
- package/build/types-ts3.8/reactrouter-compat-utils/index.d.ts +5 -0
- package/build/types-ts3.8/reactrouter-compat-utils/instrumentation.d.ts +117 -0
- package/build/types-ts3.8/reactrouter-compat-utils/lazy-routes.d.ts +18 -0
- package/build/types-ts3.8/reactrouter-compat-utils/route-manifest.d.ts +13 -0
- package/build/types-ts3.8/reactrouter-compat-utils/utils.d.ts +77 -0
- package/build/types-ts3.8/reactrouter.d.ts +41 -0
- package/build/types-ts3.8/reactrouterv3.d.ts +29 -0
- package/build/types-ts3.8/reactrouterv6.d.ts +32 -0
- package/build/types-ts3.8/reactrouterv7.d.ts +32 -0
- package/build/types-ts3.8/redux.d.ts +38 -0
- package/build/types-ts3.8/sdk.d.ts +7 -0
- package/build/types-ts3.8/tanstackrouter.d.ts +13 -0
- package/build/types-ts3.8/types.d.ts +163 -0
- package/build/types-ts3.8/vendor/tanstackrouter-types.d.ts +36 -0
- package/changes.json +5 -0
- package/package.json +108 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const debugBuild = require('../debug-build.js');
|
|
5
|
+
const routeManifest = require('./route-manifest.js');
|
|
6
|
+
|
|
7
|
+
// Global variables that these utilities depend on
|
|
8
|
+
let _matchRoutes;
|
|
9
|
+
let _stripBasename = false;
|
|
10
|
+
|
|
11
|
+
// Navigation context stack for nested/concurrent patchRoutesOnNavigation calls.
|
|
12
|
+
// Required because window.location hasn't updated yet when handlers are invoked.
|
|
13
|
+
|
|
14
|
+
const _navigationContextStack = [];
|
|
15
|
+
const MAX_CONTEXT_STACK_SIZE = 10;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Pushes a navigation context and returns a unique token for cleanup.
|
|
19
|
+
* The token uses object identity for uniqueness (no counter needed).
|
|
20
|
+
*/
|
|
21
|
+
function setNavigationContext(targetPath, span) {
|
|
22
|
+
const token = {};
|
|
23
|
+
// Prevent unbounded stack growth - oldest (likely stale) contexts are evicted first
|
|
24
|
+
if (_navigationContextStack.length >= MAX_CONTEXT_STACK_SIZE) {
|
|
25
|
+
debugBuild.DEBUG_BUILD && core.debug.warn('[React Router] Navigation context stack overflow - removing oldest context');
|
|
26
|
+
_navigationContextStack.shift();
|
|
27
|
+
}
|
|
28
|
+
_navigationContextStack.push({ token, targetPath, span });
|
|
29
|
+
return token;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Clears the navigation context if it's on top of the stack (LIFO).
|
|
34
|
+
* If our context is not on top (out-of-order completion), we leave it -
|
|
35
|
+
* it will be cleaned up by overflow protection when the stack fills up.
|
|
36
|
+
*/
|
|
37
|
+
function clearNavigationContext(token) {
|
|
38
|
+
const top = _navigationContextStack[_navigationContextStack.length - 1];
|
|
39
|
+
if (top?.token === token) {
|
|
40
|
+
_navigationContextStack.pop();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Gets the current (most recent) navigation context if inside a patchRoutesOnNavigation call. */
|
|
45
|
+
function getNavigationContext() {
|
|
46
|
+
const length = _navigationContextStack.length;
|
|
47
|
+
// The `?? null` converts undefined (from array access) to null to match return type
|
|
48
|
+
return length > 0 ? (_navigationContextStack[length - 1] ?? null) : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Initialize function to set dependencies that the router utilities need.
|
|
53
|
+
* Must be called before using any of the exported utility functions.
|
|
54
|
+
*/
|
|
55
|
+
function initializeRouterUtils(matchRoutes, stripBasename = false) {
|
|
56
|
+
_matchRoutes = matchRoutes;
|
|
57
|
+
_stripBasename = stripBasename;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Helper functions
|
|
61
|
+
function pickPath(match) {
|
|
62
|
+
return trimWildcard(match.route.path || '');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function pickSplat(match) {
|
|
66
|
+
return match.params['*'] || '';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function trimWildcard(path) {
|
|
70
|
+
return path[path.length - 1] === '*' ? path.slice(0, -1) : path;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function trimSlash(path) {
|
|
74
|
+
return path[path.length - 1] === '/' ? path.slice(0, -1) : path;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Checks if a path ends with a wildcard character (*).
|
|
79
|
+
*/
|
|
80
|
+
function pathEndsWithWildcard(path) {
|
|
81
|
+
return path.endsWith('*');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Checks if transaction name has wildcard (/* or ends with *). */
|
|
85
|
+
function transactionNameHasWildcard(name) {
|
|
86
|
+
return name.includes('/*') || name.endsWith('*');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Checks if a path is a wildcard and has child routes.
|
|
91
|
+
*/
|
|
92
|
+
function pathIsWildcardAndHasChildren(path, branch) {
|
|
93
|
+
return (pathEndsWithWildcard(path) && !!branch.route.children?.length) || false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Check if route is in descendant route (<Routes> within <Routes>) */
|
|
97
|
+
function routeIsDescendant(route) {
|
|
98
|
+
return !!(!route.children && route.element && route.path?.endsWith('/*'));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function sendIndexPath(pathBuilder, pathname, basename) {
|
|
102
|
+
const reconstructedPath =
|
|
103
|
+
pathBuilder && pathBuilder.length > 0
|
|
104
|
+
? pathBuilder
|
|
105
|
+
: _stripBasename
|
|
106
|
+
? routeManifest.stripBasenameFromPathname(pathname, basename)
|
|
107
|
+
: pathname;
|
|
108
|
+
|
|
109
|
+
let formattedPath =
|
|
110
|
+
// If the path ends with a wildcard suffix, remove both the slash and the asterisk
|
|
111
|
+
reconstructedPath.slice(-2) === '/*' ? reconstructedPath.slice(0, -2) : reconstructedPath;
|
|
112
|
+
|
|
113
|
+
// If the path ends with a slash, remove it (but keep single '/')
|
|
114
|
+
if (formattedPath.length > 1 && formattedPath[formattedPath.length - 1] === '/') {
|
|
115
|
+
formattedPath = formattedPath.slice(0, -1);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return [formattedPath, 'route'];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Returns the number of URL segments in the given URL string.
|
|
123
|
+
* Splits at '/' or '\/' to handle regex URLs correctly.
|
|
124
|
+
*
|
|
125
|
+
* @param url - The URL string to segment.
|
|
126
|
+
* @returns The number of segments in the URL.
|
|
127
|
+
*/
|
|
128
|
+
function getNumberOfUrlSegments(url) {
|
|
129
|
+
// split at '/' or at '\/' to split regex urls correctly
|
|
130
|
+
return url.split(/\\?\//).filter(s => s.length > 0 && s !== ',').length;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Exported utility functions
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Ensures a path string starts with a forward slash.
|
|
137
|
+
*/
|
|
138
|
+
function prefixWithSlash(path) {
|
|
139
|
+
return path[0] === '/' ? path : `/${path}`;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Rebuilds the route path from all available routes by matching against the current location.
|
|
144
|
+
*/
|
|
145
|
+
function rebuildRoutePathFromAllRoutes(allRoutes, location) {
|
|
146
|
+
const matchedRoutes = _matchRoutes(allRoutes, location) ;
|
|
147
|
+
|
|
148
|
+
if (!matchedRoutes || matchedRoutes.length === 0) {
|
|
149
|
+
return '';
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
for (const match of matchedRoutes) {
|
|
153
|
+
if (match.route.path && match.route.path !== '*') {
|
|
154
|
+
const path = pickPath(match);
|
|
155
|
+
const strippedPath = routeManifest.stripBasenameFromPathname(location.pathname, prefixWithSlash(match.pathnameBase));
|
|
156
|
+
|
|
157
|
+
if (location.pathname === strippedPath) {
|
|
158
|
+
return trimSlash(strippedPath);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return trimSlash(
|
|
162
|
+
trimSlash(path || '') +
|
|
163
|
+
prefixWithSlash(
|
|
164
|
+
rebuildRoutePathFromAllRoutes(
|
|
165
|
+
allRoutes.filter(route => route !== match.route),
|
|
166
|
+
{
|
|
167
|
+
pathname: strippedPath,
|
|
168
|
+
},
|
|
169
|
+
),
|
|
170
|
+
),
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return '';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Checks if the current location is inside a descendant route (route with splat parameter).
|
|
180
|
+
*/
|
|
181
|
+
function locationIsInsideDescendantRoute(location, routes) {
|
|
182
|
+
const matchedRoutes = _matchRoutes(routes, location) ;
|
|
183
|
+
|
|
184
|
+
if (matchedRoutes) {
|
|
185
|
+
for (const match of matchedRoutes) {
|
|
186
|
+
if (routeIsDescendant(match.route) && pickSplat(match)) {
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Returns a fallback transaction name from location pathname.
|
|
197
|
+
*/
|
|
198
|
+
function getFallbackTransactionName(location, basename) {
|
|
199
|
+
return _stripBasename ? routeManifest.stripBasenameFromPathname(location.pathname, basename) : location.pathname || '';
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Gets a normalized route name and transaction source from the current routes and location.
|
|
204
|
+
*/
|
|
205
|
+
function getNormalizedName(
|
|
206
|
+
routes,
|
|
207
|
+
location,
|
|
208
|
+
branches,
|
|
209
|
+
basename = '',
|
|
210
|
+
) {
|
|
211
|
+
if (!routes || routes.length === 0) {
|
|
212
|
+
return [_stripBasename ? routeManifest.stripBasenameFromPathname(location.pathname, basename) : location.pathname, 'url'];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!branches) {
|
|
216
|
+
return [getFallbackTransactionName(location, basename), 'url'];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
let pathBuilder = '';
|
|
220
|
+
|
|
221
|
+
for (const branch of branches) {
|
|
222
|
+
const route = branch.route;
|
|
223
|
+
if (!route) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Early return for index routes
|
|
228
|
+
if (route.index) {
|
|
229
|
+
return sendIndexPath(pathBuilder, branch.pathname, basename);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const path = route.path;
|
|
233
|
+
if (!path || pathIsWildcardAndHasChildren(path, branch)) {
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Build the route path
|
|
238
|
+
const newPath = path[0] === '/' || pathBuilder[pathBuilder.length - 1] === '/' ? path : `/${path}`;
|
|
239
|
+
pathBuilder = trimSlash(pathBuilder) + prefixWithSlash(newPath);
|
|
240
|
+
|
|
241
|
+
// Check if this path matches the current location
|
|
242
|
+
if (trimSlash(location.pathname) !== trimSlash(basename + branch.pathname)) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Check if this is a parameterized route like /stores/:storeId/products/:productId
|
|
247
|
+
if (
|
|
248
|
+
getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&
|
|
249
|
+
!pathEndsWithWildcard(pathBuilder)
|
|
250
|
+
) {
|
|
251
|
+
return [(_stripBasename ? '' : basename) + newPath, 'route'];
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Handle wildcard routes with children - strip trailing wildcard
|
|
255
|
+
if (pathIsWildcardAndHasChildren(pathBuilder, branch)) {
|
|
256
|
+
pathBuilder = pathBuilder.slice(0, -1);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return [(_stripBasename ? '' : basename) + pathBuilder, 'route'];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Fallback when no matching route found
|
|
263
|
+
return [getFallbackTransactionName(location, basename), 'url'];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Shared helper function to resolve route name and source
|
|
268
|
+
*/
|
|
269
|
+
function resolveRouteNameAndSource(
|
|
270
|
+
location,
|
|
271
|
+
routes,
|
|
272
|
+
allRoutes,
|
|
273
|
+
branches,
|
|
274
|
+
basename = '',
|
|
275
|
+
lazyRouteManifest,
|
|
276
|
+
enableAsyncRouteHandlers,
|
|
277
|
+
) {
|
|
278
|
+
// When lazy route manifest is provided, use it as the primary source for transaction names
|
|
279
|
+
if (enableAsyncRouteHandlers && lazyRouteManifest && lazyRouteManifest.length > 0) {
|
|
280
|
+
const manifestMatch = routeManifest.matchRouteManifest(location.pathname, lazyRouteManifest, basename);
|
|
281
|
+
if (manifestMatch) {
|
|
282
|
+
return [(_stripBasename ? '' : basename) + manifestMatch, 'route'];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Fall back to React Router route matching
|
|
287
|
+
let name;
|
|
288
|
+
let source = 'url';
|
|
289
|
+
|
|
290
|
+
const isInDescendantRoute = locationIsInsideDescendantRoute(location, allRoutes);
|
|
291
|
+
|
|
292
|
+
if (isInDescendantRoute) {
|
|
293
|
+
name = prefixWithSlash(rebuildRoutePathFromAllRoutes(allRoutes, location));
|
|
294
|
+
source = 'route';
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (!isInDescendantRoute || !name) {
|
|
298
|
+
[name, source] = getNormalizedName(routes, location, branches, basename);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return [name || location.pathname, source];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Gets the active root span if it's a pageload or navigation span.
|
|
306
|
+
*/
|
|
307
|
+
function getActiveRootSpan() {
|
|
308
|
+
const span = core.getActiveSpan();
|
|
309
|
+
const rootSpan = span ? core.getRootSpan(span) : undefined;
|
|
310
|
+
|
|
311
|
+
if (!rootSpan) {
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const op = core.spanToJSON(rootSpan).op;
|
|
316
|
+
|
|
317
|
+
// Only use this root span if it is a pageload or navigation span
|
|
318
|
+
return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
exports.clearNavigationContext = clearNavigationContext;
|
|
322
|
+
exports.getActiveRootSpan = getActiveRootSpan;
|
|
323
|
+
exports.getNavigationContext = getNavigationContext;
|
|
324
|
+
exports.getNormalizedName = getNormalizedName;
|
|
325
|
+
exports.getNumberOfUrlSegments = getNumberOfUrlSegments;
|
|
326
|
+
exports.initializeRouterUtils = initializeRouterUtils;
|
|
327
|
+
exports.locationIsInsideDescendantRoute = locationIsInsideDescendantRoute;
|
|
328
|
+
exports.pathEndsWithWildcard = pathEndsWithWildcard;
|
|
329
|
+
exports.pathIsWildcardAndHasChildren = pathIsWildcardAndHasChildren;
|
|
330
|
+
exports.prefixWithSlash = prefixWithSlash;
|
|
331
|
+
exports.rebuildRoutePathFromAllRoutes = rebuildRoutePathFromAllRoutes;
|
|
332
|
+
exports.resolveRouteNameAndSource = resolveRouteNameAndSource;
|
|
333
|
+
exports.routeIsDescendant = routeIsDescendant;
|
|
334
|
+
exports.setNavigationContext = setNavigationContext;
|
|
335
|
+
exports.transactionNameHasWildcard = transactionNameHasWildcard;
|
|
336
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/reactrouter-compat-utils/utils.ts"],"sourcesContent":["import type { Span, TransactionSource } from '@sentry/core';\nimport { debug, getActiveSpan, getRootSpan, spanToJSON } from '@sentry/core';\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":["DEBUG_BUILD","debug","stripBasenameFromPathname","matchRouteManifest","getActiveSpan","getRootSpan","spanToJSON"],"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,IAAIA,0BAAeC,UAAK,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,EAAE,KAAA,KAAU,KAA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AAAC,gBAAA,CAAA,IAAA,CAAA,GAAA,SAAA;;AAEA,EAAA,IAAA,CAAA,QAAA,EAAA;AACA,IAAA,OAAA,SAAA;AACA,EAAA;;AAEA,EAAA,MAAA,EAAA,GAAAC,eAAA,CAAA,QAAA,CAAA,CAAA,EAAA;;AAEA;AACA,EAAA,OAAA,EAAA,KAAA,YAAA,IAAA,EAAA,KAAA,UAAA,GAAA,QAAA,GAAA,SAAA;AACA;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const browser = require('@sentry/browser');
|
|
4
|
+
const core = require('@sentry/core');
|
|
5
|
+
const React = require('react');
|
|
6
|
+
const hoistNonReactStatics = require('./hoist-non-react-statics.js');
|
|
7
|
+
|
|
8
|
+
// We need to disable eslint no-explicit-any because any is required for the
|
|
9
|
+
// react-router typings.
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A browser tracing integration that uses React Router v4 to instrument navigations.
|
|
13
|
+
* Expects `history` (and optionally `routes` and `matchPath`) to be passed as options.
|
|
14
|
+
*/
|
|
15
|
+
function reactRouterV4BrowserTracingIntegration(
|
|
16
|
+
options,
|
|
17
|
+
) {
|
|
18
|
+
const integration = browser.browserTracingIntegration({
|
|
19
|
+
...options,
|
|
20
|
+
instrumentPageLoad: false,
|
|
21
|
+
instrumentNavigation: false,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const { history, routes, matchPath, instrumentPageLoad = true, instrumentNavigation = true } = options;
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
...integration,
|
|
28
|
+
afterAllSetup(client) {
|
|
29
|
+
integration.afterAllSetup(client);
|
|
30
|
+
|
|
31
|
+
instrumentReactRouter(
|
|
32
|
+
client,
|
|
33
|
+
instrumentPageLoad,
|
|
34
|
+
instrumentNavigation,
|
|
35
|
+
history,
|
|
36
|
+
'reactrouter_v4',
|
|
37
|
+
routes,
|
|
38
|
+
matchPath,
|
|
39
|
+
);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A browser tracing integration that uses React Router v5 to instrument navigations.
|
|
46
|
+
* Expects `history` (and optionally `routes` and `matchPath`) to be passed as options.
|
|
47
|
+
*/
|
|
48
|
+
function reactRouterV5BrowserTracingIntegration(
|
|
49
|
+
options,
|
|
50
|
+
) {
|
|
51
|
+
const integration = browser.browserTracingIntegration({
|
|
52
|
+
...options,
|
|
53
|
+
instrumentPageLoad: false,
|
|
54
|
+
instrumentNavigation: false,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const { history, routes, matchPath, instrumentPageLoad = true, instrumentNavigation = true } = options;
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
...integration,
|
|
61
|
+
afterAllSetup(client) {
|
|
62
|
+
integration.afterAllSetup(client);
|
|
63
|
+
|
|
64
|
+
instrumentReactRouter(
|
|
65
|
+
client,
|
|
66
|
+
instrumentPageLoad,
|
|
67
|
+
instrumentNavigation,
|
|
68
|
+
history,
|
|
69
|
+
'reactrouter_v5',
|
|
70
|
+
routes,
|
|
71
|
+
matchPath,
|
|
72
|
+
);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function instrumentReactRouter(
|
|
78
|
+
client,
|
|
79
|
+
instrumentPageLoad,
|
|
80
|
+
instrumentNavigation,
|
|
81
|
+
history,
|
|
82
|
+
instrumentationName,
|
|
83
|
+
allRoutes = [],
|
|
84
|
+
matchPath,
|
|
85
|
+
) {
|
|
86
|
+
function getInitPathName() {
|
|
87
|
+
if (history.location) {
|
|
88
|
+
return history.location.pathname;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (browser.WINDOW.location) {
|
|
92
|
+
return browser.WINDOW.location.pathname;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Normalizes a transaction name. Returns the new name as well as the
|
|
100
|
+
* source of the transaction.
|
|
101
|
+
*
|
|
102
|
+
* @param pathname The initial pathname we normalize
|
|
103
|
+
*/
|
|
104
|
+
function normalizeTransactionName(pathname) {
|
|
105
|
+
if (allRoutes.length === 0 || !matchPath) {
|
|
106
|
+
return [pathname, 'url'];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const branches = matchRoutes(allRoutes, pathname, matchPath);
|
|
110
|
+
for (const branch of branches) {
|
|
111
|
+
if (branch.match.isExact) {
|
|
112
|
+
return [branch.match.path, 'route'];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return [pathname, 'url'];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (instrumentPageLoad) {
|
|
120
|
+
const initPathName = getInitPathName();
|
|
121
|
+
if (initPathName) {
|
|
122
|
+
const [name, source] = normalizeTransactionName(initPathName);
|
|
123
|
+
browser.startBrowserTracingPageLoadSpan(client, {
|
|
124
|
+
name,
|
|
125
|
+
attributes: {
|
|
126
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
|
|
127
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: `auto.pageload.react.${instrumentationName}`,
|
|
128
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (instrumentNavigation && history.listen) {
|
|
135
|
+
history.listen((location, action) => {
|
|
136
|
+
if (action && (action === 'PUSH' || action === 'POP')) {
|
|
137
|
+
const [name, source] = normalizeTransactionName(location.pathname);
|
|
138
|
+
browser.startBrowserTracingNavigationSpan(client, {
|
|
139
|
+
name,
|
|
140
|
+
attributes: {
|
|
141
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
|
|
142
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: `auto.navigation.react.${instrumentationName}`,
|
|
143
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Matches a set of routes to a pathname
|
|
153
|
+
* Based on implementation from
|
|
154
|
+
*/
|
|
155
|
+
function matchRoutes(
|
|
156
|
+
routes,
|
|
157
|
+
pathname,
|
|
158
|
+
matchPath,
|
|
159
|
+
branch = [],
|
|
160
|
+
) {
|
|
161
|
+
routes.some(route => {
|
|
162
|
+
const match = route.path
|
|
163
|
+
? matchPath(pathname, route)
|
|
164
|
+
: branch.length
|
|
165
|
+
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
166
|
+
branch[branch.length - 1].match // use parent match
|
|
167
|
+
: computeRootMatch(pathname); // use default "root" match
|
|
168
|
+
|
|
169
|
+
if (match) {
|
|
170
|
+
branch.push({ route, match });
|
|
171
|
+
|
|
172
|
+
if (route.routes) {
|
|
173
|
+
matchRoutes(route.routes, pathname, matchPath, branch);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return !!match;
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return branch;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function computeRootMatch(pathname) {
|
|
184
|
+
return { path: '/', url: '/', params: {}, isExact: pathname === '/' };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
|
|
188
|
+
function withSentryRouting(Route) {
|
|
189
|
+
const componentDisplayName = Route.displayName || Route.name;
|
|
190
|
+
|
|
191
|
+
const WrappedRoute = (props) => {
|
|
192
|
+
if (props?.computedMatch?.isExact) {
|
|
193
|
+
const route = props.computedMatch.path;
|
|
194
|
+
const activeRootSpan = getActiveRootSpan();
|
|
195
|
+
|
|
196
|
+
core.getCurrentScope().setTransactionName(route);
|
|
197
|
+
|
|
198
|
+
if (activeRootSpan) {
|
|
199
|
+
activeRootSpan.updateName(route);
|
|
200
|
+
activeRootSpan.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// @ts-expect-error Setting more specific React Component typing for `R` generic above
|
|
205
|
+
// will break advanced type inference done by react router params:
|
|
206
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
|
|
207
|
+
return React.createElement(Route, { ...props,} );
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;
|
|
211
|
+
hoistNonReactStatics.hoistNonReactStatics(WrappedRoute, Route);
|
|
212
|
+
// @ts-expect-error Setting more specific React Component typing for `R` generic above
|
|
213
|
+
// will break advanced type inference done by react router params:
|
|
214
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
|
|
215
|
+
return WrappedRoute;
|
|
216
|
+
}
|
|
217
|
+
/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
|
|
218
|
+
|
|
219
|
+
function getActiveRootSpan() {
|
|
220
|
+
const span = core.getActiveSpan();
|
|
221
|
+
const rootSpan = span && core.getRootSpan(span);
|
|
222
|
+
|
|
223
|
+
if (!rootSpan) {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const op = core.spanToJSON(rootSpan).op;
|
|
228
|
+
|
|
229
|
+
// Only use this root span if it is a pageload or navigation span
|
|
230
|
+
return op === 'navigation' || op === 'pageload' ? rootSpan : undefined;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
exports.reactRouterV4BrowserTracingIntegration = reactRouterV4BrowserTracingIntegration;
|
|
234
|
+
exports.reactRouterV5BrowserTracingIntegration = reactRouterV5BrowserTracingIntegration;
|
|
235
|
+
exports.withSentryRouting = withSentryRouting;
|
|
236
|
+
//# sourceMappingURL=reactrouter.js.map
|
|
@@ -0,0 +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' ? rootSpan : undefined;\n}\n"],"names":["browserTracingIntegration","WINDOW","startBrowserTracingPageLoadSpan","SEMANTIC_ATTRIBUTE_SENTRY_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","startBrowserTracingNavigationSpan","getCurrentScope","hoistNonReactStatics","getActiveSpan","getRootSpan","spanToJSON"],"mappings":";;;;;;;AAqB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