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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +2 -3
  2. package/cjs/constants.js +12 -5
  3. package/cjs/constants.js.map +1 -1
  4. package/cjs/errorboundary.js +139 -112
  5. package/cjs/errorboundary.js.map +1 -1
  6. package/cjs/flags.js +7 -3
  7. package/cjs/flags.js.map +1 -1
  8. package/cjs/index.js +30 -21
  9. package/cjs/index.js.map +1 -1
  10. package/cjs/profiler.js +178 -147
  11. package/cjs/profiler.js.map +1 -1
  12. package/cjs/reactrouter.js +147 -100
  13. package/cjs/reactrouter.js.map +1 -1
  14. package/cjs/reactrouterv3.js +107 -83
  15. package/cjs/reactrouterv3.js.map +1 -1
  16. package/cjs/reactrouterv6.js +163 -0
  17. package/cjs/reactrouterv6.js.map +1 -0
  18. package/cjs/redux.js +51 -42
  19. package/cjs/redux.js.map +1 -1
  20. package/cjs/sdk.js +18 -15
  21. package/cjs/sdk.js.map +1 -1
  22. package/esm/constants.js +8 -4
  23. package/esm/constants.js.map +1 -1
  24. package/esm/errorboundary.js +124 -107
  25. package/esm/errorboundary.js.map +1 -1
  26. package/esm/flags.js +5 -2
  27. package/esm/flags.js.map +1 -1
  28. package/esm/index.js +8 -7
  29. package/esm/index.js.map +1 -1
  30. package/esm/profiler.js +161 -140
  31. package/esm/profiler.js.map +1 -1
  32. package/esm/reactrouter.js +133 -94
  33. package/esm/reactrouter.js.map +1 -1
  34. package/esm/reactrouterv3.js +103 -79
  35. package/esm/reactrouterv3.js.map +1 -1
  36. package/esm/reactrouterv6.js +153 -0
  37. package/esm/reactrouterv6.js.map +1 -0
  38. package/esm/redux.js +49 -41
  39. package/esm/redux.js.map +1 -1
  40. package/esm/sdk.js +17 -14
  41. package/esm/sdk.js.map +1 -1
  42. package/package.json +5 -5
  43. package/types/errorboundary.d.ts +1 -0
  44. package/types/errorboundary.d.ts.map +1 -1
  45. package/types/index.d.ts +1 -0
  46. package/types/index.d.ts.map +1 -1
  47. package/types/reactrouterv6.d.ts +27 -0
  48. package/types/reactrouterv6.d.ts.map +1 -0
  49. package/cjs/constants.d.ts +0 -4
  50. package/cjs/constants.d.ts.map +0 -1
  51. package/cjs/errorboundary.d.ts +0 -62
  52. package/cjs/errorboundary.d.ts.map +0 -1
  53. package/cjs/flags.d.ts +0 -3
  54. package/cjs/flags.d.ts.map +0 -1
  55. package/cjs/index.d.ts +0 -8
  56. package/cjs/index.d.ts.map +0 -1
  57. package/cjs/profiler.d.ts +0 -54
  58. package/cjs/profiler.d.ts.map +0 -1
  59. package/cjs/reactrouter.d.ts +0 -25
  60. package/cjs/reactrouter.d.ts.map +0 -1
  61. package/cjs/reactrouterv3.d.ts +0 -26
  62. package/cjs/reactrouterv3.d.ts.map +0 -1
  63. package/cjs/redux.d.ts +0 -33
  64. package/cjs/redux.d.ts.map +0 -1
  65. package/cjs/sdk.d.ts +0 -6
  66. package/cjs/sdk.d.ts.map +0 -1
  67. package/cjs/types.d.ts +0 -8
  68. package/cjs/types.d.ts.map +0 -1
  69. package/cjs/types.js +0 -2
  70. package/cjs/types.js.map +0 -1
  71. package/esm/constants.d.ts +0 -4
  72. package/esm/constants.d.ts.map +0 -1
  73. package/esm/errorboundary.d.ts +0 -62
  74. package/esm/errorboundary.d.ts.map +0 -1
  75. package/esm/flags.d.ts +0 -3
  76. package/esm/flags.d.ts.map +0 -1
  77. package/esm/index.d.ts +0 -8
  78. package/esm/index.d.ts.map +0 -1
  79. package/esm/profiler.d.ts +0 -54
  80. package/esm/profiler.d.ts.map +0 -1
  81. package/esm/reactrouter.d.ts +0 -25
  82. package/esm/reactrouter.d.ts.map +0 -1
  83. package/esm/reactrouterv3.d.ts +0 -26
  84. package/esm/reactrouterv3.d.ts.map +0 -1
  85. package/esm/redux.d.ts +0 -33
  86. package/esm/redux.d.ts.map +0 -1
  87. package/esm/sdk.d.ts +0 -6
  88. package/esm/sdk.d.ts.map +0 -1
  89. package/esm/types.d.ts +0 -8
  90. package/esm/types.d.ts.map +0 -1
  91. package/esm/types.js +0 -1
  92. package/esm/types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"errorboundary.js","sourceRoot":"","sources":["../../src/errorboundary.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAA8B,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,IAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACxC,OAAO,KAAK,KAAK,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACpD,CAAC;AAED,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;;;;;GAKG;AACH;IAA4B,iCAAuD;IAAnF;QAAA,qEAyFC;QAxFQ,WAAK,GAAuB,aAAa,CAAC;QAkD1C,wBAAkB,GAAe;YAC9B,IAAA,6BAAO,CAAgB;YACzB,IAAA,gBAA+C,EAA7C,gBAAK,EAAE,kCAAc,EAAE,oBAAsB,CAAC;YACtD,IAAI,OAAO,EAAE;gBACX,OAAO,CAAC,KAAK,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;aACzC;YACD,KAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QAC/B,CAAC,CAAC;;IA+BJ,CAAC;IAtF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AC;IAExG,IAAM,OAAO,GAAgB,UAAC,KAAQ,IAAK,OAAA,CACzC,oBAAC,aAAa,eAAK,oBAAoB;QACrC,oBAAC,gBAAgB,eAAK,KAAK,EAAI,CACjB,CACjB,EAJ0C,CAI1C,CAAC;IAEF,sEAAsE;IACtE,OAAO,CAAC,WAAW,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 { captureException, ReportDialogOptions, Scope, showReportDialog, withScope } from '@sentry/browser';\nimport { logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { IS_DEBUG_BUILD } from './flags';\n\nexport function isAtLeastReact17(version: string): boolean {\n const major = version.match(/^([^.]+)/);\n return major !== null && parseInt(major[0]) >= 17;\n}\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type FallbackRender = (errorData: {\n error: Error;\n componentStack: string | null;\n eventId: string | null;\n resetError(): void;\n}) => React.ReactElement;\n\nexport type ErrorBoundaryProps = {\n /** If a Sentry report dialog should be rendered on error */\n showDialog?: boolean;\n /**\n * Options to be passed into the Sentry report dialog.\n * No-op if {@link showDialog} is false.\n */\n dialogOptions?: ReportDialogOptions;\n /**\n * A fallback component that gets rendered when the error boundary encounters an error.\n *\n * Can either provide a React Component, or a function that returns React Component as\n * a valid fallback prop. If a function is provided, the function will be called with\n * the error, the component stack, and an function that resets the error boundary on error.\n *\n */\n fallback?: React.ReactElement | FallbackRender;\n /** Called when the error boundary encounters an error */\n onError?(error: Error, componentStack: string, eventId: string): void;\n /** Called on componentDidMount() */\n onMount?(): void;\n /** Called if resetError() is called from the fallback render props function */\n onReset?(error: Error | null, componentStack: string | null, eventId: string | null): void;\n /** Called on componentWillUnmount() */\n onUnmount?(error: Error | null, componentStack: string | null, eventId: string | null): void;\n /** Called before the error is captured by Sentry, allows for you to add tags or context using the scope */\n beforeCapture?(scope: Scope, error: Error | null, componentStack: string | null): void;\n};\n\ntype ErrorBoundaryState = {\n componentStack: React.ErrorInfo['componentStack'] | null;\n error: Error | null;\n eventId: string | null;\n};\n\nconst INITIAL_STATE = {\n componentStack: null,\n error: null,\n eventId: null,\n};\n\n/**\n * A ErrorBoundary component that logs errors to Sentry. Requires React >= 16.\n * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the\n * Sentry React SDK ErrorBoundary caught an error invoking your application code. This\n * is expected behavior and NOT indicative of a bug with the Sentry React SDK.\n */\nclass ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {\n public state: ErrorBoundaryState = INITIAL_STATE;\n\n public componentDidCatch(error: Error & { cause?: Error }, { componentStack }: React.ErrorInfo): void {\n const { beforeCapture, onError, showDialog, dialogOptions } = this.props;\n\n withScope(scope => {\n // If on React version >= 17, create stack trace from componentStack param and links\n // to to the original error using `error.cause` otherwise relies on error param for stacktrace.\n // Linking errors requires the `LinkedErrors` integration be enabled.\n if (isAtLeastReact17(React.version)) {\n const errorBoundaryError = new Error(error.message);\n errorBoundaryError.name = `React ErrorBoundary ${errorBoundaryError.name}`;\n errorBoundaryError.stack = componentStack;\n\n // Using the `LinkedErrors` integration to link the errors together.\n error.cause = errorBoundaryError;\n }\n\n if (beforeCapture) {\n beforeCapture(scope, error, componentStack);\n }\n const eventId = captureException(error, { contexts: { react: { componentStack } } });\n if (onError) {\n onError(error, componentStack, eventId);\n }\n if (showDialog) {\n showReportDialog({ ...dialogOptions, eventId });\n }\n\n // componentDidCatch is used over getDerivedStateFromError\n // so that componentStack is accessible through state.\n this.setState({ error, componentStack, eventId });\n });\n }\n\n public componentDidMount(): void {\n const { onMount } = this.props;\n if (onMount) {\n onMount();\n }\n }\n\n public componentWillUnmount(): void {\n const { error, componentStack, eventId } = this.state;\n const { onUnmount } = this.props;\n if (onUnmount) {\n onUnmount(error, componentStack, eventId);\n }\n }\n\n public resetErrorBoundary: () => void = () => {\n const { onReset } = this.props;\n const { error, componentStack, eventId } = this.state;\n if (onReset) {\n onReset(error, componentStack, eventId);\n }\n this.setState(INITIAL_STATE);\n };\n\n public render(): React.ReactNode {\n const { fallback, children } = this.props;\n const { error, componentStack, eventId } = this.state;\n\n if (error) {\n let element: React.ReactElement | undefined = undefined;\n if (typeof fallback === 'function') {\n element = fallback({ error, componentStack, resetError: this.resetErrorBoundary, eventId });\n } else {\n element = fallback;\n }\n\n if (React.isValidElement(element)) {\n return element;\n }\n\n if (fallback) {\n IS_DEBUG_BUILD && logger.warn('fallback did not produce a valid ReactElement');\n }\n\n // Fail gracefully if no fallback provided or is not valid\n return null;\n }\n\n if (typeof children === 'function') {\n return children();\n }\n return children;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction withErrorBoundary<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n errorBoundaryOptions: ErrorBoundaryProps,\n): React.FC<P> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <ErrorBoundary {...errorBoundaryOptions}>\n <WrappedComponent {...props} />\n </ErrorBoundary>\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n Wrapped.displayName = `errorBoundary(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\nexport { ErrorBoundary, withErrorBoundary };\n"]}
