@sentry/react 6.19.7 → 7.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/{dist → cjs}/constants.d.ts +0 -0
  2. package/{dist → cjs}/constants.d.ts.map +0 -0
  3. package/{dist → cjs}/constants.js +0 -0
  4. package/{dist → cjs}/constants.js.map +0 -0
  5. package/{dist → cjs}/errorboundary.d.ts +0 -0
  6. package/{dist → cjs}/errorboundary.d.ts.map +0 -0
  7. package/{dist → cjs}/errorboundary.js +43 -48
  8. package/cjs/errorboundary.js.map +1 -0
  9. package/{dist → cjs}/flags.d.ts +0 -0
  10. package/{dist → cjs}/flags.d.ts.map +0 -0
  11. package/{dist → cjs}/flags.js +0 -0
  12. package/{dist → cjs}/flags.js.map +0 -0
  13. package/{dist → cjs}/index.d.ts +0 -0
  14. package/{dist → cjs}/index.d.ts.map +0 -0
  15. package/{dist → cjs}/index.js +1 -1
  16. package/{dist → cjs}/index.js.map +0 -0
  17. package/{dist → cjs}/profiler.d.ts +0 -1
  18. package/cjs/profiler.d.ts.map +1 -0
  19. package/cjs/profiler.js +166 -0
  20. package/cjs/profiler.js.map +1 -0
  21. package/{dist → cjs}/reactrouter.d.ts +0 -0
  22. package/{dist → cjs}/reactrouter.d.ts.map +0 -0
  23. package/{dist → cjs}/reactrouter.js +22 -26
  24. package/cjs/reactrouter.js.map +1 -0
  25. package/{dist → cjs}/reactrouterv3.d.ts +0 -0
  26. package/{dist → cjs}/reactrouterv3.d.ts.map +0 -0
  27. package/{dist → cjs}/reactrouterv3.js +21 -29
  28. package/cjs/reactrouterv3.js.map +1 -0
  29. package/{dist → cjs}/redux.d.ts +0 -0
  30. package/{dist → cjs}/redux.d.ts.map +0 -0
  31. package/cjs/redux.js +53 -0
  32. package/cjs/redux.js.map +1 -0
  33. package/{dist → cjs}/sdk.d.ts +0 -0
  34. package/{dist → cjs}/sdk.d.ts.map +0 -0
  35. package/{dist → cjs}/sdk.js +1 -1
  36. package/{dist → cjs}/sdk.js.map +1 -1
  37. package/{dist → cjs}/types.d.ts +0 -0
  38. package/{dist → cjs}/types.d.ts.map +0 -0
  39. package/{dist → cjs}/types.js +0 -0
  40. package/{dist → cjs}/types.js.map +0 -0
  41. package/esm/constants.js +3 -3
  42. package/esm/constants.js.map +1 -1
  43. package/esm/errorboundary.js +38 -44
  44. package/esm/errorboundary.js.map +1 -1
  45. package/esm/flags.js +1 -1
  46. package/esm/flags.js.map +1 -1
  47. package/esm/profiler.d.ts +0 -1
  48. package/esm/profiler.d.ts.map +1 -1
  49. package/esm/profiler.js +51 -127
  50. package/esm/profiler.js.map +1 -1
  51. package/esm/reactrouter.js +18 -23
  52. package/esm/reactrouter.js.map +1 -1
  53. package/esm/reactrouterv3.js +20 -28
  54. package/esm/reactrouterv3.js.map +1 -1
  55. package/esm/redux.js +38 -41
  56. package/esm/redux.js.map +1 -1
  57. package/package.json +6 -8
  58. package/types/profiler.d.ts +0 -1
  59. package/types/profiler.d.ts.map +1 -1
  60. package/dist/errorboundary.js.map +0 -1
  61. package/dist/profiler.d.ts.map +0 -1
  62. package/dist/profiler.js +0 -241
  63. package/dist/profiler.js.map +0 -1
  64. package/dist/reactrouter.js.map +0 -1
  65. package/dist/reactrouterv3.js.map +0 -1
  66. package/dist/redux.js +0 -56
  67. package/dist/redux.js.map +0 -1
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,17 +1,17 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- var tslib_1 = require("tslib");
3
- var browser_1 = require("@sentry/browser");
4
- var utils_1 = require("@sentry/utils");
5
- var hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics"));
6
- var React = tslib_1.__importStar(require("react"));
7
- var flags_1 = require("./flags");
2
+ const tslib_1 = require("tslib");
3
+ const browser_1 = require("@sentry/browser");
4
+ const utils_1 = require("@sentry/utils");
5
+ const hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics"));
6
+ const React = tslib_1.__importStar(require("react"));
7
+ const flags_1 = require("./flags");
8
8
  function isAtLeastReact17(version) {
9
- var major = version.match(/^([^.]+)/);
9
+ const major = version.match(/^([^.]+)/);
10
10
  return major !== null && parseInt(major[0]) >= 17;
11
11
  }
12
12
  exports.isAtLeastReact17 = isAtLeastReact17;
13
13
  exports.UNKNOWN_COMPONENT = 'unknown';
