@sentry/react 7.0.0-alpha.1 → 7.0.0-beta.2

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.
Files changed (92) hide show
  1. package/README.md +2 -3
  2. package/cjs/constants.js +12 -5
  3. package/cjs/constants.js.map +1 -1
  4. package/cjs/errorboundary.js +139 -112
  5. package/cjs/errorboundary.js.map +1 -1
  6. package/cjs/flags.js +7 -3
  7. package/cjs/flags.js.map +1 -1
  8. package/cjs/index.js +30 -21
  9. package/cjs/index.js.map +1 -1
  10. package/cjs/profiler.js +178 -147
  11. package/cjs/profiler.js.map +1 -1
  12. package/cjs/reactrouter.js +147 -100
  13. package/cjs/reactrouter.js.map +1 -1
  14. package/cjs/reactrouterv3.js +107 -83
  15. package/cjs/reactrouterv3.js.map +1 -1
  16. package/cjs/reactrouterv6.js +163 -0
  17. package/cjs/reactrouterv6.js.map +1 -0
  18. package/cjs/redux.js +51 -42
  19. package/cjs/redux.js.map +1 -1
  20. package/cjs/sdk.js +18 -15
  21. package/cjs/sdk.js.map +1 -1
  22. package/esm/constants.js +8 -4
  23. package/esm/constants.js.map +1 -1
  24. package/esm/errorboundary.js +124 -107
  25. package/esm/errorboundary.js.map +1 -1
  26. package/esm/flags.js +5 -2
  27. package/esm/flags.js.map +1 -1
  28. package/esm/index.js +8 -7
  29. package/esm/index.js.map +1 -1
  30. package/esm/profiler.js +161 -140
  31. package/esm/profiler.js.map +1 -1
  32. package/esm/reactrouter.js +133 -94
  33. package/esm/reactrouter.js.map +1 -1
  34. package/esm/reactrouterv3.js +103 -79
  35. package/esm/reactrouterv3.js.map +1 -1
  36. package/esm/reactrouterv6.js +153 -0
  37. package/esm/reactrouterv6.js.map +1 -0
  38. package/esm/redux.js +49 -41
  39. package/esm/redux.js.map +1 -1
  40. package/esm/sdk.js +17 -14
  41. package/esm/sdk.js.map +1 -1
  42. package/package.json +5 -5
  43. package/types/errorboundary.d.ts +1 -0
  44. package/types/errorboundary.d.ts.map +1 -1
  45. package/types/index.d.ts +1 -0
  46. package/types/index.d.ts.map +1 -1
  47. package/types/reactrouterv6.d.ts +27 -0
  48. package/types/reactrouterv6.d.ts.map +1 -0
  49. package/cjs/constants.d.ts +0 -4
  50. package/cjs/constants.d.ts.map +0 -1
  51. package/cjs/errorboundary.d.ts +0 -62
  52. package/cjs/errorboundary.d.ts.map +0 -1
  53. package/cjs/flags.d.ts +0 -3
  54. package/cjs/flags.d.ts.map +0 -1
  55. package/cjs/index.d.ts +0 -8
  56. package/cjs/index.d.ts.map +0 -1
  57. package/cjs/profiler.d.ts +0 -54
  58. package/cjs/profiler.d.ts.map +0 -1
  59. package/cjs/reactrouter.d.ts +0 -25
  60. package/cjs/reactrouter.d.ts.map +0 -1
  61. package/cjs/reactrouterv3.d.ts +0 -26
  62. package/cjs/reactrouterv3.d.ts.map +0 -1
  63. package/cjs/redux.d.ts +0 -33
  64. package/cjs/redux.d.ts.map +0 -1
  65. package/cjs/sdk.d.ts +0 -6
  66. package/cjs/sdk.d.ts.map +0 -1
  67. package/cjs/types.d.ts +0 -8
  68. package/cjs/types.d.ts.map +0 -1
  69. package/cjs/types.js +0 -2
  70. package/cjs/types.js.map +0 -1
  71. package/esm/constants.d.ts +0 -4
  72. package/esm/constants.d.ts.map +0 -1
  73. package/esm/errorboundary.d.ts +0 -62
  74. package/esm/errorboundary.d.ts.map +0 -1
  75. package/esm/flags.d.ts +0 -3
  76. package/esm/flags.d.ts.map +0 -1
  77. package/esm/index.d.ts +0 -8
  78. package/esm/index.d.ts.map +0 -1
  79. package/esm/profiler.d.ts +0 -54
  80. package/esm/profiler.d.ts.map +0 -1
  81. package/esm/reactrouter.d.ts +0 -25
  82. package/esm/reactrouter.d.ts.map +0 -1
  83. package/esm/reactrouterv3.d.ts +0 -26
  84. package/esm/reactrouterv3.d.ts.map +0 -1
  85. package/esm/redux.d.ts +0 -33
  86. package/esm/redux.d.ts.map +0 -1
  87. package/esm/sdk.d.ts +0 -6
  88. package/esm/sdk.d.ts.map +0 -1
  89. package/esm/types.d.ts +0 -8
  90. package/esm/types.d.ts.map +0 -1
  91. package/esm/types.js +0 -1
  92. package/esm/types.js.map +0 -1
