@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
package/esm/profiler.js CHANGED
@@ -1,4 +1,3 @@
1
- import { __assign, __extends, __read } from "tslib";
2
1
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
4
3
  import { getCurrentHub } from '@sentry/browser';
@@ -6,159 +5,86 @@ import { timestampWithMs } from '@sentry/utils';
6
5
  import hoistNonReactStatics from 'hoist-non-react-statics';
7
6
  import * as React from 'react';
8
7
  import { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';
9
- export var UNKNOWN_COMPONENT = 'unknown';
10
- var TRACING_GETTER = {
11
- id: 'Tracing',
12
- };
13
- var globalTracingIntegration = null;
14
- /** @deprecated remove when @sentry/apm no longer used */
15
- var getTracingIntegration = function () {
16
- if (globalTracingIntegration) {
17
- return globalTracingIntegration;
18
- }
19
- globalTracingIntegration = getCurrentHub().getIntegration(TRACING_GETTER);
20
- return globalTracingIntegration;
21
- };
22
- /**
23
- * pushActivity creates an new react activity.
24
- * Is a no-op if Tracing integration is not valid
25
- * @param name displayName of component that started activity
26
- * @deprecated remove when @sentry/apm no longer used
27
- */
28
- function pushActivity(name, op) {
29
- if (globalTracingIntegration === null) {
30
- return null;
31
- }
32
- return globalTracingIntegration.constructor.pushActivity(name, {
33
- description: "<" + name + ">",
34
- op: op,
35
- });
36
- }
37
- /**
38
- * popActivity removes a React activity.
39
- * Is a no-op if Tracing integration is not valid.
40
- * @param activity id of activity that is being popped
41
- * @deprecated remove when @sentry/apm no longer used
42
- */
43
- function popActivity(activity) {
44
- if (activity === null || globalTracingIntegration === null) {
45
- return;
46
- }
47
- globalTracingIntegration.constructor.popActivity(activity);
48
- }
49
- /**
50
- * Obtain a span given an activity id.
51
- * Is a no-op if Tracing integration is not valid.
52
- * @param activity activity id associated with obtained span
53
- * @deprecated remove when @sentry/apm no longer used
54
- */
55
- function getActivitySpan(activity) {
56
- if (activity === null || globalTracingIntegration === null) {
57
- return undefined;
58
- }
59
- return globalTracingIntegration.constructor.getActivitySpan(activity);
60
- }
8
+ export const UNKNOWN_COMPONENT = 'unknown';
61
9
  /**
62
10
  * The Profiler component leverages Sentry's Tracing integration to generate
63
11
  * spans based on component lifecycles.
64
12
  */
65
- var Profiler = /** @class */ (function (_super) {
66
- __extends(Profiler, _super);
67
- function Profiler(props) {
68
- var _this = _super.call(this, props) || this;
13
+ class Profiler extends React.Component {
14
+ constructor(props) {
15
+ super(props);
69
16
  /**
70
17
  * The span of the mount activity
71
18
  * Made protected for the React Native SDK to access
72
19
  */
73
- _this._mountSpan = undefined;
74
- // The activity representing how long it takes to mount a component.
75
- _this._mountActivity = null;
76
- var _a = _this.props, name = _a.name, _b = _a.disabled, disabled = _b === void 0 ? false : _b;
20
+ this._mountSpan = undefined;
21
+ const { name, disabled = false } = this.props;
77
22
  if (disabled) {
78
- return _this;
79
- }
80
- // If they are using @sentry/apm, we need to push/pop activities
81
- // eslint-disable-next-line deprecation/deprecation
82
- if (getTracingIntegration()) {
83
- // eslint-disable-next-line deprecation/deprecation
84
- _this._mountActivity = pushActivity(name, REACT_MOUNT_OP);
23
+ return;
85
24
  }
86
- else {
87
- var activeTransaction = getActiveTransaction();
88
- if (activeTransaction) {
89
- _this._mountSpan = activeTransaction.startChild({
90
- description: "<" + name + ">",
91
- op: REACT_MOUNT_OP,
92
- });
93
- }
25
+ const activeTransaction = getActiveTransaction();
26
+ if (activeTransaction) {
27
+ this._mountSpan = activeTransaction.startChild({
28
+ description: `<${name}>`,
29
+ op: REACT_MOUNT_OP,
30
+ });
94
31
  }
95
- return _this;
96
32
  }
97
33
  // If a component mounted, we can finish the mount activity.
98
- Profiler.prototype.componentDidMount = function () {
34
+ componentDidMount() {
99
35
  if (this._mountSpan) {
100
36
  this._mountSpan.finish();
101
37
  }
102
- else {
103
- // eslint-disable-next-line deprecation/deprecation
104
- this._mountSpan = getActivitySpan(this._mountActivity);
105
- // eslint-disable-next-line deprecation/deprecation
106
- popActivity(this._mountActivity);
107
- this._mountActivity = null;
108
- }
109
- };
110
- Profiler.prototype.componentDidUpdate = function (_a) {
111
- var _this = this;
112
- var updateProps = _a.updateProps, _b = _a.includeUpdates, includeUpdates = _b === void 0 ? true : _b;
38
+ }
39
+ componentDidUpdate({ updateProps, includeUpdates = true }) {
113
40
  // Only generate an update span if hasUpdateSpan is true, if there is a valid mountSpan,
114
41
  // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.
115
42
  // We are just trying to give baseline clues for further investigation.
116
43
  if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {
117
44
  // See what props haved changed between the previous props, and the current props. This is
118
45
  // set as data on the span. We just store the prop keys as the values could be potenially very large.
119
- var changedProps = Object.keys(updateProps).filter(function (k) { return updateProps[k] !== _this.props.updateProps[k]; });
46
+ const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);
120
47
  if (changedProps.length > 0) {
121
48
  // The update span is a point in time span with 0 duration, just signifying that the component
122
49
  // has been updated.
123
- var now = timestampWithMs();
50
+ const now = timestampWithMs();
124
51
  this._mountSpan.startChild({
125
52
  data: {
126
- changedProps: changedProps,
53
+ changedProps,
127
54
  },
128
- description: "<" + this.props.name + ">",
55
+ description: `<${this.props.name}>`,
129
56
  endTimestamp: now,
130
57
  op: REACT_UPDATE_OP,
131
58
  startTimestamp: now,
132
59
  });
133
60
  }
134
61
  }
135
- };
62
+ }
136
63
  // If a component is unmounted, we can say it is no longer on the screen.
137
64
  // This means we can finish the span representing the component render.
138
- Profiler.prototype.componentWillUnmount = function () {
139
- var _a = this.props, name = _a.name, _b = _a.includeRender, includeRender = _b === void 0 ? true : _b;
65
+ componentWillUnmount() {
66
+ const { name, includeRender = true } = this.props;
140
67
  if (this._mountSpan && includeRender) {
141
68
  // If we were able to obtain the spanId of the mount activity, we should set the
142
69
  // next activity as a child to the component mount activity.
143
70
  this._mountSpan.startChild({
144
- description: "<" + name + ">",
71
+ description: `<${name}>`,
145
72
  endTimestamp: timestampWithMs(),
146
73
  op: REACT_RENDER_OP,
147
74
  startTimestamp: this._mountSpan.endTimestamp,
148
75
  });
149
76
  }
150
- };
151
- Profiler.prototype.render = function () {
77
+ }
78
+ render() {
152
79
  return this.props.children;
153
- };
154
- // eslint-disable-next-line @typescript-eslint/member-ordering
155
- Profiler.defaultProps = {
156
- disabled: false,
157
- includeRender: true,
158
- includeUpdates: true,
159
- };
160
- return Profiler;
161
- }(React.Component));
80
+ }
81
+ }
82
+ // eslint-disable-next-line @typescript-eslint/member-ordering
83
+ Profiler.defaultProps = {
84
+ disabled: false,
85
+ includeRender: true,
86
+ includeUpdates: true,
87
+ };
162
88
  /**
163
89
  * withProfiler is a higher order component that wraps a
164
90
  * component in a {@link Profiler} component. It is recommended that
@@ -170,10 +96,10 @@ var Profiler = /** @class */ (function (_super) {
170
96
  function withProfiler(WrappedComponent,
171
97
  // We do not want to have `updateProps` given in options, it is instead filled through the HOC.
172
98
  options) {
173
- var componentDisplayName = (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
174
- var Wrapped = function (props) { return (React.createElement(Profiler, __assign({}, options, { name: componentDisplayName, updateProps: props }),
175
- React.createElement(WrappedComponent, __assign({}, props)))); };
176
- Wrapped.displayName = "profiler(" + componentDisplayName + ")";
99
+ const componentDisplayName = (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
100
+ const Wrapped = (props) => (React.createElement(Profiler, Object.assign({}, options, { name: componentDisplayName, updateProps: props }),
101
+ React.createElement(WrappedComponent, Object.assign({}, props))));
102
+ Wrapped.displayName = `profiler(${componentDisplayName})`;
177
103
  // Copy over static methods from Wrapped component to Profiler HOC
178
104
  // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
179
105
  hoistNonReactStatics(Wrapped, WrappedComponent);
@@ -186,32 +112,31 @@ options) {
186
112
  * Requires React 16.8 or above.
187
113
  * @param name displayName of component being profiled
188
114
  */
189
- function useProfiler(name, options) {
190
- if (options === void 0) { options = {
191
- disabled: false,
192
- hasRenderSpan: true,
193
- }; }
194
- var _a = __read(React.useState(function () {
115
+ function useProfiler(name, options = {
116
+ disabled: false,
117
+ hasRenderSpan: true,
118
+ }) {
119
+ const [mountSpan] = React.useState(() => {
195
120
  if (options && options.disabled) {
196
121
  return undefined;
197
122
  }
198
- var activeTransaction = getActiveTransaction();
123
+ const activeTransaction = getActiveTransaction();
199
124
  if (activeTransaction) {
200
125
  return activeTransaction.startChild({
201
- description: "<" + name + ">",
126
+ description: `<${name}>`,
202
127
  op: REACT_MOUNT_OP,
203
128
  });
204
129
  }
205
130
  return undefined;
206
- }), 1), mountSpan = _a[0];
207
- React.useEffect(function () {
131
+ });
132
+ React.useEffect(() => {
208
133
  if (mountSpan) {
209
134
  mountSpan.finish();
210
135
  }
211
- return function () {
136
+ return () => {
212
137
  if (mountSpan && options.hasRenderSpan) {
213
138
  mountSpan.startChild({
214
- description: "<" + name + ">",
139
+ description: `<${name}>`,
215
140
  endTimestamp: timestampWithMs(),
216
141
  op: REACT_RENDER_OP,
217
142
  startTimestamp: mountSpan.endTimestamp,
@@ -224,10 +149,9 @@ function useProfiler(name, options) {
224
149
  }
225
150
  export { withProfiler, Profiler, useProfiler };
226
151
  /** Grabs active transaction off scope */
227
- export function getActiveTransaction(hub) {
228
- if (hub === void 0) { hub = getCurrentHub(); }
152
+ export function getActiveTransaction(hub = getCurrentHub()) {
229
153
  if (hub) {
230
- var scope = hub.getScope();
154
+ const scope = hub.getScope();
231
155
  if (scope) {
232
156
  return scope.getTransaction();
233
157
  }
@@ -1 +1 @@
1
- {"version":3,"file":"profiler.js","sourceRoot":"","sources":["../../src/profiler.tsx"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,uDAAuD;AACvD,OAAO,EAAE,aAAa,EAAO,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE/E,MAAM,CAAC,IAAM,iBAAiB,GAAG,SAAS,CAAC;AAE3C,IAAM,cAAc,GAAI;IACtB,EAAE,EAAE,SAAS;CAC2B,CAAC;AAE3C,IAAI,wBAAwB,GAAuB,IAAI,CAAC;AACxD,yDAAyD;AACzD,IAAM,qBAAqB,GAAG;IAC5B,IAAI,wBAAwB,EAAE;QAC5B,OAAO,wBAAwB,CAAC;KACjC;IAED,wBAAwB,GA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AC;AACnB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { getCurrentHub, Hub } from '@sentry/browser';\nimport { Integration, IntegrationClass, 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\nconst TRACING_GETTER = ({\n id: 'Tracing',\n} as any) as IntegrationClass<Integration>;\n\nlet globalTracingIntegration: Integration | null = null;\n/** @deprecated remove when @sentry/apm no longer used */\nconst getTracingIntegration = (): Integration | null => {\n if (globalTracingIntegration) {\n return globalTracingIntegration;\n }\n\n globalTracingIntegration = getCurrentHub().getIntegration(TRACING_GETTER);\n return globalTracingIntegration;\n};\n\n/**\n * pushActivity creates an new react activity.\n * Is a no-op if Tracing integration is not valid\n * @param name displayName of component that started activity\n * @deprecated remove when @sentry/apm no longer used\n */\nfunction pushActivity(name: string, op: string): number | null {\n if (globalTracingIntegration === null) {\n return null;\n }\n\n return (globalTracingIntegration as any).constructor.pushActivity(name, {\n description: `<${name}>`,\n op,\n });\n}\n\n/**\n * popActivity removes a React activity.\n * Is a no-op if Tracing integration is not valid.\n * @param activity id of activity that is being popped\n * @deprecated remove when @sentry/apm no longer used\n */\nfunction popActivity(activity: number | null): void {\n if (activity === null || globalTracingIntegration === null) {\n return;\n }\n\n (globalTracingIntegration as any).constructor.popActivity(activity);\n}\n\n/**\n * Obtain a span given an activity id.\n * Is a no-op if Tracing integration is not valid.\n * @param activity activity id associated with obtained span\n * @deprecated remove when @sentry/apm no longer used\n */\nfunction getActivitySpan(activity: number | null): Span | undefined {\n if (activity === null || globalTracingIntegration === null) {\n return undefined;\n }\n\n return (globalTracingIntegration as any).constructor.getActivitySpan(activity) as Span | undefined;\n}\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 // The activity representing how long it takes to mount a component.\n private _mountActivity: number | null = null;\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 // If they are using @sentry/apm, we need to push/pop activities\n // eslint-disable-next-line deprecation/deprecation\n if (getTracingIntegration()) {\n // eslint-disable-next-line deprecation/deprecation\n this._mountActivity = pushActivity(name, REACT_MOUNT_OP);\n } else {\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\n // If a component mounted, we can finish the mount activity.\n public componentDidMount(): void {\n if (this._mountSpan) {\n this._mountSpan.finish();\n } else {\n // eslint-disable-next-line deprecation/deprecation\n this._mountSpan = getActivitySpan(this._mountActivity);\n // eslint-disable-next-line deprecation/deprecation\n popActivity(this._mountActivity);\n this._mountActivity = null;\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","sourceRoot":"","sources":["../../src/profiler.tsx"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,uDAAuD;AACvD,OAAO,EAAE,aAAa,EAAO,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS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,EAAE,WAAW,EAAE,CAAC;AAE/C,yCAAyC;AACzC,MAAM,UAAU,oBAAoB,CAAwB,MAAW,aAAa,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","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,18 +1,16 @@
1
- import { __assign } from "tslib";
2
1
  import { getGlobalObject } from '@sentry/utils';
3
2
  import hoistNonReactStatics from 'hoist-non-react-statics';
4
3
  import * as React from 'react';
5
4
  /* eslint-enable @typescript-eslint/no-explicit-any */
6
- var global = getGlobalObject();
7
- var activeTransaction;
5
+ const global = getGlobalObject();
6
+ let activeTransaction;
8
7
  export function reactRouterV4Instrumentation(history, routes, matchPath) {
9
8
  return createReactRouterInstrumentation(history, 'react-router-v4', routes, matchPath);
10
9
  }
11
10
  export function reactRouterV5Instrumentation(history, routes, matchPath) {
12
11
  return createReactRouterInstrumentation(history, 'react-router-v5', routes, matchPath);
13
12
  }
14
- function createReactRouterInstrumentation(history, name, allRoutes, matchPath) {
15
- if (allRoutes === void 0) { allRoutes = []; }
13
+ function createReactRouterInstrumentation(history, name, allRoutes = [], matchPath) {
16
14
  function getInitPathName() {
17
15
  if (history && history.location) {
18
16
  return history.location.pathname;
@@ -26,19 +24,17 @@ function createReactRouterInstrumentation(history, name, allRoutes, matchPath) {
26
24
  if (allRoutes.length === 0 || !matchPath) {
27
25
  return pathname;
28
26
  }
29
- var branches = matchRoutes(allRoutes, pathname, matchPath);
27
+ const branches = matchRoutes(allRoutes, pathname, matchPath);
30
28
  // eslint-disable-next-line @typescript-eslint/prefer-for-of
31
- for (var x = 0; x < branches.length; x++) {
29
+ for (let x = 0; x < branches.length; x++) {
32
30
  if (branches[x].match.isExact) {
33
31
  return branches[x].match.path;
34
32
  }
35
33
  }
36
34
  return pathname;
37
35
  }
38
- return function (customStartTransaction, startTransactionOnPageLoad, startTransactionOnLocationChange) {
39
- if (startTransactionOnPageLoad === void 0) { startTransactionOnPageLoad = true; }
40
- if (startTransactionOnLocationChange === void 0) { startTransactionOnLocationChange = true; }
41
- var initPathName = getInitPathName();
36
+ return (customStartTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true) => {
37
+ const initPathName = getInitPathName();
42
38
  if (startTransactionOnPageLoad && initPathName) {
43
39
  activeTransaction = customStartTransaction({
44
40
  name: getTransactionName(initPathName),
@@ -49,18 +45,18 @@ function createReactRouterInstrumentation(history, name, allRoutes, matchPath) {
49
45
  });
50
46
  }
51
47
  if (startTransactionOnLocationChange && history.listen) {
52
- history.listen(function (location, action) {
48
+ history.listen((location, action) => {
53
49
  if (action && (action === 'PUSH' || action === 'POP')) {
54
50
  if (activeTransaction) {
55
51
  activeTransaction.finish();
56
52
  }
57
- var tags = {
53
+ const tags = {
58
54
  'routing.instrumentation': name,
59
55
  };
60
56
  activeTransaction = customStartTransaction({
61
57
  name: getTransactionName(location.pathname),
62
58
  op: 'navigation',
63
- tags: tags,
59
+ tags,
64
60
  });
65
61
  }
66
62
  });
@@ -71,16 +67,15 @@ function createReactRouterInstrumentation(history, name, allRoutes, matchPath) {
71
67
  * Matches a set of routes to a pathname
72
68
  * Based on implementation from
73
69
  */
74
- function matchRoutes(routes, pathname, matchPath, branch) {
75
- if (branch === void 0) { branch = []; }
76
- routes.some(function (route) {
77
- var match = route.path
70
+ function matchRoutes(routes, pathname, matchPath, branch = []) {
71
+ routes.some(route => {
72
+ const match = route.path
78
73
  ? matchPath(pathname, route)
79
74
  : branch.length
80
75
  ? branch[branch.length - 1].match // use parent match
81
76
  : computeRootMatch(pathname); // use default "root" match
82
77
  if (match) {
83
- branch.push({ route: route, match: match });
78
+ branch.push({ route, match });
84
79
  if (route.routes) {
85
80
  matchRoutes(route.routes, pathname, matchPath, branch);
86
81
  }
@@ -94,17 +89,17 @@ function computeRootMatch(pathname) {
94
89
  }
95
90
  /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
96
91
  export function withSentryRouting(Route) {
97
- var componentDisplayName = Route.displayName || Route.name;
98
- var WrappedRoute = function (props) {
92
+ const componentDisplayName = Route.displayName || Route.name;
93
+ const WrappedRoute = (props) => {
99
94
  if (activeTransaction && props && props.computedMatch && props.computedMatch.isExact) {
100
95
  activeTransaction.setName(props.computedMatch.path);
101
96
  }
102
97
  // @ts-ignore Setting more specific React Component typing for `R` generic above
103
98
  // will break advanced type inference done by react router params:
104
99
  // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/13dc4235c069e25fe7ee16e11f529d909f9f3ff8/types/react-router/index.d.ts#L154-L164
105
- return React.createElement(Route, __assign({}, props));
100
+ return React.createElement(Route, Object.assign({}, props));
106
101
  };
107
- WrappedRoute.displayName = "sentryRoute(" + componentDisplayName + ")";
102
+ WrappedRoute.displayName = `sentryRoute(${componentDisplayName})`;
108
103
  hoistNonReactStatics(WrappedRoute, Route);
109
104
  // @ts-ignore Setting more specific React Component typing for `R` generic above
110
105
  // will break advanced type inference done by react router params:
@@ -1 +1 @@
1
- {"version":3,"file":"reactrouter.js","sourceRoot":"","sources":["../../src/reactrouter.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAuB/B,sDAAsD;AAEtD,IAAM,MAAM,GAAG,eAAe,EAAU,CAAC;AAEzC,IAAI,iBAA0C,CAAC;AAE/C,MAAM,UAAU,4BAA4B,CAC1C,OAAsB,EACtB,MAAsB,EACtB,SAAqB;IAErB,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACzF,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,OAAsB,EACtB,MAAsB,EACtB,SAAqB;IAErB,OAAO,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACzF,CAAC;AAED,SAAS,gCAAgC,CACvC,OAAsB,EACtB,IAAY,EACZ,SAA6B,EAC7B,SAAqB;IADrB,0BAAA,EAAA,cAA6B;IAG7B,SAAS,eAAe;QACtB,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE;YAC/B,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;SAClC;QAED,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE;YAC7B,OAAO,MAAM,CAA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E,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,iBAAiB,CAAkE,KAAQ;IACzG,IAAM,oBAAoB,GAAI,KAAa,CAAC,WAAW,IAAK,KAAa,CAAC,IAAI,CAAC;IAE/E,IAAM,YAAY,GAAgB,UAAC,KAAQ;QACzC,IAAI,iBAAiB,IAAI,KAAK,IAAI,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE;YACpF,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;SACrD;QAED,gFAAgF;QAChF,kEAAkE;QAClE,2IAA2I;QAC3I,OAAO,oBAAC,KAAK,eAAK,KAAK,EAAI,CAAC;IAC9B,CAAC,CAAC;IAEF,YAAY,CAAC,WAAW,GAAG,iBAAe,oBAAoB,MAAG,CAAC;IAClE,oBAAoB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IAC1C,gFAAgF;IAChF,kEAAkE;IAClE,2IAA2I;IAC3I,OAAO,YAAY,CAAC;AACtB,CAAC;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"]}
1
+ {"version":3,"file":"reactrouter.js","sourceRoot":"","sources":["../../src/reactrouter.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;A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C;IAC1C,gFAAgF;IAChF,kEAAkE;IAClE,2IAA2I;IAC3I,OAAO,YAAY,CAAC;AACtB,CAAC;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"]}
@@ -1,5 +1,5 @@
1
1
  import { getGlobalObject } from '@sentry/utils';
2
- var global = getGlobalObject();
2
+ const global = getGlobalObject();
3
3
  /**
4
4
  * Creates routing instrumentation for React Router v3
5
5
  * Works for React Router >= 3.2.0 and < 4.0.0
@@ -9,14 +9,12 @@ var global = getGlobalObject();
9
9
  * @param match `Router.match` utility
10
10
  */
11
11
  export function reactRouterV3Instrumentation(history, routes, match) {
12
- return function (startTransaction, startTransactionOnPageLoad, startTransactionOnLocationChange) {
13
- if (startTransactionOnPageLoad === void 0) { startTransactionOnPageLoad = true; }
14
- if (startTransactionOnLocationChange === void 0) { startTransactionOnLocationChange = true; }
15
- var activeTransaction;
16
- var prevName;
12
+ return (startTransaction, startTransactionOnPageLoad = true, startTransactionOnLocationChange = true) => {
13
+ let activeTransaction;
14
+ let prevName;
17
15
  // Have to use global.location because history.location might not be defined.
18
16
  if (startTransactionOnPageLoad && global && global.location) {
19
- normalizeTransactionName(routes, global.location, match, function (localName) {
17
+ normalizeTransactionName(routes, global.location, match, (localName) => {
20
18
  prevName = localName;
21
19
  activeTransaction = startTransaction({
22
20
  name: prevName,
@@ -28,23 +26,23 @@ export function reactRouterV3Instrumentation(history, routes, match) {
28
26
  });
29
27
  }
30
28
  if (startTransactionOnLocationChange && history.listen) {
31
- history.listen(function (location) {
29
+ history.listen(location => {
32
30
  if (location.action === 'PUSH' || location.action === 'POP') {
33
31
  if (activeTransaction) {
34
32
  activeTransaction.finish();
35
33
  }
36
- var tags_1 = {
34
+ const tags = {
37
35
  'routing.instrumentation': 'react-router-v3',
38
36
  };
39
37
  if (prevName) {
40
- tags_1.from = prevName;
38
+ tags.from = prevName;
41
39
  }
42
- normalizeTransactionName(routes, location, match, function (localName) {
40
+ normalizeTransactionName(routes, location, match, (localName) => {
43
41
  prevName = localName;
44
42
  activeTransaction = startTransaction({
45
43
  name: prevName,
46
44
  op: 'navigation',
47
- tags: tags_1,
45
+ tags,
48
46
  });
49
47
  });
50
48
  }
@@ -56,15 +54,15 @@ export function reactRouterV3Instrumentation(history, routes, match) {
56
54
  * Normalize transaction names using `Router.match`
57
55
  */
58
56
  function normalizeTransactionName(appRoutes, location, match, callback) {
59
- var name = location.pathname;
57
+ let name = location.pathname;
60
58
  match({
61
- location: location,
59
+ location,
62
60
  routes: appRoutes,
63
- }, function (error, _redirectLocation, renderProps) {
61
+ }, (error, _redirectLocation, renderProps) => {
64
62
  if (error || !renderProps) {
65
63
  return callback(name);
66
64
  }
67
- var routePath = getRouteStringFromRoutes(renderProps.routes || []);
65
+ const routePath = getRouteStringFromRoutes(renderProps.routes || []);
68
66
  if (routePath.length === 0 || routePath === '/*') {
69
67
  return callback(name);
70
68
  }
@@ -79,10 +77,10 @@ function getRouteStringFromRoutes(routes) {
79
77
  if (!Array.isArray(routes) || routes.length === 0) {
80
78
  return '';
81
79
  }
82
- var routesWithPaths = routes.filter(function (route) { return !!route.path; });
83
- var index = -1;
84
- for (var x = routesWithPaths.length - 1; x >= 0; x--) {
85
- var route = routesWithPaths[x];
80
+ const routesWithPaths = routes.filter((route) => !!route.path);
81
+ let index = -1;
82
+ for (let x = routesWithPaths.length - 1; x >= 0; x--) {
83
+ const route = routesWithPaths[x];
86
84
  if (route.path && route.path.startsWith('/')) {
87
85
  index = x;
88
86
  break;
@@ -90,14 +88,8 @@ function getRouteStringFromRoutes(routes) {
90
88
  }
91
89
  return routesWithPaths
92
90
  .slice(index)
93
- .filter(function (_a) {
94
- var path = _a.path;
95
- return !!path;
96
- })
97
- .map(function (_a) {
98
- var path = _a.path;
99
- return path;
100
- })
91
+ .filter(({ path }) => !!path)
92
+ .map(({ path }) => path)
101
93
  .join('');
102
94
  }
103
95
  //# sourceMappingURL=reactrouterv3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reactrouterv3.js","sourceRoot":"","sources":["../../src/reactrouterv3.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAoBhD,IAAM,MAAM,GAAG,eAAe,EAAU,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAC1C,OAAkB,EAClB,MAAe,EACf,KAAY;IAEZ,OAAO,UACL,gBAA0E,EAC1E,0BAA0C,EAC1C,gCAAgD;QADhD,2CAAA,EAAA,iCAA0C;QAC1C,iDAAA,EAAA,uCAAgD;QAEhD,IAAI,iBAA0C,CAAC;QAC/C,IAAI,QAA4B,CAAC;QAEjC,6EAA6E;QAC7E,IAAI,0BAA0B,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE;YAC3D,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,QAA+B,EAAE,KAAK,EAAE,UAAC,SAAiB;gBAChG,QAAQ,GAAG,SAAS,CAAC;gBACrB,iBAAiB,GAAG,gBAAgB,CAAC;oBACnC,IAAI,EAAE,QAAQ;oBACd,EAAE,EAAE,UAAU;oBACd,IAAI,EAAE;wBACJ,yBAAyB,EAAE,iBAAiB;qBAC7C;iBACF,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;QAED,IAAI,gCAAgC,IAAI,OAAO,CAAC,MAAM,EAAE;YACtD,OAAO,CAAC,MAAM,CAAC,UAAA,QAAQ;gBACrB,IAAI,QAAQ,CAAC,MAAM,KA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AAC;AAED;;GAEG;AACH,SAAS,wBAAwB,CAAC,MAAe;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACjD,OAAO,EAAE,CAAC;KACX;IAED,IAAM,eAAe,GAAY,MAAM,CAAC,MAAM,CAAC,UAAC,KAAY,IAAK,OAAA,CAAC,CAAC,KAAK,CAAC,IAAI,EAAZ,CAAY,CAAC,CAAC;IAE/E,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QACpD,IAAM,KAAK,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC5C,KAAK,GAAG,CAAC,CAAC;YACV,MAAM;SACP;KACF;IAED,OAAO,eAAe;SACnB,KAAK,CAAC,KAAK,CAAC;SACZ,MAAM,CAAC,UAAC,EAAQ;YAAN,cAAI;QAAO,OAAA,CAAC,CAAC,IAAI;IAAN,CAAM,CAAC;SAC5B,GAAG,CAAC,UAAC,EAAQ;YAAN,cAAI;QAAO,OAAA,IAAI;IAAJ,CAAI,CAAC;SACvB,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC","sourcesContent":["import { Primitive, Transaction, TransactionContext } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\n\nimport { Location, ReactRouterInstrumentation } from './types';\n\n// Many of the types below had to be mocked out to prevent typescript issues\n// these types are required for correct functionality.\n\ntype HistoryV3 = {\n location?: Location;\n listen?(cb: (location: Location) => void): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport type Route = { path?: string; childRoutes?: Route[] };\n\nexport type Match = (\n props: { location: Location; routes: Route[] },\n cb: (error?: Error, _redirectLocation?: Location, renderProps?: { routes?: Route[] }) => void,\n) => void;\n\nconst global = getGlobalObject<Window>();\n\n/**\n * Creates routing instrumentation for React Router v3\n * Works for React Router >= 3.2.0 and < 4.0.0\n *\n * @param history object from the `history` library\n * @param routes a list of all routes, should be\n * @param match `Router.match` utility\n */\nexport function reactRouterV3Instrumentation(\n history: HistoryV3,\n routes: Route[],\n match: Match,\n): ReactRouterInstrumentation {\n return (\n startTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad: boolean = true,\n startTransactionOnLocationChange: boolean = true,\n ) => {\n let activeTransaction: Transaction | undefined;\n let prevName: string | undefined;\n\n // Have to use global.location because history.location might not be defined.\n if (startTransactionOnPageLoad && global && global.location) {\n normalizeTransactionName(routes, global.location as unknown as Location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'pageload',\n tags: {\n 'routing.instrumentation': 'react-router-v3',\n },\n });\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen(location => {\n if (location.action === 'PUSH' || location.action === 'POP') {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags: Record<string, Primitive> = {\n 'routing.instrumentation': 'react-router-v3',\n };\n if (prevName) {\n tags.from = prevName;\n }\n normalizeTransactionName(routes, location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'navigation',\n tags,\n });\n });\n }\n });\n }\n };\n}\n\n/**\n * Normalize transaction names using `Router.match`\n */\nfunction normalizeTransactionName(\n appRoutes: Route[],\n location: Location,\n match: Match,\n callback: (pathname: string) => void,\n): void {\n let name = location.pathname;\n match(\n {\n location,\n routes: appRoutes,\n },\n (error, _redirectLocation, renderProps) => {\n if (error || !renderProps) {\n return callback(name);\n }\n\n const routePath = getRouteStringFromRoutes(renderProps.routes || []);\n if (routePath.length === 0 || routePath === '/*') {\n return callback(name);\n }\n\n name = routePath;\n return callback(name);\n },\n );\n}\n\n/**\n * Generate route name from array of routes\n */\nfunction getRouteStringFromRoutes(routes: Route[]): string {\n if (!Array.isArray(routes) || routes.length === 0) {\n return '';\n }\n\n const routesWithPaths: Route[] = routes.filter((route: Route) => !!route.path);\n\n let index = -1;\n for (let x = routesWithPaths.length - 1; x >= 0; x--) {\n const route = routesWithPaths[x];\n if (route.path && route.path.startsWith('/')) {\n index = x;\n break;\n }\n }\n\n return routesWithPaths\n .slice(index)\n .filter(({ path }) => !!path)\n .map(({ path }) => path)\n .join('');\n}\n"]}
1
+ {"version":3,"file":"reactrouterv3.js","sourceRoot":"","sources":["../../src/reactrouterv3.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAoBhD,MAAM,MAAM,GAAG,eAAe,EAAU,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAC1C,OAAkB,EAClB,MAAe,EACf,KAAY;IAEZ,OAAO,CACL,gBAA0E,EAC1E,6BAAsC,IAAI,EAC1C,mCAA4C,IAAI,EAChD,EAAE;QACF,IAAI,iBAA0C,CAAC;QAC/C,IAAI,QAA4B,CAAC;QAEjC,6EAA6E;QAC7E,IAAI,0BAA0B,IAAI,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE;YAC3D,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,QAA+B,EAAE,KAAK,EAAE,CAAC,SAAiB,EAAE,EAAE;gBACpG,QAAQ,GAAG,SAAS,CAAC;gBACrB,iBAAiB,GAAG,gBAAgB,CAAC;oBACnC,IAAI,EAAE,QAAQ;oBACd,EAAE,EAAE,UAAU;oBACd,IAAI,EAAE;wBACJ,yBAAyB,EAAE,iBAAiB;qBAC7C;iBACF,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;QAED,IAAI,gCAAgC,IAAI,OAAO,CAAC,MAAM,EAAE;YACtD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;gBACxB,IAAI,QAAQ,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B,CAAC,CACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,wBAAwB,CAAC,MAAe;IAC/C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACjD,OAAO,EAAE,CAAC;KACX;IAED,MAAM,eAAe,GAAY,MAAM,CAAC,MAAM,CAAC,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE/E,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IACf,KAAK,IAAI,CAAC,GAAG,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QACpD,MAAM,KAAK,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC5C,KAAK,GAAG,CAAC,CAAC;YACV,MAAM;SACP;KACF;IAED,OAAO,eAAe;SACnB,KAAK,CAAC,KAAK,CAAC;SACZ,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SAC5B,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC;SACvB,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC","sourcesContent":["import { Primitive, Transaction, TransactionContext } from '@sentry/types';\nimport { getGlobalObject } from '@sentry/utils';\n\nimport { Location, ReactRouterInstrumentation } from './types';\n\n// Many of the types below had to be mocked out to prevent typescript issues\n// these types are required for correct functionality.\n\ntype HistoryV3 = {\n location?: Location;\n listen?(cb: (location: Location) => void): void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport type Route = { path?: string; childRoutes?: Route[] };\n\nexport type Match = (\n props: { location: Location; routes: Route[] },\n cb: (error?: Error, _redirectLocation?: Location, renderProps?: { routes?: Route[] }) => void,\n) => void;\n\nconst global = getGlobalObject<Window>();\n\n/**\n * Creates routing instrumentation for React Router v3\n * Works for React Router >= 3.2.0 and < 4.0.0\n *\n * @param history object from the `history` library\n * @param routes a list of all routes, should be\n * @param match `Router.match` utility\n */\nexport function reactRouterV3Instrumentation(\n history: HistoryV3,\n routes: Route[],\n match: Match,\n): ReactRouterInstrumentation {\n return (\n startTransaction: (context: TransactionContext) => Transaction | undefined,\n startTransactionOnPageLoad: boolean = true,\n startTransactionOnLocationChange: boolean = true,\n ) => {\n let activeTransaction: Transaction | undefined;\n let prevName: string | undefined;\n\n // Have to use global.location because history.location might not be defined.\n if (startTransactionOnPageLoad && global && global.location) {\n normalizeTransactionName(routes, global.location as unknown as Location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'pageload',\n tags: {\n 'routing.instrumentation': 'react-router-v3',\n },\n });\n });\n }\n\n if (startTransactionOnLocationChange && history.listen) {\n history.listen(location => {\n if (location.action === 'PUSH' || location.action === 'POP') {\n if (activeTransaction) {\n activeTransaction.finish();\n }\n const tags: Record<string, Primitive> = {\n 'routing.instrumentation': 'react-router-v3',\n };\n if (prevName) {\n tags.from = prevName;\n }\n normalizeTransactionName(routes, location, match, (localName: string) => {\n prevName = localName;\n activeTransaction = startTransaction({\n name: prevName,\n op: 'navigation',\n tags,\n });\n });\n }\n });\n }\n };\n}\n\n/**\n * Normalize transaction names using `Router.match`\n */\nfunction normalizeTransactionName(\n appRoutes: Route[],\n location: Location,\n match: Match,\n callback: (pathname: string) => void,\n): void {\n let name = location.pathname;\n match(\n {\n location,\n routes: appRoutes,\n },\n (error, _redirectLocation, renderProps) => {\n if (error || !renderProps) {\n return callback(name);\n }\n\n const routePath = getRouteStringFromRoutes(renderProps.routes || []);\n if (routePath.length === 0 || routePath === '/*') {\n return callback(name);\n }\n\n name = routePath;\n return callback(name);\n },\n );\n}\n\n/**\n * Generate route name from array of routes\n */\nfunction getRouteStringFromRoutes(routes: Route[]): string {\n if (!Array.isArray(routes) || routes.length === 0) {\n return '';\n }\n\n const routesWithPaths: Route[] = routes.filter((route: Route) => !!route.path);\n\n let index = -1;\n for (let x = routesWithPaths.length - 1; x >= 0; x--) {\n const route = routesWithPaths[x];\n if (route.path && route.path.startsWith('/')) {\n index = x;\n break;\n }\n }\n\n return routesWithPaths\n .slice(index)\n .filter(({ path }) => !!path)\n .map(({ path }) => path)\n .join('');\n}\n"]}