@sentry/react 7.0.0-alpha.0 → 7.0.0-beta.1
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/README.md +2 -3
- package/cjs/constants.js +12 -5
- package/cjs/constants.js.map +1 -1
- package/cjs/errorboundary.js +139 -112
- package/cjs/errorboundary.js.map +1 -1
- package/cjs/flags.js +7 -3
- package/cjs/flags.js.map +1 -1
- package/cjs/index.js +30 -21
- package/cjs/index.js.map +1 -1
- package/cjs/profiler.js +178 -147
- package/cjs/profiler.js.map +1 -1
- package/cjs/reactrouter.js +149 -99
- package/cjs/reactrouter.js.map +1 -1
- package/cjs/reactrouterv3.js +107 -83
- package/cjs/reactrouterv3.js.map +1 -1
- package/cjs/reactrouterv6.js +163 -0
- package/cjs/reactrouterv6.js.map +1 -0
- package/cjs/redux.js +51 -42
- package/cjs/redux.js.map +1 -1
- package/cjs/sdk.js +18 -15
- package/cjs/sdk.js.map +1 -1
- package/esm/constants.js +8 -4
- package/esm/constants.js.map +1 -1
- package/esm/errorboundary.js +124 -107
- package/esm/errorboundary.js.map +1 -1
- package/esm/flags.js +5 -2
- package/esm/flags.js.map +1 -1
- package/esm/index.js +8 -7
- package/esm/index.js.map +1 -1
- package/esm/profiler.js +161 -140
- package/esm/profiler.js.map +1 -1
- package/esm/reactrouter.js +134 -92
- package/esm/reactrouter.js.map +1 -1
- package/esm/reactrouterv3.js +103 -79
- package/esm/reactrouterv3.js.map +1 -1
- package/esm/reactrouterv6.js +153 -0
- package/esm/reactrouterv6.js.map +1 -0
- package/esm/redux.js +49 -41
- package/esm/redux.js.map +1 -1
- package/esm/sdk.js +17 -14
- package/esm/sdk.js.map +1 -1
- package/package.json +5 -6
- package/types/errorboundary.d.ts +1 -0
- package/types/errorboundary.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/reactrouterv6.d.ts +27 -0
- package/types/reactrouterv6.d.ts.map +1 -0
- package/cjs/constants.d.ts +0 -4
- package/cjs/constants.d.ts.map +0 -1
- package/cjs/errorboundary.d.ts +0 -62
- package/cjs/errorboundary.d.ts.map +0 -1
- package/cjs/flags.d.ts +0 -3
- package/cjs/flags.d.ts.map +0 -1
- package/cjs/index.d.ts +0 -8
- package/cjs/index.d.ts.map +0 -1
- package/cjs/profiler.d.ts +0 -54
- package/cjs/profiler.d.ts.map +0 -1
- package/cjs/reactrouter.d.ts +0 -25
- package/cjs/reactrouter.d.ts.map +0 -1
- package/cjs/reactrouterv3.d.ts +0 -26
- package/cjs/reactrouterv3.d.ts.map +0 -1
- package/cjs/redux.d.ts +0 -33
- package/cjs/redux.d.ts.map +0 -1
- package/cjs/sdk.d.ts +0 -6
- package/cjs/sdk.d.ts.map +0 -1
- package/cjs/types.d.ts +0 -8
- package/cjs/types.d.ts.map +0 -1
- package/cjs/types.js +0 -2
- package/cjs/types.js.map +0 -1
- package/esm/constants.d.ts +0 -4
- package/esm/constants.d.ts.map +0 -1
- package/esm/errorboundary.d.ts +0 -62
- package/esm/errorboundary.d.ts.map +0 -1
- package/esm/flags.d.ts +0 -3
- package/esm/flags.d.ts.map +0 -1
- package/esm/index.d.ts +0 -8
- package/esm/index.d.ts.map +0 -1
- package/esm/profiler.d.ts +0 -54
- package/esm/profiler.d.ts.map +0 -1
- package/esm/reactrouter.d.ts +0 -25
- package/esm/reactrouter.d.ts.map +0 -1
- package/esm/reactrouterv3.d.ts +0 -26
- package/esm/reactrouterv3.d.ts.map +0 -1
- package/esm/redux.d.ts +0 -33
- package/esm/redux.d.ts.map +0 -1
- package/esm/sdk.d.ts +0 -6
- package/esm/sdk.d.ts.map +0 -1
- package/esm/types.d.ts +0 -8
- package/esm/types.d.ts.map +0 -1
- package/esm/types.js +0 -1
- package/esm/types.js.map +0 -1
package/esm/reactrouter.js
CHANGED
|
@@ -1,115 +1,157 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
import { getGlobalObject } from '@sentry/utils';
|
|
3
2
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
4
3
|
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
var _jsxFileName = "/home/runner/work/sentry-javascript/sentry-javascript/packages/react/src/reactrouter.tsx";
|
|
6
|
+
|
|
7
|
+
// We need to disable eslint no-explict-any because any is required for the
|
|
8
|
+
// react-router typings.
|
|
9
|
+
|
|
5
10
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
11
|
+
|
|
6
12
|
var global = getGlobalObject();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
|
|
14
|
+
let activeTransaction;
|
|
15
|
+
|
|
16
|
+
function reactRouterV4Instrumentation(
|
|
17
|
+
history,
|
|
18
|
+
routes,
|
|
19
|
+
matchPath,
|
|
20
|
+
) {
|
|
21
|
+
return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);
|
|
10
22
|
}
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
|
|
24
|
+
function reactRouterV5Instrumentation(
|
|
25
|
+
history,
|
|
26
|
+
routes,
|
|
27
|
+
matchPath,
|
|
28
|
+
) {
|
|
29
|
+
return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);
|
|
13
30
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
|
|
32
|
+
function createReactRouterInstrumentation(
|
|
33
|
+
history,
|
|
34
|
+
name,
|
|
35
|
+
allRoutes = [],
|
|
36
|
+
matchPath,
|
|
37
|
+
) {
|
|
38
|
+
function getInitPathName() {
|
|
39
|
+
if (history && history.location) {
|
|
40
|
+
return history.location.pathname;
|
|
24
41
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
var branches = matchRoutes(allRoutes, pathname, matchPath);
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
31
|
-
for (var x = 0; x < branches.length; x++) {
|
|
32
|
-
if (branches[x].match.isExact) {
|
|
33
|
-
return branches[x].match.path;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return pathname;
|
|
42
|
+
|
|
43
|
+
if (global && global.location) {
|
|
44
|
+
return global.location.pathname;
|
|
37
45
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
46
|
+
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getTransactionName(pathname) {
|
|
51
|
+
if (allRoutes.length === 0 || !matchPath) {
|
|
52
|
+
return pathname;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var branches = matchRoutes(allRoutes, pathname, matchPath);
|
|
56
|
+
for (let x = 0; x < branches.length; x++) {
|
|
57
|
+
if (branches[x].match.isExact) {
|
|
58
|
+
return branches[x].match.path;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return pathname;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true) => {
|
|
66
|
+
var initPathName = getInitPathName();
|
|
67
|
+
if (startTransactionOnPageLoad && initPathName) {
|
|
68
|
+
activeTransaction = customStartTransaction({
|
|
69
|
+
name: getTransactionName(initPathName),
|
|
70
|
+
op: 'pageload',
|
|
71
|
+
tags: {
|
|
72
|
+
'routing.instrumentation': name,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (startTransactionOnLocationChange && history.listen) {
|
|
78
|
+
history.listen((location, action) => {
|
|
79
|
+
if (action && (action === 'PUSH' || action === 'POP')) {
|
|
80
|
+
if (activeTransaction) {
|
|
81
|
+
activeTransaction.finish();
|
|
82
|
+
}
|
|
83
|
+
var tags = {
|
|
84
|
+
'routing.instrumentation': name,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
activeTransaction = customStartTransaction({
|
|
88
|
+
name: getTransactionName(location.pathname),
|
|
89
|
+
op: 'navigation',
|
|
90
|
+
tags,
|
|
91
|
+
});
|
|
67
92
|
}
|
|
68
|
-
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
69
96
|
}
|
|
97
|
+
|
|
70
98
|
/**
|
|
71
99
|
* Matches a set of routes to a pathname
|
|
72
100
|
* Based on implementation from
|
|
73
101
|
*/
|
|
74
|
-
function matchRoutes(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
102
|
+
function matchRoutes(
|
|
103
|
+
routes,
|
|
104
|
+
pathname,
|
|
105
|
+
matchPath,
|
|
106
|
+
branch = [],
|
|
107
|
+
) {
|
|
108
|
+
routes.some(route => {
|
|
109
|
+
var match = route.path
|
|
110
|
+
? matchPath(pathname, route)
|
|
111
|
+
: branch.length
|
|
112
|
+
? branch[branch.length - 1].match // use parent match
|
|
113
|
+
: computeRootMatch(pathname); // use default "root" match
|
|
114
|
+
|
|
115
|
+
if (match) {
|
|
116
|
+
branch.push({ route, match });
|
|
117
|
+
|
|
118
|
+
if (route.routes) {
|
|
119
|
+
matchRoutes(route.routes, pathname, matchPath, branch);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return !!match;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return branch;
|
|
91
127
|
}
|
|
128
|
+
|
|
92
129
|
function computeRootMatch(pathname) {
|
|
93
|
-
|
|
130
|
+
return { path: '/', url: '/', params: {}, isExact: pathname === '/' };
|
|
94
131
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
|
|
105
|
-
return React.createElement(Route, __assign({}, props));
|
|
106
|
-
};
|
|
107
|
-
WrappedRoute.displayName = "sentryRoute(" + componentDisplayName + ")";
|
|
108
|
-
hoistNonReactStatics(WrappedRoute, Route);
|
|
132
|
+
|
|
133
|
+
function withSentryRouting(Route) {
|
|
134
|
+
var componentDisplayName = (Route ).displayName || (Route ).name;
|
|
135
|
+
|
|
136
|
+
var WrappedRoute = (props) => {
|
|
137
|
+
if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {
|
|
138
|
+
activeTransaction.setName(props.computedMatch.path);
|
|
139
|
+
}
|
|
140
|
+
|
|
109
141
|
// @ts-ignore Setting more specific React Component typing for `R` generic above
|
|
110
142
|
// will break advanced type inference done by react router params:
|
|
111
143
|
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
|
|
112
|
-
return
|
|
144
|
+
return React.createElement(Route, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 163}} );
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;
|
|
148
|
+
hoistNonReactStatics(WrappedRoute, Route);
|
|
149
|
+
// @ts-ignore Setting more specific React Component typing for `R` generic above
|
|
150
|
+
// will break advanced type inference done by react router params:
|
|
151
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
|
|
152
|
+
return WrappedRoute;
|
|
113
153
|
}
|
|
114
154
|
/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
|
|
115
|
-
|
|
155
|
+
|
|
156
|
+
export { reactRouterV4Instrumentation, reactRouterV5Instrumentation, withSentryRouting };
|
|
157
|
+
//# sourceMappingURL=reactrouter.js.map
|
package/esm/reactrouter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouter.js","
|
|
1
|
+
{"version":3,"file":"reactrouter.js","sources":["../../src/reactrouter.tsx"],"sourcesContent":["import { Transaction } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { Action, Location, ReactRouterInstrumentation } from './types';\n\n// We need to disable eslint no-explict-any because any is required for the\n// react-router typings.\n/* eslint-disable @typescript-eslint/no-explicit-any */\ntype Match = { path: string; url: string; params: Record<string, any>; isExact: boolean };\n\nexport type RouterHistory = {\n location?: Location;\n listen?(cb: (location: Location, action: Action) => void): void;\n} & Record<string, any>;\n\nexport type RouteConfig = {\n [propName: string]: any;\n path?: string | string[];\n exact?: boolean;\n component?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null;\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\nconst global = getGlobalObject<Window>();\n\nlet activeTransaction: Transaction | undefined;\n\nexport function reactRouterV4Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);\n}\n\nexport function reactRouterV5Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);\n}\n\nfunction createReactRouterInstrumentation(\n history: RouterHistory,\n name: string,\n allRoutes: RouteConfig[] = [],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n function getInitPathName(): string | undefined {\n if (history && history.location) {\n return history.location.pathname;\n }\n\n if (global && global.location) {\n return global.location.pathname;\n }\n\n return undefined;\n }\n\n function getTransactionName(pathname: string): string {\n if (allRoutes.length === 0 || !matchPath) {\n return pathname;\n }\n\n const branches = matchRoutes(allRoutes, pathname, matchPath);\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n if (branches[x].match.isExact) {\n return branches[x].match.path;\n }\n }\n\n return pathname;\n }\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: getTransactionName(initPathName),\n op: 'pageload',\n tags: {\n 'routing.instrumentation': name,\n },\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen((location, action) => {\n if (action && (action === 'PUSH' || action === 'POP')) {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags = {\n 'routing.instrumentation': name,\n };\n\n activeTransaction = customStartTransaction({\n name: getTransactionName(location.pathname),\n op: 'navigation',\n tags,\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 ? 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 as any).displayName || (Route as any).name;\n\n const WrappedRoute: React.FC<P> = (props: P) => {\n if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {\n activeTransaction.setName(props.computedMatch.path);\n }\n\n // @ts-ignore 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-ignore 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"],"names":[],"mappings":";;;;AAAA;;AAOA;AACA;;AAkBA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;"}
|
package/esm/reactrouterv3.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { getGlobalObject } from '@sentry/utils';
|
|
2
|
+
|
|
3
|
+
// Many of the types below had to be mocked out to prevent typescript issues
|
|
4
|
+
// these types are required for correct functionality.
|
|
5
|
+
|
|
2
6
|
var global = getGlobalObject();
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
9
|
* Creates routing instrumentation for React Router v3
|
|
5
10
|
* Works for React Router >= 3.2.0 and < 4.0.0
|
|
@@ -8,96 +13,115 @@ var global = getGlobalObject();
|
|
|
8
13
|
* @param routes a list of all routes, should be
|
|
9
14
|
* @param match `Router.match` utility
|
|
10
15
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
16
|
+
function reactRouterV3Instrumentation(
|
|
17
|
+
history,
|
|
18
|
+
routes,
|
|
19
|
+
match,
|
|
20
|
+
) {
|
|
21
|
+
return (
|
|
22
|
+
startTransaction,
|
|
23
|
+
startTransactionOnPageLoad = true,
|
|
24
|
+
startTransactionOnLocationChange = true,
|
|
25
|
+
) => {
|
|
26
|
+
let activeTransaction;
|
|
27
|
+
let prevName;
|
|
28
|
+
|
|
29
|
+
// Have to use global.location because history.location might not be defined.
|
|
30
|
+
if (startTransactionOnPageLoad && global && global.location) {
|
|
31
|
+
normalizeTransactionName(routes, global.location , match, (localName) => {
|
|
32
|
+
prevName = localName;
|
|
33
|
+
activeTransaction = startTransaction({
|
|
34
|
+
name: prevName,
|
|
35
|
+
op: 'pageload',
|
|
36
|
+
tags: {
|
|
37
|
+
'routing.instrumentation': 'react-router-v3',
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (startTransactionOnLocationChange && history.listen) {
|
|
44
|
+
history.listen(location => {
|
|
45
|
+
if (location.action === 'PUSH' || location.action === 'POP') {
|
|
46
|
+
if (activeTransaction) {
|
|
47
|
+
activeTransaction.finish();
|
|
48
|
+
}
|
|
49
|
+
var tags = {
|
|
50
|
+
'routing.instrumentation': 'react-router-v3',
|
|
51
|
+
};
|
|
52
|
+
if (prevName) {
|
|
53
|
+
tags.from = prevName;
|
|
54
|
+
}
|
|
55
|
+
normalizeTransactionName(routes, location, match, (localName) => {
|
|
56
|
+
prevName = localName;
|
|
57
|
+
activeTransaction = startTransaction({
|
|
58
|
+
name: prevName,
|
|
59
|
+
op: 'navigation',
|
|
60
|
+
tags,
|
|
51
61
|
});
|
|
62
|
+
});
|
|
52
63
|
}
|
|
53
|
-
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
54
67
|
}
|
|
68
|
+
|
|
55
69
|
/**
|
|
56
70
|
* Normalize transaction names using `Router.match`
|
|
57
71
|
*/
|
|
58
|
-
function normalizeTransactionName(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
function normalizeTransactionName(
|
|
73
|
+
appRoutes,
|
|
74
|
+
location,
|
|
75
|
+
match,
|
|
76
|
+
callback,
|
|
77
|
+
) {
|
|
78
|
+
let name = location.pathname;
|
|
79
|
+
match(
|
|
80
|
+
{
|
|
81
|
+
location,
|
|
82
|
+
routes: appRoutes,
|
|
83
|
+
},
|
|
84
|
+
(error, _redirectLocation, renderProps) => {
|
|
85
|
+
if (error || !renderProps) {
|
|
86
|
+
return callback(name);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
var routePath = getRouteStringFromRoutes(renderProps.routes || []);
|
|
90
|
+
if (routePath.length === 0 || routePath === '/*') {
|
|
72
91
|
return callback(name);
|
|
73
|
-
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
name = routePath;
|
|
95
|
+
return callback(name);
|
|
96
|
+
},
|
|
97
|
+
);
|
|
74
98
|
}
|
|
99
|
+
|
|
75
100
|
/**
|
|
76
101
|
* Generate route name from array of routes
|
|
77
102
|
*/
|
|
78
103
|
function getRouteStringFromRoutes(routes) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
104
|
+
if (!Array.isArray(routes) || routes.length === 0) {
|
|
105
|
+
return '';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
var routesWithPaths = routes.filter((route) => !!route.path);
|
|
109
|
+
|
|
110
|
+
let index = -1;
|
|
111
|
+
for (let x = routesWithPaths.length - 1; x >= 0; x--) {
|
|
112
|
+
var route = routesWithPaths[x];
|
|
113
|
+
if (route.path && route.path.startsWith('/')) {
|
|
114
|
+
index = x;
|
|
115
|
+
break;
|
|
90
116
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
var path = _a.path;
|
|
99
|
-
return path;
|
|
100
|
-
})
|
|
101
|
-
.join('');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return routesWithPaths
|
|
120
|
+
.slice(index)
|
|
121
|
+
.filter(({ path }) => !!path)
|
|
122
|
+
.map(({ path }) => path)
|
|
123
|
+
.join('');
|
|
102
124
|
}
|
|
103
|
-
|
|
125
|
+
|
|
126
|
+
export { reactRouterV3Instrumentation };
|
|
127
|
+
//# sourceMappingURL=reactrouterv3.js.map
|
package/esm/reactrouterv3.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouterv3.js","
|
|
1
|
+
{"version":3,"file":"reactrouterv3.js","sources":["../../src/reactrouterv3.ts"],"sourcesContent":["import { Primitive, Transaction, TransactionContext } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\n\nimport { Location, ReactRouterInstrumentation } 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\nconst global = getGlobalObject<Window>();\n\n/**\n * Creates routing instrumentation for React Router v3\n * Works for React Router >= 3.2.0 and < 4.0.0\n *\n * @param history object from the `history` library\n * @param routes a list of all routes, should be\n * @param match `Router.match` utility\n */\nexport function reactRouterV3Instrumentation(\n history: HistoryV3,\n routes: Route[],\n match: Match,\n): ReactRouterInstrumentation {\n return (\n startTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad: boolean = true,\n startTransactionOnLocationChange: boolean = true,\n ) => {\n let activeTransaction: Transaction | undefined;\n let prevName: string | undefined;\n\n // Have to use global.location because history.location might not be defined.\n if (startTransactionOnPageLoad && global && global.location) {\n normalizeTransactionName(routes, global.location as unknown as Location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'pageload',\n tags: {\n 'routing.instrumentation': 'react-router-v3',\n },\n });\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen(location => {\n if (location.action === 'PUSH' || location.action === 'POP') {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags: Record<string, Primitive> = {\n 'routing.instrumentation': 'react-router-v3',\n };\n if (prevName) {\n tags.from = prevName;\n }\n normalizeTransactionName(routes, location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'navigation',\n tags,\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) => 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);\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 const route = routesWithPaths[x];\n if (route.path && route.path.startsWith('/')) {\n index = x;\n break;\n }\n }\n\n return routesWithPaths\n .slice(index)\n .filter(({ path }) => !!path)\n .map(({ path }) => path)\n .join('');\n}\n"],"names":[],"mappings":";;AAKA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;"}
|