package/cjs/profiler.js CHANGED
@@ -1,98 +1,110 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- var tslib_1 = require("tslib");
3
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
4
- /* eslint-disable @typescript-eslint/no-explicit-any */
5
- var browser_1 = require("@sentry/browser");
6
- var utils_1 = require("@sentry/utils");
7
- var hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics"));
8
- var React = tslib_1.__importStar(require("react"));
9
- var constants_1 = require("./constants");
10
- exports.UNKNOWN_COMPONENT = 'unknown';
1
+ var {
2
+ _interopDefault,
3
+ _interopNamespace
4
+ } = require('@sentry/utils/cjs/buildPolyfills');
5
+
6
+ Object.defineProperty(exports, '__esModule', { value: true });
7
+
8
+ var browser = require('@sentry/browser');
9
+ var utils = require('@sentry/utils');
10
+ var hoistNonReactStatics = require('hoist-non-react-statics');
11
+ var React = require('react');
12
+ var constants = require('./constants.js');
13
+
14
+ var hoistNonReactStatics__default = /*#__PURE__*/_interopDefault(hoistNonReactStatics);
15
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
16
+
17
+ var _jsxFileName = "/home/runner/work/sentry-javascript/sentry-javascript/packages/react/src/profiler.tsx";
18
+ var UNKNOWN_COMPONENT = 'unknown';
19
+
11
20
  /**
12
21
  * The Profiler component leverages Sentry's Tracing integration to generate
13
22
  * spans based on component lifecycles.
14
23
  */