1
+ {"version":3,"file":"errorboundary.js","sources":["../../src/errorboundary.tsx"],"sourcesContent":["import { captureException, ReportDialogOptions, Scope, showReportDialog, withScope } from '@sentry/browser';\nimport { logger } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { IS_DEBUG_BUILD } from './flags';\n\nexport function isAtLeastReact17(version: string): boolean {\n const major = version.match(/^([^.]+)/);\n return major !== null && parseInt(major[0]) >= 17;\n}\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type FallbackRender = (errorData: {\n error: Error;\n componentStack: string | null;\n eventId: string | null;\n resetError(): void;\n}) => React.ReactElement;\n\nexport type ErrorBoundaryProps = {\n children?: React.ReactNode | (() => React.ReactNode);\n /** If a Sentry report dialog should be rendered on error */\n showDialog?: boolean;\n /**\n * Options to be passed into the Sentry report dialog.\n * No-op if {@link showDialog} is false.\n */\n dialogOptions?: ReportDialogOptions;\n /**\n * A fallback component that gets rendered when the error boundary encounters an error.\n *\n * Can either provide a React Component, or a function that returns React Component as\n * a valid fallback prop. If a function is provided, the function will be called with\n * the error, the component stack, and an function that resets the error boundary on error.\n *\n */\n fallback?: React.ReactElement | FallbackRender;\n /** Called when the error boundary encounters an error */\n onError?(error: Error, componentStack: string, eventId: string): void;\n /** Called on componentDidMount() */\n onMount?(): void;\n /** Called if resetError() is called from the fallback render props function */\n onReset?(error: Error | null, componentStack: string | null, eventId: string | null): void;\n /** Called on componentWillUnmount() */\n onUnmount?(error: Error | null, componentStack: string | null, eventId: string | null): void;\n /** Called before the error is captured by Sentry, allows for you to add tags or context using the scope */\n beforeCapture?(scope: Scope, error: Error | null, componentStack: string | null): void;\n};\n\ntype ErrorBoundaryState = {\n componentStack: React.ErrorInfo['componentStack'] | null;\n error: Error | null;\n eventId: string | null;\n};\n\nconst INITIAL_STATE = {\n componentStack: null,\n error: null,\n eventId: null,\n};\n\n/**\n * A ErrorBoundary component that logs errors to Sentry. Requires React >= 16.\n * NOTE: If you are a Sentry user, and you are seeing this stack frame, it means the\n * Sentry React SDK ErrorBoundary caught an error invoking your application code. This\n * is expected behavior and NOT indicative of a bug with the Sentry React SDK.\n */\nclass ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {\n public state: ErrorBoundaryState = INITIAL_STATE;\n\n public componentDidCatch(error: Error & { cause?: Error }, { componentStack }: React.ErrorInfo): void {\n const { beforeCapture, onError, showDialog, dialogOptions } = this.props;\n\n withScope(scope => {\n // If on React version >= 17, create stack trace from componentStack param and links\n // to to the original error using `error.cause` otherwise relies on error param for stacktrace.\n // Linking errors requires the `LinkedErrors` integration be enabled.\n if (isAtLeastReact17(React.version)) {\n const errorBoundaryError = new Error(error.message);\n errorBoundaryError.name = `React ErrorBoundary ${errorBoundaryError.name}`;\n errorBoundaryError.stack = componentStack;\n\n // Using the `LinkedErrors` integration to link the errors together.\n error.cause = errorBoundaryError;\n }\n\n if (beforeCapture) {\n beforeCapture(scope, error, componentStack);\n }\n const eventId = captureException(error, { contexts: { react: { componentStack } } });\n if (onError) {\n onError(error, componentStack, eventId);\n }\n if (showDialog) {\n showReportDialog({ ...dialogOptions, eventId });\n }\n\n // componentDidCatch is used over getDerivedStateFromError\n // so that componentStack is accessible through state.\n this.setState({ error, componentStack, eventId });\n });\n }\n\n public componentDidMount(): void {\n const { onMount } = this.props;\n if (onMount) {\n onMount();\n }\n }\n\n public componentWillUnmount(): void {\n const { error, componentStack, eventId } = this.state;\n const { onUnmount } = this.props;\n if (onUnmount) {\n onUnmount(error, componentStack, eventId);\n }\n }\n\n public resetErrorBoundary: () => void = () => {\n const { onReset } = this.props;\n const { error, componentStack, eventId } = this.state;\n if (onReset) {\n onReset(error, componentStack, eventId);\n }\n this.setState(INITIAL_STATE);\n };\n\n public render(): React.ReactNode {\n const { fallback, children } = this.props;\n const { error, componentStack, eventId } = this.state;\n\n if (error) {\n let element: React.ReactElement | undefined = undefined;\n if (typeof fallback === 'function') {\n element = fallback({ error, componentStack, resetError: this.resetErrorBoundary, eventId });\n } else {\n element = fallback;\n }\n\n if (React.isValidElement(element)) {\n return element;\n }\n\n if (fallback) {\n IS_DEBUG_BUILD && logger.warn('fallback did not produce a valid ReactElement');\n }\n\n // Fail gracefully if no fallback provided or is not valid\n return null;\n }\n\n if (typeof children === 'function') {\n return (children as () => React.ReactNode)();\n }\n return children;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction withErrorBoundary<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n errorBoundaryOptions: ErrorBoundaryProps,\n): React.FC<P> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const componentDisplayName = WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <ErrorBoundary {...errorBoundaryOptions}>\n <WrappedComponent {...props} />\n </ErrorBoundary>\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n Wrapped.displayName = `errorBoundary(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\nexport { ErrorBoundary, withErrorBoundary };\n"],"names":[],"mappings":";;;;;;AAAA,gHAMA;;AAEA;AACA;AACA;AACA;;;AA8CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;;;;"}
package/esm/flags.js CHANGED
@@ -11,6 +11,9 @@
11
11
  * our, or the user's build process. Take care when introducing new flags - they must not throw if they are not
