@sentry/react 6.13.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +92 -0
  3. package/dist/errorboundary.d.ts +59 -0
  4. package/dist/errorboundary.d.ts.map +1 -0
  5. package/dist/errorboundary.js +138 -0
  6. package/dist/errorboundary.js.map +1 -0
  7. package/dist/index.d.ts +8 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +21 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/profiler.d.ts +55 -0
  12. package/dist/profiler.d.ts.map +1 -0
  13. package/dist/profiler.js +239 -0
  14. package/dist/profiler.js.map +1 -0
  15. package/dist/reactrouter.d.ts +25 -0
  16. package/dist/reactrouter.d.ts.map +1 -0
  17. package/dist/reactrouter.js +119 -0
  18. package/dist/reactrouter.js.map +1 -0
  19. package/dist/reactrouterv3.d.ts +26 -0
  20. package/dist/reactrouterv3.d.ts.map +1 -0
  21. package/dist/reactrouterv3.js +105 -0
  22. package/dist/reactrouterv3.js.map +1 -0
  23. package/dist/redux.d.ts +33 -0
  24. package/dist/redux.d.ts.map +1 -0
  25. package/dist/redux.js +54 -0
  26. package/dist/redux.js.map +1 -0
  27. package/dist/sdk.d.ts +6 -0
  28. package/dist/sdk.d.ts.map +1 -0
  29. package/dist/sdk.js +21 -0
  30. package/dist/sdk.js.map +1 -0
  31. package/dist/types.d.ts +8 -0
  32. package/dist/types.d.ts.map +1 -0
  33. package/dist/types.js +2 -0
  34. package/dist/types.js.map +1 -0
  35. package/esm/errorboundary.d.ts +59 -0
  36. package/esm/errorboundary.d.ts.map +1 -0
  37. package/esm/errorboundary.js +136 -0
  38. package/esm/errorboundary.js.map +1 -0
  39. package/esm/index.d.ts +8 -0
  40. package/esm/index.d.ts.map +1 -0
  41. package/esm/index.js +8 -0
  42. package/esm/index.js.map +1 -0
  43. package/esm/profiler.d.ts +55 -0
  44. package/esm/profiler.d.ts.map +1 -0
  45. package/esm/profiler.js +235 -0
  46. package/esm/profiler.js.map +1 -0
  47. package/esm/reactrouter.d.ts +25 -0
  48. package/esm/reactrouter.d.ts.map +1 -0
  49. package/esm/reactrouter.js +115 -0
  50. package/esm/reactrouter.js.map +1 -0
  51. package/esm/reactrouterv3.d.ts +26 -0
  52. package/esm/reactrouterv3.d.ts.map +1 -0
  53. package/esm/reactrouterv3.js +103 -0
  54. package/esm/reactrouterv3.js.map +1 -0
  55. package/esm/redux.d.ts +33 -0
  56. package/esm/redux.d.ts.map +1 -0
  57. package/esm/redux.js +53 -0
  58. package/esm/redux.js.map +1 -0
  59. package/esm/sdk.d.ts +6 -0
  60. package/esm/sdk.d.ts.map +1 -0
  61. package/esm/sdk.js +19 -0
  62. package/esm/sdk.js.map +1 -0
  63. package/esm/types.d.ts +8 -0
  64. package/esm/types.d.ts.map +1 -0
  65. package/esm/types.js +1 -0
  66. package/esm/types.js.map +1 -0
  67. package/package.json +107 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Transaction, TransactionContext } from '@sentry/types';\n\nexport type Action = 'PUSH' | 'REPLACE' | 'POP';\n\nexport type Location = {\n pathname: string;\n action?: Action;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n} & Record<string, any>;\n\nexport type ReactRouterInstrumentation = <T extends Transaction>(\n startTransaction: (context: TransactionContext) => T | undefined,\n startTransactionOnPageLoad?: boolean,\n startTransactionOnLocationChange?: boolean,\n) => void;\n"]}