15
- var Profiler = /** @class */ (function (_super) {
16
- tslib_1.__extends(Profiler, _super);
17
- function Profiler(props) {
18
- var _this = _super.call(this, props) || this;
19
- /**
20
- * The span of the mount activity
21
- * Made protected for the React Native SDK to access
22
- */
23
- _this._mountSpan = undefined;
24
- var _a = _this.props, name = _a.name, _b = _a.disabled, disabled = _b === void 0 ? false : _b;
25
- if (disabled) {
26
- return _this;
27
- }
28
- var activeTransaction = getActiveTransaction();
29
- if (activeTransaction) {
30
- _this._mountSpan = activeTransaction.startChild({
31
- description: "<" + name + ">",
32
- op: constants_1.REACT_MOUNT_OP,
33
- });
34
- }
35
- return _this;
24
+ class Profiler extends React__namespace.Component {
25
+ /**
26
+ * The span of the mount activity
27
+ * Made protected for the React Native SDK to access
28
+ */
29
+ __init() {this._mountSpan = undefined;}
30
+
31
+ static __initStatic() {this.defaultProps = {
32
+ disabled: false,
33
+ includeRender: true,
34
+ includeUpdates: true,
35
+ };}
36
+
37
+ constructor(props) {
38
+ super(props);Profiler.prototype.__init.call(this);;
39
+ const { name, disabled = false } = this.props;
40
+
41
+ if (disabled) {
42
+ return;
36
43
  }
37
- // If a component mounted, we can finish the mount activity.
38
- Profiler.prototype.componentDidMount = function () {
39
- if (this._mountSpan) {
40
- this._mountSpan.finish();
41
- }
42
- };
43
- Profiler.prototype.componentDidUpdate = function (_a) {
44
- var _this = this;
45
- var updateProps = _a.updateProps, _b = _a.includeUpdates, includeUpdates = _b === void 0 ? true : _b;
46
- // Only generate an update span if hasUpdateSpan is true, if there is a valid mountSpan,
47
- // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.
48
- // We are just trying to give baseline clues for further investigation.
49
- if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {
50
- // See what props haved changed between the previous props, and the current props. This is
51
- // set as data on the span. We just store the prop keys as the values could be potenially very large.
52
- var changedProps = Object.keys(updateProps).filter(function (k) { return updateProps[k] !== _this.props.updateProps[k]; });
53
- if (changedProps.length > 0) {
54
- // The update span is a point in time span with 0 duration, just signifying that the component
55
- // has been updated.
56
- var now = utils_1.timestampWithMs();
57
- this._mountSpan.startChild({
58
- data: {
59
- changedProps: changedProps,
60
- },
61
- description: "<" + this.props.name + ">",
62
- endTimestamp: now,
63
- op: constants_1.REACT_UPDATE_OP,
64
- startTimestamp: now,
65
- });
66
- }
67
- }
68
- };
69
- // If a component is unmounted, we can say it is no longer on the screen.
70
- // This means we can finish the span representing the component render.
71
- Profiler.prototype.componentWillUnmount = function () {
72
- var _a = this.props, name = _a.name, _b = _a.includeRender, includeRender = _b === void 0 ? true : _b;
73
- if (this._mountSpan && includeRender) {
74
- // If we were able to obtain the spanId of the mount activity, we should set the
75
- // next activity as a child to the component mount activity.
76
- this._mountSpan.startChild({
77
- description: "<" + name + ">",
78
- endTimestamp: utils_1.timestampWithMs(),
79
- op: constants_1.REACT_RENDER_OP,
80
- startTimestamp: this._mountSpan.endTimestamp,
81
- });
82
- }
83
- };
84
- Profiler.prototype.render = function () {
85
- return this.props.children;
86
- };
87
- // eslint-disable-next-line @typescript-eslint/member-ordering
88
- Profiler.defaultProps = {
89
- disabled: false,
90
- includeRender: true,
91
- includeUpdates: true,
92
- };
93
- return Profiler;
94
- }(React.Component));
95
- exports.Profiler = Profiler;
44
+
45
+ var activeTransaction = getActiveTransaction();
46
+ if (activeTransaction) {
47
+ this._mountSpan = activeTransaction.startChild({
48
+ description: `<${name}>`,
49
+ op: constants.REACT_MOUNT_OP,
50
+ });
51
+ }
52
+ }
53
+
54
+ // If a component mounted, we can finish the mount activity.
55
+ componentDidMount() {
56
+ if (this._mountSpan) {
57
+ this._mountSpan.finish();
58
+ }
59
+ }
60
+
61
+ componentDidUpdate({ updateProps, includeUpdates = true }) {
62
+ // Only generate an update span if hasUpdateSpan is true, if there is a valid mountSpan,
63
+ // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.
64
+ // We are just trying to give baseline clues for further investigation.
65
+ if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {
66
+ // See what props haved changed between the previous props, and the current props. This is
67
+ // set as data on the span. We just store the prop keys as the values could be potenially very large.
68
+ var changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);
69
+ if (changedProps.length > 0) {
70
+ // The update span is a point in time span with 0 duration, just signifying that the component
71
+ // has been updated.
72
+ var now = utils.timestampWithMs();
73
+ this._mountSpan.startChild({
74
+ data: {
75
+ changedProps,
76
+ },
77
+ description: `<${this.props.name}>`,
78
+ endTimestamp: now,
79
+ op: constants.REACT_UPDATE_OP,
80
+ startTimestamp: now,
81
+ });
82
+ }
83
+ }
84
+ }
85
+
86
+ // If a component is unmounted, we can say it is no longer on the screen.
87
+ // This means we can finish the span representing the component render.
88
+ componentWillUnmount() {
89
+ const { name, includeRender = true } = this.props;
90
+
91
+ if (this._mountSpan && includeRender) {
92
+ // If we were able to obtain the spanId of the mount activity, we should set the
93
+ // next activity as a child to the component mount activity.
94
+ this._mountSpan.startChild({
95
+ description: `<${name}>`,
96
+ endTimestamp: utils.timestampWithMs(),
97
+ op: constants.REACT_RENDER_OP,
98
+ startTimestamp: this._mountSpan.endTimestamp,
99
+ });
100
+ }
101
+ }
102
+
103
+ render() {
104
+ return this.props.children;
105
+ }
106
+ }Profiler.__initStatic();
107
+
96
108
  /**
97
109
  * withProfiler is a higher order component that wraps a
98
110
  * component in a {@link Profiler} component. It is recommended that
@@ -101,19 +113,28 @@ exports.Profiler = Profiler;
101
113
  * @param WrappedComponent component that is wrapped by Profiler
102
114
  * @param options the {@link ProfilerProps} you can pass into the Profiler
103
115
  */