12
12
  * replaced.
13
13
  */
14
+
14
15
  /** Flag that is true for debug builds, false otherwise. */
15
- export var IS_DEBUG_BUILD = typeof __SENTRY_DEBUG__ === 'undefined' ? true : __SENTRY_DEBUG__;
16
- //# sourceMappingURL=flags.js.map
16
+ var IS_DEBUG_BUILD = typeof __SENTRY_DEBUG__ === 'undefined' ? true : __SENTRY_DEBUG__;
17
+
18
+ export { IS_DEBUG_BUILD };
19
+ //# sourceMappingURL=flags.js.map
package/esm/flags.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"flags.js","sourceRoot":"","sources":["../../src/flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,2DAA2D;AAC3D,MAAM,CAAC,IAAM,cAAc,GAAG,OAAO,gBAAgB,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC","sourcesContent":["/*\n * This file defines flags and constants that can be modified during compile time in order to facilitate tree shaking\n * for users.\n *\n * Debug flags need to be declared in each package individually and must not be imported across package boundaries,\n * because some build tools have trouble tree-shaking imported guards.\n *\n * As a convention, we define debug flags in a `flags.ts` file in the root of a package's `src` folder.\n *\n * Debug flag files will contain \"magic strings\" like `__SENTRY_DEBUG__` that may get replaced with actual values during\n * our, or the user's build process. Take care when introducing new flags - they must not throw if they are not\n * replaced.\n */\n\ndeclare const __SENTRY_DEBUG__: boolean;\n\n/** Flag that is true for debug builds, false otherwise. */\nexport const IS_DEBUG_BUILD = typeof __SENTRY_DEBUG__ === 'undefined' ? true : __SENTRY_DEBUG__;\n"]}
1
+ {"version":3,"file":"flags.js","sources":["../../src/flags.ts"],"sourcesContent":["/*\n * This file defines flags and constants that can be modified during compile time in order to facilitate tree shaking\n * for users.\n *\n * Debug flags need to be declared in each package individually and must not be imported across package boundaries,\n * because some build tools have trouble tree-shaking imported guards.\n *\n * As a convention, we define debug flags in a `flags.ts` file in the root of a package's `src` folder.\n *\n * Debug flag files will contain \"magic strings\" like `__SENTRY_DEBUG__` that may get replaced with actual values during\n * our, or the user's build process. Take care when introducing new flags - they must not throw if they are not\n * replaced.\n */\n\ndeclare const __SENTRY_DEBUG__: boolean;\n\n/** Flag that is true for debug builds, false otherwise. */\nexport const IS_DEBUG_BUILD = typeof __SENTRY_DEBUG__ === 'undefined' ? true : __SENTRY_DEBUG__;\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;;;;;"}
package/esm/index.js CHANGED
@@ -1,8 +1,9 @@
1
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
2
+ export { init } from './sdk.js';
3
+ export { Profiler, useProfiler, withProfiler } from './profiler.js';
4
+ export { ErrorBoundary, withErrorBoundary } from './errorboundary.js';
5
+ export { createReduxEnhancer } from './redux.js';
6
+ export { reactRouterV3Instrumentation } from './reactrouterv3.js';
7
+ export { reactRouterV4Instrumentation, reactRouterV5Instrumentation, withSentryRouting } from './reactrouter.js';
8
+ export { reactRouterV6Instrumentation, withSentryReactRouterV6Routing } from './reactrouterv6.js';
9
+ //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +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"]}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
package/esm/profiler.js CHANGED
@@ -1,96 +1,100 @@
1
- import { __assign, __extends, __read } from "tslib";
2
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
1
  import { getCurrentHub } from '@sentry/browser';
5
2
  import { timestampWithMs } from '@sentry/utils';
6
3
  import hoistNonReactStatics from 'hoist-non-react-statics';
7
4
  import * as React from 'react';
8
- import { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';
9
- export var UNKNOWN_COMPONENT = 'unknown';
5
+ import { REACT_MOUNT_OP, REACT_UPDATE_OP, REACT_RENDER_OP } from './constants.js';
6
+
7
+ var _jsxFileName = "/home/runner/work/sentry-javascript/sentry-javascript/packages/react/src/profiler.tsx";
8
+ var UNKNOWN_COMPONENT = 'unknown';
9
+
10
10
  /**
11
11
  * The Profiler component leverages Sentry's Tracing integration to generate
12
12
  * spans based on component lifecycles.
13
13
  */
14
- var Profiler = /** @class */ (function (_super) {
15
- __extends(Profiler, _super);
16
- function Profiler(props) {
17
- var _this = _super.call(this, props) || this;
18
- /**
19
- * The span of the mount activity
20
- * Made protected for the React Native SDK to access
21
- */
22
- _this._mountSpan = undefined;
23
- var _a = _this.props, name = _a.name, _b = _a.disabled, disabled = _b === void 0 ? false : _b;
24
- if (disabled) {
25
- return _this;
26
- }
27
- var activeTransaction = getActiveTransaction();
28
- if (activeTransaction) {
29
- _this._mountSpan = activeTransaction.startChild({
30
- description: "<" + name + ">",
31
- op: REACT_MOUNT_OP,
32
- });
33
- }
34
- return _this;
14
+ class Profiler extends React.Component {
15
+ /**
16
+ * The span of the mount activity
17
+ * Made protected for the React Native SDK to access
18
+ */
19
+ __init() {this._mountSpan = undefined;}
20
+
21
+ static __initStatic() {this.defaultProps = {
22
+ disabled: false,
23
+ includeRender: true,
24
+ includeUpdates: true,
25
+ };}
26
+
27
+ constructor(props) {
28
+ super(props);Profiler.prototype.__init.call(this);;
29
+ const { name, disabled = false } = this.props;
30
+
31
+ if (disabled) {
32
+ return;
35
33
  }
36
- // If a component mounted, we can finish the mount activity.
37
- Profiler.prototype.componentDidMount = function () {
38
- if (this._mountSpan) {
39
- this._mountSpan.finish();
40
- }
41
- };
42
- Profiler.prototype.componentDidUpdate = function (_a) {
43
- var _this = this;
44
- var updateProps = _a.updateProps, _b = _a.includeUpdates, includeUpdates = _b === void 0 ? true : _b;
45
- // Only generate an update span if hasUpdateSpan is true, if there is a valid mountSpan,
46
- // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.
47
- // We are just trying to give baseline clues for further investigation.
48
- if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {
49
- // See what props haved changed between the previous props, and the current props. This is
50
- // set as data on the span. We just store the prop keys as the values could be potenially very large.
51
- var changedProps = Object.keys(updateProps).filter(function (k) { return updateProps[k] !== _this.props.updateProps[k]; });
52
- if (changedProps.length > 0) {
53
- // The update span is a point in time span with 0 duration, just signifying that the component
54
- // has been updated.
55
- var now = timestampWithMs();
56
- this._mountSpan.startChild({
57
- data: {
58
- changedProps: changedProps,
59
- },
60
- description: "<" + this.props.name + ">",
61
- endTimestamp: now,
62
- op: REACT_UPDATE_OP,
63
- startTimestamp: now,
64
- });
65
- }
66
- }
67
- };
68
- // If a component is unmounted, we can say it is no longer on the screen.
69
- // This means we can finish the span representing the component render.
70
- Profiler.prototype.componentWillUnmount = function () {
71
- var _a = this.props, name = _a.name, _b = _a.includeRender, includeRender = _b === void 0 ? true : _b;
72
- if (this._mountSpan && includeRender) {
73
- // If we were able to obtain the spanId of the mount activity, we should set the
74
- // next activity as a child to the component mount activity.
75
- this._mountSpan.startChild({
76
- description: "<" + name + ">",
77
- endTimestamp: timestampWithMs(),
78
- op: REACT_RENDER_OP,
79
- startTimestamp: this._mountSpan.endTimestamp,
80
- });
81
- }
82
- };
83
- Profiler.prototype.render = function () {
84
- return this.props.children;
85
- };
86
- // eslint-disable-next-line @typescript-eslint/member-ordering
87
- Profiler.defaultProps = {
88
- disabled: false,
89
- includeRender: true,
90
- includeUpdates: true,
91
- };
92
- return Profiler;
93
- }(React.Component));
34
+
35
+ var activeTransaction = getActiveTransaction();
36
+ if (activeTransaction) {
37
+ this._mountSpan = activeTransaction.startChild({
38
+ description: `<${name}>`,
39
+ op: REACT_MOUNT_OP,
40
+ });
41
+ }
42
+ }
43
+
44
+ // If a component mounted, we can finish the mount activity.
45
+ componentDidMount() {
46
+ if (this._mountSpan) {
47
+ this._mountSpan.finish();
48
+ }
49
+ }
50
+
51
+ componentDidUpdate({ updateProps, includeUpdates = true }) {
52
+ // Only generate an update span if hasUpdateSpan is true, if there is a valid mountSpan,
53
+ // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.
54
+ // We are just trying to give baseline clues for further investigation.
55
+ if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {
56
+ // See what props haved changed between the previous props, and the current props. This is
57
+ // set as data on the span. We just store the prop keys as the values could be potenially very large.
58
+ var changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);
59
+ if (changedProps.length > 0) {
60
+ // The update span is a point in time span with 0 duration, just signifying that the component
61
+ // has been updated.
62
+ var now = timestampWithMs();
63
+ this._mountSpan.startChild({
64
+ data: {
65
+ changedProps,
66
+ },
67
+ description: `<${this.props.name}>`,
68
+ endTimestamp: now,
69
+ op: REACT_UPDATE_OP,
70
+ startTimestamp: now,
71
+ });
72
+ }
73
+ }
74
+ }
75
+
76
+ // If a component is unmounted, we can say it is no longer on the screen.
77
+ // This means we can finish the span representing the component render.
78
+ componentWillUnmount() {
79
+ const { name, includeRender = true } = this.props;
80
+
81
+ if (this._mountSpan && includeRender) {
82
+ // If we were able to obtain the spanId of the mount activity, we should set the
83
+ // next activity as a child to the component mount activity.
84
+ this._mountSpan.startChild({
85
+ description: `<${name}>`,
86
+ endTimestamp: timestampWithMs(),
87
+ op: REACT_RENDER_OP,
88
+ startTimestamp: this._mountSpan.endTimestamp,
89
+ });
90
+ }
91
+ }
92
+
93
+ render() {
94
+ return this.props.children;
95
+ }
96
+ } Profiler.__initStatic();
97
+
94
98
  /**
95
99
  * withProfiler is a higher order component that wraps a
96
100
  * component in a {@link Profiler} component. It is recommended that
@@ -99,18 +103,28 @@ var Profiler = /** @class */ (function (_super) {
99
103
  * @param WrappedComponent component that is wrapped by Profiler
100
104
  * @param options the {@link ProfilerProps} you can pass into the Profiler
101
105
  */
102
- function withProfiler(WrappedComponent,
103
- // We do not want to have `updateProps` given in options, it is instead filled through the HOC.
104
- options) {
105
- var componentDisplayName = (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
106
- var Wrapped = function (props) { return (React.createElement(Profiler, __assign({}, options, { name: componentDisplayName, updateProps: props }),
107
- React.createElement(WrappedComponent, __assign({}, props)))); };
108
- Wrapped.displayName = "profiler(" + componentDisplayName + ")";
109
- // Copy over static methods from Wrapped component to Profiler HOC
110
- // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
111
- hoistNonReactStatics(Wrapped, WrappedComponent);
112
- return Wrapped;
106
+ function withProfiler(
107
+ WrappedComponent,
108
+ // We do not want to have `updateProps` given in options, it is instead filled through the HOC.
109
+ options,
110
+ ) {
111
+ var componentDisplayName =
112
+ (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;
113
+
114
+ var Wrapped = (props) => (
115
+ React.createElement(Profiler, { ...options, name: componentDisplayName, updateProps: props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 133}}
116
+ , React.createElement(WrappedComponent, { ...props, __self: this, __source: {fileName: _jsxFileName, lineNumber: 134}} )
117
+ )
118
+ );
119
+
120
+ Wrapped.displayName = `profiler(${componentDisplayName})`;
121
+
122
+ // Copy over static methods from Wrapped component to Profiler HOC
123
+ // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
124
+ hoistNonReactStatics(Wrapped, WrappedComponent);
125
+ return Wrapped;
113
126
  }
127
+
114
128
  /**
115
129
  *
116
130
  * `useProfiler` is a React hook that profiles a React component.
@@ -118,52 +132,59 @@ options) {
118
132
  * Requires React 16.8 or above.
119
133
  * @param name displayName of component being profiled
120
134
  */
121
- function useProfiler(name, options) {
122
- if (options === void 0) { options = {
123
- disabled: false,
124
- hasRenderSpan: true,
125
- }; }
126
- var _a = __read(React.useState(function () {
127
- if (options && options.disabled) {
128
- return undefined;
129
- }
130
- var activeTransaction = getActiveTransaction();
131
- if (activeTransaction) {
132
- return activeTransaction.startChild({
133
- description: "<" + name + ">",
134
- op: REACT_MOUNT_OP,
135
- });
136
- }
137
- return undefined;
138
- }), 1), mountSpan = _a[0];
139
- React.useEffect(function () {
140
- if (mountSpan) {
141
- mountSpan.finish();
142
- }
143
- return function () {
144
- if (mountSpan && options.hasRenderSpan) {
145
- mountSpan.startChild({
146
- description: "<" + name + ">",
147
- endTimestamp: timestampWithMs(),
148
- op: REACT_RENDER_OP,
149
- startTimestamp: mountSpan.endTimestamp,
150
- });
151
- }
152
- };
153
- // We only want this to run once.
154
- // eslint-disable-next-line react-hooks/exhaustive-deps
155
- }, []);
135
+ function useProfiler(
136
+ name,
137
+ options = {
138
+ disabled: false,
139
+ hasRenderSpan: true,
140
+ },
141
+ ) {
142
+ const [mountSpan] = React.useState(() => {
143
+ if (options && options.disabled) {
144
+ return undefined;
145
+ }
146
+
147
+ var activeTransaction = getActiveTransaction();
148
+ if (activeTransaction) {
149
+ return activeTransaction.startChild({
150
+ description: `<${name}>`,
151
+ op: REACT_MOUNT_OP,
152
+ });
153
+ }
154
+
155
+ return undefined;
156
+ });
157
+
158
+ React.useEffect(() => {
159
+ if (mountSpan) {
160
+ mountSpan.finish();
161
+ }
162
+
163
+ return () => {
164
+ if (mountSpan && options.hasRenderSpan) {
165
+ mountSpan.startChild({
166
+ description: `<${name}>`,
167
+ endTimestamp: timestampWithMs(),
168
+ op: REACT_RENDER_OP,
169
+ startTimestamp: mountSpan.endTimestamp,
170
+ });
171
+ }
172
+ };
173
+ // We only want this to run once.
174
+ }, []);
156
175
  }
157
- export { withProfiler, Profiler, useProfiler };
176
+
158
177
  /** Grabs active transaction off scope */
159
- export function getActiveTransaction(hub) {
160
- if (hub === void 0) { hub = getCurrentHub(); }
161
- if (hub) {
162
- var scope = hub.getScope();
163
- if (scope) {
164
- return scope.getTransaction();
165
- }
178
+ function getActiveTransaction(hub = getCurrentHub()) {
179
+ if (hub) {
180
+ var scope = hub.getScope();
181
+ if (scope) {
182
+ return scope.getTransaction() ;
166
183
  }
167
- return undefined;
184
+ }
185
+
186
+ return undefined;
168
187
  }
169
- //# sourceMappingURL=profiler.js.map
188
+
189
+ export { Profiler, UNKNOWN_COMPONENT, getActiveTransaction, useProfiler, withProfiler };
190
+ //# sourceMappingURL=profiler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"profiler.js","sourceRoot":"","sources":["../../src/profiler.tsx"],"names":[],"mappings":";AAAA,+DAA+D;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AAC;AAED,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AAE/C,yCAAyC;AACzC,MAAM,UAAU,oBAAoB,CAAwB,GAA0B;IAA1B,oBAAA,EAAA,MAAW,aAAa,EAAE;IACpF,IAAI,GAAG,EAAE;QACP,IAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC7B,IAAI,KAAK,EAAE;YACT,OAAO,KAAK,CAAC,cAAc,EAAmB,CAAC;SAChD;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { getCurrentHub, Hub } from '@sentry/browser';\nimport { Span, Transaction } from '@sentry/types';\nimport { timestampWithMs } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type ProfilerProps = {\n // The name of the component being profiled.\n name: string;\n // If the Profiler is disabled. False by default. This is useful if you want to disable profilers\n // in certain environments.\n disabled?: boolean;\n // If time component is on page should be displayed as spans. True by default.\n includeRender?: boolean;\n // If component updates should be displayed as spans. True by default.\n includeUpdates?: boolean;\n // props given to component being profiled.\n updateProps: { [key: string]: unknown };\n};\n\n/**\n * The Profiler component leverages Sentry's Tracing integration to generate\n * spans based on component lifecycles.\n */\nclass Profiler extends React.Component<ProfilerProps> {\n /**\n * The span of the mount activity\n * Made protected for the React Native SDK to access\n */\n protected _mountSpan: Span | undefined = undefined;\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static defaultProps: Partial<ProfilerProps> = {\n disabled: false,\n includeRender: true,\n includeUpdates: true,\n };\n\n public constructor(props: ProfilerProps) {\n super(props);\n const { name, disabled = false } = this.props;\n\n if (disabled) {\n return;\n }\n\n const activeTransaction = getActiveTransaction();\n if (activeTransaction) {\n this._mountSpan = activeTransaction.startChild({\n description: `<${name}>`,\n op: REACT_MOUNT_OP,\n });\n }\n }\n\n // If a component mounted, we can finish the mount activity.\n public componentDidMount(): void {\n if (this._mountSpan) {\n this._mountSpan.finish();\n }\n }\n\n public componentDidUpdate({ updateProps, includeUpdates = true }: ProfilerProps): void {\n // Only generate an update span if hasUpdateSpan is true, if there is a valid mountSpan,\n // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.\n // We are just trying to give baseline clues for further investigation.\n if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {\n // See what props haved changed between the previous props, and the current props. This is\n // set as data on the span. We just store the prop keys as the values could be potenially very large.\n const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);\n if (changedProps.length > 0) {\n // The update span is a point in time span with 0 duration, just signifying that the component\n // has been updated.\n const now = timestampWithMs();\n this._mountSpan.startChild({\n data: {\n changedProps,\n },\n description: `<${this.props.name}>`,\n endTimestamp: now,\n op: REACT_UPDATE_OP,\n startTimestamp: now,\n });\n }\n }\n }\n\n // If a component is unmounted, we can say it is no longer on the screen.\n // This means we can finish the span representing the component render.\n public componentWillUnmount(): void {\n const { name, includeRender = true } = this.props;\n\n if (this._mountSpan && includeRender) {\n // If we were able to obtain the spanId of the mount activity, we should set the\n // next activity as a child to the component mount activity.\n this._mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampWithMs(),\n op: REACT_RENDER_OP,\n startTimestamp: this._mountSpan.endTimestamp,\n });\n }\n }\n\n public render(): React.ReactNode {\n return this.props.children;\n }\n}\n\n/**\n * withProfiler is a higher order component that wraps a\n * component in a {@link Profiler} component. It is recommended that\n * the higher order component be used over the regular {@link Profiler} component.\n *\n * @param WrappedComponent component that is wrapped by Profiler\n * @param options the {@link ProfilerProps} you can pass into the Profiler\n */\nfunction withProfiler<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n // We do not want to have `updateProps` given in options, it is instead filled through the HOC.\n options?: Pick<Partial<ProfilerProps>, Exclude<keyof ProfilerProps, 'updateProps'>>,\n): React.FC<P> {\n const componentDisplayName =\n (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <Profiler {...options} name={componentDisplayName} updateProps={props}>\n <WrappedComponent {...props} />\n </Profiler>\n );\n\n Wrapped.displayName = `profiler(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\n/**\n *\n * `useProfiler` is a React hook that profiles a React component.\n *\n * Requires React 16.8 or above.\n * @param name displayName of component being profiled\n */\nfunction useProfiler(\n name: string,\n options: { disabled?: boolean; hasRenderSpan?: boolean } = {\n disabled: false,\n hasRenderSpan: true,\n },\n): void {\n const [mountSpan] = React.useState(() => {\n if (options && options.disabled) {\n return undefined;\n }\n\n const activeTransaction = getActiveTransaction();\n if (activeTransaction) {\n return activeTransaction.startChild({\n description: `<${name}>`,\n op: REACT_MOUNT_OP,\n });\n }\n\n return undefined;\n });\n\n React.useEffect(() => {\n if (mountSpan) {\n mountSpan.finish();\n }\n\n return (): void => {\n if (mountSpan && options.hasRenderSpan) {\n mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampWithMs(),\n op: REACT_RENDER_OP,\n startTimestamp: mountSpan.endTimestamp,\n });\n }\n };\n // We only want this to run once.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n}\n\nexport { withProfiler, Profiler, useProfiler };\n\n/** Grabs active transaction off scope */\nexport function getActiveTransaction<T extends Transaction>(hub: Hub = getCurrentHub()): T | undefined {\n if (hub) {\n const scope = hub.getScope();\n if (scope) {\n return scope.getTransaction() as T | undefined;\n }\n }\n\n return undefined;\n}\n"]}
1
+ {"version":3,"file":"profiler.js","sources":["../../src/profiler.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { getCurrentHub, Hub } from '@sentry/browser';\nimport { Span, Transaction } from '@sentry/types';\nimport { timestampWithMs } from '@sentry/utils';\nimport hoistNonReactStatics from 'hoist-non-react-statics';\nimport * as React from 'react';\n\nimport { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';\n\nexport const UNKNOWN_COMPONENT = 'unknown';\n\nexport type ProfilerProps = {\n // The name of the component being profiled.\n name: string;\n // If the Profiler is disabled. False by default. This is useful if you want to disable profilers\n // in certain environments.\n disabled?: boolean;\n // If time component is on page should be displayed as spans. True by default.\n includeRender?: boolean;\n // If component updates should be displayed as spans. True by default.\n includeUpdates?: boolean;\n // props given to component being profiled.\n updateProps: { [key: string]: unknown };\n};\n\n/**\n * The Profiler component leverages Sentry's Tracing integration to generate\n * spans based on component lifecycles.\n */\nclass Profiler extends React.Component<ProfilerProps> {\n /**\n * The span of the mount activity\n * Made protected for the React Native SDK to access\n */\n protected _mountSpan: Span | undefined = undefined;\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n public static defaultProps: Partial<ProfilerProps> = {\n disabled: false,\n includeRender: true,\n includeUpdates: true,\n };\n\n public constructor(props: ProfilerProps) {\n super(props);\n const { name, disabled = false } = this.props;\n\n if (disabled) {\n return;\n }\n\n const activeTransaction = getActiveTransaction();\n if (activeTransaction) {\n this._mountSpan = activeTransaction.startChild({\n description: `<${name}>`,\n op: REACT_MOUNT_OP,\n });\n }\n }\n\n // If a component mounted, we can finish the mount activity.\n public componentDidMount(): void {\n if (this._mountSpan) {\n this._mountSpan.finish();\n }\n }\n\n public componentDidUpdate({ updateProps, includeUpdates = true }: ProfilerProps): void {\n // Only generate an update span if hasUpdateSpan is true, if there is a valid mountSpan,\n // and if the updateProps have changed. It is ok to not do a deep equality check here as it is expensive.\n // We are just trying to give baseline clues for further investigation.\n if (includeUpdates && this._mountSpan && updateProps !== this.props.updateProps) {\n // See what props haved changed between the previous props, and the current props. This is\n // set as data on the span. We just store the prop keys as the values could be potenially very large.\n const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);\n if (changedProps.length > 0) {\n // The update span is a point in time span with 0 duration, just signifying that the component\n // has been updated.\n const now = timestampWithMs();\n this._mountSpan.startChild({\n data: {\n changedProps,\n },\n description: `<${this.props.name}>`,\n endTimestamp: now,\n op: REACT_UPDATE_OP,\n startTimestamp: now,\n });\n }\n }\n }\n\n // If a component is unmounted, we can say it is no longer on the screen.\n // This means we can finish the span representing the component render.\n public componentWillUnmount(): void {\n const { name, includeRender = true } = this.props;\n\n if (this._mountSpan && includeRender) {\n // If we were able to obtain the spanId of the mount activity, we should set the\n // next activity as a child to the component mount activity.\n this._mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampWithMs(),\n op: REACT_RENDER_OP,\n startTimestamp: this._mountSpan.endTimestamp,\n });\n }\n }\n\n public render(): React.ReactNode {\n return this.props.children;\n }\n}\n\n/**\n * withProfiler is a higher order component that wraps a\n * component in a {@link Profiler} component. It is recommended that\n * the higher order component be used over the regular {@link Profiler} component.\n *\n * @param WrappedComponent component that is wrapped by Profiler\n * @param options the {@link ProfilerProps} you can pass into the Profiler\n */\nfunction withProfiler<P extends Record<string, any>>(\n WrappedComponent: React.ComponentType<P>,\n // We do not want to have `updateProps` given in options, it is instead filled through the HOC.\n options?: Pick<Partial<ProfilerProps>, Exclude<keyof ProfilerProps, 'updateProps'>>,\n): React.FC<P> {\n const componentDisplayName =\n (options && options.name) || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT;\n\n const Wrapped: React.FC<P> = (props: P) => (\n <Profiler {...options} name={componentDisplayName} updateProps={props}>\n <WrappedComponent {...props} />\n </Profiler>\n );\n\n Wrapped.displayName = `profiler(${componentDisplayName})`;\n\n // Copy over static methods from Wrapped component to Profiler HOC\n // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\n hoistNonReactStatics(Wrapped, WrappedComponent);\n return Wrapped;\n}\n\n/**\n *\n * `useProfiler` is a React hook that profiles a React component.\n *\n * Requires React 16.8 or above.\n * @param name displayName of component being profiled\n */\nfunction useProfiler(\n name: string,\n options: { disabled?: boolean; hasRenderSpan?: boolean } = {\n disabled: false,\n hasRenderSpan: true,\n },\n): void {\n const [mountSpan] = React.useState(() => {\n if (options && options.disabled) {\n return undefined;\n }\n\n const activeTransaction = getActiveTransaction();\n if (activeTransaction) {\n return activeTransaction.startChild({\n description: `<${name}>`,\n op: REACT_MOUNT_OP,\n });\n }\n\n return undefined;\n });\n\n React.useEffect(() => {\n if (mountSpan) {\n mountSpan.finish();\n }\n\n return (): void => {\n if (mountSpan && options.hasRenderSpan) {\n mountSpan.startChild({\n description: `<${name}>`,\n endTimestamp: timestampWithMs(),\n op: REACT_RENDER_OP,\n startTimestamp: mountSpan.endTimestamp,\n });\n }\n };\n // We only want this to run once.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n}\n\nexport { withProfiler, Profiler, useProfiler };\n\n/** Grabs active transaction off scope */\nexport function getActiveTransaction<T extends Transaction>(hub: Hub = getCurrentHub()): T | undefined {\n if (hub) {\n const scope = hub.getScope();\n if (scope) {\n return scope.getTransaction() as T | undefined;\n }\n }\n\n return undefined;\n}\n"],"names":[],"mappings":";;;;;;AAAA,2GASA;;;AAiBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAGA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;"}