@@ -0,0 +1,59 @@
1
+ import { ReportDialogOptions, Scope } from '@sentry/browser';
2
+ import * as React from 'react';
3
+ export declare const UNKNOWN_COMPONENT = "unknown";
4
+ export declare type FallbackRender = (errorData: {
5
+ error: Error;
6
+ componentStack: string | null;
7
+ eventId: string | null;
8
+ resetError(): void;
9
+ }) => React.ReactElement;
10
+ export declare type ErrorBoundaryProps = {
11
+ /** If a Sentry report dialog should be rendered on error */
12
+ showDialog?: boolean;
13
+ /**
14
+ * Options to be passed into the Sentry report dialog.
15
+ * No-op if {@link showDialog} is false.
16
+ */
17
+ dialogOptions?: ReportDialogOptions;
18
+ /**
19
+ * A fallback component that gets rendered when the error boundary encounters an error.
20
+ *
21
+ * Can either provide a React Component, or a function that returns React Component as
22
+ * a valid fallback prop. If a function is provided, the function will be called with
23
+ * the error, the component stack, and an function that resets the error boundary on error.
24
+ *
25
+ */
26
+ fallback?: React.ReactElement | FallbackRender;
27
+ /** Called when the error boundary encounters an error */
28
+ onError?(error: Error, componentStack: string, eventId: string): void;
29
+ /** Called on componentDidMount() */
30
+ onMount?(): void;
31
+ /** Called if resetError() is called from the fallback render props function */
32
+ onReset?(error: Error | null, componentStack: string | null, eventId: string | null): void;
33
+ /** Called on componentWillUnmount() */
34
+ onUnmount?(error: Error | null, componentStack: string | null, eventId: string | null): void;
35
+ /** Called before the error is captured by Sentry, allows for you to add tags or context using the scope */
36
+ beforeCapture?(scope: Scope, error: Error | null, componentStack: string | null): void;
37
+ };
38
+ declare type ErrorBoundaryState = {
39
+ componentStack: string | null;
40
+ error: Error | null;
41
+ eventId: string | null;
42
+ };
43
+ /**
44
+ * A ErrorBoundary component that logs errors to Sentry. Requires React >= 16.
45
+ * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the
46
+ * Sentry React SDK ErrorBoundary caught an error invoking your application code. This
47
+ * is expected behavior and NOT indicative of a bug with the Sentry React SDK.
48
+ */
49
+ declare class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
50
+ state: ErrorBoundaryState;
51
+ componentDidCatch(error: Error, { componentStack }: React.ErrorInfo): void;
52
+ componentDidMount(): void;
53
+ componentWillUnmount(): void;
54
+ resetErrorBoundary: () => void;
55
+ render(): React.ReactNode;
56
+ }
57
+ declare function withErrorBoundary<P extends Record<string, any>>(WrappedComponent: React.ComponentType<P>, errorBoundaryOptions: ErrorBoundaryProps): React.FC<P>;
58
+ export { ErrorBoundary, withErrorBoundary };
59
+ //# sourceMappingURL=errorboundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorboundary.d.ts","sourceRoot":"","sources":["../src/errorboundary.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,mBAAmB,EACnB,KAAK,EAGN,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,oBAAY,cAAc,GAAG,CAAC,SAAS,EAAE;IACvC,KAAK,EAAE,KAAK,CAAC;IACb,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,UAAU,IAAI,IAAI,CAAC;CACpB,KAAK,KAAK,CAAC,YAAY,CAAC;AAEzB,oBAAY,kBAAkB,GAAG;IAC/B,4DAA4D;IAC5D,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,YAAY,GAAG,cAAc,CAAC;IAC/C,yDAAyD;IACzD,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACtE,oCAAoC;IACpC,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB,gFAAgF;IAChF,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAC3F,uCAAuC;IACvC,SAAS,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAC7F,2GAA2G;IAC3G,aAAa,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CACxF,CAAC;AAEF,aAAK,kBAAkB,GAAG;IACxB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AA6CF;;;;;GAKG;AACH,cAAM,aAAc,SAAQ,KAAK,CAAC,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IAC1E,KAAK,EAAE,kBAAkB,CAAiB;IAE1C,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,cAAc,EAAE,EAAE,KAAK,CAAC,SAAS,GAAG,IAAI;IAqB1E,iBAAiB,IAAI,IAAI;IAOzB,oBAAoB,IAAI,IAAI;IAQ5B,kBAAkB,EAAE,MAAM,IAAI,CAOnC;IAEK,MAAM,IAAI,KAAK,CAAC,SAAS;CA6BjC;AAGD,iBAAS,iBAAiB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACtD,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EACxC,oBAAoB,EAAE,kBAAkB,GACvC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAeb;AAED,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,136 @@
1
+ import { __assign, __extends, __read, __spread } from "tslib";
2
+ import { captureEvent, captureException, eventFromException, showReportDialog, withScope, } from '@sentry/browser';
3
+ import { logger, parseSemver } from '@sentry/utils';
4
+ import hoistNonReactStatics from 'hoist-non-react-statics';
5
+ import * as React from 'react';
6
+ var reactVersion = parseSemver(React.version);
7
+ export var UNKNOWN_COMPONENT = 'unknown';
8
+ var INITIAL_STATE = {
9
+ componentStack: null,
10
+ error: null,
11
+ eventId: null,
12
+ };
13
+ /**
14
+ * Logs react error boundary errors to Sentry. If on React version >= 17, creates stack trace
15
+ * from componentStack param, otherwise relies on error param for stacktrace.
16
+ *
17
+ * @param error An error captured by React Error Boundary
18
+ * @param componentStack The component stacktrace
19
+ */
20
+ function captureReactErrorBoundaryError(error, componentStack) {
21
+ var errorBoundaryError = new Error(error.message);
22
+ errorBoundaryError.name = "React ErrorBoundary " + errorBoundaryError.name;
23
+ errorBoundaryError.stack = componentStack;
24
+ var errorBoundaryEvent = {};
25
+ void eventFromException({}, errorBoundaryError).then(function (e) {
26
+ errorBoundaryEvent = e;
27
+ });
28
+ if (errorBoundaryEvent.exception &&
29
+ Array.isArray(errorBoundaryEvent.exception.values) &&
30
+ reactVersion.major &&
31
+ reactVersion.major >= 17) {
32
+ var originalEvent_1 = {};
33
+ void eventFromException({}, error).then(function (e) {
34
+ originalEvent_1 = e;
35
+ });
36
+ if (originalEvent_1.exception && Array.isArray(originalEvent_1.exception.values)) {
37
+ originalEvent_1.exception.values = __spread(errorBoundaryEvent.exception.values, originalEvent_1.exception.values);
38
+ }
39
+ return captureEvent(originalEvent_1);
40
+ }
41
+ return captureException(error, { contexts: { react: { componentStack: componentStack } } });
42
+ }
43
+ /**
44
+ * A ErrorBoundary component that logs errors to Sentry. Requires React >= 16.
45
+ * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the
46
+ * Sentry React SDK ErrorBoundary caught an error invoking your application code. This
47
+ * is expected behavior and NOT indicative of a bug with the Sentry React SDK.
48
+ */
49
+ var ErrorBoundary = /** @class */ (function (_super) {
50
+ __extends(ErrorBoundary, _super);
51
+ function ErrorBoundary() {
52
+ var _this = _super !== null && _super.apply(this, arguments) || this;
53
+ _this.state = INITIAL_STATE;
54
+ _this.resetErrorBoundary = function () {
55
+ var onReset = _this.props.onReset;
56
+ var _a = _this.state, error = _a.error, componentStack = _a.componentStack, eventId = _a.eventId;
57
+ if (onReset) {
58
+ onReset(error, componentStack, eventId);
59
+ }
60
+ _this.setState(INITIAL_STATE);
61
+ };
62
+ return _this;
63
+ }
64
+ ErrorBoundary.prototype.componentDidCatch = function (error, _a) {
65
+ var _this = this;
66
+ var componentStack = _a.componentStack;
67
+ var _b = this.props, beforeCapture = _b.beforeCapture, onError = _b.onError, showDialog = _b.showDialog, dialogOptions = _b.dialogOptions;
68
+ withScope(function (scope) {
69
+ if (beforeCapture) {
70
+ beforeCapture(scope, error, componentStack);
71
+ }
72
+ var eventId = captureReactErrorBoundaryError(error, componentStack);
73
+ if (onError) {
74
+ onError(error, componentStack, eventId);
75
+ }
76
+ if (showDialog) {
77
+ showReportDialog(__assign(__assign({}, dialogOptions), { eventId: eventId }));
78
+ }
79
+ // componentDidCatch is used over getDerivedStateFromError
80
+ // so that componentStack is accessible through state.
81
+ _this.setState({ error: error, componentStack: componentStack, eventId: eventId });
82
+ });
83
+ };
84
+ ErrorBoundary.prototype.componentDidMount = function () {
85
+ var onMount = this.props.onMount;
86
+ if (onMount) {
87
+ onMount();
88
+ }
89
+ };
90
+ ErrorBoundary.prototype.componentWillUnmount = function () {
91
+ var _a = this.state, error = _a.error, componentStack = _a.componentStack, eventId = _a.eventId;
92
+ var onUnmount = this.props.onUnmount;
93
+ if (onUnmount) {
94
+ onUnmount(error, componentStack, eventId);
95
+ }
96
+ };
97
+ ErrorBoundary.prototype.render = function () {
98
+ var _a = this.props, fallback = _a.fallback, children = _a.children;
99
+ var _b = this.state, error = _b.error, componentStack = _b.componentStack, eventId = _b.eventId;
100
+ if (error) {
101
+ var element = undefined;
102
+ if (typeof fallback === 'function') {
103
+ element = fallback({ error: error, componentStack: componentStack, resetError: this.resetErrorBoundary, eventId: eventId });
104
+ }
105
+ else {
106
+ element = fallback;
107
+ }
108
+ if (React.isValidElement(element)) {
109
+ return element;
110
+ }
111
+ if (fallback) {
112
+ logger.warn('fallback did not produce a valid ReactElement');
113
+ }
114
+ // Fail gracefully if no fallback provided or is not valid
115
+ return null;
116
+ }
117
+ if (typeof children === 'function') {
118
+ return children();
119
+ }
120
+ return children;
121
+ };
122
+ return ErrorBoundary;
123
+ }(React.Component));
124
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
125
+ function withErrorBoundary(WrappedComponent, errorBoundaryOptions) {
126
+ var componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
127
+ var Wrapped = function (props) { return (React.createElement(ErrorBoundary, __assign({}, errorBoundaryOptions),
128
+ React.createElement(WrappedComponent, __assign({}, props)))); };
129
+ Wrapped.displayName = "errorBoundary(" + componentDisplayName + ")";
130
+ // Copy over static methods from Wrapped component to Profiler HOC
131
+ // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
132
+ hoistNonReactStatics(Wrapped, WrappedComponent);
133
+ return Wrapped;
134
+ }
135
+ export { ErrorBoundary, withErrorBoundary };
136
+ //# sourceMappingURL=errorboundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorboundary.js","sourceRoot":"","sources":["../src/errorboundary.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAGlB,gBAAgB,EAChB,SAAS,GACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,IAAM,YAAY,GAAG,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAEhD,MAAM,CAAC,IAAM,iBAAiB,GAAG,SAAS,CAAC;AA4C3C,IAAM,aAAa,GAAG;IACpB,cAAc,EAAE,IAAI;IACpB,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,IAAI;CACd,CAAC;AAEF;;;;;;GAMG;AACH,SAAS,8BAA8B,CAAC,KAAY,EAAE,cAAsB;IAC1E,IAA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GAAG,mBAAiB,oBAAoB,MAAG,CAAC;IAE/D,kEAAkE;IAClE,gGAAgG;IAChG,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAChD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import {\n captureEvent,\n captureException,\n eventFromException,\n ReportDialogOptions,\n Scope,\n showReportDialog,\n withScope,\n} from '@sentry/browser';\nimport { Event } from '@sentry/types';\nimport { logger, parseSemver } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nconst reactVersion = parseSemver(React.version);\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 /** 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: string | 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 * Logs react error boundary errors to Sentry. If on React version >= 17, creates stack trace\n * from componentStack param, otherwise relies on error param for stacktrace.\n *\n * @param error An error captured by React Error Boundary\n * @param componentStack The component stacktrace\n */\nfunction captureReactErrorBoundaryError(error: Error, componentStack: string): string {\n const errorBoundaryError = new Error(error.message);\n errorBoundaryError.name = `React ErrorBoundary ${errorBoundaryError.name}`;\n errorBoundaryError.stack = componentStack;\n\n let errorBoundaryEvent: Event = {};\n void eventFromException({}, errorBoundaryError).then(e => {\n errorBoundaryEvent = e;\n });\n\n if (\n errorBoundaryEvent.exception &&\n Array.isArray(errorBoundaryEvent.exception.values) &&\n reactVersion.major &&\n reactVersion.major >= 17\n ) {\n let originalEvent: Event = {};\n void eventFromException({}, error).then(e => {\n originalEvent = e;\n });\n if (originalEvent.exception && Array.isArray(originalEvent.exception.values)) {\n originalEvent.exception.values = [...errorBoundaryEvent.exception.values, ...originalEvent.exception.values];\n }\n\n return captureEvent(originalEvent);\n }\n\n return captureException(error, { contexts: { react: { componentStack } } });\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, { componentStack }: React.ErrorInfo): void {\n const { beforeCapture, onError, showDialog, dialogOptions } = this.props;\n\n withScope(scope => {\n if (beforeCapture) {\n beforeCapture(scope, error, componentStack);\n }\n const eventId = captureReactErrorBoundaryError(error, 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 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();\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 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 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"]}
package/esm/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from '@sentry/browser';
2
+ export { init } from './sdk';
3
+ export { Profiler, withProfiler, useProfiler } from './profiler';
4
+ export { ErrorBoundary, withErrorBoundary } from './errorboundary';
5
+ export { createReduxEnhancer } from './redux';
6
+ export { reactRouterV3Instrumentation } from './reactrouterv3';
7
+ export { reactRouterV4Instrumentation, reactRouterV5Instrumentation, withSentryRouting } from './reactrouter';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
package/esm/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export * from '@sentry/browser';
2
+ export { init } from './sdk';
3
+ export { Profiler, withProfiler, useProfiler } from './profiler';
4
+ export { ErrorBoundary, withErrorBoundary } from './errorboundary';
5
+ export { createReduxEnhancer } from './redux';
6
+ export { reactRouterV3Instrumentation } from './reactrouterv3';
7
+ export { reactRouterV4Instrumentation, reactRouterV5Instrumentation, withSentryRouting } from './reactrouter';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC","sourcesContent":["export * from '@sentry/browser';\n\nexport { init } from './sdk';\nexport { Profiler, withProfiler, useProfiler } from './profiler';\nexport { ErrorBoundary, withErrorBoundary } from './errorboundary';\nexport { createReduxEnhancer } from './redux';\nexport { reactRouterV3Instrumentation } from './reactrouterv3';\nexport { reactRouterV4Instrumentation, reactRouterV5Instrumentation, withSentryRouting } from './reactrouter';\n"]}
@@ -0,0 +1,55 @@
1
+ import { Hub } from '@sentry/browser';
2
+ import { Span, Transaction } from '@sentry/types';
3
+ import * as React from 'react';
4
+ export declare const UNKNOWN_COMPONENT = "unknown";
5
+ export declare type ProfilerProps = {
6
+ name: string;
7
+ disabled?: boolean;
8
+ includeRender?: boolean;
9
+ includeUpdates?: boolean;
10
+ updateProps: {
11
+ [key: string]: unknown;
12
+ };
13
+ };
14
+ /**
15
+ * The Profiler component leverages Sentry's Tracing integration to generate
16
+ * spans based on component lifecycles.
17
+ */
18
+ declare class Profiler extends React.Component<ProfilerProps> {
19
+ /**
20
+ * The span of the mount activity
21
+ * Made protected for the React Native SDK to access
22
+ */
23
+ protected _mountSpan: Span | undefined;
24
+ private _mountActivity;
25
+ static defaultProps: Partial<ProfilerProps>;
26
+ constructor(props: ProfilerProps);
27
+ componentDidMount(): void;
28
+ componentDidUpdate({ updateProps, includeUpdates }: ProfilerProps): void;
29
+ componentWillUnmount(): void;
30
+ render(): React.ReactNode;
31
+ }
32
+ /**
33
+ * withProfiler is a higher order component that wraps a
34
+ * component in a {@link Profiler} component. It is recommended that
35
+ * the higher order component be used over the regular {@link Profiler} component.
36
+ *
37
+ * @param WrappedComponent component that is wrapped by Profiler
38
+ * @param options the {@link ProfilerProps} you can pass into the Profiler
39
+ */
40
+ declare function withProfiler<P extends Record<string, any>>(WrappedComponent: React.ComponentType<P>, options?: Pick<Partial<ProfilerProps>, Exclude<keyof ProfilerProps, 'updateProps'>>): React.FC<P>;
41
+ /**
42
+ *
43
+ * `useProfiler` is a React hook that profiles a React component.
44
+ *
45
+ * Requires React 16.8 or above.
46
+ * @param name displayName of component being profiled
47
+ */
48
+ declare function useProfiler(name: string, options?: {
49
+ disabled?: boolean;
50
+ hasRenderSpan?: boolean;
51
+ }): void;
52
+ export { withProfiler, Profiler, useProfiler };
53
+ /** Grabs active transaction off scope */
54
+ export declare function getActiveTransaction<T extends Transaction>(hub?: Hub): T | undefined;
55
+ //# sourceMappingURL=profiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiler.d.ts","sourceRoot":"","sources":["../src/profiler.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAiC,IAAI,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGjF,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,eAAO,MAAM,iBAAiB,YAAY,CAAC;AA8D3C,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,OAAO,CAAC,cAAc,CAAuB;IAG7C,OAAc,YAAY,EAAE,OAAO,CAAC,aAAa,CAAC,CAIhD;gBAEiB,KAAK,EAAE,aAAa;IAyBhC,iBAAiB,IAAI,IAAI;IAYzB,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,235 @@
1
+ import { __assign, __extends, __read } from "tslib";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ import { getCurrentHub } from '@sentry/browser';
4
+ import { timestampWithMs } from '@sentry/utils';
5
+ import hoistNonReactStatics from 'hoist-non-react-statics';
6
+ import * as React from 'react';
7
+ export var UNKNOWN_COMPONENT = 'unknown';
8
+ var TRACING_GETTER = {
9
+ id: 'Tracing',
10
+ };
11
+ var globalTracingIntegration = null;
12
+ /** @deprecated remove when @sentry/apm no longer used */
13
+ var getTracingIntegration = function () {
14
+ if (globalTracingIntegration) {
15
+ return globalTracingIntegration;
16
+ }
17
+ globalTracingIntegration = getCurrentHub().getIntegration(TRACING_GETTER);
18
+ return globalTracingIntegration;
19
+ };
20
+ /**
21
+ * pushActivity creates an new react activity.
22
+ * Is a no-op if Tracing integration is not valid
23
+ * @param name displayName of component that started activity
24
+ * @deprecated remove when @sentry/apm no longer used
25
+ */
26
+ function pushActivity(name, op) {
27
+ if (globalTracingIntegration === null) {
28
+ return null;
29
+ }
30
+ return globalTracingIntegration.constructor.pushActivity(name, {
31
+ description: "<" + name + ">",
32
+ op: "react." + op,
33
+ });
34
+ }
35
+ /**
36
+ * popActivity removes a React activity.
37
+ * Is a no-op if Tracing integration is not valid.
38
+ * @param activity id of activity that is being popped
39
+ * @deprecated remove when @sentry/apm no longer used
40
+ */
41
+ function popActivity(activity) {
42
+ if (activity === null || globalTracingIntegration === null) {
43
+ return;
44
+ }
45
+ globalTracingIntegration.constructor.popActivity(activity);
46
+ }
47
+ /**
48
+ * Obtain a span given an activity id.
49
+ * Is a no-op if Tracing integration is not valid.
50
+ * @param activity activity id associated with obtained span
51
+ * @deprecated remove when @sentry/apm no longer used
52
+ */
53
+ function getActivitySpan(activity) {
54
+ if (activity === null || globalTracingIntegration === null) {
55
+ return undefined;
56
+ }
57
+ return globalTracingIntegration.constructor.getActivitySpan(activity);
58
+ }
59
+ /**
60
+ * The Profiler component leverages Sentry's Tracing integration to generate
61
+ * spans based on component lifecycles.
62
+ */
63
+ var Profiler = /** @class */ (function (_super) {
64
+ __extends(Profiler, _super);
65
+ function Profiler(props) {
66
+ var _this = _super.call(this, props) || this;
67
+ /**
68
+ * The span of the mount activity
69
+ * Made protected for the React Native SDK to access
70
+ */
71
+ _this._mountSpan = undefined;
72
+ // The activity representing how long it takes to mount a component.
73
+ _this._mountActivity = null;
74
+ var _a = _this.props, name = _a.name, _b = _a.disabled, disabled = _b === void 0 ? false : _b;
75
+ if (disabled) {
76
+ return _this;
77
+ }
78
+ // If they are using @sentry/apm, we need to push/pop activities
79
+ // eslint-disable-next-line deprecation/deprecation
80
+ if (getTracingIntegration()) {
81
+ // eslint-disable-next-line deprecation/deprecation
82
+ _this._mountActivity = pushActivity(name, 'mount');
83
+ }
84
+ else {
85
+ var activeTransaction = getActiveTransaction();
86
+ if (activeTransaction) {
87
+ _this._mountSpan = activeTransaction.startChild({
88
+ description: "<" + name + ">",
89
+ op: 'react.mount',
90
+ });
91
+ }
92
+ }
93
+ return _this;
94
+ }
95
+ // If a component mounted, we can finish the mount activity.
96
+ Profiler.prototype.componentDidMount = function () {
97
+ if (this._mountSpan) {
98
+ this._mountSpan.finish();
99
+ }
100
+ else {
101
+ // eslint-disable-next-line deprecation/deprecation
102
+ this._mountSpan = getActivitySpan(this._mountActivity);
103
+ // eslint-disable-next-line deprecation/deprecation
104
+ popActivity(this._mountActivity);
105
+ this._mountActivity = null;
106
+ }
107
+ };
108
+ Profiler.prototype.componentDidUpdate = function (_a) {
109
+ var _this = this;
110
+ var updateProps = _a.updateProps, _b = _a.includeUpdates, includeUpdates = _b === void 0 ? true : _b;
111
+ // Only generate an update span if hasUpdateSpan is true, if there is a valid mountSpan,
112
+ // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.
113
+ // We are just trying to give baseline clues for further investigation.
114
+ if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {
115
+ // See what props haved changed between the previous props, and the current props. This is
116
+ // set as data on the span. We just store the prop keys as the values could be potenially very large.
117
+ var changedProps = Object.keys(updateProps).filter(function (k) { return updateProps[k] !== _this.props.updateProps[k]; });
118
+ if (changedProps.length > 0) {
119
+ // The update span is a point in time span with 0 duration, just signifying that the component
120
+ // has been updated.
121
+ var now = timestampWithMs();
122
+ this._mountSpan.startChild({
123
+ data: {
124
+ changedProps: changedProps,
125
+ },
126
+ description: "<" + this.props.name + ">",
127
+ endTimestamp: now,
128
+ op: "react.update",
129
+ startTimestamp: now,
130
+ });
131
+ }
132
+ }
133
+ };
134
+ // If a component is unmounted, we can say it is no longer on the screen.
135
+ // This means we can finish the span representing the component render.
136
+ Profiler.prototype.componentWillUnmount = function () {
137
+ var _a = this.props, name = _a.name, _b = _a.includeRender, includeRender = _b === void 0 ? true : _b;
138
+ if (this._mountSpan && includeRender) {
139
+ // If we were able to obtain the spanId of the mount activity, we should set the
140
+ // next activity as a child to the component mount activity.
141
+ this._mountSpan.startChild({
142
+ description: "<" + name + ">",
143
+ endTimestamp: timestampWithMs(),
144
+ op: "react.render",
145
+ startTimestamp: this._mountSpan.endTimestamp,
146
+ });
147
+ }
148
+ };
149
+ Profiler.prototype.render = function () {
150
+ return this.props.children;
151
+ };
152
+ // eslint-disable-next-line @typescript-eslint/member-ordering
153
+ Profiler.defaultProps = {
154
+ disabled: false,
155
+ includeRender: true,
156
+ includeUpdates: true,
157
+ };
158
+ return Profiler;
159
+ }(React.Component));
160
+ /**
161
+ * withProfiler is a higher order component that wraps a
162
+ * component in a {@link Profiler} component. It is recommended that
163
+ * the higher order component be used over the regular {@link Profiler} component.
164
+ *
165
+ * @param WrappedComponent component that is wrapped by Profiler
166
+ * @param options the {@link ProfilerProps} you can pass into the Profiler
167
+ */
168
+ function withProfiler(WrappedComponent,
169
+ // We do not want to have `updateProps` given in options, it is instead filled through the HOC.
170
+ options) {
171
+ var componentDisplayName = (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
172
+ var Wrapped = function (props) { return (React.createElement(Profiler, __assign({}, options, { name: componentDisplayName, updateProps: props }),
173
+ React.createElement(WrappedComponent, __assign({}, props)))); };
174
+ Wrapped.displayName = "profiler(" + componentDisplayName + ")";
175
+ // Copy over static methods from Wrapped component to Profiler HOC
176
+ // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
177
+ hoistNonReactStatics(Wrapped, WrappedComponent);
178
+ return Wrapped;
179
+ }
180
+ /**
181
+ *
182
+ * `useProfiler` is a React hook that profiles a React component.
183
+ *
184
+ * Requires React 16.8 or above.
185
+ * @param name displayName of component being profiled
186
+ */
187
+ function useProfiler(name, options) {
188
+ if (options === void 0) { options = {
189
+ disabled: false,
190
+ hasRenderSpan: true,
191
+ }; }
192
+ var _a = __read(React.useState(function () {
193
+ if (options && options.disabled) {
194
+ return undefined;
195
+ }
196
+ var activeTransaction = getActiveTransaction();
197
+ if (activeTransaction) {
198
+ return activeTransaction.startChild({
199
+ description: "<" + name + ">",
200
+ op: 'react.mount',
201
+ });
202
+ }
203
+ return undefined;
204
+ }), 1), mountSpan = _a[0];
205
+ React.useEffect(function () {
206
+ if (mountSpan) {
207
+ mountSpan.finish();
208
+ }
209
+ return function () {
210
+ if (mountSpan && options.hasRenderSpan) {
211
+ mountSpan.startChild({
212
+ description: "<" + name + ">",
213
+ endTimestamp: timestampWithMs(),
214
+ op: "react.render",
215
+ startTimestamp: mountSpan.endTimestamp,
216
+ });
217
+ }
218
+ };
219
+ // We only want this to run once.
220
+ // eslint-disable-next-line react-hooks/exhaustive-deps
221
+ }, []);
222
+ }
223
+ export { withProfiler, Profiler, useProfiler };
224
+ /** Grabs active transaction off scope */
225
+ export function getActiveTransaction(hub) {
226
+ if (hub === void 0) { hub = getCurrentHub(); }
227
+ if (hub) {
228
+ var scope = hub.getScope();
229
+ if (scope) {
230
+ return scope.getTransaction();
231
+ }
232
+ }
233
+ return undefined;
234
+ }
235
+ //# sourceMappingURL=profiler.js.map