14
- var INITIAL_STATE = {
14
+ const INITIAL_STATE = {
15
15
  componentStack: null,
16
16
  error: null,
17
17
  eventId: null,
@@ -22,32 +22,28 @@ var INITIAL_STATE = {
22
22
  * Sentry React SDK ErrorBoundary caught an error invoking your application code. This
23
23
  * is expected behavior and NOT indicative of a bug with the Sentry React SDK.
24
24
  */
25
- var ErrorBoundary = /** @class */ (function (_super) {
26
- tslib_1.__extends(ErrorBoundary, _super);
27
- function ErrorBoundary() {
28
- var _this = _super !== null && _super.apply(this, arguments) || this;
29
- _this.state = INITIAL_STATE;
30
- _this.resetErrorBoundary = function () {
31
- var onReset = _this.props.onReset;
32
- var _a = _this.state, error = _a.error, componentStack = _a.componentStack, eventId = _a.eventId;
25
+ class ErrorBoundary extends React.Component {
26
+ constructor() {
27
+ super(...arguments);
28
+ this.state = INITIAL_STATE;
29
+ this.resetErrorBoundary = () => {
30
+ const { onReset } = this.props;
31
+ const { error, componentStack, eventId } = this.state;
33
32
  if (onReset) {
34
33
  onReset(error, componentStack, eventId);
35
34
  }
36
- _this.setState(INITIAL_STATE);
35
+ this.setState(INITIAL_STATE);
37
36
  };
38
- return _this;
39
37
  }
40
- ErrorBoundary.prototype.componentDidCatch = function (error, _a) {
41
- var _this = this;
42
- var componentStack = _a.componentStack;
43
- var _b = this.props, beforeCapture = _b.beforeCapture, onError = _b.onError, showDialog = _b.showDialog, dialogOptions = _b.dialogOptions;
44
- browser_1.withScope(function (scope) {
38
+ componentDidCatch(error, { componentStack }) {
39
+ const { beforeCapture, onError, showDialog, dialogOptions } = this.props;
40
+ browser_1.withScope(scope => {
45
41
  // If on React version >= 17, create stack trace from componentStack param and links
46
42
  // to to the original error using `error.cause` otherwise relies on error param for stacktrace.
47
43
  // Linking errors requires the `LinkedErrors` integration be enabled.
48
44
  if (isAtLeastReact17(React.version)) {
49
- var errorBoundaryError = new Error(error.message);
50
- errorBoundaryError.name = "React ErrorBoundary " + errorBoundaryError.name;
45
+ const errorBoundaryError = new Error(error.message);
46
+ errorBoundaryError.name = `React ErrorBoundary ${errorBoundaryError.name}`;
51
47
  errorBoundaryError.stack = componentStack;
52
48
  // Using the `LinkedErrors` integration to link the errors together.
53
49
  error.cause = errorBoundaryError;
@@ -55,38 +51,38 @@ var ErrorBoundary = /** @class */ (function (_super) {
55
51
  if (beforeCapture) {
56
52
  beforeCapture(scope, error, componentStack);
57
53
  }
58
- var eventId = browser_1.captureException(error, { contexts: { react: { componentStack: componentStack } } });
54
+ const eventId = browser_1.captureException(error, { contexts: { react: { componentStack } } });
59
55
  if (onError) {
60
56
  onError(error, componentStack, eventId);
61
57
  }
62
58
  if (showDialog) {
63
- browser_1.showReportDialog(tslib_1.__assign(tslib_1.__assign({}, dialogOptions), { eventId: eventId }));
59
+ browser_1.showReportDialog(Object.assign(Object.assign({}, dialogOptions), { eventId }));
64
60
  }
65
61
  // componentDidCatch is used over getDerivedStateFromError
66
62
  // so that componentStack is accessible through state.
67
- _this.setState({ error: error, componentStack: componentStack, eventId: eventId });
63
+ this.setState({ error, componentStack, eventId });
68
64
  });
69
- };
70
- ErrorBoundary.prototype.componentDidMount = function () {
71
- var onMount = this.props.onMount;
65
+ }
66
+ componentDidMount() {
67
+ const { onMount } = this.props;
72
68
  if (onMount) {
73
69
  onMount();
74
70
  }
75
- };
76
- ErrorBoundary.prototype.componentWillUnmount = function () {
77
- var _a = this.state, error = _a.error, componentStack = _a.componentStack, eventId = _a.eventId;
78
- var onUnmount = this.props.onUnmount;
71
+ }
72
+ componentWillUnmount() {
73
+ const { error, componentStack, eventId } = this.state;
74
+ const { onUnmount } = this.props;
79
75
  if (onUnmount) {
80
76
  onUnmount(error, componentStack, eventId);
81
77
  }
82
- };
83
- ErrorBoundary.prototype.render = function () {
84
- var _a = this.props, fallback = _a.fallback, children = _a.children;
85
- var _b = this.state, error = _b.error, componentStack = _b.componentStack, eventId = _b.eventId;
78
+ }
79
+ render() {
80
+ const { fallback, children } = this.props;
81
+ const { error, componentStack, eventId } = this.state;
86
82
  if (error) {
87
- var element = undefined;
83
+ let element = undefined;
88
84
  if (typeof fallback === 'function') {
89
- element = fallback({ error: error, componentStack: componentStack, resetError: this.resetErrorBoundary, eventId: eventId });
85
+ element = fallback({ error, componentStack, resetError: this.resetErrorBoundary, eventId });
90
86
  }
91
87
  else {
92
88
  element = fallback;
@@ -104,18 +100,17 @@ var ErrorBoundary = /** @class */ (function (_super) {
104
100
  return children();
105
101
  }
106
102
  return children;
107
- };
108
- return ErrorBoundary;
109
- }(React.Component));
103
+ }
104
+ }
110
105
  exports.ErrorBoundary = ErrorBoundary;
111
106
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
112
107
  function withErrorBoundary(WrappedComponent, errorBoundaryOptions) {
113
108
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
114
- var componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || exports.UNKNOWN_COMPONENT;
115
- var Wrapped = function (props) { return (React.createElement(ErrorBoundary, tslib_1.__assign({}, errorBoundaryOptions),
116
- React.createElement(WrappedComponent, tslib_1.__assign({}, props)))); };
109
+ const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || exports.UNKNOWN_COMPONENT;
110
+ const Wrapped = (props) => (React.createElement(ErrorBoundary, Object.assign({}, errorBoundaryOptions),
111
+ React.createElement(WrappedComponent, Object.assign({}, props))));
117
112
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
118
- Wrapped.displayName = "errorBoundary(" + componentDisplayName + ")";
113
+ Wrapped.displayName = `errorBoundary(${componentDisplayName})`;
119
114
  // Copy over static methods from Wrapped component to Profiler HOC
120
115
  // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
121
116
  hoist_non_react_statics_1.default(Wrapped, WrappedComponent);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorboundary.js","sourceRoot":"","sources":["../../src/errorboundary.tsx"],"names":[],"mappings":";;AAAA,6CAA4G;AAC5G,yCAAuC;AACvC,8FAA2D;AAC3D,qDAA+B;AAE/B,mCAAyC;AAEzC,SAAgB,gBAAgB,CAAC,OAAe;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACxC,OAAO,KAAK,KAAK,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACpD,CAAC;AAHD,4CAGC;AAEY,QAAA,iBAAiB,GAAG,SAAS,CAAC;AA6C3C,MAAM,aAAa,GAAG;IACpB,cAAc,EAAE,IAAI;IACpB,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,IAAI;CACd,CAAC;AAEF;;;;;GAKG;AACH,MAAM,aAAc,SAAQ,KAAK,CAAC,SAAiD;IAAnF;;QACS,UAAK,GAAuB,aAAa,CAAC;QAkD1C,uBAAkB,GAAe,GAAG,EAAE;YAC3C,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAC/B,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YACtD,IAAI,OAAO,EAAE;gBACX,OAAO,CAAC,KAAK,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;aACzC;YACD,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QAC/B,CAAC,CAAC;IA+BJ,CAAC;IAtFQ,iBAAiB,CAAC,KAAgC,EAAE,EAAE,cAAc,EAAmB;QAC5F,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC,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,KAAK,EAAI,CACjB,CACjB,CAAC;IAEF,sEAAsE;IACtE,OAAO,CAAC,WAAW,GAAG,iBAAiB,oBAAoB,GAAG,CAAC;IAE/D,kEAAkE;IAClE,gGAAgG;IAChG,iCAAoB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAChD,OAAO,OAAO,CAAC;AACjB,CAAC;AAEuB,8CAAiB","sourcesContent":["import { captureException, ReportDialogOptions, Scope, showReportDialog, withScope } from '@sentry/browser';\nimport { logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { IS_DEBUG_BUILD } from './flags';\n\nexport function isAtLeastReact17(version: string): boolean {\n const major = version.match(/^([^.]+)/);\n return major !== null && parseInt(major[0]) >= 17;\n}\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type FallbackRender = (errorData: {\n error: Error;\n componentStack: string | null;\n eventId: string | null;\n resetError(): void;\n}) => React.ReactElement;\n\nexport type ErrorBoundaryProps = {\n children?: React.ReactNode | (() => React.ReactNode);\n /** If a Sentry report dialog should be rendered on error */\n showDialog?: boolean;\n /**\n * Options to be passed into the Sentry report dialog.\n * No-op if {@link showDialog} is false.\n */\n dialogOptions?: ReportDialogOptions;\n /**\n * A fallback component that gets rendered when the error boundary encounters an error.\n *\n * Can either provide a React Component, or a function that returns React Component as\n * a valid fallback prop. If a function is provided, the function will be called with\n * the error, the component stack, and an function that resets the error boundary on error.\n *\n */\n fallback?: React.ReactElement | FallbackRender;\n /** Called when the error boundary encounters an error */\n onError?(error: Error, componentStack: string, eventId: string): void;\n /** Called on componentDidMount() */\n onMount?(): void;\n /** Called if resetError() is called from the fallback render props function */\n onReset?(error: Error | null, componentStack: string | null, eventId: string | null): void;\n /** Called on componentWillUnmount() */\n onUnmount?(error: Error | null, componentStack: string | null, eventId: string | null): void;\n /** Called before the error is captured by Sentry, allows for you to add tags or context using the scope */\n beforeCapture?(scope: Scope, error: Error | null, componentStack: string | null): void;\n};\n\ntype ErrorBoundaryState = {\n componentStack: React.ErrorInfo['componentStack'] | null;\n error: Error | null;\n eventId: string | null;\n};\n\nconst INITIAL_STATE = {\n componentStack: null,\n error: null,\n eventId: null,\n};\n\n/**\n * A ErrorBoundary component that logs errors to Sentry. Requires React >= 16.\n * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the\n * Sentry React SDK ErrorBoundary caught an error invoking your application code. This\n * is expected behavior and NOT indicative of a bug with the Sentry React SDK.\n */\nclass ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {\n public state: ErrorBoundaryState = INITIAL_STATE;\n\n public componentDidCatch(error: Error & { cause?: Error }, { componentStack }: React.ErrorInfo): void {\n const { beforeCapture, onError, showDialog, dialogOptions } = this.props;\n\n withScope(scope => {\n // If on React version >= 17, create stack trace from componentStack param and links\n // to to the original error using `error.cause` otherwise relies on error param for stacktrace.\n // Linking errors requires the `LinkedErrors` integration be enabled.\n if (isAtLeastReact17(React.version)) {\n const errorBoundaryError = new Error(error.message);\n errorBoundaryError.name = `React ErrorBoundary ${errorBoundaryError.name}`;\n errorBoundaryError.stack = componentStack;\n\n // Using the `LinkedErrors` integration to link the errors together.\n error.cause = errorBoundaryError;\n }\n\n if (beforeCapture) {\n beforeCapture(scope, error, componentStack);\n }\n const eventId = captureException(error, { contexts: { react: { componentStack } } });\n if (onError) {\n onError(error, componentStack, eventId);\n }\n if (showDialog) {\n showReportDialog({ ...dialogOptions, eventId });\n }\n\n // componentDidCatch is used over getDerivedStateFromError\n // so that componentStack is accessible through state.\n this.setState({ error, componentStack, eventId });\n });\n }\n\n public componentDidMount(): void {\n const { onMount } = this.props;\n if (onMount) {\n onMount();\n }\n }\n\n public componentWillUnmount(): void {\n const { error, componentStack, eventId } = this.state;\n const { onUnmount } = this.props;\n if (onUnmount) {\n onUnmount(error, componentStack, eventId);\n }\n }\n\n public resetErrorBoundary: () => void = () => {\n const { onReset } = this.props;\n const { error, componentStack, eventId } = this.state;\n if (onReset) {\n onReset(error, componentStack, eventId);\n }\n this.setState(INITIAL_STATE);\n };\n\n public render(): React.ReactNode {\n const { fallback, children } = this.props;\n const { error, componentStack, eventId } = this.state;\n\n if (error) {\n let element: React.ReactElement | undefined = undefined;\n if (typeof fallback === 'function') {\n element = fallback({ error, componentStack, resetError: this.resetErrorBoundary, eventId });\n } else {\n element = fallback;\n }\n\n if (React.isValidElement(element)) {\n return element;\n }\n\n if (fallback) {\n IS_DEBUG_BUILD && logger.warn('fallback did not produce a valid ReactElement');\n }\n\n // Fail gracefully if no fallback provided or is not valid\n return null;\n }\n\n if (typeof children === 'function') {\n return (children as () => React.ReactNode)();\n }\n return children;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction withErrorBoundary<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n errorBoundaryOptions: ErrorBoundaryProps,\n): React.FC<P> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <ErrorBoundary {...errorBoundaryOptions}>\n <WrappedComponent {...props} />\n </ErrorBoundary>\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n Wrapped.displayName = `errorBoundary(${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\nexport { ErrorBoundary, withErrorBoundary };\n"]}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- var tslib_1 = require("tslib");
2
+ const tslib_1 = require("tslib");
3
3
  tslib_1.__exportStar(require("@sentry/browser"), exports);
4
4
  var sdk_1 = require("./sdk");
5
5
  exports.init = sdk_1.init;
File without changes
@@ -21,7 +21,6 @@ declare class Profiler extends React.Component<ProfilerProps> {
21
21
  * Made protected for the React Native SDK to access
22
22
  */
23
23
  protected _mountSpan: Span | undefined;
24
- private _mountActivity;
25
24
  static defaultProps: Partial<ProfilerProps>;
26
25
  constructor(props: ProfilerProps);
27
26
  componentDidMount(): void;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiler.d.ts","sourceRoot":"","sources":["../../src/profiler.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGlD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,oBAAY,aAAa,GAAG;IAE1B,IAAI,EAAE,MAAM,CAAC;IAGb,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB,WAAW,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CACzC,CAAC;AAEF;;;GAGG;AACH,cAAM,QAAS,SAAQ,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC;IACnD;;;OAGG;IACH,SAAS,CAAC,UAAU,EAAE,IAAI,GAAG,SAAS,CAAa;IAGnD,OAAc,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,CAIhD;gBAEiB,KAAK,EAAE,aAAa;IAkBhC,iBAAiB,IAAI,IAAI;IAMzB,kBAAkB,CAAC,EAAE,WAAW,EAAE,cAAqB,EAAE,EAAE,aAAa,GAAG,IAAI;IA2B/E,oBAAoB,IAAI,IAAI;IAe5B,MAAM,IAAI,KAAK,CAAC,SAAS;CAGjC;AAED;;;;;;;GAOG;AACH,iBAAS,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjD,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAExC,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC,MAAM,aAAa,EAAE,aAAa,CAAC,CAAC,GAClF,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAgBb;AAED;;;;;;GAMG;AACH,iBAAS,WAAW,CAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAGrD,GACA,IAAI,CAmCN;AAED,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AAE/C,yCAAyC;AACzC,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,WAAW,EAAE,GAAG,GAAE,GAAqB,GAAG,CAAC,GAAG,SAAS,CASrG"}
@@ -0,0 +1,166 @@
1
+ Object.defineProperty(exports, "__esModule", { value: true });
2
+ const tslib_1 = require("tslib");
3
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ const browser_1 = require("@sentry/browser");
6
+ const utils_1 = require("@sentry/utils");
7
+ const hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics"));
8
+ const React = tslib_1.__importStar(require("react"));
9
+ const constants_1 = require("./constants");
10
+ exports.UNKNOWN_COMPONENT = 'unknown';
11
+ /**
12
+ * The Profiler component leverages Sentry's Tracing integration to generate
13
+ * spans based on component lifecycles.
14
+ */
15
+ class Profiler extends React.Component {
16
+ constructor(props) {
17
+ super(props);
18
+ /**
19
+ * The span of the mount activity
20
+ * Made protected for the React Native SDK to access
21
+ */
22
+ this._mountSpan = undefined;
23
+ const { name, disabled = false } = this.props;
24
+ if (disabled) {
25
+ return;
26
+ }
27
+ const activeTransaction = getActiveTransaction();
28
+ if (activeTransaction) {
29
+ this._mountSpan = activeTransaction.startChild({
30
+ description: `<${name}>`,
31
+ op: constants_1.REACT_MOUNT_OP,
32
+ });
33
+ }
34
+ }
35
+ // If a component mounted, we can finish the mount activity.
36
+ componentDidMount() {
37
+ if (this._mountSpan) {
38
+ this._mountSpan.finish();
39
+ }
40
+ }
41
+ componentDidUpdate({ updateProps, includeUpdates = true }) {
42
+ // Only generate an update span if hasUpdateSpan is true, if there is a valid mountSpan,
43
+ // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.
44
+ // We are just trying to give baseline clues for further investigation.
45
+ if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {
46
+ // See what props haved changed between the previous props, and the current props. This is
47
+ // set as data on the span. We just store the prop keys as the values could be potenially very large.
48
+ const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);
49
+ if (changedProps.length > 0) {
50
+ // The update span is a point in time span with 0 duration, just signifying that the component
51
+ // has been updated.
52
+ const now = utils_1.timestampWithMs();
53
+ this._mountSpan.startChild({
54
+ data: {
55
+ changedProps,
56
+ },
57
+ description: `<${this.props.name}>`,
58
+ endTimestamp: now,
59
+ op: constants_1.REACT_UPDATE_OP,
60
+ startTimestamp: now,
61
+ });
62
+ }
63
+ }
64
+ }
65
+ // If a component is unmounted, we can say it is no longer on the screen.
66
+ // This means we can finish the span representing the component render.
67
+ componentWillUnmount() {
68
+ const { name, includeRender = true } = this.props;
69
+ if (this._mountSpan && includeRender) {
70
+ // If we were able to obtain the spanId of the mount activity, we should set the
71
+ // next activity as a child to the component mount activity.
72
+ this._mountSpan.startChild({
73
+ description: `<${name}>`,
74
+ endTimestamp: utils_1.timestampWithMs(),
75
+ op: constants_1.REACT_RENDER_OP,
76
+ startTimestamp: this._mountSpan.endTimestamp,
77
+ });
78
+ }
79
+ }
80
+ render() {
81
+ return this.props.children;
82
+ }
83
+ }
84
+ exports.Profiler = Profiler;
85
+ // eslint-disable-next-line @typescript-eslint/member-ordering
86
+ Profiler.defaultProps = {
87
+ disabled: false,
88
+ includeRender: true,
89
+ includeUpdates: true,
90
+ };
91
+ /**
92
+ * withProfiler is a higher order component that wraps a
93
+ * component in a {@link Profiler} component. It is recommended that
94
+ * the higher order component be used over the regular {@link Profiler} component.
95
+ *
96
+ * @param WrappedComponent component that is wrapped by Profiler
97
+ * @param options the {@link ProfilerProps} you can pass into the Profiler
98
+ */
99
+ function withProfiler(WrappedComponent,
100
+ // We do not want to have `updateProps` given in options, it is instead filled through the HOC.
101
+ options) {
102
+ const componentDisplayName = (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || exports.UNKNOWN_COMPONENT;
103
+ const Wrapped = (props) => (React.createElement(Profiler, Object.assign({}, options, { name: componentDisplayName, updateProps: props }),
104
+ React.createElement(WrappedComponent, Object.assign({}, props))));
105
+ Wrapped.displayName = `profiler(${componentDisplayName})`;
106
+ // Copy over static methods from Wrapped component to Profiler HOC
107
+ // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
108
+ hoist_non_react_statics_1.default(Wrapped, WrappedComponent);
109
+ return Wrapped;
110
+ }
111
+ exports.withProfiler = withProfiler;
112
+ /**
113
+ *
114
+ * `useProfiler` is a React hook that profiles a React component.
115
+ *
116
+ * Requires React 16.8 or above.
117
+ * @param name displayName of component being profiled
118
+ */
119
+ function useProfiler(name, options = {
120
+ disabled: false,
121
+ hasRenderSpan: true,
122
+ }) {
123
+ const [mountSpan] = React.useState(() => {
124
+ if (options && options.disabled) {
125
+ return undefined;
126
+ }
127
+ const activeTransaction = getActiveTransaction();
128
+ if (activeTransaction) {
129
+ return activeTransaction.startChild({
130
+ description: `<${name}>`,
131
+ op: constants_1.REACT_MOUNT_OP,
132
+ });
133
+ }
134
+ return undefined;
135
+ });
136
+ React.useEffect(() => {
137
+ if (mountSpan) {
138
+ mountSpan.finish();
139
+ }
140
+ return () => {
141
+ if (mountSpan && options.hasRenderSpan) {
142
+ mountSpan.startChild({
143
+ description: `<${name}>`,
144
+ endTimestamp: utils_1.timestampWithMs(),
145
+ op: constants_1.REACT_RENDER_OP,
146
+ startTimestamp: mountSpan.endTimestamp,
147
+ });
148
+ }
149
+ };
150
+ // We only want this to run once.
151
+ // eslint-disable-next-line react-hooks/exhaustive-deps
152
+ }, []);
153
+ }
154
+ exports.useProfiler = useProfiler;
155
+ /** Grabs active transaction off scope */
156
+ function getActiveTransaction(hub = browser_1.getCurrentHub()) {
157
+ if (hub) {
158
+ const scope = hub.getScope();
159
+ if (scope) {
160
+ return scope.getTransaction();
161
+ }
162
+ }
163
+ return undefined;
164
+ }
165
+ exports.getActiveTransaction = getActiveTransaction;
166
+ //# sourceMappingURL=profiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiler.js","sourceRoot":"","sources":["../../src/profiler.tsx"],"names":[],"mappings":";;AAAA,+DAA+D;AAC/D,uDAAuD;AACvD,6CAAqD;AAErD,yCAAgD;AAChD,8FAA2D;AAC3D,qDAA+B;AAE/B,2CAA+E;AAElE,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAgB3C;;;GAGG;AACH,MAAM,QAAS,SAAQ,KAAK,CAAC,SAAwB;IAcnD,YAAmB,KAAoB;QACrC,KAAK,CAAC,KAAK,CAAC,CAAC;QAdf;;;WAGG;QACO,eAAU,GAAqB,SAAS,CAAC;QAWjD,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAE9C,IAAI,QAAQ,EAAE;YACZ,OAAO;SACR;QAED,MAAM,iBAAiB,GAAG,oBAAoB,EAAE,CAAC;QACjD,IAAI,iBAAiB,EAAE;YACrB,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC,UAAU,CAAC;gBAC7C,WAAW,EAAE,IAAI,IAAI,GAAG;gBACxB,EAAE,EAAE,0BAAc;aACnB,CAAC,CAAC;SACJ;IACH,CAAC;IAED,4DAA4D;IACrD,iBAAiB;QACtB,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,IAAI,CAAC,UAAU,CAAC,MAAM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AiB,CAAC,UAAU,CAAC;gBAClC,WAAW,EAAE,IAAI,IAAI,GAAG;gBACxB,EAAE,EAAE,0BAAc;aACnB,CAAC,CAAC;SACJ;QAED,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,SAAS,EAAE;YACb,SAAS,CAAC,MAAM,EAAE,CAAC;SACpB;QAED,OAAO,GAAS,EAAE;YAChB,IAAI,SAAS,IAAI,OAAO,CAAC,aAAa,EAAE;gBACtC,SAAS,CAAC,UAAU,CAAC;oBACnB,WAAW,EAAE,IAAI,IAAI,GAAG;oBACxB,YAAY,EAAE,uBAAe,EAAE;oBAC/B,EAAE,EAAE,2BAAe;oBACnB,cAAc,EAAE,SAAS,CAAC,YAAY;iBACvC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC;QACF,iCAAiC;QACjC,uDAAuD;IACzD,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AAEgC,kCAAW;AAE5C,yCAAyC;AACzC,SAAgB,oBAAoB,CAAwB,MAAW,uBAAa,EAAE;IACpF,IAAI,GAAG,EAAE;QACP,MAAM,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"]}
File without changes
File without changes
@@ -1,11 +1,11 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- var tslib_1 = require("tslib");
3
- var utils_1 = require("@sentry/utils");
4
- var hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics"));
5
- var React = tslib_1.__importStar(require("react"));
2
+ const tslib_1 = require("tslib");
3
+ const utils_1 = require("@sentry/utils");
4
+ const hoist_non_react_statics_1 = tslib_1.__importDefault(require("hoist-non-react-statics"));
5
+ const React = tslib_1.__importStar(require("react"));
6
6
  /* eslint-enable @typescript-eslint/no-explicit-any */
7
- var global = utils_1.getGlobalObject();
8
- var activeTransaction;
7
+ const global = utils_1.getGlobalObject();
8
+ let activeTransaction;
9
9
  function reactRouterV4Instrumentation(history, routes, matchPath) {
10
10
  return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);
11
11
  }
@@ -14,8 +14,7 @@ function reactRouterV5Instrumentation(history, routes, matchPath) {
14
14
  return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);
15
15
  }
16
16
  exports.reactRouterV5Instrumentation = reactRouterV5Instrumentation;
17
- function createReactRouterInstrumentation(history, name, allRoutes, matchPath) {
18
- if (allRoutes === void 0) { allRoutes = []; }
17
+ function createReactRouterInstrumentation(history, name, allRoutes = [], matchPath) {
19
18
  function getInitPathName() {
20
19
  if (history && history.location) {
21
20
  return history.location.pathname;
@@ -29,19 +28,17 @@ function createReactRouterInstrumentation(history, name, allRoutes, matchPath) {
29
28
  if (allRoutes.length === 0 || !matchPath) {
30
29
  return pathname;
31
30
  }
32
- var branches = matchRoutes(allRoutes, pathname, matchPath);
31
+ const branches = matchRoutes(allRoutes, pathname, matchPath);
33
32
  // eslint-disable-next-line @typescript-eslint/prefer-for-of
34
- for (var x = 0; x < branches.length; x++) {
33
+ for (let x = 0; x < branches.length; x++) {
35
34
  if (branches[x].match.isExact) {
36
35
  return branches[x].match.path;
37
36
  }
38
37
  }
39
38
  return pathname;
40
39
  }
41
- return function (customStartTransaction, startTransactionOnPageLoad, startTransactionOnLocationChange) {
42
- if (startTransactionOnPageLoad === void 0) { startTransactionOnPageLoad = true; }
43
- if (startTransactionOnLocationChange === void 0) { startTransactionOnLocationChange = true; }
44
- var initPathName = getInitPathName();
40
+ return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true) => {
41
+ const initPathName = getInitPathName();
45
42
  if (startTransactionOnPageLoad && initPathName) {
46
43
  activeTransaction = customStartTransaction({
47
44
  name: getTransactionName(initPathName),
@@ -52,18 +49,18 @@ function createReactRouterInstrumentation(history, name, allRoutes, matchPath) {
52
49
  });
53
50
  }
54
51
  if (startTransactionOnLocationChange && history.listen) {
55
- history.listen(function (location, action) {
52
+ history.listen((location, action) => {
56
53
  if (action && (action === 'PUSH' || action === 'POP')) {
57
54
  if (activeTransaction) {
58
55
  activeTransaction.finish();
59
56
  }
60
- var tags = {
57
+ const tags = {
61
58
  'routing.instrumentation': name,
62
59
  };
63
60
  activeTransaction = customStartTransaction({
64
61
  name: getTransactionName(location.pathname),
65
62
  op: 'navigation',
66
- tags: tags,
63
+ tags,
67
64
  });
68
65
  }
69
66
  });
@@ -74,16 +71,15 @@ function createReactRouterInstrumentation(history, name, allRoutes, matchPath) {
74
71
  * Matches a set of routes to a pathname
75
72
  * Based on implementation from
76
73
  */
77
- function matchRoutes(routes, pathname, matchPath, branch) {
78
- if (branch === void 0) { branch = []; }
79
- routes.some(function (route) {
80
- var match = route.path
74
+ function matchRoutes(routes, pathname, matchPath, branch = []) {
75
+ routes.some(route => {
76
+ const match = route.path
81
77
  ? matchPath(pathname, route)
82
78
  : branch.length
83
79
  ? branch[branch.length - 1].match // use parent match
84
80
  : computeRootMatch(pathname); // use default "root" match
85
81
  if (match) {
86
- branch.push({ route: route, match: match });
82
+ branch.push({ route, match });
87
83
  if (route.routes) {
88
84
  matchRoutes(route.routes, pathname, matchPath, branch);
89
85
  }
@@ -97,17 +93,17 @@ function computeRootMatch(pathname) {
97
93
  }
98
94
  /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
99
95
  function withSentryRouting(Route) {
100
- var componentDisplayName = Route.displayName || Route.name;
101
- var WrappedRoute = function (props) {
96
+ const componentDisplayName = Route.displayName || Route.name;
97
+ const WrappedRoute = (props) => {
102
98
  if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {
103
99
  activeTransaction.setName(props.computedMatch.path);
104
100
  }
105
101
  // @ts-ignore Setting more specific React Component typing for `R` generic above
106
102
  // will break advanced type inference done by react router params:
107
103
  // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
108
- return React.createElement(Route, tslib_1.__assign({}, props));
104
+ return React.createElement(Route, Object.assign({}, props));
109
105
  };
110
- WrappedRoute.displayName = "sentryRoute(" + componentDisplayName + ")";
106
+ WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;
111
107
  hoist_non_react_statics_1.default(WrappedRoute, Route);
112
108
  // @ts-ignore Setting more specific React Component typing for `R` generic above
113
109
  // will break advanced type inference done by react router params:
@@ -0,0 +1 @@
1
+ {"version":3,"file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AAC,CAAC;IAEF,YAAY,CAAC,WAAW,GAAG,eAAe,oBAAoB,GAAG,CAAC;IAClE,iCAAoB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IAC1C,gFAAgF;IAChF,kEAAkE;IAClE,2IAA2I;IAC3I,OAAO,YAAY,CAAC;AACtB,CAAC;AApBD,8CAoBC;AACD,kGAAkG","sourcesContent":["import { Transaction } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { Action, Location, ReactRouterInstrumentation } from './types';\n\n// We need to disable eslint no-explict-any because any is required for the\n// react-router typings.\n/* eslint-disable @typescript-eslint/no-explicit-any */\ntype Match = { path: string; url: string; params: Record<string, any>; isExact: boolean };\n\nexport type RouterHistory = {\n location?: Location;\n listen?(cb: (location: Location, action: Action) => void): void;\n} & Record<string, any>;\n\nexport type RouteConfig = {\n [propName: string]: any;\n path?: string | string[];\n exact?: boolean;\n component?: JSX.Element;\n routes?: RouteConfig[];\n};\n\ntype MatchPath = (pathname: string, props: string | string[] | any, parent?: Match | null) => Match | null;\n/* eslint-enable @typescript-eslint/no-explicit-any */\n\nconst global = getGlobalObject<Window>();\n\nlet activeTransaction: Transaction | undefined;\n\nexport function reactRouterV4Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);\n}\n\nexport function reactRouterV5Instrumentation(\n history: RouterHistory,\n routes?: RouteConfig[],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);\n}\n\nfunction createReactRouterInstrumentation(\n history: RouterHistory,\n name: string,\n allRoutes: RouteConfig[] = [],\n matchPath?: MatchPath,\n): ReactRouterInstrumentation {\n function getInitPathName(): string | undefined {\n if (history && history.location) {\n return history.location.pathname;\n }\n\n if (global && global.location) {\n return global.location.pathname;\n }\n\n return undefined;\n }\n\n function getTransactionName(pathname: string): string {\n if (allRoutes.length === 0 || !matchPath) {\n return pathname;\n }\n\n const branches = matchRoutes(allRoutes, pathname, matchPath);\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let x = 0; x < branches.length; x++) {\n if (branches[x].match.isExact) {\n return branches[x].match.path;\n }\n }\n\n return pathname;\n }\n\n return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true): void => {\n const initPathName = getInitPathName();\n if (startTransactionOnPageLoad && initPathName) {\n activeTransaction = customStartTransaction({\n name: getTransactionName(initPathName),\n op: 'pageload',\n tags: {\n 'routing.instrumentation': name,\n },\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen((location, action) => {\n if (action && (action === 'PUSH' || action === 'POP')) {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags = {\n 'routing.instrumentation': name,\n };\n\n activeTransaction = customStartTransaction({\n name: getTransactionName(location.pathname),\n op: 'navigation',\n tags,\n });\n }\n });\n }\n };\n}\n\n/**\n * Matches a set of routes to a pathname\n * Based on implementation from\n */\nfunction matchRoutes(\n routes: RouteConfig[],\n pathname: string,\n matchPath: MatchPath,\n branch: Array<{ route: RouteConfig; match: Match }> = [],\n): Array<{ route: RouteConfig; match: Match }> {\n routes.some(route => {\n const match = route.path\n ? matchPath(pathname, route)\n : branch.length\n ? branch[branch.length - 1].match // use parent match\n : computeRootMatch(pathname); // use default \"root\" match\n\n if (match) {\n branch.push({ route, match });\n\n if (route.routes) {\n matchRoutes(route.routes, pathname, matchPath, branch);\n }\n }\n\n return !!match;\n });\n\n return branch;\n}\n\nfunction computeRootMatch(pathname: string): Match {\n return { path: '/', url: '/', params: {}, isExact: pathname === '/' };\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\nexport function withSentryRouting<P extends Record<string, any>, R extends React.ComponentType<P>>(Route: R): R {\n const componentDisplayName = (Route as any).displayName || (Route as any).name;\n\n const WrappedRoute: React.FC<P> = (props: P) => {\n if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {\n activeTransaction.setName(props.computedMatch.path);\n }\n\n // @ts-ignore Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return <Route {...props} />;\n };\n\n WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;\n hoistNonReactStatics(WrappedRoute, Route);\n // @ts-ignore Setting more specific React Component typing for `R` generic above\n // will break advanced type inference done by react router params:\n // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164\n return WrappedRoute;\n}\n/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */\n"]}
File without changes
File without changes