104
- function withProfiler(WrappedComponent,
105
- // We do not want to have `updateProps` given in options, it is instead filled through the HOC.
106
- options) {
107
- var componentDisplayName = (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || exports.UNKNOWN_COMPONENT;
108
- var Wrapped = function (props) { return (React.createElement(Profiler, tslib_1.__assign({}, options, { name: componentDisplayName, updateProps: props }),
109
- React.createElement(WrappedComponent, tslib_1.__assign({}, props)))); };
110
- Wrapped.displayName = "profiler(" + componentDisplayName + ")";
111
- // Copy over static methods from Wrapped component to Profiler HOC
112
- // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
113
- hoist_non_react_statics_1.default(Wrapped, WrappedComponent);
114
- return Wrapped;
116
+ function withProfiler(
117
+ WrappedComponent,
118
+ // We do not want to have `updateProps` given in options, it is instead filled through the HOC.
119
+ options,
120
+ ) {
121
+ var componentDisplayName =
122
+ (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
123
+
124
+ var Wrapped = (props) => (
125
+ React__namespace.createElement(Profiler, { ...options, name: componentDisplayName, updateProps: props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 133}}
126
+ , React__namespace.createElement(WrappedComponent, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 134}} )
127
+ )
128
+ );
129
+
130
+ Wrapped.displayName = `profiler(${componentDisplayName})`;
131
+
132
+ // Copy over static methods from Wrapped component to Profiler HOC
133
+ // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
134
+ hoistNonReactStatics__default(Wrapped, WrappedComponent);
135
+ return Wrapped;
115
136
  }
116
- exports.withProfiler = withProfiler;
137
+
117
138
  /**
118
139
  *
119
140
  * `useProfiler` is a React hook that profiles a React component.
@@ -121,53 +142,63 @@ exports.withProfiler = withProfiler;
121
142
  * Requires React 16.8 or above.
122
143
  * @param name displayName of component being profiled
123
144
  */
