@sentry/react 7.92.0 → 7.94.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/cjs/profiler.js +54 -57
- package/cjs/profiler.js.map +1 -1
- package/cjs/reactrouter.js +3 -2
- package/cjs/reactrouter.js.map +1 -1
- package/cjs/reactrouterv6.js +4 -3
- package/cjs/reactrouterv6.js.map +1 -1
- package/esm/profiler.js +56 -58
- package/esm/profiler.js.map +1 -1
- package/esm/reactrouter.js +3 -2
- package/esm/reactrouter.js.map +1 -1
- package/esm/reactrouterv6.js +4 -3
- package/esm/reactrouterv6.js.map +1 -1
- package/package.json +5 -4
- package/types/profiler.d.ts +1 -4
- package/types/profiler.d.ts.map +1 -1
- package/types/reactrouter.d.ts.map +1 -1
- package/types/reactrouterv6.d.ts.map +1 -1
- package/types-ts3.8/profiler.d.ts +1 -4
package/cjs/profiler.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
3
|
const browser = require('@sentry/browser');
|
|
4
|
+
const core = require('@sentry/core');
|
|
4
5
|
const utils = require('@sentry/utils');
|
|
5
6
|
const hoistNonReactStatics = require('hoist-non-react-statics');
|
|
6
7
|
const React = require('react');
|
|
@@ -24,7 +25,6 @@ const hoistNonReactStatics__default = /*#__PURE__*/_interopDefault(hoistNonReact
|
|
|
24
25
|
const React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
25
26
|
|
|
26
27
|
const _jsxFileName = "/home/runner/work/sentry-javascript/sentry-javascript/packages/react/src/profiler.tsx";
|
|
27
|
-
|
|
28
28
|
const UNKNOWN_COMPONENT = 'unknown';
|
|
29
29
|
|
|
30
30
|
/**
|
|
@@ -56,15 +56,12 @@ class Profiler extends React__namespace.Component {
|
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
data: { 'ui.component_name': name },
|
|
66
|
-
});
|
|
67
|
-
}
|
|
59
|
+
this._mountSpan = browser.startInactiveSpan({
|
|
60
|
+
name: `<${name}>`,
|
|
61
|
+
op: constants.REACT_MOUNT_OP,
|
|
62
|
+
origin: 'auto.ui.react.profiler',
|
|
63
|
+
attributes: { 'ui.component_name': name },
|
|
64
|
+
});
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
// If a component mounted, we can finish the mount activity.
|
|
@@ -84,15 +81,17 @@ class Profiler extends React__namespace.Component {
|
|
|
84
81
|
const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);
|
|
85
82
|
if (changedProps.length > 0) {
|
|
86
83
|
const now = utils.timestampInSeconds();
|
|
87
|
-
this._updateSpan = this._mountSpan
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
84
|
+
this._updateSpan = core.withActiveSpan(this._mountSpan, () => {
|
|
85
|
+
return browser.startInactiveSpan({
|
|
86
|
+
name: `<${this.props.name}>`,
|
|
87
|
+
op: constants.REACT_UPDATE_OP,
|
|
88
|
+
origin: 'auto.ui.react.profiler',
|
|
89
|
+
startTimestamp: now,
|
|
90
|
+
attributes: {
|
|
91
|
+
'ui.component_name': this.props.name,
|
|
92
|
+
'ui.react.changed_props': changedProps,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
96
95
|
});
|
|
97
96
|
}
|
|
98
97
|
}
|
|
@@ -110,18 +109,24 @@ class Profiler extends React__namespace.Component {
|
|
|
110
109
|
// If a component is unmounted, we can say it is no longer on the screen.
|
|
111
110
|
// This means we can finish the span representing the component render.
|
|
112
111
|
componentWillUnmount() {
|
|
112
|
+
const endTimestamp = utils.timestampInSeconds();
|
|
113
113
|
const { name, includeRender = true } = this.props;
|
|
114
114
|
|
|
115
115
|
if (this._mountSpan && includeRender) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
116
|
+
const startTimestamp = core.spanToJSON(this._mountSpan).timestamp;
|
|
117
|
+
core.withActiveSpan(this._mountSpan, () => {
|
|
118
|
+
const renderSpan = browser.startInactiveSpan({
|
|
119
|
+
name: `<${name}>`,
|
|
120
|
+
op: constants.REACT_RENDER_OP,
|
|
121
|
+
origin: 'auto.ui.react.profiler',
|
|
122
|
+
startTimestamp,
|
|
123
|
+
attributes: { 'ui.component_name': name },
|
|
124
|
+
});
|
|
125
|
+
if (renderSpan) {
|
|
126
|
+
// Have to cast to Span because the type of _mountSpan is Span | undefined
|
|
127
|
+
// and not getting narrowed properly
|
|
128
|
+
renderSpan.end(endTimestamp);
|
|
129
|
+
}
|
|
125
130
|
});
|
|
126
131
|
}
|
|
127
132
|
}
|
|
@@ -139,6 +144,7 @@ class Profiler extends React__namespace.Component {
|
|
|
139
144
|
* @param WrappedComponent component that is wrapped by Profiler
|
|
140
145
|
* @param options the {@link ProfilerProps} you can pass into the Profiler
|
|
141
146
|
*/
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
142
148
|
function withProfiler(
|
|
143
149
|
WrappedComponent,
|
|
144
150
|
// We do not want to have `updateProps` given in options, it is instead filled through the HOC.
|
|
@@ -148,8 +154,8 @@ function withProfiler(
|
|
|
148
154
|
(options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
|
|
149
155
|
|
|
150
156
|
const Wrapped = (props) => (
|
|
151
|
-
React__namespace.createElement(Profiler, { ...options, name: componentDisplayName, updateProps: props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
152
|
-
, React__namespace.createElement(WrappedComponent, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
157
|
+
React__namespace.createElement(Profiler, { ...options, name: componentDisplayName, updateProps: props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 156}}
|
|
158
|
+
, React__namespace.createElement(WrappedComponent, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 157}} )
|
|
153
159
|
)
|
|
154
160
|
);
|
|
155
161
|
|
|
@@ -180,17 +186,12 @@ function useProfiler(
|
|
|
180
186
|
return undefined;
|
|
181
187
|
}
|
|
182
188
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
data: { 'ui.component_name': name },
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return undefined;
|
|
189
|
+
return browser.startInactiveSpan({
|
|
190
|
+
name: `<${name}>`,
|
|
191
|
+
op: constants.REACT_MOUNT_OP,
|
|
192
|
+
origin: 'auto.ui.react.profiler',
|
|
193
|
+
attributes: { 'ui.component_name': name },
|
|
194
|
+
});
|
|
194
195
|
});
|
|
195
196
|
|
|
196
197
|
React__namespace.useEffect(() => {
|
|
@@ -200,14 +201,21 @@ function useProfiler(
|
|
|
200
201
|
|
|
201
202
|
return () => {
|
|
202
203
|
if (mountSpan && options.hasRenderSpan) {
|
|
203
|
-
mountSpan.
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
const startTimestamp = core.spanToJSON(mountSpan).timestamp;
|
|
205
|
+
const endTimestamp = utils.timestampInSeconds();
|
|
206
|
+
|
|
207
|
+
const renderSpan = browser.startInactiveSpan({
|
|
208
|
+
name: `<${name}>`,
|
|
206
209
|
op: constants.REACT_RENDER_OP,
|
|
207
210
|
origin: 'auto.ui.react.profiler',
|
|
208
|
-
startTimestamp
|
|
209
|
-
|
|
211
|
+
startTimestamp,
|
|
212
|
+
attributes: { 'ui.component_name': name },
|
|
210
213
|
});
|
|
214
|
+
if (renderSpan) {
|
|
215
|
+
// Have to cast to Span because the type of _mountSpan is Span | undefined
|
|
216
|
+
// and not getting narrowed properly
|
|
217
|
+
renderSpan.end(endTimestamp);
|
|
218
|
+
}
|
|
211
219
|
}
|
|
212
220
|
};
|
|
213
221
|
// We only want this to run once.
|
|
@@ -215,19 +223,8 @@ function useProfiler(
|
|
|
215
223
|
}, []);
|
|
216
224
|
}
|
|
217
225
|
|
|
218
|
-
/** Grabs active transaction off scope */
|
|
219
|
-
function getActiveTransaction(hub = browser.getCurrentHub()) {
|
|
220
|
-
if (hub) {
|
|
221
|
-
const scope = hub.getScope();
|
|
222
|
-
return scope.getTransaction() ;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return undefined;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
226
|
exports.Profiler = Profiler;
|
|
229
227
|
exports.UNKNOWN_COMPONENT = UNKNOWN_COMPONENT;
|
|
230
|
-
exports.getActiveTransaction = getActiveTransaction;
|
|
231
228
|
exports.useProfiler = useProfiler;
|
|
232
229
|
exports.withProfiler = withProfiler;
|
|
233
230
|
//# sourceMappingURL=profiler.js.map
|
package/cjs/profiler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiler.js","sources":["../../src/profiler.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Hub } from '@sentry/browser';\nimport { getCurrentHub } from '@sentry/browser';\nimport type { Span, Transaction } from '@sentry/types';\nimport { timestampInSeconds } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type ProfilerProps = {\n // The name of the component being profiled.\n name: string;\n // If the Profiler is disabled. False by default. This is useful if you want to disable profilers\n // in certain environments.\n disabled?: boolean;\n // If time component is on page should be displayed as spans. True by default.\n includeRender?: boolean;\n // If component updates should be displayed as spans. True by default.\n includeUpdates?: boolean;\n // Component that is being profiled.\n children?: React.ReactNode;\n // props given to component being profiled.\n updateProps: { [key: string]: unknown };\n};\n\n/**\n * The Profiler component leverages Sentry's Tracing integration to generate\n * spans based on component lifecycles.\n */\nclass Profiler extends React.Component<ProfilerProps> {\n /**\n * The span of the mount activity\n * Made protected for the React Native SDK to access\n */\n protected _mountSpan: Span | undefined;\n /**\n * The span that represents the duration of time between shouldComponentUpdate and componentDidUpdate\n */\n protected _updateSpan: Span | undefined;\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static defaultProps: Partial<ProfilerProps> = {\n disabled: false,\n includeRender: true,\n includeUpdates: true,\n };\n\n public constructor(props: ProfilerProps) {\n super(props);\n const { name, disabled = false } = this.props;\n\n if (disabled) {\n return;\n }\n\n const activeTransaction = getActiveTransaction();\n if (activeTransaction) {\n this._mountSpan = activeTransaction.startChild({\n description: `<${name}>`,\n op: REACT_MOUNT_OP,\n origin: 'auto.ui.react.profiler',\n data: { 'ui.component_name': name },\n });\n }\n }\n\n // If a component mounted, we can finish the mount activity.\n public componentDidMount(): void {\n if (this._mountSpan) {\n this._mountSpan.end();\n }\n }\n\n public shouldComponentUpdate({ updateProps, includeUpdates = true }: ProfilerProps): boolean {\n // Only generate an update span if includeUpdates is true, if there is a valid mountSpan,\n // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.\n // We are just trying to give baseline clues for further investigation.\n if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {\n // See what props haved changed between the previous props, and the current props. This is\n // set as data on the span. We just store the prop keys as the values could be potenially very large.\n const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);\n if (changedProps.length > 0) {\n const now = timestampInSeconds();\n this._updateSpan = this._mountSpan.startChild({\n data: {\n changedProps,\n 'ui.component_name': this.props.name,\n },\n description: `<${this.props.name}>`,\n op: REACT_UPDATE_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: now,\n });\n }\n }\n\n return true;\n }\n\n public componentDidUpdate(): void {\n if (this._updateSpan) {\n this._updateSpan.end();\n this._updateSpan = undefined;\n }\n }\n\n // If a component is unmounted, we can say it is no longer on the screen.\n // This means we can finish the span representing the component render.\n public componentWillUnmount(): void {\n const { name, includeRender = true } = this.props;\n\n if (this._mountSpan && includeRender) {\n // If we were able to obtain the spanId of the mount activity, we should set the\n // next activity as a child to the component mount activity.\n this._mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampInSeconds(),\n op: REACT_RENDER_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: this._mountSpan.endTimestamp,\n data: { 'ui.component_name': name },\n });\n }\n }\n\n public render(): React.ReactNode {\n return this.props.children;\n }\n}\n\n/**\n * withProfiler is a higher order component that wraps a\n * component in a {@link Profiler} component. It is recommended that\n * the higher order component be used over the regular {@link Profiler} component.\n *\n * @param WrappedComponent component that is wrapped by Profiler\n * @param options the {@link ProfilerProps} you can pass into the Profiler\n */\nfunction withProfiler<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n // We do not want to have `updateProps` given in options, it is instead filled through the HOC.\n options?: Pick<Partial<ProfilerProps>, Exclude<keyof ProfilerProps, 'updateProps' | 'children'>>,\n): React.FC<P> {\n const componentDisplayName =\n (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <Profiler {...options} name={componentDisplayName} updateProps={props}>\n <WrappedComponent {...props} />\n </Profiler>\n );\n\n Wrapped.displayName = `profiler(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\n/**\n *\n * `useProfiler` is a React hook that profiles a React component.\n *\n * Requires React 16.8 or above.\n * @param name displayName of component being profiled\n */\nfunction useProfiler(\n name: string,\n options: { disabled?: boolean; hasRenderSpan?: boolean } = {\n disabled: false,\n hasRenderSpan: true,\n },\n): void {\n const [mountSpan] = React.useState(() => {\n if (options && options.disabled) {\n return undefined;\n }\n\n const activeTransaction = getActiveTransaction();\n if (activeTransaction) {\n return activeTransaction.startChild({\n description: `<${name}>`,\n op: REACT_MOUNT_OP,\n origin: 'auto.ui.react.profiler',\n data: { 'ui.component_name': name },\n });\n }\n\n return undefined;\n });\n\n React.useEffect(() => {\n if (mountSpan) {\n mountSpan.end();\n }\n\n return (): void => {\n if (mountSpan && options.hasRenderSpan) {\n mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampInSeconds(),\n op: REACT_RENDER_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: mountSpan.endTimestamp,\n data: { 'ui.component_name': name },\n });\n }\n };\n // We only want this to run once.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n}\n\nexport { withProfiler, Profiler, useProfiler };\n\n/** Grabs active transaction off scope */\nexport function getActiveTransaction<T extends Transaction>(hub: Hub = getCurrentHub()): T | undefined {\n if (hub) {\n const scope = hub.getScope();\n return scope.getTransaction() as T | undefined;\n }\n\n return undefined;\n}\n"],"names":["React","REACT_MOUNT_OP","timestampInSeconds","REACT_UPDATE_OP","REACT_RENDER_OP","hoistNonReactStatics","getCurrentHub"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,uFAAA,CAAA;AAUA;AACO,MAAM,iBAAkB,GAAE,UAAS;;AAkB1C;AACA;AACA;AACA;AACA,MAAM,QAAS,SAAQA,gBAAK,CAAC,SAAS,CAAgB;AACtD;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA,GAAS,OAAA,YAAA,GAAA,CAAA,IAAA,CAAO,YAAY,GAA2B;AACvD,IAAI,QAAQ,EAAE,KAAK;AACnB,IAAI,aAAa,EAAE,IAAI;AACvB,IAAI,cAAc,EAAE,IAAI;AACxB,IAAG,CAAA;AACH;AACA,GAAS,WAAW,CAAC,KAAK,EAAiB;AAC3C,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;AAChB,IAAI,MAAM,EAA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EAAE;AACX,IAAI,MAAM,KAAM,GAAE,GAAG,CAAC,QAAQ,EAAE,CAAA;AAChC,IAAI,OAAO,KAAK,CAAC,cAAc,EAAG,EAAA;AAClC,GAAE;AACF;AACA,EAAE,OAAO,SAAS,CAAA;AAClB;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"profiler.js","sources":["../../src/profiler.tsx"],"sourcesContent":["import { startInactiveSpan } from '@sentry/browser';\nimport { spanToJSON, withActiveSpan } from '@sentry/core';\nimport type { Span } from '@sentry/types';\nimport { timestampInSeconds } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type ProfilerProps = {\n // The name of the component being profiled.\n name: string;\n // If the Profiler is disabled. False by default. This is useful if you want to disable profilers\n // in certain environments.\n disabled?: boolean;\n // If time component is on page should be displayed as spans. True by default.\n includeRender?: boolean;\n // If component updates should be displayed as spans. True by default.\n includeUpdates?: boolean;\n // Component that is being profiled.\n children?: React.ReactNode;\n // props given to component being profiled.\n updateProps: { [key: string]: unknown };\n};\n\n/**\n * The Profiler component leverages Sentry's Tracing integration to generate\n * spans based on component lifecycles.\n */\nclass Profiler extends React.Component<ProfilerProps> {\n /**\n * The span of the mount activity\n * Made protected for the React Native SDK to access\n */\n protected _mountSpan: Span | undefined;\n /**\n * The span that represents the duration of time between shouldComponentUpdate and componentDidUpdate\n */\n protected _updateSpan: Span | undefined;\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static defaultProps: Partial<ProfilerProps> = {\n disabled: false,\n includeRender: true,\n includeUpdates: true,\n };\n\n public constructor(props: ProfilerProps) {\n super(props);\n const { name, disabled = false } = this.props;\n\n if (disabled) {\n return;\n }\n\n this._mountSpan = startInactiveSpan({\n name: `<${name}>`,\n op: REACT_MOUNT_OP,\n origin: 'auto.ui.react.profiler',\n attributes: { 'ui.component_name': name },\n });\n }\n\n // If a component mounted, we can finish the mount activity.\n public componentDidMount(): void {\n if (this._mountSpan) {\n this._mountSpan.end();\n }\n }\n\n public shouldComponentUpdate({ updateProps, includeUpdates = true }: ProfilerProps): boolean {\n // Only generate an update span if includeUpdates is true, if there is a valid mountSpan,\n // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.\n // We are just trying to give baseline clues for further investigation.\n if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {\n // See what props haved changed between the previous props, and the current props. This is\n // set as data on the span. We just store the prop keys as the values could be potenially very large.\n const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);\n if (changedProps.length > 0) {\n const now = timestampInSeconds();\n this._updateSpan = withActiveSpan(this._mountSpan, () => {\n return startInactiveSpan({\n name: `<${this.props.name}>`,\n op: REACT_UPDATE_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: now,\n attributes: {\n 'ui.component_name': this.props.name,\n 'ui.react.changed_props': changedProps,\n },\n });\n });\n }\n }\n\n return true;\n }\n\n public componentDidUpdate(): void {\n if (this._updateSpan) {\n this._updateSpan.end();\n this._updateSpan = undefined;\n }\n }\n\n // If a component is unmounted, we can say it is no longer on the screen.\n // This means we can finish the span representing the component render.\n public componentWillUnmount(): void {\n const endTimestamp = timestampInSeconds();\n const { name, includeRender = true } = this.props;\n\n if (this._mountSpan && includeRender) {\n const startTimestamp = spanToJSON(this._mountSpan).timestamp;\n withActiveSpan(this._mountSpan, () => {\n const renderSpan = startInactiveSpan({\n name: `<${name}>`,\n op: REACT_RENDER_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp,\n attributes: { 'ui.component_name': name },\n });\n if (renderSpan) {\n // Have to cast to Span because the type of _mountSpan is Span | undefined\n // and not getting narrowed properly\n renderSpan.end(endTimestamp);\n }\n });\n }\n }\n\n public render(): React.ReactNode {\n return this.props.children;\n }\n}\n\n/**\n * withProfiler is a higher order component that wraps a\n * component in a {@link Profiler} component. It is recommended that\n * the higher order component be used over the regular {@link Profiler} component.\n *\n * @param WrappedComponent component that is wrapped by Profiler\n * @param options the {@link ProfilerProps} you can pass into the Profiler\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction withProfiler<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n // We do not want to have `updateProps` given in options, it is instead filled through the HOC.\n options?: Pick<Partial<ProfilerProps>, Exclude<keyof ProfilerProps, 'updateProps' | 'children'>>,\n): React.FC<P> {\n const componentDisplayName =\n (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <Profiler {...options} name={componentDisplayName} updateProps={props}>\n <WrappedComponent {...props} />\n </Profiler>\n );\n\n Wrapped.displayName = `profiler(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\n/**\n *\n * `useProfiler` is a React hook that profiles a React component.\n *\n * Requires React 16.8 or above.\n * @param name displayName of component being profiled\n */\nfunction useProfiler(\n name: string,\n options: { disabled?: boolean; hasRenderSpan?: boolean } = {\n disabled: false,\n hasRenderSpan: true,\n },\n): void {\n const [mountSpan] = React.useState(() => {\n if (options && options.disabled) {\n return undefined;\n }\n\n return startInactiveSpan({\n name: `<${name}>`,\n op: REACT_MOUNT_OP,\n origin: 'auto.ui.react.profiler',\n attributes: { 'ui.component_name': name },\n });\n });\n\n React.useEffect(() => {\n if (mountSpan) {\n mountSpan.end();\n }\n\n return (): void => {\n if (mountSpan && options.hasRenderSpan) {\n const startTimestamp = spanToJSON(mountSpan).timestamp;\n const endTimestamp = timestampInSeconds();\n\n const renderSpan = startInactiveSpan({\n name: `<${name}>`,\n op: REACT_RENDER_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp,\n attributes: { 'ui.component_name': name },\n });\n if (renderSpan) {\n // Have to cast to Span because the type of _mountSpan is Span | undefined\n // and not getting narrowed properly\n renderSpan.end(endTimestamp);\n }\n }\n };\n // We only want this to run once.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n}\n\nexport { withProfiler, Profiler, useProfiler };\n"],"names":["React","startInactiveSpan","REACT_MOUNT_OP","timestampInSeconds","withActiveSpan","REACT_UPDATE_OP","spanToJSON","REACT_RENDER_OP","hoistNonReactStatics"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,uFAAA,CAQA;AACO,MAAM,iBAAkB,GAAE,UAAS;;AAkB1C;AACA;AACA;AACA;AACA,MAAM,QAAS,SAAQA,gBAAK,CAAC,SAAS,CAAgB;AACtD;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA,GAAS,OAAA,YAAA,GAAA,CAAA,IAAA,CAAO,YAAY,GAA2B;AACvD,IAAI,QAAQ,EAAE,KAAK;AACnB,IAAI,aAAa,EAAE,IAAI;AACvB,IAAI,cAAc,EAAE,IAAI;AACxB,IAAG,CAAA;AACH;AACA,GAAS,WAAW,CAAC,KAAK,EAAiB;AAC3C,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;AAChB,IAAI,MAAM,EAAE,IAAI,EAAE,QAAA,GAAW,KAAA,EAAQ,GAAE,IAAI,CAAC,KAAK,CAAA;AACjD;AACA,IAAI,IAAI,QAAQ,EAAE;AAClB,MAAM,OAAM;AACZ,KAAI;AACJ;AACA,IAAI,IAAI,CAAC,UAAW,GAAEC,yBAAiB,CAAC;AACxC,MAAM,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AACvB,MAAM,EAAE,EAAEC,wBAAc;AACxB,MAAM,MAAM,EAAE,wBAAwB;AACtC,MAAM,UAAU,EAAE,EAAE,mBAAmB,EAAE,MAAM;AAC/C,KAAK,CAAC,CAAA;AACN,GAAE;AACF;AACA;AACA,GAAS,iBAAiB,GAAS;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EAAE,wBAAwB;AACtC,MAAM,UAAU,EAAE,EAAE,mBAAmB,EAAE,MAAM;AAC/C,KAAK,CAAC,CAAA;AACN,GAAG,CAAC,CAAA;AACJ;AACA,EAAEF,gBAAK,CAAC,SAAS,CAAC,MAAM;AACxB,IAAI,IAAI,SAAS,EAAE;AACnB,MAAM,SAAS,CAAC,GAAG,EAAE,CAAA;AACrB,KAAI;AACJ;AACA,IAAI,OAAO,MAAY;AACvB,MAAM,IAAI,SAAA,IAAa,OAAO,CAAC,aAAa,EAAE;AAC9C,QAAQ,MAAM,iBAAiBM,eAAU,CAAC,SAAS,CAAC,CAAC,SAAS,CAAA;AAC9D,QAAQ,MAAM,YAAA,GAAeH,wBAAkB,EAAE,CAAA;AACjD;AACA,QAAQ,MAAM,UAAA,GAAaF,yBAAiB,CAAC;AAC7C,UAAU,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AAC3B,UAAU,EAAE,EAAEM,yBAAe;AAC7B,UAAU,MAAM,EAAE,wBAAwB;AAC1C,UAAU,cAAc;AACxB,UAAU,UAAU,EAAE,EAAE,mBAAmB,EAAE,MAAM;AACnD,SAAS,CAAC,CAAA;AACV,QAAQ,IAAI,UAAU,EAAE;AACxB;AACA;AACA,UAAU,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;AACtC,SAAQ;AACR,OAAM;AACN,KAAK,CAAA;AACL;AACA;AACA,GAAG,EAAE,EAAE,CAAC,CAAA;AACR;;;;;;;"}
|
package/cjs/reactrouter.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
3
|
const browser = require('@sentry/browser');
|
|
4
|
+
const core = require('@sentry/core');
|
|
4
5
|
const hoistNonReactStatics = require('hoist-non-react-statics');
|
|
5
6
|
const React = require('react');
|
|
6
7
|
|
|
@@ -169,13 +170,13 @@ function withSentryRouting(Route) {
|
|
|
169
170
|
const WrappedRoute = (props) => {
|
|
170
171
|
if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {
|
|
171
172
|
activeTransaction.updateName(props.computedMatch.path);
|
|
172
|
-
activeTransaction.
|
|
173
|
+
activeTransaction.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
|
|
173
174
|
}
|
|
174
175
|
|
|
175
176
|
// @ts-expect-error Setting more specific React Component typing for `R` generic above
|
|
176
177
|
// will break advanced type inference done by react router params:
|
|
177
178
|
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
|
|
178
|
-
return React__namespace.createElement(Route, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
179
|
+
return React__namespace.createElement(Route, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 176}} );
|
|
179
180
|
};
|
|
180
181
|
|
|
181
182
|
WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;
|
package/cjs/reactrouter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouter.js","sources":["../../src/reactrouter.tsx"],"sourcesContent":["import { WINDOW } from '@sentry/browser';\nimport type { Transaction, TransactionSource } from '@sentry/types';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport type { 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.\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?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null; // eslint-disable-line @typescript-eslint/no-explicit-any\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 (WINDOW && 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 // 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, 'route'];\n }\n }\n\n return [pathname, 'url'];\n }\n\n const tags = {\n 'routing.instrumentation': name,\n };\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n const [name, source] = normalizeTransactionName(initPathName);\n activeTransaction = customStartTransaction({\n name,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouter',\n tags,\n metadata: {\n source,\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.end();\n }\n\n const [name, source] = normalizeTransactionName(location.pathname);\n activeTransaction = customStartTransaction({\n name,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouter',\n tags,\n metadata: {\n source,\n },\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.updateName(props.computedMatch.path);\n activeTransaction.setMetadata({ source: 'route' });\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"],"names":["WINDOW","React","hoistNonReactStatics"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,0FAAA;AAOA;AACA;;AAgBA;AACA;AACA,IAAI,iBAAiB,CAAA;AACrB;AACO,SAAS,4BAA4B;AAC5C,EAAE,OAAO;AACT,EAAE,MAAM;AACR,EAAE,SAAS;AACX,EAA8B;AAC9B,EAAE,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;AACxF,CAAA;AACA;AACO,SAAS,4BAA4B;AAC5C,EAAE,OAAO;AACT,EAAE,MAAM;AACR,EAAE,SAAS;AACX,EAA8B;AAC9B,EAAE,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;AACxF,CAAA;AACA;AACA,SAAS,gCAAgC;AACzC,EAAE,OAAO;AACT,EAAE,IAAI;AACN,EAAE,SAAS,GAAkB,EAAE;AAC/B,EAAE,SAAS;AACX,EAA8B;AAC9B,EAAE,SAAS,eAAe,GAAuB;AACjD,IAAI,IAAI,OAAA,IAAW,OAAO,CAAC,QAAQ,EAAE;AACrC,MAAM,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAA;AACtC,KAAI;AACJ;AACA,IAAI,IAAIA,cAAA,IAAUA,cAAM,CAAC,QAAQ,EAAE;AACnC,MAAM,OAAOA,cAAM,CAAC,QAAQ,CAAC,QAAQ,CAAA;AACrC,KAAI;AACJ;AACA,IAAI,OAAO,SAAS,CAAA;AACpB,GAAE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,SAAS,wBAAwB,CAAC,QAAQ,EAAuC;AACnF,IAAI,IAAI,SAAS,CAAC,MAAA,KAAW,CAAE,IAAG,C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"file":"reactrouter.js","sources":["../../src/reactrouter.tsx"],"sourcesContent":["import { WINDOW } from '@sentry/browser';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';\nimport type { Transaction, TransactionSource } from '@sentry/types';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport type { 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.\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?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null; // eslint-disable-line @typescript-eslint/no-explicit-any\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 (WINDOW && 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 // 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, 'route'];\n }\n }\n\n return [pathname, 'url'];\n }\n\n const tags = {\n 'routing.instrumentation': name,\n };\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n const [name, source] = normalizeTransactionName(initPathName);\n activeTransaction = customStartTransaction({\n name,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouter',\n tags,\n metadata: {\n source,\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.end();\n }\n\n const [name, source] = normalizeTransactionName(location.pathname);\n activeTransaction = customStartTransaction({\n name,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouter',\n tags,\n metadata: {\n source,\n },\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.updateName(props.computedMatch.path);\n activeTransaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');\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"],"names":["WINDOW","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","React","hoistNonReactStatics"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,0FAAA;AAQA;AACA;;AAgBA;AACA;AACA,IAAI,iBAAiB,CAAA;AACrB;AACO,SAAS,4BAA4B;AAC5C,EAAE,OAAO;AACT,EAAE,MAAM;AACR,EAAE,SAAS;AACX,EAA8B;AAC9B,EAAE,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;AACxF,CAAA;AACA;AACO,SAAS,4BAA4B;AAC5C,EAAE,OAAO;AACT,EAAE,MAAM;AACR,EAAE,SAAS;AACX,EAA8B;AAC9B,EAAE,OAAO,gCAAgC,CAA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CAAC,KAAK,KAAQ;AAClD,IAAI,IAAI,iBAAkB,IAAG,SAAS,KAAK,CAAC,aAAA,IAAiB,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE;AAC1F,MAAM,iBAAiB,CAAC,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;AAC5D,MAAM,iBAAiB,CAAC,YAAY,CAACC,qCAAgC,EAAE,OAAO,CAAC,CAAA;AAC/E,KAAI;AACJ;AACA;AACA;AACA;AACA,IAAI,OAAOC,gBAAC,CAAA,aAAA,CAAA,KAAA,EAAA,EAAM,GAAI,KAAK,sEAAI,CAAA;AAC/B,GAAG,CAAA;AACH;AACA,EAAE,YAAY,CAAC,WAAA,GAAc,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAA;AACnE,EAAEC,6BAAoB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;AAC3C;AACA;AACA;AACA,EAAE,OAAO,YAAY,CAAA;AACrB,CAAA;AACA;;;;;;"}
|
package/cjs/reactrouterv6.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
3
|
const browser = require('@sentry/browser');
|
|
4
|
+
const core = require('@sentry/core');
|
|
4
5
|
const utils = require('@sentry/utils');
|
|
5
6
|
const hoistNonReactStatics = require('hoist-non-react-statics');
|
|
6
7
|
const React = require('react');
|
|
@@ -136,7 +137,7 @@ function updatePageloadTransaction(
|
|
|
136
137
|
if (activeTransaction && branches) {
|
|
137
138
|
const [name, source] = getNormalizedName(routes, location, branches, basename);
|
|
138
139
|
activeTransaction.updateName(name);
|
|
139
|
-
activeTransaction.
|
|
140
|
+
activeTransaction.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
|
|
@@ -209,7 +210,7 @@ function withSentryReactRouterV6Routing(Routes) {
|
|
|
209
210
|
|
|
210
211
|
// @ts-expect-error Setting more specific React Component typing for `R` generic above
|
|
211
212
|
// will break advanced type inference done by react router params
|
|
212
|
-
return React__namespace.createElement(Routes, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
213
|
+
return React__namespace.createElement(Routes, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 213}} );
|
|
213
214
|
};
|
|
214
215
|
|
|
215
216
|
hoistNonReactStatics__default(SentryRoutes, Routes);
|
|
@@ -264,7 +265,7 @@ function wrapUseRoutes(origUseRoutes) {
|
|
|
264
265
|
|
|
265
266
|
// eslint-disable-next-line react/display-name
|
|
266
267
|
return (routes, locationArg) => {
|
|
267
|
-
return React__namespace.createElement(SentryRoutes, { routes: routes, locationArg: locationArg, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
268
|
+
return React__namespace.createElement(SentryRoutes, { routes: routes, locationArg: locationArg, __self: this, __source: {fileName: _jsxFileName, lineNumber: 270}} );
|
|
268
269
|
};
|
|
269
270
|
}
|
|
270
271
|
|
package/cjs/reactrouterv6.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouterv6.js","sources":["../../src/reactrouterv6.tsx"],"sourcesContent":["// Inspired from Donnie McNeal's solution:\n// https://gist.github.com/wontondon/e8c4bdf2888875e4c755712e99279536\n\nimport { WINDOW } from '@sentry/browser';\nimport type { Transaction, TransactionContext, TransactionSource } from '@sentry/types';\nimport { getNumberOfUrlSegments, logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport type {\n Action,\n AgnosticDataRouteMatch,\n CreateRouterFunction,\n CreateRoutesFromChildren,\n Location,\n MatchRoutes,\n RouteMatch,\n RouteObject,\n Router,\n RouterState,\n UseEffect,\n UseLocation,\n UseNavigationType,\n UseRoutes,\n} from './types';\n\nlet activeTransaction: Transaction | undefined;\n\nlet _useEffect: UseEffect;\nlet _useLocation: UseLocation;\nlet _useNavigationType: UseNavigationType;\nlet _createRoutesFromChildren: CreateRoutesFromChildren;\nlet _matchRoutes: MatchRoutes;\nlet _customStartTransaction: (context: TransactionContext) => Transaction | undefined;\nlet _startTransactionOnLocationChange: boolean;\n\nconst SENTRY_TAGS = {\n 'routing.instrumentation': 'react-router-v6',\n};\n\nexport function reactRouterV6Instrumentation(\n useEffect: UseEffect,\n useLocation: UseLocation,\n useNavigationType: UseNavigationType,\n createRoutesFromChildren: CreateRoutesFromChildren,\n matchRoutes: MatchRoutes,\n) {\n return (\n customStartTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad = true,\n startTransactionOnLocationChange = true,\n ): void => {\n const initPathName = WINDOW && WINDOW.location && WINDOW.location.pathname;\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: initPathName,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouterv6',\n tags: SENTRY_TAGS,\n metadata: {\n source: 'url',\n },\n });\n }\n\n _useEffect = useEffect;\n _useLocation = useLocation;\n _useNavigationType = useNavigationType;\n _matchRoutes = matchRoutes;\n _createRoutesFromChildren = createRoutesFromChildren;\n\n _customStartTransaction = customStartTransaction;\n _startTransactionOnLocationChange = startTransactionOnLocationChange;\n };\n}\n\nfunction getNormalizedName(\n routes: RouteObject[],\n location: Location,\n branches: RouteMatch[],\n basename: string = '',\n): [string, TransactionSource] {\n if (!routes || routes.length === 0) {\n return [location.pathname, 'url'];\n }\n\n let pathBuilder = '';\n if (branches) {\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n const branch = branches[x];\n const route = branch.route;\n if (route) {\n // Early return if index route\n if (route.index) {\n return [branch.pathname, 'route'];\n }\n\n const path = route.path;\n if (path) {\n const newPath = path[0] === '/' || pathBuilder[pathBuilder.length - 1] === '/' ? path : `/${path}`;\n pathBuilder += newPath;\n\n if (basename + branch.pathname === location.pathname) {\n if (\n // If the route defined on the element is something like\n // <Route path=\"/stores/:storeId/products/:productId\" element={<div>Product</div>} />\n // We should check against the branch.pathname for the number of / seperators\n getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&\n // We should not count wildcard operators in the url segments calculation\n pathBuilder.slice(-2) !== '/*'\n ) {\n return [basename + newPath, 'route'];\n }\n return [basename + pathBuilder, 'route'];\n }\n }\n }\n }\n }\n\n return [location.pathname, 'url'];\n}\n\nfunction updatePageloadTransaction(\n location: Location,\n routes: RouteObject[],\n matches?: AgnosticDataRouteMatch,\n basename?: string,\n): void {\n const branches = Array.isArray(matches)\n ? matches\n : (_matchRoutes(routes, location, basename) as unknown as RouteMatch[]);\n\n if (activeTransaction && branches) {\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n activeTransaction.updateName(name);\n activeTransaction.setMetadata({ source });\n }\n}\n\nfunction handleNavigation(\n location: Location,\n routes: RouteObject[],\n navigationType: Action,\n matches?: AgnosticDataRouteMatch,\n basename?: string,\n): void {\n const branches = Array.isArray(matches) ? matches : _matchRoutes(routes, location, basename);\n\n if (_startTransactionOnLocationChange && (navigationType === 'PUSH' || navigationType === 'POP') && branches) {\n if (activeTransaction) {\n activeTransaction.end();\n }\n\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n activeTransaction = _customStartTransaction({\n name,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouterv6',\n tags: SENTRY_TAGS,\n metadata: {\n source,\n },\n });\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withSentryReactRouterV6Routing<P extends Record<string, any>, R extends React.FC<P>>(Routes: R): R {\n if (\n !_useEffect ||\n !_useLocation ||\n !_useNavigationType ||\n !_createRoutesFromChildren ||\n !_matchRoutes ||\n !_customStartTransaction\n ) {\n DEBUG_BUILD &&\n logger.warn(`reactRouterV6Instrumentation was unable to wrap Routes because of one or more missing parameters.\n useEffect: ${_useEffect}. useLocation: ${_useLocation}. useNavigationType: ${_useNavigationType}.\n createRoutesFromChildren: ${_createRoutesFromChildren}. matchRoutes: ${_matchRoutes}. customStartTransaction: ${_customStartTransaction}.`);\n\n return Routes;\n }\n\n let isMountRenderPass: boolean = true;\n\n const SentryRoutes: React.FC<P> = (props: P) => {\n const location = _useLocation();\n const navigationType = _useNavigationType();\n\n _useEffect(\n () => {\n const routes = _createRoutesFromChildren(props.children) as RouteObject[];\n\n if (isMountRenderPass) {\n updatePageloadTransaction(location, routes);\n isMountRenderPass = false;\n } else {\n handleNavigation(location, routes, navigationType);\n }\n },\n // `props.children` is purpusely not included in the dependency array, because we do not want to re-run this effect\n // when the children change. We only want to start transactions when the location or navigation type change.\n [location, navigationType],\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 return <Routes {...props} />;\n };\n\n hoistNonReactStatics(SentryRoutes, Routes);\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 return SentryRoutes;\n}\n\nexport function wrapUseRoutes(origUseRoutes: UseRoutes): UseRoutes {\n if (!_useEffect || !_useLocation || !_useNavigationType || !_matchRoutes || !_customStartTransaction) {\n DEBUG_BUILD &&\n logger.warn(\n 'reactRouterV6Instrumentation was unable to wrap `useRoutes` because of one or more missing parameters.',\n );\n\n return origUseRoutes;\n }\n\n let isMountRenderPass: boolean = true;\n\n const SentryRoutes: React.FC<{\n children?: React.ReactNode;\n routes: RouteObject[];\n locationArg?: Partial<Location> | string;\n }> = (props: { children?: React.ReactNode; routes: RouteObject[]; locationArg?: Partial<Location> | string }) => {\n const { routes, locationArg } = props;\n\n const Routes = origUseRoutes(routes, locationArg);\n\n const location = _useLocation();\n const navigationType = _useNavigationType();\n\n // A value with stable identity to either pick `locationArg` if available or `location` if not\n const stableLocationParam =\n typeof locationArg === 'string' || (locationArg && locationArg.pathname)\n ? (locationArg as { pathname: string })\n : location;\n\n _useEffect(() => {\n const normalizedLocation =\n typeof stableLocationParam === 'string' ? { pathname: stableLocationParam } : stableLocationParam;\n\n if (isMountRenderPass) {\n updatePageloadTransaction(normalizedLocation, routes);\n isMountRenderPass = false;\n } else {\n handleNavigation(normalizedLocation, routes, navigationType);\n }\n }, [navigationType, stableLocationParam]);\n\n return Routes;\n };\n\n // eslint-disable-next-line react/display-name\n return (routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null => {\n return <SentryRoutes routes={routes} locationArg={locationArg} />;\n };\n}\n\nexport function wrapCreateBrowserRouter<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n // `opts` for createBrowserHistory and createMemoryHistory are different, but also not relevant for us at the moment.\n // `basename` is the only option that is relevant for us, and it is the same for all.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function (routes: RouteObject[], opts?: Record<string, any> & { basename?: string }): TRouter {\n const router = createRouterFunction(routes, opts);\n const basename = opts && opts.basename;\n\n // The initial load ends when `createBrowserRouter` is called.\n // This is the earliest convenient time to update the transaction name.\n // Callbacks to `router.subscribe` are not called for the initial load.\n if (router.state.historyAction === 'POP' && activeTransaction) {\n updatePageloadTransaction(router.state.location, routes, undefined, basename);\n }\n\n router.subscribe((state: RouterState) => {\n const location = state.location;\n\n if (\n _startTransactionOnLocationChange &&\n (state.historyAction === 'PUSH' || state.historyAction === 'POP') &&\n activeTransaction\n ) {\n handleNavigation(location, routes, state.historyAction, undefined, basename);\n }\n });\n\n return router;\n };\n}\n"],"names":["WINDOW","getNumberOfUrlSegments","DEBUG_BUILD","logger","React","hoistNonReactStatics"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,4FAAA,CAAA;;AA2BA,IAAI,iBAAiB,CAAA;AACrB;AACA,IAAI,UAAU,CAAA;AACd,IAAI,YAAY,CAAA;AAChB,IAAI,kBAAkB,CAAA;AACtB,IAAI,yBAAyB,CAAA;AAC7B,IAAI,YAAY,CAAA;AACh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AA,KAAA,IAAA,iBAAA,EAAA;AACA,MAAA,yBAAA,CAAA,MAAA,CAAA,KAAA,CAAA,QAAA,EAAA,MAAA,EAAA,SAAA,EAAA,QAAA,CAAA,CAAA;AACA,KAAA;AACA;AACA,IAAA,MAAA,CAAA,SAAA,CAAA,CAAA,KAAA,KAAA;AACA,MAAA,MAAA,QAAA,GAAA,KAAA,CAAA,QAAA,CAAA;AACA;AACA,MAAA;AACA,QAAA,iCAAA;AACA,SAAA,KAAA,CAAA,aAAA,KAAA,MAAA,IAAA,KAAA,CAAA,aAAA,KAAA,KAAA,CAAA;AACA,QAAA,iBAAA;AACA,QAAA;AACA,QAAA,gBAAA,CAAA,QAAA,EAAA,MAAA,EAAA,KAAA,CAAA,aAAA,EAAA,SAAA,EAAA,QAAA,CAAA,CAAA;AACA,OAAA;AACA,KAAA,CAAA,CAAA;AACA;AACA,IAAA,OAAA,MAAA,CAAA;AACA,GAAA,CAAA;AACA;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"reactrouterv6.js","sources":["../../src/reactrouterv6.tsx"],"sourcesContent":["// Inspired from Donnie McNeal's solution:\n// https://gist.github.com/wontondon/e8c4bdf2888875e4c755712e99279536\n\nimport { WINDOW } from '@sentry/browser';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';\nimport type { Transaction, TransactionContext, TransactionSource } from '@sentry/types';\nimport { getNumberOfUrlSegments, logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport type {\n Action,\n AgnosticDataRouteMatch,\n CreateRouterFunction,\n CreateRoutesFromChildren,\n Location,\n MatchRoutes,\n RouteMatch,\n RouteObject,\n Router,\n RouterState,\n UseEffect,\n UseLocation,\n UseNavigationType,\n UseRoutes,\n} from './types';\n\nlet activeTransaction: Transaction | undefined;\n\nlet _useEffect: UseEffect;\nlet _useLocation: UseLocation;\nlet _useNavigationType: UseNavigationType;\nlet _createRoutesFromChildren: CreateRoutesFromChildren;\nlet _matchRoutes: MatchRoutes;\nlet _customStartTransaction: (context: TransactionContext) => Transaction | undefined;\nlet _startTransactionOnLocationChange: boolean;\n\nconst SENTRY_TAGS = {\n 'routing.instrumentation': 'react-router-v6',\n};\n\nexport function reactRouterV6Instrumentation(\n useEffect: UseEffect,\n useLocation: UseLocation,\n useNavigationType: UseNavigationType,\n createRoutesFromChildren: CreateRoutesFromChildren,\n matchRoutes: MatchRoutes,\n) {\n return (\n customStartTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad = true,\n startTransactionOnLocationChange = true,\n ): void => {\n const initPathName = WINDOW && WINDOW.location && WINDOW.location.pathname;\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: initPathName,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouterv6',\n tags: SENTRY_TAGS,\n metadata: {\n source: 'url',\n },\n });\n }\n\n _useEffect = useEffect;\n _useLocation = useLocation;\n _useNavigationType = useNavigationType;\n _matchRoutes = matchRoutes;\n _createRoutesFromChildren = createRoutesFromChildren;\n\n _customStartTransaction = customStartTransaction;\n _startTransactionOnLocationChange = startTransactionOnLocationChange;\n };\n}\n\nfunction getNormalizedName(\n routes: RouteObject[],\n location: Location,\n branches: RouteMatch[],\n basename: string = '',\n): [string, TransactionSource] {\n if (!routes || routes.length === 0) {\n return [location.pathname, 'url'];\n }\n\n let pathBuilder = '';\n if (branches) {\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n const branch = branches[x];\n const route = branch.route;\n if (route) {\n // Early return if index route\n if (route.index) {\n return [branch.pathname, 'route'];\n }\n\n const path = route.path;\n if (path) {\n const newPath = path[0] === '/' || pathBuilder[pathBuilder.length - 1] === '/' ? path : `/${path}`;\n pathBuilder += newPath;\n\n if (basename + branch.pathname === location.pathname) {\n if (\n // If the route defined on the element is something like\n // <Route path=\"/stores/:storeId/products/:productId\" element={<div>Product</div>} />\n // We should check against the branch.pathname for the number of / seperators\n getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&\n // We should not count wildcard operators in the url segments calculation\n pathBuilder.slice(-2) !== '/*'\n ) {\n return [basename + newPath, 'route'];\n }\n return [basename + pathBuilder, 'route'];\n }\n }\n }\n }\n }\n\n return [location.pathname, 'url'];\n}\n\nfunction updatePageloadTransaction(\n location: Location,\n routes: RouteObject[],\n matches?: AgnosticDataRouteMatch,\n basename?: string,\n): void {\n const branches = Array.isArray(matches)\n ? matches\n : (_matchRoutes(routes, location, basename) as unknown as RouteMatch[]);\n\n if (activeTransaction && branches) {\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n activeTransaction.updateName(name);\n activeTransaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);\n }\n}\n\nfunction handleNavigation(\n location: Location,\n routes: RouteObject[],\n navigationType: Action,\n matches?: AgnosticDataRouteMatch,\n basename?: string,\n): void {\n const branches = Array.isArray(matches) ? matches : _matchRoutes(routes, location, basename);\n\n if (_startTransactionOnLocationChange && (navigationType === 'PUSH' || navigationType === 'POP') && branches) {\n if (activeTransaction) {\n activeTransaction.end();\n }\n\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n activeTransaction = _customStartTransaction({\n name,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouterv6',\n tags: SENTRY_TAGS,\n metadata: {\n source,\n },\n });\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withSentryReactRouterV6Routing<P extends Record<string, any>, R extends React.FC<P>>(Routes: R): R {\n if (\n !_useEffect ||\n !_useLocation ||\n !_useNavigationType ||\n !_createRoutesFromChildren ||\n !_matchRoutes ||\n !_customStartTransaction\n ) {\n DEBUG_BUILD &&\n logger.warn(`reactRouterV6Instrumentation was unable to wrap Routes because of one or more missing parameters.\n useEffect: ${_useEffect}. useLocation: ${_useLocation}. useNavigationType: ${_useNavigationType}.\n createRoutesFromChildren: ${_createRoutesFromChildren}. matchRoutes: ${_matchRoutes}. customStartTransaction: ${_customStartTransaction}.`);\n\n return Routes;\n }\n\n let isMountRenderPass: boolean = true;\n\n const SentryRoutes: React.FC<P> = (props: P) => {\n const location = _useLocation();\n const navigationType = _useNavigationType();\n\n _useEffect(\n () => {\n const routes = _createRoutesFromChildren(props.children) as RouteObject[];\n\n if (isMountRenderPass) {\n updatePageloadTransaction(location, routes);\n isMountRenderPass = false;\n } else {\n handleNavigation(location, routes, navigationType);\n }\n },\n // `props.children` is purpusely not included in the dependency array, because we do not want to re-run this effect\n // when the children change. We only want to start transactions when the location or navigation type change.\n [location, navigationType],\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 return <Routes {...props} />;\n };\n\n hoistNonReactStatics(SentryRoutes, Routes);\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 return SentryRoutes;\n}\n\nexport function wrapUseRoutes(origUseRoutes: UseRoutes): UseRoutes {\n if (!_useEffect || !_useLocation || !_useNavigationType || !_matchRoutes || !_customStartTransaction) {\n DEBUG_BUILD &&\n logger.warn(\n 'reactRouterV6Instrumentation was unable to wrap `useRoutes` because of one or more missing parameters.',\n );\n\n return origUseRoutes;\n }\n\n let isMountRenderPass: boolean = true;\n\n const SentryRoutes: React.FC<{\n children?: React.ReactNode;\n routes: RouteObject[];\n locationArg?: Partial<Location> | string;\n }> = (props: { children?: React.ReactNode; routes: RouteObject[]; locationArg?: Partial<Location> | string }) => {\n const { routes, locationArg } = props;\n\n const Routes = origUseRoutes(routes, locationArg);\n\n const location = _useLocation();\n const navigationType = _useNavigationType();\n\n // A value with stable identity to either pick `locationArg` if available or `location` if not\n const stableLocationParam =\n typeof locationArg === 'string' || (locationArg && locationArg.pathname)\n ? (locationArg as { pathname: string })\n : location;\n\n _useEffect(() => {\n const normalizedLocation =\n typeof stableLocationParam === 'string' ? { pathname: stableLocationParam } : stableLocationParam;\n\n if (isMountRenderPass) {\n updatePageloadTransaction(normalizedLocation, routes);\n isMountRenderPass = false;\n } else {\n handleNavigation(normalizedLocation, routes, navigationType);\n }\n }, [navigationType, stableLocationParam]);\n\n return Routes;\n };\n\n // eslint-disable-next-line react/display-name\n return (routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null => {\n return <SentryRoutes routes={routes} locationArg={locationArg} />;\n };\n}\n\nexport function wrapCreateBrowserRouter<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n // `opts` for createBrowserHistory and createMemoryHistory are different, but also not relevant for us at the moment.\n // `basename` is the only option that is relevant for us, and it is the same for all.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function (routes: RouteObject[], opts?: Record<string, any> & { basename?: string }): TRouter {\n const router = createRouterFunction(routes, opts);\n const basename = opts && opts.basename;\n\n // The initial load ends when `createBrowserRouter` is called.\n // This is the earliest convenient time to update the transaction name.\n // Callbacks to `router.subscribe` are not called for the initial load.\n if (router.state.historyAction === 'POP' && activeTransaction) {\n updatePageloadTransaction(router.state.location, routes, undefined, basename);\n }\n\n router.subscribe((state: RouterState) => {\n const location = state.location;\n\n if (\n _startTransactionOnLocationChange &&\n (state.historyAction === 'PUSH' || state.historyAction === 'POP') &&\n activeTransaction\n ) {\n handleNavigation(location, routes, state.historyAction, undefined, basename);\n }\n });\n\n return router;\n };\n}\n"],"names":["WINDOW","getNumberOfUrlSegments","SEMANTIC_ATTRIBUTE_SENTRY_SOURCE","DEBUG_BUILD","logger","React","hoistNonReactStatics"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAA,YAAA,GAAA,4FAAA,CAAA;;AA4BA,IAAI,iBAAiB,CAAA;AACrB;AACA,IAAI,UAAU,CAAA;AACd,IAAI,YAAY,CAAA;AAChB,IAAI,kBAAkB,CAAA;AACtB,IAAI,yBAAyB,C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AA,MAAA,CAAA,KAAA,CAAA,aAAA,KAAA,KAAA,IAAA,iBAAA,EAAA;AACA,MAAA,yBAAA,CAAA,MAAA,CAAA,KAAA,CAAA,QAAA,EAAA,MAAA,EAAA,SAAA,EAAA,QAAA,CAAA,CAAA;AACA,KAAA;AACA;AACA,IAAA,MAAA,CAAA,SAAA,CAAA,CAAA,KAAA,KAAA;AACA,MAAA,MAAA,QAAA,GAAA,KAAA,CAAA,QAAA,CAAA;AACA;AACA,MAAA;AACA,QAAA,iCAAA;AACA,SAAA,KAAA,CAAA,aAAA,KAAA,MAAA,IAAA,KAAA,CAAA,aAAA,KAAA,KAAA,CAAA;AACA,QAAA,iBAAA;AACA,QAAA;AACA,QAAA,gBAAA,CAAA,QAAA,EAAA,MAAA,EAAA,KAAA,CAAA,aAAA,EAAA,SAAA,EAAA,QAAA,CAAA,CAAA;AACA,OAAA;AACA,KAAA,CAAA,CAAA;AACA;AACA,IAAA,OAAA,MAAA,CAAA;AACA,GAAA,CAAA;AACA;;;;;;;"}
|
package/esm/profiler.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { startInactiveSpan } from '@sentry/browser';
|
|
2
|
+
import { withActiveSpan, spanToJSON } from '@sentry/core';
|
|
2
3
|
import { timestampInSeconds } from '@sentry/utils';
|
|
3
4
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
4
5
|
import * as React from 'react';
|
|
5
6
|
import { REACT_MOUNT_OP, REACT_UPDATE_OP, REACT_RENDER_OP } from './constants.js';
|
|
6
7
|
|
|
7
8
|
const _jsxFileName = "/home/runner/work/sentry-javascript/sentry-javascript/packages/react/src/profiler.tsx";
|
|
8
|
-
|
|
9
9
|
const UNKNOWN_COMPONENT = 'unknown';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -37,15 +37,12 @@ class Profiler extends React.Component {
|
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
data: { 'ui.component_name': name },
|
|
47
|
-
});
|
|
48
|
-
}
|
|
40
|
+
this._mountSpan = startInactiveSpan({
|
|
41
|
+
name: `<${name}>`,
|
|
42
|
+
op: REACT_MOUNT_OP,
|
|
43
|
+
origin: 'auto.ui.react.profiler',
|
|
44
|
+
attributes: { 'ui.component_name': name },
|
|
45
|
+
});
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
// If a component mounted, we can finish the mount activity.
|
|
@@ -65,15 +62,17 @@ class Profiler extends React.Component {
|
|
|
65
62
|
const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);
|
|
66
63
|
if (changedProps.length > 0) {
|
|
67
64
|
const now = timestampInSeconds();
|
|
68
|
-
this._updateSpan = this._mountSpan
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
65
|
+
this._updateSpan = withActiveSpan(this._mountSpan, () => {
|
|
66
|
+
return startInactiveSpan({
|
|
67
|
+
name: `<${this.props.name}>`,
|
|
68
|
+
op: REACT_UPDATE_OP,
|
|
69
|
+
origin: 'auto.ui.react.profiler',
|
|
70
|
+
startTimestamp: now,
|
|
71
|
+
attributes: {
|
|
72
|
+
'ui.component_name': this.props.name,
|
|
73
|
+
'ui.react.changed_props': changedProps,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
77
76
|
});
|
|
78
77
|
}
|
|
79
78
|
}
|
|
@@ -91,18 +90,24 @@ class Profiler extends React.Component {
|
|
|
91
90
|
// If a component is unmounted, we can say it is no longer on the screen.
|
|
92
91
|
// This means we can finish the span representing the component render.
|
|
93
92
|
componentWillUnmount() {
|
|
93
|
+
const endTimestamp = timestampInSeconds();
|
|
94
94
|
const { name, includeRender = true } = this.props;
|
|
95
95
|
|
|
96
96
|
if (this._mountSpan && includeRender) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
const startTimestamp = spanToJSON(this._mountSpan).timestamp;
|
|
98
|
+
withActiveSpan(this._mountSpan, () => {
|
|
99
|
+
const renderSpan = startInactiveSpan({
|
|
100
|
+
name: `<${name}>`,
|
|
101
|
+
op: REACT_RENDER_OP,
|
|
102
|
+
origin: 'auto.ui.react.profiler',
|
|
103
|
+
startTimestamp,
|
|
104
|
+
attributes: { 'ui.component_name': name },
|
|
105
|
+
});
|
|
106
|
+
if (renderSpan) {
|
|
107
|
+
// Have to cast to Span because the type of _mountSpan is Span | undefined
|
|
108
|
+
// and not getting narrowed properly
|
|
109
|
+
renderSpan.end(endTimestamp);
|
|
110
|
+
}
|
|
106
111
|
});
|
|
107
112
|
}
|
|
108
113
|
}
|
|
@@ -120,6 +125,7 @@ class Profiler extends React.Component {
|
|
|
120
125
|
* @param WrappedComponent component that is wrapped by Profiler
|
|
121
126
|
* @param options the {@link ProfilerProps} you can pass into the Profiler
|
|
122
127
|
*/
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
129
|
function withProfiler(
|
|
124
130
|
WrappedComponent,
|
|
125
131
|
// We do not want to have `updateProps` given in options, it is instead filled through the HOC.
|
|
@@ -129,8 +135,8 @@ function withProfiler(
|
|
|
129
135
|
(options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
|
|
130
136
|
|
|
131
137
|
const Wrapped = (props) => (
|
|
132
|
-
React.createElement(Profiler, { ...options, name: componentDisplayName, updateProps: props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
133
|
-
, React.createElement(WrappedComponent, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
138
|
+
React.createElement(Profiler, { ...options, name: componentDisplayName, updateProps: props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 156}}
|
|
139
|
+
, React.createElement(WrappedComponent, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 157}} )
|
|
134
140
|
)
|
|
135
141
|
);
|
|
136
142
|
|
|
@@ -161,17 +167,12 @@ function useProfiler(
|
|
|
161
167
|
return undefined;
|
|
162
168
|
}
|
|
163
169
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
data: { 'ui.component_name': name },
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return undefined;
|
|
170
|
+
return startInactiveSpan({
|
|
171
|
+
name: `<${name}>`,
|
|
172
|
+
op: REACT_MOUNT_OP,
|
|
173
|
+
origin: 'auto.ui.react.profiler',
|
|
174
|
+
attributes: { 'ui.component_name': name },
|
|
175
|
+
});
|
|
175
176
|
});
|
|
176
177
|
|
|
177
178
|
React.useEffect(() => {
|
|
@@ -181,14 +182,21 @@ function useProfiler(
|
|
|
181
182
|
|
|
182
183
|
return () => {
|
|
183
184
|
if (mountSpan && options.hasRenderSpan) {
|
|
184
|
-
mountSpan.
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
const startTimestamp = spanToJSON(mountSpan).timestamp;
|
|
186
|
+
const endTimestamp = timestampInSeconds();
|
|
187
|
+
|
|
188
|
+
const renderSpan = startInactiveSpan({
|
|
189
|
+
name: `<${name}>`,
|
|
187
190
|
op: REACT_RENDER_OP,
|
|
188
191
|
origin: 'auto.ui.react.profiler',
|
|
189
|
-
startTimestamp
|
|
190
|
-
|
|
192
|
+
startTimestamp,
|
|
193
|
+
attributes: { 'ui.component_name': name },
|
|
191
194
|
});
|
|
195
|
+
if (renderSpan) {
|
|
196
|
+
// Have to cast to Span because the type of _mountSpan is Span | undefined
|
|
197
|
+
// and not getting narrowed properly
|
|
198
|
+
renderSpan.end(endTimestamp);
|
|
199
|
+
}
|
|
192
200
|
}
|
|
193
201
|
};
|
|
194
202
|
// We only want this to run once.
|
|
@@ -196,15 +204,5 @@ function useProfiler(
|
|
|
196
204
|
}, []);
|
|
197
205
|
}
|
|
198
206
|
|
|
199
|
-
|
|
200
|
-
function getActiveTransaction(hub = getCurrentHub()) {
|
|
201
|
-
if (hub) {
|
|
202
|
-
const scope = hub.getScope();
|
|
203
|
-
return scope.getTransaction() ;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return undefined;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export { Profiler, UNKNOWN_COMPONENT, getActiveTransaction, useProfiler, withProfiler };
|
|
207
|
+
export { Profiler, UNKNOWN_COMPONENT, useProfiler, withProfiler };
|
|
210
208
|
//# sourceMappingURL=profiler.js.map
|
package/esm/profiler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiler.js","sources":["../../src/profiler.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Hub } from '@sentry/browser';\nimport { getCurrentHub } from '@sentry/browser';\nimport type { Span, Transaction } from '@sentry/types';\nimport { timestampInSeconds } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type ProfilerProps = {\n // The name of the component being profiled.\n name: string;\n // If the Profiler is disabled. False by default. This is useful if you want to disable profilers\n // in certain environments.\n disabled?: boolean;\n // If time component is on page should be displayed as spans. True by default.\n includeRender?: boolean;\n // If component updates should be displayed as spans. True by default.\n includeUpdates?: boolean;\n // Component that is being profiled.\n children?: React.ReactNode;\n // props given to component being profiled.\n updateProps: { [key: string]: unknown };\n};\n\n/**\n * The Profiler component leverages Sentry's Tracing integration to generate\n * spans based on component lifecycles.\n */\nclass Profiler extends React.Component<ProfilerProps> {\n /**\n * The span of the mount activity\n * Made protected for the React Native SDK to access\n */\n protected _mountSpan: Span | undefined;\n /**\n * The span that represents the duration of time between shouldComponentUpdate and componentDidUpdate\n */\n protected _updateSpan: Span | undefined;\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static defaultProps: Partial<ProfilerProps> = {\n disabled: false,\n includeRender: true,\n includeUpdates: true,\n };\n\n public constructor(props: ProfilerProps) {\n super(props);\n const { name, disabled = false } = this.props;\n\n if (disabled) {\n return;\n }\n\n const activeTransaction = getActiveTransaction();\n if (activeTransaction) {\n this._mountSpan = activeTransaction.startChild({\n description: `<${name}>`,\n op: REACT_MOUNT_OP,\n origin: 'auto.ui.react.profiler',\n data: { 'ui.component_name': name },\n });\n }\n }\n\n // If a component mounted, we can finish the mount activity.\n public componentDidMount(): void {\n if (this._mountSpan) {\n this._mountSpan.end();\n }\n }\n\n public shouldComponentUpdate({ updateProps, includeUpdates = true }: ProfilerProps): boolean {\n // Only generate an update span if includeUpdates is true, if there is a valid mountSpan,\n // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.\n // We are just trying to give baseline clues for further investigation.\n if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {\n // See what props haved changed between the previous props, and the current props. This is\n // set as data on the span. We just store the prop keys as the values could be potenially very large.\n const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);\n if (changedProps.length > 0) {\n const now = timestampInSeconds();\n this._updateSpan = this._mountSpan.startChild({\n data: {\n changedProps,\n 'ui.component_name': this.props.name,\n },\n description: `<${this.props.name}>`,\n op: REACT_UPDATE_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: now,\n });\n }\n }\n\n return true;\n }\n\n public componentDidUpdate(): void {\n if (this._updateSpan) {\n this._updateSpan.end();\n this._updateSpan = undefined;\n }\n }\n\n // If a component is unmounted, we can say it is no longer on the screen.\n // This means we can finish the span representing the component render.\n public componentWillUnmount(): void {\n const { name, includeRender = true } = this.props;\n\n if (this._mountSpan && includeRender) {\n // If we were able to obtain the spanId of the mount activity, we should set the\n // next activity as a child to the component mount activity.\n this._mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampInSeconds(),\n op: REACT_RENDER_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: this._mountSpan.endTimestamp,\n data: { 'ui.component_name': name },\n });\n }\n }\n\n public render(): React.ReactNode {\n return this.props.children;\n }\n}\n\n/**\n * withProfiler is a higher order component that wraps a\n * component in a {@link Profiler} component. It is recommended that\n * the higher order component be used over the regular {@link Profiler} component.\n *\n * @param WrappedComponent component that is wrapped by Profiler\n * @param options the {@link ProfilerProps} you can pass into the Profiler\n */\nfunction withProfiler<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n // We do not want to have `updateProps` given in options, it is instead filled through the HOC.\n options?: Pick<Partial<ProfilerProps>, Exclude<keyof ProfilerProps, 'updateProps' | 'children'>>,\n): React.FC<P> {\n const componentDisplayName =\n (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <Profiler {...options} name={componentDisplayName} updateProps={props}>\n <WrappedComponent {...props} />\n </Profiler>\n );\n\n Wrapped.displayName = `profiler(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\n/**\n *\n * `useProfiler` is a React hook that profiles a React component.\n *\n * Requires React 16.8 or above.\n * @param name displayName of component being profiled\n */\nfunction useProfiler(\n name: string,\n options: { disabled?: boolean; hasRenderSpan?: boolean } = {\n disabled: false,\n hasRenderSpan: true,\n },\n): void {\n const [mountSpan] = React.useState(() => {\n if (options && options.disabled) {\n return undefined;\n }\n\n const activeTransaction = getActiveTransaction();\n if (activeTransaction) {\n return activeTransaction.startChild({\n description: `<${name}>`,\n op: REACT_MOUNT_OP,\n origin: 'auto.ui.react.profiler',\n data: { 'ui.component_name': name },\n });\n }\n\n return undefined;\n });\n\n React.useEffect(() => {\n if (mountSpan) {\n mountSpan.end();\n }\n\n return (): void => {\n if (mountSpan && options.hasRenderSpan) {\n mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampInSeconds(),\n op: REACT_RENDER_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: mountSpan.endTimestamp,\n data: { 'ui.component_name': name },\n });\n }\n };\n // We only want this to run once.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n}\n\nexport { withProfiler, Profiler, useProfiler };\n\n/** Grabs active transaction off scope */\nexport function getActiveTransaction<T extends Transaction>(hub: Hub = getCurrentHub()): T | undefined {\n if (hub) {\n const scope = hub.getScope();\n return scope.getTransaction() as T | undefined;\n }\n\n return undefined;\n}\n"],"names":[],"mappings":";;;;;;AAAA,MAAA,YAAA,GAAA,uFAAA,CAAA;AAUA;AACO,MAAM,iBAAkB,GAAE,UAAS;;AAkB1C;AACA;AACA;AACA;AACA,MAAM,QAAS,SAAQ,KAAK,CAAC,SAAS,CAAgB;AACtD;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA,GAAS,OAAA,YAAA,GAAA,CAAA,IAAA,CAAO,YAAY,GAA2B;AACvD,IAAI,QAAQ,EAAE,KAAK;AACnB,IAAI,aAAa,EAAE,IAAI;AACvB,IAAI,cAAc,EAAE,IAAI;AACxB,IAAG,CAAA;AACH;AACA,GAAS,WAAW,CAAC,KAAK,EAAiB;AAC3C,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;AAChB,IAAI,MAAM,EAAE,IAAI,EAAE,QAAA,GAAW,KAAA,EAAQ,GAAE,IAAI,CAAC,KAAK,CAAA;AACjD;AACA,IAAI,IAAI,QAAQ,EAAE;AAClB,MAAM,OAAM;AACZ,KAAI;AACJ;AACA,IAAI,MAAM,iBAAA,GAAoB,oBAAoB,EAAE,CAAA;AACpD,IAAI,IAAI,iBAAiB,EAAE;AAC3B,MAAM,IAAI,CAAC,UAAA,GA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,CAAC,CAAC;AAChC,QAAQ,EAAE,EAAE,cAAc;AAC1B,QAAQ,MAAM,EAAE,wBAAwB;AACxC,QAAQ,IAAI,EAAE,EAAE,mBAAmB,EAAE,MAAM;AAC3C,OAAO,CAAC,CAAA;AACR,KAAI;AACJ;AACA,IAAI,OAAO,SAAS,CAAA;AACpB,GAAG,CAAC,CAAA;AACJ;AACA,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM;AACxB,IAAI,IAAI,SAAS,EAAE;AACnB,MAAM,SAAS,CAAC,GAAG,EAAE,CAAA;AACrB,KAAI;AACJ;AACA,IAAI,OAAO,MAAY;AACvB,MAAM,IAAI,SAAA,IAAa,OAAO,CAAC,aAAa,EAAE;AAC9C,QAAQ,SAAS,CAAC,UAAU,CAAC;AAC7B,UAAU,WAAW,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AAClC,UAAU,YAAY,EAAE,kBAAkB,EAAE;AAC5C,UAAU,EAAE,EAAE,eAAe;AAC7B,UAAU,MAAM,EAAE,wBAAwB;AAC1C,UAAU,cAAc,EAAE,SAAS,CAAC,YAAY;AAChD,UAAU,IAAI,EAAE,EAAE,mBAAmB,EAAE,MAAM;AAC7C,SAAS,CAAC,CAAA;AACV,OAAM;AACN,KAAK,CAAA;AACL;AACA;AACA,GAAG,EAAE,EAAE,CAAC,CAAA;AACR,CAAA;AAGA;AACA;AACO,SAAS,oBAAoB,CAAwB,GAAG,GAAQ,aAAa,EAAE,EAAiB;AACvG,EAAE,IAAI,GAAG,EAAE;AACX,IAAI,MAAM,KAAM,GAAE,GAAG,CAAC,QAAQ,EAAE,CAAA;AAChC,IAAI,OAAO,KAAK,CAAC,cAAc,EAAG,EAAA;AAClC,GAAE;AACF;AACA,EAAE,OAAO,SAAS,CAAA;AAClB;;;;"}
|
|
1
|
+
{"version":3,"file":"profiler.js","sources":["../../src/profiler.tsx"],"sourcesContent":["import { startInactiveSpan } from '@sentry/browser';\nimport { spanToJSON, withActiveSpan } from '@sentry/core';\nimport type { Span } from '@sentry/types';\nimport { timestampInSeconds } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type ProfilerProps = {\n // The name of the component being profiled.\n name: string;\n // If the Profiler is disabled. False by default. This is useful if you want to disable profilers\n // in certain environments.\n disabled?: boolean;\n // If time component is on page should be displayed as spans. True by default.\n includeRender?: boolean;\n // If component updates should be displayed as spans. True by default.\n includeUpdates?: boolean;\n // Component that is being profiled.\n children?: React.ReactNode;\n // props given to component being profiled.\n updateProps: { [key: string]: unknown };\n};\n\n/**\n * The Profiler component leverages Sentry's Tracing integration to generate\n * spans based on component lifecycles.\n */\nclass Profiler extends React.Component<ProfilerProps> {\n /**\n * The span of the mount activity\n * Made protected for the React Native SDK to access\n */\n protected _mountSpan: Span | undefined;\n /**\n * The span that represents the duration of time between shouldComponentUpdate and componentDidUpdate\n */\n protected _updateSpan: Span | undefined;\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static defaultProps: Partial<ProfilerProps> = {\n disabled: false,\n includeRender: true,\n includeUpdates: true,\n };\n\n public constructor(props: ProfilerProps) {\n super(props);\n const { name, disabled = false } = this.props;\n\n if (disabled) {\n return;\n }\n\n this._mountSpan = startInactiveSpan({\n name: `<${name}>`,\n op: REACT_MOUNT_OP,\n origin: 'auto.ui.react.profiler',\n attributes: { 'ui.component_name': name },\n });\n }\n\n // If a component mounted, we can finish the mount activity.\n public componentDidMount(): void {\n if (this._mountSpan) {\n this._mountSpan.end();\n }\n }\n\n public shouldComponentUpdate({ updateProps, includeUpdates = true }: ProfilerProps): boolean {\n // Only generate an update span if includeUpdates is true, if there is a valid mountSpan,\n // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.\n // We are just trying to give baseline clues for further investigation.\n if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {\n // See what props haved changed between the previous props, and the current props. This is\n // set as data on the span. We just store the prop keys as the values could be potenially very large.\n const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);\n if (changedProps.length > 0) {\n const now = timestampInSeconds();\n this._updateSpan = withActiveSpan(this._mountSpan, () => {\n return startInactiveSpan({\n name: `<${this.props.name}>`,\n op: REACT_UPDATE_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp: now,\n attributes: {\n 'ui.component_name': this.props.name,\n 'ui.react.changed_props': changedProps,\n },\n });\n });\n }\n }\n\n return true;\n }\n\n public componentDidUpdate(): void {\n if (this._updateSpan) {\n this._updateSpan.end();\n this._updateSpan = undefined;\n }\n }\n\n // If a component is unmounted, we can say it is no longer on the screen.\n // This means we can finish the span representing the component render.\n public componentWillUnmount(): void {\n const endTimestamp = timestampInSeconds();\n const { name, includeRender = true } = this.props;\n\n if (this._mountSpan && includeRender) {\n const startTimestamp = spanToJSON(this._mountSpan).timestamp;\n withActiveSpan(this._mountSpan, () => {\n const renderSpan = startInactiveSpan({\n name: `<${name}>`,\n op: REACT_RENDER_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp,\n attributes: { 'ui.component_name': name },\n });\n if (renderSpan) {\n // Have to cast to Span because the type of _mountSpan is Span | undefined\n // and not getting narrowed properly\n renderSpan.end(endTimestamp);\n }\n });\n }\n }\n\n public render(): React.ReactNode {\n return this.props.children;\n }\n}\n\n/**\n * withProfiler is a higher order component that wraps a\n * component in a {@link Profiler} component. It is recommended that\n * the higher order component be used over the regular {@link Profiler} component.\n *\n * @param WrappedComponent component that is wrapped by Profiler\n * @param options the {@link ProfilerProps} you can pass into the Profiler\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction withProfiler<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n // We do not want to have `updateProps` given in options, it is instead filled through the HOC.\n options?: Pick<Partial<ProfilerProps>, Exclude<keyof ProfilerProps, 'updateProps' | 'children'>>,\n): React.FC<P> {\n const componentDisplayName =\n (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <Profiler {...options} name={componentDisplayName} updateProps={props}>\n <WrappedComponent {...props} />\n </Profiler>\n );\n\n Wrapped.displayName = `profiler(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\n/**\n *\n * `useProfiler` is a React hook that profiles a React component.\n *\n * Requires React 16.8 or above.\n * @param name displayName of component being profiled\n */\nfunction useProfiler(\n name: string,\n options: { disabled?: boolean; hasRenderSpan?: boolean } = {\n disabled: false,\n hasRenderSpan: true,\n },\n): void {\n const [mountSpan] = React.useState(() => {\n if (options && options.disabled) {\n return undefined;\n }\n\n return startInactiveSpan({\n name: `<${name}>`,\n op: REACT_MOUNT_OP,\n origin: 'auto.ui.react.profiler',\n attributes: { 'ui.component_name': name },\n });\n });\n\n React.useEffect(() => {\n if (mountSpan) {\n mountSpan.end();\n }\n\n return (): void => {\n if (mountSpan && options.hasRenderSpan) {\n const startTimestamp = spanToJSON(mountSpan).timestamp;\n const endTimestamp = timestampInSeconds();\n\n const renderSpan = startInactiveSpan({\n name: `<${name}>`,\n op: REACT_RENDER_OP,\n origin: 'auto.ui.react.profiler',\n startTimestamp,\n attributes: { 'ui.component_name': name },\n });\n if (renderSpan) {\n // Have to cast to Span because the type of _mountSpan is Span | undefined\n // and not getting narrowed properly\n renderSpan.end(endTimestamp);\n }\n }\n };\n // We only want this to run once.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n}\n\nexport { withProfiler, Profiler, useProfiler };\n"],"names":[],"mappings":";;;;;;;AAAA,MAAA,YAAA,GAAA,uFAAA,CAQA;AACO,MAAM,iBAAkB,GAAE,UAAS;;AAkB1C;AACA;AACA;AACA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AA;AACjD;AACA,QAAQ,MAAM,UAAA,GAAa,iBAAiB,CAAC;AAC7C,UAAU,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AAC3B,UAAU,EAAE,EAAE,eAAe;AAC7B,UAAU,MAAM,EAAE,wBAAwB;AAC1C,UAAU,cAAc;AACxB,UAAU,UAAU,EAAE,EAAE,mBAAmB,EAAE,MAAM;AACnD,SAAS,CAAC,CAAA;AACV,QAAQ,IAAI,UAAU,EAAE;AACxB;AACA;AACA,UAAU,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;AACtC,SAAQ;AACR,OAAM;AACN,KAAK,CAAA;AACL;AACA;AACA,GAAG,EAAE,EAAE,CAAC,CAAA;AACR;;;;"}
|
package/esm/reactrouter.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WINDOW } from '@sentry/browser';
|
|
2
|
+
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
|
|
2
3
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
3
4
|
import * as React from 'react';
|
|
4
5
|
|
|
@@ -150,13 +151,13 @@ function withSentryRouting(Route) {
|
|
|
150
151
|
const WrappedRoute = (props) => {
|
|
151
152
|
if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {
|
|
152
153
|
activeTransaction.updateName(props.computedMatch.path);
|
|
153
|
-
activeTransaction.
|
|
154
|
+
activeTransaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
// @ts-expect-error Setting more specific React Component typing for `R` generic above
|
|
157
158
|
// will break advanced type inference done by react router params:
|
|
158
159
|
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
|
|
159
|
-
return React.createElement(Route, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
160
|
+
return React.createElement(Route, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 176}} );
|
|
160
161
|
};
|
|
161
162
|
|
|
162
163
|
WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;
|
package/esm/reactrouter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouter.js","sources":["../../src/reactrouter.tsx"],"sourcesContent":["import { WINDOW } from '@sentry/browser';\nimport type { Transaction, TransactionSource } from '@sentry/types';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport type { 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.\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?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null; // eslint-disable-line @typescript-eslint/no-explicit-any\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 (WINDOW && 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 // 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, 'route'];\n }\n }\n\n return [pathname, 'url'];\n }\n\n const tags = {\n 'routing.instrumentation': name,\n };\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n const [name, source] = normalizeTransactionName(initPathName);\n activeTransaction = customStartTransaction({\n name,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouter',\n tags,\n metadata: {\n source,\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.end();\n }\n\n const [name, source] = normalizeTransactionName(location.pathname);\n activeTransaction = customStartTransaction({\n name,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouter',\n tags,\n metadata: {\n source,\n },\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.updateName(props.computedMatch.path);\n activeTransaction.setMetadata({ source: 'route' });\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"],"names":[],"mappings":";;;;AAAA,MAAA,YAAA,GAAA,0FAAA;AAOA;AACA;;AAgBA;AACA;AACA,IAAI,iBAAiB,CAAA;AACrB;AACO,SAAS,4BAA4B;AAC5C,EAAE,OAAO;AACT,EAAE,MAAM;AACR,EAAE,SAAS;AACX,EAA8B;AAC9B,EAAE,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;AACxF,CAAA;AACA;AACO,SAAS,4BAA4B;AAC5C,EAAE,OAAO;AACT,EAAE,MAAM;AACR,EAAE,SAAS;AACX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AAChF;AACA,EAAE,MAAM,YAAY,GAAgB,CAAC,KAAK,KAAQ;AAClD,IAAI,IAAI,iBAAkB,IAAG,SAAS,KAAK,CAAC,aAAA,IAAiB,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE;AAC1F,MAAM,iBAAiB,CAAC,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;AAC5D,MAAM,iBAAiB,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,OAAQ,EAAC,CAAC,CAAA;AACxD,KAAI;AACJ;AACA;AACA;AACA;AACA,IAAI,OAAO,KAAC,CAAA,aAAA,CAAA,KAAA,EAAA,EAAM,GAAI,KAAK,sEAAI,CAAA;AAC/B,GAAG,CAAA;AACH;AACA,EAAE,YAAY,CAAC,WAAA,GAAc,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAA;AACnE,EAAE,oBAAoB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;AAC3C;AACA;AACA;AACA,EAAE,OAAO,YAAY,CAAA;AACrB,CAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"reactrouter.js","sources":["../../src/reactrouter.tsx"],"sourcesContent":["import { WINDOW } from '@sentry/browser';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';\nimport type { Transaction, TransactionSource } from '@sentry/types';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport type { 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.\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?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null; // eslint-disable-line @typescript-eslint/no-explicit-any\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 (WINDOW && 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 // 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, 'route'];\n }\n }\n\n return [pathname, 'url'];\n }\n\n const tags = {\n 'routing.instrumentation': name,\n };\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n const [name, source] = normalizeTransactionName(initPathName);\n activeTransaction = customStartTransaction({\n name,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouter',\n tags,\n metadata: {\n source,\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.end();\n }\n\n const [name, source] = normalizeTransactionName(location.pathname);\n activeTransaction = customStartTransaction({\n name,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouter',\n tags,\n metadata: {\n source,\n },\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.updateName(props.computedMatch.path);\n activeTransaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');\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"],"names":[],"mappings":";;;;;AAAA,MAAA,YAAA,GAAA,0FAAA;AAQA;AACA;;AAgBA;AACA;AACA,IAAI,iBAAiB,CAAA;AACrB;AACO,SAAS,4BAA4B;AAC5C,EAAE,OAAO;AACT,EAAE,MAAM;AACR,EAAE,SAAS;AACX,EAA8B;AAC9B,EAAE,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;AACxF,CAAA;AACA;AACO,SAAS,4BAA4B;AAC5C,EAAE,OAAO;AACT,EAAE,MAAM;AACR,EAAE,SAAS;AACX,EAA8B;AAC9B,EAAE,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;AACxF,CAAA;AACA;AACA,SAAS,gCAAgC;AACzC,EAAE,OAAO;AACT,EAAE,IAAI;AACN,EAAE,SAAS,GAAkB,EAAE;AAC/B,EAAE,SAAS;AACX,EAA8B;AAC9B,EAAE,SAAS,eAAe,GAAuB;AACjD,IAAI,IAAI,OAAA,IAAW,OAAO,CAAC,QAAQ,EAAE;AACrC,MAAM,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAA;AACtC,KAAI;AACJ;AACA,IAAI,IAAI,MAAA,IAAU,MAAM,CAAC,QAAQ,EAAE;AACnC,MAAM,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAA;AACrC,KAAI;AACJ;AACA,IAAI,OAAO,SAAS,CAAA;AACpB,GAAE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,SAAS,wBAAwB,CAAC,QAAQ,EAAuC;AACnF,IAAI,IAAI,S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
|
package/esm/reactrouterv6.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WINDOW } from '@sentry/browser';
|
|
2
|
+
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
|
|
2
3
|
import { logger, getNumberOfUrlSegments } from '@sentry/utils';
|
|
3
4
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
4
5
|
import * as React from 'react';
|
|
@@ -117,7 +118,7 @@ function updatePageloadTransaction(
|
|
|
117
118
|
if (activeTransaction && branches) {
|
|
118
119
|
const [name, source] = getNormalizedName(routes, location, branches, basename);
|
|
119
120
|
activeTransaction.updateName(name);
|
|
120
|
-
activeTransaction.
|
|
121
|
+
activeTransaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
|
|
@@ -190,7 +191,7 @@ function withSentryReactRouterV6Routing(Routes) {
|
|
|
190
191
|
|
|
191
192
|
// @ts-expect-error Setting more specific React Component typing for `R` generic above
|
|
192
193
|
// will break advanced type inference done by react router params
|
|
193
|
-
return React.createElement(Routes, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
194
|
+
return React.createElement(Routes, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 213}} );
|
|
194
195
|
};
|
|
195
196
|
|
|
196
197
|
hoistNonReactStatics(SentryRoutes, Routes);
|
|
@@ -245,7 +246,7 @@ function wrapUseRoutes(origUseRoutes) {
|
|
|
245
246
|
|
|
246
247
|
// eslint-disable-next-line react/display-name
|
|
247
248
|
return (routes, locationArg) => {
|
|
248
|
-
return React.createElement(SentryRoutes, { routes: routes, locationArg: locationArg, __self: this, __source: {fileName: _jsxFileName, lineNumber:
|
|
249
|
+
return React.createElement(SentryRoutes, { routes: routes, locationArg: locationArg, __self: this, __source: {fileName: _jsxFileName, lineNumber: 270}} );
|
|
249
250
|
};
|
|
250
251
|
}
|
|
251
252
|
|
package/esm/reactrouterv6.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouterv6.js","sources":["../../src/reactrouterv6.tsx"],"sourcesContent":["// Inspired from Donnie McNeal's solution:\n// https://gist.github.com/wontondon/e8c4bdf2888875e4c755712e99279536\n\nimport { WINDOW } from '@sentry/browser';\nimport type { Transaction, TransactionContext, TransactionSource } from '@sentry/types';\nimport { getNumberOfUrlSegments, logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport type {\n Action,\n AgnosticDataRouteMatch,\n CreateRouterFunction,\n CreateRoutesFromChildren,\n Location,\n MatchRoutes,\n RouteMatch,\n RouteObject,\n Router,\n RouterState,\n UseEffect,\n UseLocation,\n UseNavigationType,\n UseRoutes,\n} from './types';\n\nlet activeTransaction: Transaction | undefined;\n\nlet _useEffect: UseEffect;\nlet _useLocation: UseLocation;\nlet _useNavigationType: UseNavigationType;\nlet _createRoutesFromChildren: CreateRoutesFromChildren;\nlet _matchRoutes: MatchRoutes;\nlet _customStartTransaction: (context: TransactionContext) => Transaction | undefined;\nlet _startTransactionOnLocationChange: boolean;\n\nconst SENTRY_TAGS = {\n 'routing.instrumentation': 'react-router-v6',\n};\n\nexport function reactRouterV6Instrumentation(\n useEffect: UseEffect,\n useLocation: UseLocation,\n useNavigationType: UseNavigationType,\n createRoutesFromChildren: CreateRoutesFromChildren,\n matchRoutes: MatchRoutes,\n) {\n return (\n customStartTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad = true,\n startTransactionOnLocationChange = true,\n ): void => {\n const initPathName = WINDOW && WINDOW.location && WINDOW.location.pathname;\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: initPathName,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouterv6',\n tags: SENTRY_TAGS,\n metadata: {\n source: 'url',\n },\n });\n }\n\n _useEffect = useEffect;\n _useLocation = useLocation;\n _useNavigationType = useNavigationType;\n _matchRoutes = matchRoutes;\n _createRoutesFromChildren = createRoutesFromChildren;\n\n _customStartTransaction = customStartTransaction;\n _startTransactionOnLocationChange = startTransactionOnLocationChange;\n };\n}\n\nfunction getNormalizedName(\n routes: RouteObject[],\n location: Location,\n branches: RouteMatch[],\n basename: string = '',\n): [string, TransactionSource] {\n if (!routes || routes.length === 0) {\n return [location.pathname, 'url'];\n }\n\n let pathBuilder = '';\n if (branches) {\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n const branch = branches[x];\n const route = branch.route;\n if (route) {\n // Early return if index route\n if (route.index) {\n return [branch.pathname, 'route'];\n }\n\n const path = route.path;\n if (path) {\n const newPath = path[0] === '/' || pathBuilder[pathBuilder.length - 1] === '/' ? path : `/${path}`;\n pathBuilder += newPath;\n\n if (basename + branch.pathname === location.pathname) {\n if (\n // If the route defined on the element is something like\n // <Route path=\"/stores/:storeId/products/:productId\" element={<div>Product</div>} />\n // We should check against the branch.pathname for the number of / seperators\n getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&\n // We should not count wildcard operators in the url segments calculation\n pathBuilder.slice(-2) !== '/*'\n ) {\n return [basename + newPath, 'route'];\n }\n return [basename + pathBuilder, 'route'];\n }\n }\n }\n }\n }\n\n return [location.pathname, 'url'];\n}\n\nfunction updatePageloadTransaction(\n location: Location,\n routes: RouteObject[],\n matches?: AgnosticDataRouteMatch,\n basename?: string,\n): void {\n const branches = Array.isArray(matches)\n ? matches\n : (_matchRoutes(routes, location, basename) as unknown as RouteMatch[]);\n\n if (activeTransaction && branches) {\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n activeTransaction.updateName(name);\n activeTransaction.setMetadata({ source });\n }\n}\n\nfunction handleNavigation(\n location: Location,\n routes: RouteObject[],\n navigationType: Action,\n matches?: AgnosticDataRouteMatch,\n basename?: string,\n): void {\n const branches = Array.isArray(matches) ? matches : _matchRoutes(routes, location, basename);\n\n if (_startTransactionOnLocationChange && (navigationType === 'PUSH' || navigationType === 'POP') && branches) {\n if (activeTransaction) {\n activeTransaction.end();\n }\n\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n activeTransaction = _customStartTransaction({\n name,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouterv6',\n tags: SENTRY_TAGS,\n metadata: {\n source,\n },\n });\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withSentryReactRouterV6Routing<P extends Record<string, any>, R extends React.FC<P>>(Routes: R): R {\n if (\n !_useEffect ||\n !_useLocation ||\n !_useNavigationType ||\n !_createRoutesFromChildren ||\n !_matchRoutes ||\n !_customStartTransaction\n ) {\n DEBUG_BUILD &&\n logger.warn(`reactRouterV6Instrumentation was unable to wrap Routes because of one or more missing parameters.\n useEffect: ${_useEffect}. useLocation: ${_useLocation}. useNavigationType: ${_useNavigationType}.\n createRoutesFromChildren: ${_createRoutesFromChildren}. matchRoutes: ${_matchRoutes}. customStartTransaction: ${_customStartTransaction}.`);\n\n return Routes;\n }\n\n let isMountRenderPass: boolean = true;\n\n const SentryRoutes: React.FC<P> = (props: P) => {\n const location = _useLocation();\n const navigationType = _useNavigationType();\n\n _useEffect(\n () => {\n const routes = _createRoutesFromChildren(props.children) as RouteObject[];\n\n if (isMountRenderPass) {\n updatePageloadTransaction(location, routes);\n isMountRenderPass = false;\n } else {\n handleNavigation(location, routes, navigationType);\n }\n },\n // `props.children` is purpusely not included in the dependency array, because we do not want to re-run this effect\n // when the children change. We only want to start transactions when the location or navigation type change.\n [location, navigationType],\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 return <Routes {...props} />;\n };\n\n hoistNonReactStatics(SentryRoutes, Routes);\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 return SentryRoutes;\n}\n\nexport function wrapUseRoutes(origUseRoutes: UseRoutes): UseRoutes {\n if (!_useEffect || !_useLocation || !_useNavigationType || !_matchRoutes || !_customStartTransaction) {\n DEBUG_BUILD &&\n logger.warn(\n 'reactRouterV6Instrumentation was unable to wrap `useRoutes` because of one or more missing parameters.',\n );\n\n return origUseRoutes;\n }\n\n let isMountRenderPass: boolean = true;\n\n const SentryRoutes: React.FC<{\n children?: React.ReactNode;\n routes: RouteObject[];\n locationArg?: Partial<Location> | string;\n }> = (props: { children?: React.ReactNode; routes: RouteObject[]; locationArg?: Partial<Location> | string }) => {\n const { routes, locationArg } = props;\n\n const Routes = origUseRoutes(routes, locationArg);\n\n const location = _useLocation();\n const navigationType = _useNavigationType();\n\n // A value with stable identity to either pick `locationArg` if available or `location` if not\n const stableLocationParam =\n typeof locationArg === 'string' || (locationArg && locationArg.pathname)\n ? (locationArg as { pathname: string })\n : location;\n\n _useEffect(() => {\n const normalizedLocation =\n typeof stableLocationParam === 'string' ? { pathname: stableLocationParam } : stableLocationParam;\n\n if (isMountRenderPass) {\n updatePageloadTransaction(normalizedLocation, routes);\n isMountRenderPass = false;\n } else {\n handleNavigation(normalizedLocation, routes, navigationType);\n }\n }, [navigationType, stableLocationParam]);\n\n return Routes;\n };\n\n // eslint-disable-next-line react/display-name\n return (routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null => {\n return <SentryRoutes routes={routes} locationArg={locationArg} />;\n };\n}\n\nexport function wrapCreateBrowserRouter<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n // `opts` for createBrowserHistory and createMemoryHistory are different, but also not relevant for us at the moment.\n // `basename` is the only option that is relevant for us, and it is the same for all.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function (routes: RouteObject[], opts?: Record<string, any> & { basename?: string }): TRouter {\n const router = createRouterFunction(routes, opts);\n const basename = opts && opts.basename;\n\n // The initial load ends when `createBrowserRouter` is called.\n // This is the earliest convenient time to update the transaction name.\n // Callbacks to `router.subscribe` are not called for the initial load.\n if (router.state.historyAction === 'POP' && activeTransaction) {\n updatePageloadTransaction(router.state.location, routes, undefined, basename);\n }\n\n router.subscribe((state: RouterState) => {\n const location = state.location;\n\n if (\n _startTransactionOnLocationChange &&\n (state.historyAction === 'PUSH' || state.historyAction === 'POP') &&\n activeTransaction\n ) {\n handleNavigation(location, routes, state.historyAction, undefined, basename);\n }\n });\n\n return router;\n };\n}\n"],"names":[],"mappings":";;;;;;AAAA,MAAA,YAAA,GAAA,4FAAA,CAAA;;AA2BA,IAAI,iBAAiB,CAAA;AACrB;AACA,IAAI,UAAU,CAAA;AACd,IAAI,YAAY,CAAA;AAChB,IAAI,kBAAkB,CAAA;AACtB,IAAI,yBAAyB,CAAA;AAC7B,IAAI,YAAY,CAAA;AAChB,IAAI,uBAAuB,CAAA;AAC3B,IAAI,iCAAiC,CAAA;AACrC;AACA,MAAM,cAAc;AACpB,EAAE,yBAAyB,EAAE,iBAAiB;AAC9C,CAAC,CAAA;AACD;AACO,SAAS,4BAA4B;AAC5C,EAAE,SAAS;AACX,EAAE,WAAW;AACb,EAAE,iBAAiB;AACnB,EAAE,wBAAwB;AAC1B,EAAE,WAAW;AACb,EAAE;AACF,EAAE,OAAO;AACT,IAAI,sBAAsB;AAC1B,IAAI,0BAAA,GAA6B,IAAI;AACrC,IAAI,gCAAA,GAAmC,IAAI;AAC3C,OAAa;AACb,IAAI,MAAM,YAAA,GAAe,MAAA,IAAU,MAAM,CAAC,QAAA,IAAY,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAA;AAC9E,IAAI,IAAI,0BAA2B,IAAG,YAAY,EAAE;AACpD,MAAM,iBAAA,GAAoB,sBAAsB,CAAC;AACjD,QAAQ,IAAI,EAAE,YAAY;AAC1B,QAAQ,EAAE,EAAE,UAAU;AACtB,QAAQ,MAAM,EAAE,mCAAmC;AACnD,QAAQ,IAAI,EAAE,WAAW;AACzB,QAAQ,QAAQ,EAAE;AAClB,UAAU,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EAAA,WAAA,EAAA,WAAA,EAAA,MAAA,EAAA,IAAA,EAAA,QAAA,EAAA,CAAA,QAAA,EAAA,YAAA,EAAA,UAAA,EAAA,GAAA,CAAA,CAAA,EAAA,CAAA;AACA,GAAA,CAAA;AACA,CAAA;AACA;AACA,SAAA,uBAAA;;AAGA,CAAA,oBAAA,EAAA;AACA;AACA;AACA;AACA,EAAA,OAAA,UAAA,MAAA,EAAA,IAAA,EAAA;AACA,IAAA,MAAA,MAAA,GAAA,oBAAA,CAAA,MAAA,EAAA,IAAA,CAAA,CAAA;AACA,IAAA,MAAA,QAAA,GAAA,IAAA,IAAA,IAAA,CAAA,QAAA,CAAA;AACA;AACA;AACA;AACA;AACA,IAAA,IAAA,MAAA,CAAA,KAAA,CAAA,aAAA,KAAA,KAAA,IAAA,iBAAA,EAAA;AACA,MAAA,yBAAA,CAAA,MAAA,CAAA,KAAA,CAAA,QAAA,EAAA,MAAA,EAAA,SAAA,EAAA,QAAA,CAAA,CAAA;AACA,KAAA;AACA;AACA,IAAA,MAAA,CAAA,SAAA,CAAA,CAAA,KAAA,KAAA;AACA,MAAA,MAAA,QAAA,GAAA,KAAA,CAAA,QAAA,CAAA;AACA;AACA,MAAA;AACA,QAAA,iCAAA;AACA,SAAA,KAAA,CAAA,aAAA,KAAA,MAAA,IAAA,KAAA,CAAA,aAAA,KAAA,KAAA,CAAA;AACA,QAAA,iBAAA;AACA,QAAA;AACA,QAAA,gBAAA,CAAA,QAAA,EAAA,MAAA,EAAA,KAAA,CAAA,aAAA,EAAA,SAAA,EAAA,QAAA,CAAA,CAAA;AACA,OAAA;AACA,KAAA,CAAA,CAAA;AACA;AACA,IAAA,OAAA,MAAA,CAAA;AACA,GAAA,CAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"reactrouterv6.js","sources":["../../src/reactrouterv6.tsx"],"sourcesContent":["// Inspired from Donnie McNeal's solution:\n// https://gist.github.com/wontondon/e8c4bdf2888875e4c755712e99279536\n\nimport { WINDOW } from '@sentry/browser';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';\nimport type { Transaction, TransactionContext, TransactionSource } from '@sentry/types';\nimport { getNumberOfUrlSegments, logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport type {\n Action,\n AgnosticDataRouteMatch,\n CreateRouterFunction,\n CreateRoutesFromChildren,\n Location,\n MatchRoutes,\n RouteMatch,\n RouteObject,\n Router,\n RouterState,\n UseEffect,\n UseLocation,\n UseNavigationType,\n UseRoutes,\n} from './types';\n\nlet activeTransaction: Transaction | undefined;\n\nlet _useEffect: UseEffect;\nlet _useLocation: UseLocation;\nlet _useNavigationType: UseNavigationType;\nlet _createRoutesFromChildren: CreateRoutesFromChildren;\nlet _matchRoutes: MatchRoutes;\nlet _customStartTransaction: (context: TransactionContext) => Transaction | undefined;\nlet _startTransactionOnLocationChange: boolean;\n\nconst SENTRY_TAGS = {\n 'routing.instrumentation': 'react-router-v6',\n};\n\nexport function reactRouterV6Instrumentation(\n useEffect: UseEffect,\n useLocation: UseLocation,\n useNavigationType: UseNavigationType,\n createRoutesFromChildren: CreateRoutesFromChildren,\n matchRoutes: MatchRoutes,\n) {\n return (\n customStartTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad = true,\n startTransactionOnLocationChange = true,\n ): void => {\n const initPathName = WINDOW && WINDOW.location && WINDOW.location.pathname;\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: initPathName,\n op: 'pageload',\n origin: 'auto.pageload.react.reactrouterv6',\n tags: SENTRY_TAGS,\n metadata: {\n source: 'url',\n },\n });\n }\n\n _useEffect = useEffect;\n _useLocation = useLocation;\n _useNavigationType = useNavigationType;\n _matchRoutes = matchRoutes;\n _createRoutesFromChildren = createRoutesFromChildren;\n\n _customStartTransaction = customStartTransaction;\n _startTransactionOnLocationChange = startTransactionOnLocationChange;\n };\n}\n\nfunction getNormalizedName(\n routes: RouteObject[],\n location: Location,\n branches: RouteMatch[],\n basename: string = '',\n): [string, TransactionSource] {\n if (!routes || routes.length === 0) {\n return [location.pathname, 'url'];\n }\n\n let pathBuilder = '';\n if (branches) {\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n const branch = branches[x];\n const route = branch.route;\n if (route) {\n // Early return if index route\n if (route.index) {\n return [branch.pathname, 'route'];\n }\n\n const path = route.path;\n if (path) {\n const newPath = path[0] === '/' || pathBuilder[pathBuilder.length - 1] === '/' ? path : `/${path}`;\n pathBuilder += newPath;\n\n if (basename + branch.pathname === location.pathname) {\n if (\n // If the route defined on the element is something like\n // <Route path=\"/stores/:storeId/products/:productId\" element={<div>Product</div>} />\n // We should check against the branch.pathname for the number of / seperators\n getNumberOfUrlSegments(pathBuilder) !== getNumberOfUrlSegments(branch.pathname) &&\n // We should not count wildcard operators in the url segments calculation\n pathBuilder.slice(-2) !== '/*'\n ) {\n return [basename + newPath, 'route'];\n }\n return [basename + pathBuilder, 'route'];\n }\n }\n }\n }\n }\n\n return [location.pathname, 'url'];\n}\n\nfunction updatePageloadTransaction(\n location: Location,\n routes: RouteObject[],\n matches?: AgnosticDataRouteMatch,\n basename?: string,\n): void {\n const branches = Array.isArray(matches)\n ? matches\n : (_matchRoutes(routes, location, basename) as unknown as RouteMatch[]);\n\n if (activeTransaction && branches) {\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n activeTransaction.updateName(name);\n activeTransaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);\n }\n}\n\nfunction handleNavigation(\n location: Location,\n routes: RouteObject[],\n navigationType: Action,\n matches?: AgnosticDataRouteMatch,\n basename?: string,\n): void {\n const branches = Array.isArray(matches) ? matches : _matchRoutes(routes, location, basename);\n\n if (_startTransactionOnLocationChange && (navigationType === 'PUSH' || navigationType === 'POP') && branches) {\n if (activeTransaction) {\n activeTransaction.end();\n }\n\n const [name, source] = getNormalizedName(routes, location, branches, basename);\n activeTransaction = _customStartTransaction({\n name,\n op: 'navigation',\n origin: 'auto.navigation.react.reactrouterv6',\n tags: SENTRY_TAGS,\n metadata: {\n source,\n },\n });\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withSentryReactRouterV6Routing<P extends Record<string, any>, R extends React.FC<P>>(Routes: R): R {\n if (\n !_useEffect ||\n !_useLocation ||\n !_useNavigationType ||\n !_createRoutesFromChildren ||\n !_matchRoutes ||\n !_customStartTransaction\n ) {\n DEBUG_BUILD &&\n logger.warn(`reactRouterV6Instrumentation was unable to wrap Routes because of one or more missing parameters.\n useEffect: ${_useEffect}. useLocation: ${_useLocation}. useNavigationType: ${_useNavigationType}.\n createRoutesFromChildren: ${_createRoutesFromChildren}. matchRoutes: ${_matchRoutes}. customStartTransaction: ${_customStartTransaction}.`);\n\n return Routes;\n }\n\n let isMountRenderPass: boolean = true;\n\n const SentryRoutes: React.FC<P> = (props: P) => {\n const location = _useLocation();\n const navigationType = _useNavigationType();\n\n _useEffect(\n () => {\n const routes = _createRoutesFromChildren(props.children) as RouteObject[];\n\n if (isMountRenderPass) {\n updatePageloadTransaction(location, routes);\n isMountRenderPass = false;\n } else {\n handleNavigation(location, routes, navigationType);\n }\n },\n // `props.children` is purpusely not included in the dependency array, because we do not want to re-run this effect\n // when the children change. We only want to start transactions when the location or navigation type change.\n [location, navigationType],\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 return <Routes {...props} />;\n };\n\n hoistNonReactStatics(SentryRoutes, Routes);\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 return SentryRoutes;\n}\n\nexport function wrapUseRoutes(origUseRoutes: UseRoutes): UseRoutes {\n if (!_useEffect || !_useLocation || !_useNavigationType || !_matchRoutes || !_customStartTransaction) {\n DEBUG_BUILD &&\n logger.warn(\n 'reactRouterV6Instrumentation was unable to wrap `useRoutes` because of one or more missing parameters.',\n );\n\n return origUseRoutes;\n }\n\n let isMountRenderPass: boolean = true;\n\n const SentryRoutes: React.FC<{\n children?: React.ReactNode;\n routes: RouteObject[];\n locationArg?: Partial<Location> | string;\n }> = (props: { children?: React.ReactNode; routes: RouteObject[]; locationArg?: Partial<Location> | string }) => {\n const { routes, locationArg } = props;\n\n const Routes = origUseRoutes(routes, locationArg);\n\n const location = _useLocation();\n const navigationType = _useNavigationType();\n\n // A value with stable identity to either pick `locationArg` if available or `location` if not\n const stableLocationParam =\n typeof locationArg === 'string' || (locationArg && locationArg.pathname)\n ? (locationArg as { pathname: string })\n : location;\n\n _useEffect(() => {\n const normalizedLocation =\n typeof stableLocationParam === 'string' ? { pathname: stableLocationParam } : stableLocationParam;\n\n if (isMountRenderPass) {\n updatePageloadTransaction(normalizedLocation, routes);\n isMountRenderPass = false;\n } else {\n handleNavigation(normalizedLocation, routes, navigationType);\n }\n }, [navigationType, stableLocationParam]);\n\n return Routes;\n };\n\n // eslint-disable-next-line react/display-name\n return (routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null => {\n return <SentryRoutes routes={routes} locationArg={locationArg} />;\n };\n}\n\nexport function wrapCreateBrowserRouter<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n // `opts` for createBrowserHistory and createMemoryHistory are different, but also not relevant for us at the moment.\n // `basename` is the only option that is relevant for us, and it is the same for all.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return function (routes: RouteObject[], opts?: Record<string, any> & { basename?: string }): TRouter {\n const router = createRouterFunction(routes, opts);\n const basename = opts && opts.basename;\n\n // The initial load ends when `createBrowserRouter` is called.\n // This is the earliest convenient time to update the transaction name.\n // Callbacks to `router.subscribe` are not called for the initial load.\n if (router.state.historyAction === 'POP' && activeTransaction) {\n updatePageloadTransaction(router.state.location, routes, undefined, basename);\n }\n\n router.subscribe((state: RouterState) => {\n const location = state.location;\n\n if (\n _startTransactionOnLocationChange &&\n (state.historyAction === 'PUSH' || state.historyAction === 'POP') &&\n activeTransaction\n ) {\n handleNavigation(location, routes, state.historyAction, undefined, basename);\n }\n });\n\n return router;\n };\n}\n"],"names":[],"mappings":";;;;;;;AAAA,MAAA,YAAA,GAAA,4FAAA,CAAA;;AA4BA,IAAI,iBAAiB,CAAA;AACrB;AACA,IAAI,UAAU,CAAA;AACd,IAAI,YAAY,CAAA;AAChB,IAAI,kBAAkB,CAAA;AACtB,IAAI,yBAAyB,CAAA;AAC7B,IAAI,YAAY,CAAA;AAChB,IAAI,uBAAuB,CAAA;AAC3B,IAAI,iCAAiC,CAAA;AACrC;AACA,MAAM,cAAc;AACpB,EAAE,yBAAyB,EAAE,iBAAiB;AAC9C,CAAC,CAAA;AACD;AACO,SAAS,4BAA4B;AAC5C,EAAE,SAAS;AACX,EAAE,WAAW;AACb,EAAE,iBAAiB;AACnB,EAAE,wBAAwB;AAC1B,EAAE,WAAW;AACb,EAAE;AACF,EAAE,OAAO;AACT,IAAI,sBAAsB;AAC1B,IAAI,0BAAA,GAA6B,IAAI;AACrC,IAAI,gCAAA,GAAmC,IAAI;AAC3C,OAAa;AACb,IAAI,MAAM,YAAA,GAAe,MAAA,IAAU,MAAM,CAAC,QAAA,IAAY,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAA;AAC9E,IAAI,IAAI,0BAA2B,IAAG,YAAY,EAAE;AACpD,MAAM,iBAAA,GAAoB,sBAAsB,CAAC;AACjD,QAAQ,IAAI,EAAE,YAAY;AAC1B,QAAQ,EAAE,EAAE,UAAU;AACtB,QAAQ,MAAM,EAAE,mCAAmC;AACnD,QAAQ,IAAI,EAAE,WAAW;AACzB,QAAQ,QAAQ,EAAE;AAClB,UAAU,MAAM,EAAE,KAAK;AACvB,SAAS;AACT,OAAO,CAAC,CAAA;AACR,KAAI;AACJ;AACA,IAAI,UAAA,GAAa,SAAS,CAAA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EAAA,GAAA,CAAA,CAAA,EAAA,CAAA;AACA,GAAA,CAAA;AACA,CAAA;AACA;AACA,SAAA,uBAAA;;AAGA,CAAA,oBAAA,EAAA;AACA;AACA;AACA;AACA,EAAA,OAAA,UAAA,MAAA,EAAA,IAAA,EAAA;AACA,IAAA,MAAA,MAAA,GAAA,oBAAA,CAAA,MAAA,EAAA,IAAA,CAAA,CAAA;AACA,IAAA,MAAA,QAAA,GAAA,IAAA,IAAA,IAAA,CAAA,QAAA,CAAA;AACA;AACA;AACA;AACA;AACA,IAAA,IAAA,MAAA,CAAA,KAAA,CAAA,aAAA,KAAA,KAAA,IAAA,iBAAA,EAAA;AACA,MAAA,yBAAA,CAAA,MAAA,CAAA,KAAA,CAAA,QAAA,EAAA,MAAA,EAAA,SAAA,EAAA,QAAA,CAAA,CAAA;AACA,KAAA;AACA;AACA,IAAA,MAAA,CAAA,SAAA,CAAA,CAAA,KAAA,KAAA;AACA,MAAA,MAAA,QAAA,GAAA,KAAA,CAAA,QAAA,CAAA;AACA;AACA,MAAA;AACA,QAAA,iCAAA;AACA,SAAA,KAAA,CAAA,aAAA,KAAA,MAAA,IAAA,KAAA,CAAA,aAAA,KAAA,KAAA,CAAA;AACA,QAAA,iBAAA;AACA,QAAA;AACA,QAAA,gBAAA,CAAA,QAAA,EAAA,MAAA,EAAA,KAAA,CAAA,aAAA,EAAA,SAAA,EAAA,QAAA,CAAA,CAAA;AACA,OAAA;AACA,KAAA,CAAA,CAAA;AACA;AACA,IAAA,OAAA,MAAA,CAAA;AACA,GAAA,CAAA;AACA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/react",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.94.1",
|
|
4
4
|
"description": "Official Sentry SDK for React.js",
|
|
5
5
|
"repository": "git://github.com/getsentry/sentry-javascript.git",
|
|
6
6
|
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/react",
|
|
@@ -29,9 +29,10 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@sentry/browser": "7.
|
|
33
|
-
"@sentry/
|
|
34
|
-
"@sentry/
|
|
32
|
+
"@sentry/browser": "7.94.1",
|
|
33
|
+
"@sentry/core": "7.94.1",
|
|
34
|
+
"@sentry/types": "7.94.1",
|
|
35
|
+
"@sentry/utils": "7.94.1",
|
|
35
36
|
"hoist-non-react-statics": "^3.3.2"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
package/types/profiler.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Span, Transaction } from '@sentry/types';
|
|
1
|
+
import type { Span } from '@sentry/types';
|
|
3
2
|
import * as React from 'react';
|
|
4
3
|
export declare const UNKNOWN_COMPONENT = "unknown";
|
|
5
4
|
export type ProfilerProps = {
|
|
@@ -55,6 +54,4 @@ declare function useProfiler(name: string, options?: {
|
|
|
55
54
|
hasRenderSpan?: boolean;
|
|
56
55
|
}): void;
|
|
57
56
|
export { withProfiler, Profiler, useProfiler };
|
|
58
|
-
/** Grabs active transaction off scope */
|
|
59
|
-
export declare function getActiveTransaction<T extends Transaction>(hub?: Hub): T | undefined;
|
|
60
57
|
//# sourceMappingURL=profiler.d.ts.map
|
package/types/profiler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiler.d.ts","sourceRoot":"","sources":["../../src/profiler.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"profiler.d.ts","sourceRoot":"","sources":["../../src/profiler.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAG1C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,MAAM,MAA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AAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAGrD,GACA,IAAI,CAyCN;AAED,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouter.d.ts","sourceRoot":"","sources":["../../src/reactrouter.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reactrouter.d.ts","sourceRoot":"","sources":["../../src/reactrouter.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAI5E,KAAK,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAE1F,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;CACjE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAExB,MAAM,MAAM,WAAW,GAAG;IACxB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC;AAEF,KAAK,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,GAAG,EAAE,MAAM,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,KAAK,GAAG,IAAI,CAAC;AAI3G,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,aAAa,EACtB,MAAM,CAAC,EAAE,WAAW,EAAE,EACtB,SAAS,CAAC,EAAE,SAAS,GACpB,0BAA0B,CAE5B;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,aAAa,EACtB,MAAM,CAAC,EAAE,WAAW,EAAE,EACtB,SAAS,CAAC,EAAE,SAAS,GACpB,0BAA0B,CAE5B;AAwHD,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAqB9G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactrouterv6.d.ts","sourceRoot":"","sources":["../../src/reactrouterv6.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reactrouterv6.d.ts","sourceRoot":"","sources":["../../src/reactrouterv6.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAqB,MAAM,eAAe,CAAC;AAGxF,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAGV,oBAAoB,EACpB,wBAAwB,EAExB,WAAW,EAGX,MAAM,EACN,WAAW,EACX,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,SAAS,EACV,MAAM,SAAS,CAAC;AAgBjB,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,EACxB,iBAAiB,EAAE,iBAAiB,EACpC,wBAAwB,EAAE,wBAAwB,EAClD,WAAW,EAAE,WAAW,sCAGY,kBAAkB,KAAK,WAAW,GAAG,SAAS,uFAG/E,IAAI,CAuBR;AA+FD,wBAAgB,8BAA8B,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAiDjH;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,SAAS,GAAG,SAAS,CAiDjE;AAED,wBAAgB,uBAAuB,CACrC,MAAM,SAAS,WAAW,GAAG,WAAW,EACxC,OAAO,SAAS,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,EAC/C,oBAAoB,EAAE,oBAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,oBAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,CA6BpG"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Span, Transaction } from '@sentry/types';
|
|
1
|
+
import { Span } from '@sentry/types';
|
|
3
2
|
import * as React from 'react';
|
|
4
3
|
export declare const UNKNOWN_COMPONENT = "unknown";
|
|
5
4
|
export type ProfilerProps = {
|
|
@@ -55,6 +54,4 @@ declare function useProfiler(name: string, options?: {
|
|
|
55
54
|
hasRenderSpan?: boolean;
|
|
56
55
|
}): void;
|
|
57
56
|
export { withProfiler, Profiler, useProfiler };
|
|
58
|
-
/** Grabs active transaction off scope */
|
|
59
|
-
export declare function getActiveTransaction<T extends Transaction>(hub?: Hub): T | undefined;
|
|
60
57
|
//# sourceMappingURL=profiler.d.ts.map
|