124
- function useProfiler(name, options) {
125
- if (options === void 0) { options = {
126
- disabled: false,
127
- hasRenderSpan: true,
128
- }; }
129
- var _a = tslib_1.__read(React.useState(function () {
130
- if (options && options.disabled) {
131
- return undefined;
132
- }
133
- var activeTransaction = getActiveTransaction();
134
- if (activeTransaction) {
135
- return activeTransaction.startChild({
136
- description: "<" + name + ">",
137
- op: constants_1.REACT_MOUNT_OP,
138
- });
139
- }
140
- return undefined;
141
- }), 1), mountSpan = _a[0];
142
- React.useEffect(function () {
143
- if (mountSpan) {
144
- mountSpan.finish();
145
- }
146
- return function () {
147
- if (mountSpan && options.hasRenderSpan) {
148
- mountSpan.startChild({
149
- description: "<" + name + ">",
150
- endTimestamp: utils_1.timestampWithMs(),
151
- op: constants_1.REACT_RENDER_OP,
152
- startTimestamp: mountSpan.endTimestamp,
153
- });
154
- }
155
- };
156
- // We only want this to run once.
157
- // eslint-disable-next-line react-hooks/exhaustive-deps
158
- }, []);
145
+ function useProfiler(
146
+ name,
147
+ options = {
148
+ disabled: false,
149
+ hasRenderSpan: true,
150
+ },
151
+ ) {
152
+ const [mountSpan] = React__namespace.useState(() => {
153
+ if (options && options.disabled) {
154
+ return undefined;
155
+ }
156
+
157
+ var activeTransaction = getActiveTransaction();
158
+ if (activeTransaction) {
159
+ return activeTransaction.startChild({
160
+ description: `<${name}>`,
161
+ op: constants.REACT_MOUNT_OP,
162
+ });
163
+ }
164
+
165
+ return undefined;
166
+ });
167
+
168
+ React__namespace.useEffect(() => {
169
+ if (mountSpan) {
170
+ mountSpan.finish();
171
+ }
172
+
173
+ return () => {
174
+ if (mountSpan && options.hasRenderSpan) {
175
+ mountSpan.startChild({
176
+ description: `<${name}>`,
177
+ endTimestamp: utils.timestampWithMs(),
178
+ op: constants.REACT_RENDER_OP,
179
+ startTimestamp: mountSpan.endTimestamp,
180
+ });
181
+ }
182
+ };
183
+ // We only want this to run once.
184
+ }, []);
159
185
  }
160
- exports.useProfiler = useProfiler;
186
+
161
187
  /** Grabs active transaction off scope */
162
- function getActiveTransaction(hub) {
163
- if (hub === void 0) { hub = browser_1.getCurrentHub(); }
164
- if (hub) {
165
- var scope = hub.getScope();
166
- if (scope) {
167
- return scope.getTransaction();
168
- }
188
+ function getActiveTransaction(hub = browser.getCurrentHub()) {
189
+ if (hub) {
190
+ var scope = hub.getScope();
191
+ if (scope) {
192
+ return scope.getTransaction() ;
169
193
  }
170
- return undefined;
194
+ }
195
+
196
+ return undefined;
171
197
  }
198
+
199
+ exports.Profiler = Profiler;
200
+ exports.UNKNOWN_COMPONENT = UNKNOWN_COMPONENT;
172
201
  exports.getActiveTransaction = getActiveTransaction;
173
- //# sourceMappingURL=profiler.js.map
202
+ exports.useProfiler = useProfiler;
203
+ exports.withProfiler = withProfiler;
204
+ //# sourceMappingURL=profiler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"profiler.js","sourceRoot":"","sources":["../../src/profiler.tsx"],"names":[],"mappings":";;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AAE;QACP,IAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC7B,IAAI,KAAK,EAAE;YACT,OAAO,KAAK,CAAC,cAAc,EAAmB,CAAC;SAChD;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AATD,oDASC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { getCurrentHub, Hub } from '@sentry/browser';\nimport { Span, Transaction } from '@sentry/types';\nimport { timestampWithMs } 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 // 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 = 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 });\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.finish();\n }\n }\n\n public componentDidUpdate({ updateProps, includeUpdates = true }: ProfilerProps): void {\n // Only generate an update span if hasUpdateSpan 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 // The update span is a point in time span with 0 duration, just signifying that the component\n // has been updated.\n const now = timestampWithMs();\n this._mountSpan.startChild({\n data: {\n changedProps,\n },\n description: `<${this.props.name}>`,\n endTimestamp: now,\n op: REACT_UPDATE_OP,\n startTimestamp: now,\n });\n }\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: timestampWithMs(),\n op: REACT_RENDER_OP,\n startTimestamp: this._mountSpan.endTimestamp,\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'>>,\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 });\n }\n\n return undefined;\n });\n\n React.useEffect(() => {\n if (mountSpan) {\n mountSpan.finish();\n }\n\n return (): void => {\n if (mountSpan && options.hasRenderSpan) {\n mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampWithMs(),\n op: REACT_RENDER_OP,\n startTimestamp: mountSpan.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\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 if (scope) {\n return scope.getTransaction() as T | undefined;\n }\n }\n\n return undefined;\n}\n"]}
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 { getCurrentHub, Hub } from '@sentry/browser';\nimport { Span, Transaction } from '@sentry/types';\nimport { timestampWithMs } 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 // 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 = 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 });\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.finish();\n }\n }\n\n public componentDidUpdate({ updateProps, includeUpdates = true }: ProfilerProps): void {\n // Only generate an update span if hasUpdateSpan 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 // The update span is a point in time span with 0 duration, just signifying that the component\n // has been updated.\n const now = timestampWithMs();\n this._mountSpan.startChild({\n data: {\n changedProps,\n },\n description: `<${this.props.name}>`,\n endTimestamp: now,\n op: REACT_UPDATE_OP,\n startTimestamp: now,\n });\n }\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: timestampWithMs(),\n op: REACT_RENDER_OP,\n startTimestamp: this._mountSpan.endTimestamp,\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'>>,\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 });\n }\n\n return undefined;\n });\n\n React.useEffect(() => {\n if (mountSpan) {\n mountSpan.finish();\n }\n\n return (): void => {\n if (mountSpan && options.hasRenderSpan) {\n mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampWithMs(),\n op: REACT_RENDER_OP,\n startTimestamp: mountSpan.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\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 if (scope) {\n return scope.getTransaction() as T | undefined;\n }\n }\n\n return undefined;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;AA0BA;;;;AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA;;AAEA;;;;;;;;AAQA;;;;AAIA;;;;;;;;;;;;;;;;AAgBA;;AAEA;;;;;;;AAOA;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA;;AAIA;;;;;;;;;;AAUA;;;;;;"}