@sentry/react 10.70.0 → 11.0.0-alpha.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.
- package/build/cjs/error.js +1 -7
- package/build/cjs/error.js.map +1 -1
- package/build/cjs/hoist-non-react-statics.js +1 -7
- package/build/cjs/hoist-non-react-statics.js.map +1 -1
- package/build/cjs/profiler.js +12 -8
- package/build/cjs/profiler.js.map +1 -1
- package/build/cjs/reactrouter-compat-utils/instrumentation.js +24 -41
- package/build/cjs/reactrouter-compat-utils/instrumentation.js.map +1 -1
- package/build/cjs/reactrouter-compat-utils/utils.js +2 -1
- package/build/cjs/reactrouter-compat-utils/utils.js.map +1 -1
- package/build/cjs/reactrouter.js +5 -2
- package/build/cjs/reactrouter.js.map +1 -1
- package/build/cjs/reactrouterv3.js.map +1 -1
- package/build/cjs/tanstackrouter.js +2 -1
- package/build/cjs/tanstackrouter.js.map +1 -1
- package/build/esm/error.js +2 -7
- package/build/esm/error.js.map +1 -1
- package/build/esm/hoist-non-react-statics.js +1 -7
- package/build/esm/hoist-non-react-statics.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/profiler.js +12 -8
- package/build/esm/profiler.js.map +1 -1
- package/build/esm/reactrouter-compat-utils/instrumentation.js +25 -42
- package/build/esm/reactrouter-compat-utils/instrumentation.js.map +1 -1
- package/build/esm/reactrouter-compat-utils/utils.js +2 -1
- package/build/esm/reactrouter-compat-utils/utils.js.map +1 -1
- package/build/esm/reactrouter.js +5 -2
- package/build/esm/reactrouter.js.map +1 -1
- package/build/esm/reactrouterv3.js.map +1 -1
- package/build/esm/tanstackrouter.js +2 -1
- package/build/esm/tanstackrouter.js.map +1 -1
- package/build/types/error.d.ts +0 -4
- package/build/types/error.d.ts.map +1 -1
- package/build/types/errorboundary.d.ts.map +1 -1
- package/build/types/hoist-non-react-statics.d.ts.map +1 -1
- package/build/types/profiler.d.ts +0 -1
- package/build/types/profiler.d.ts.map +1 -1
- package/build/types/reactrouter-compat-utils/instrumentation.d.ts.map +1 -1
- package/build/types/reactrouter-compat-utils/utils.d.ts.map +1 -1
- package/build/types/reactrouter.d.ts.map +1 -1
- package/build/types/tanstackrouter.d.ts.map +1 -1
- package/package.json +9 -20
- package/build/cjs/constants.js +0 -10
- package/build/cjs/constants.js.map +0 -1
- package/build/esm/constants.js +0 -6
- package/build/esm/constants.js.map +0 -1
- package/build/types/constants.d.ts +0 -4
- package/build/types/constants.d.ts.map +0 -1
- package/build/types-ts3.8/constants.d.ts +0 -4
- package/build/types-ts3.8/debug-build.d.ts +0 -7
- package/build/types-ts3.8/error.d.ts +0 -41
- package/build/types-ts3.8/errorboundary.d.ts +0 -87
- package/build/types-ts3.8/hoist-non-react-statics.d.ts +0 -21
- package/build/types-ts3.8/index.d.ts +0 -14
- package/build/types-ts3.8/isSyntheticEvent.d.ts +0 -10
- package/build/types-ts3.8/profiler.d.ts +0 -56
- package/build/types-ts3.8/reactrouter-compat-utils/index.d.ts +0 -5
- package/build/types-ts3.8/reactrouter-compat-utils/instrumentation.d.ts +0 -117
- package/build/types-ts3.8/reactrouter-compat-utils/lazy-routes.d.ts +0 -18
- package/build/types-ts3.8/reactrouter-compat-utils/route-manifest.d.ts +0 -13
- package/build/types-ts3.8/reactrouter-compat-utils/utils.d.ts +0 -77
- package/build/types-ts3.8/reactrouter.compat.d.ts +0 -42
- package/build/types-ts3.8/reactrouter.d.ts +0 -41
- package/build/types-ts3.8/reactrouterv3.d.ts +0 -29
- package/build/types-ts3.8/reactrouterv6.d.ts +0 -42
- package/build/types-ts3.8/reactrouterv7.d.ts +0 -42
- package/build/types-ts3.8/redux.d.ts +0 -38
- package/build/types-ts3.8/sdk.d.ts +0 -7
- package/build/types-ts3.8/tanstackrouter.d.ts +0 -13
- package/build/types-ts3.8/types.d.ts +0 -163
- package/build/types-ts3.8/vendor/tanstackrouter-types.d.ts +0 -37
package/build/cjs/error.js
CHANGED
|
@@ -2,12 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const browser$1 = require('@sentry/browser');
|
|
4
4
|
const browser = require('@sentry/core/browser');
|
|
5
|
-
const React = require('react');
|
|
6
5
|
|
|
7
|
-
function isAtLeastReact17(reactVersion) {
|
|
8
|
-
const reactMajor = reactVersion.match(/^([^.]+)/);
|
|
9
|
-
return reactMajor !== null && parseInt(reactMajor[0]) >= 17;
|
|
10
|
-
}
|
|
11
6
|
function setCause(error, cause) {
|
|
12
7
|
const seenErrors = /* @__PURE__ */ new WeakSet();
|
|
13
8
|
function recurse(error2, cause2) {
|
|
@@ -23,7 +18,7 @@ function setCause(error, cause) {
|
|
|
23
18
|
recurse(error, cause);
|
|
24
19
|
}
|
|
25
20
|
function captureReactException(error, { componentStack }, hint) {
|
|
26
|
-
if (
|
|
21
|
+
if (browser.isError(error) && componentStack) {
|
|
27
22
|
const errorBoundaryError = new Error(error.message);
|
|
28
23
|
errorBoundaryError.name = `React ErrorBoundary ${error.name}`;
|
|
29
24
|
errorBoundaryError.stack = componentStack;
|
|
@@ -44,7 +39,6 @@ function reactErrorHandler(callback) {
|
|
|
44
39
|
}
|
|
45
40
|
|
|
46
41
|
exports.captureReactException = captureReactException;
|
|
47
|
-
exports.isAtLeastReact17 = isAtLeastReact17;
|
|
48
42
|
exports.reactErrorHandler = reactErrorHandler;
|
|
49
43
|
exports.setCause = setCause;
|
|
50
44
|
//# sourceMappingURL=error.js.map
|
package/build/cjs/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sources":["../../src/error.ts"],"sourcesContent":["import { captureException } from '@sentry/browser';\nimport { isError } from '@sentry/core/browser';\nimport type { ErrorInfo } from 'react';\
|
|
1
|
+
{"version":3,"file":"error.js","sources":["../../src/error.ts"],"sourcesContent":["import { captureException } from '@sentry/browser';\nimport { isError } from '@sentry/core/browser';\nimport type { ErrorInfo } from 'react';\n\n/**\n * Recurse through `error.cause` chain to set cause on an error.\n */\nexport function setCause(error: Error & { cause?: Error }, cause: Error): void {\n const seenErrors = new WeakSet();\n\n function recurse(error: Error & { cause?: Error }, cause: Error): void {\n // If we've already seen the error, there is a recursive loop somewhere in the error's\n // cause chain. Let's just bail out then to prevent a stack overflow.\n if (seenErrors.has(error)) {\n return;\n }\n if (error.cause) {\n seenErrors.add(error);\n return recurse(error.cause, cause);\n }\n error.cause = cause;\n }\n\n recurse(error, cause);\n}\n\n/**\n * Captures an error that was thrown by a React ErrorBoundary or React root.\n *\n * @param error The error to capture.\n * @param errorInfo The errorInfo provided by React.\n * @param hint Optional additional data to attach to the Sentry event.\n * @returns the id of the captured Sentry event.\n */\nexport function captureReactException(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error: any,\n { componentStack }: ErrorInfo,\n hint?: Parameters<typeof captureException>[1],\n): string {\n // Create a stack trace from the componentStack param and link it to the original error\n // using `error.cause`. Linking errors requires the `LinkedErrors` integration be enabled.\n // See: https://reactjs.org/blog/2020/08/10/react-v17-rc.html#native-component-stacks\n //\n // Although `componentDidCatch` is typed to accept an `Error` object, it can also be invoked\n // with non-error objects. This is why we need to check if the error is an error-like object.\n // See: https://github.com/getsentry/sentry-javascript/issues/6167\n if (isError(error) && componentStack) {\n const errorBoundaryError = new Error(error.message);\n errorBoundaryError.name = `React ErrorBoundary ${error.name}`;\n errorBoundaryError.stack = componentStack;\n\n // Using the `LinkedErrors` integration to link the errors together.\n setCause(error, errorBoundaryError);\n }\n\n return captureException(error, hint);\n}\n\n/**\n * Creates an error handler that can be used with the `onCaughtError`, `onUncaughtError`,\n * and `onRecoverableError` options in `createRoot` and `hydrateRoot` React DOM methods.\n *\n * @param callback An optional callback that will be called after the error is captured.\n * Use this to add custom handling for errors.\n *\n * @example\n *\n * ```JavaScript\n * const root = createRoot(container, {\n * onCaughtError: Sentry.reactErrorHandler(),\n * onUncaughtError: Sentry.reactErrorHandler((error, errorInfo) => {\n * console.warn('Caught error', error, errorInfo.componentStack);\n * });\n * });\n * ```\n */\nexport function reactErrorHandler(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callback?: (error: any, errorInfo: ErrorInfo, eventId: string) => void,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): (error: any, errorInfo: ErrorInfo) => void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (error: any, errorInfo: ErrorInfo) => {\n const hasCallback = !!callback;\n const eventId = captureReactException(error, errorInfo, {\n mechanism: { handled: hasCallback, type: 'auto.function.react.error_handler' },\n });\n if (hasCallback) {\n callback(error, errorInfo, eventId);\n }\n };\n}\n"],"names":["error","cause","isError","captureException"],"mappings":";;;;;AAOO,SAAS,QAAA,CAAS,OAAkC,KAAA,EAAoB;AAC7E,EAAA,MAAM,UAAA,uBAAiB,OAAA,EAAQ;AAE/B,EAAA,SAAS,OAAA,CAAQA,QAAkCC,MAAAA,EAAoB;AAGrE,IAAA,IAAI,UAAA,CAAW,GAAA,CAAID,MAAK,CAAA,EAAG;AACzB,MAAA;AAAA,IACF;AACA,IAAA,IAAIA,OAAM,KAAA,EAAO;AACf,MAAA,UAAA,CAAW,IAAIA,MAAK,CAAA;AACpB,MAAA,OAAO,OAAA,CAAQA,MAAAA,CAAM,KAAA,EAAOC,MAAK,CAAA;AAAA,IACnC;AACA,IAAAD,OAAM,KAAA,GAAQC,MAAAA;AAAA,EAChB;AAEA,EAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AACtB;AAUO,SAAS,qBAAA,CAEd,KAAA,EACA,EAAE,cAAA,IACF,IAAA,EACQ;AAQR,EAAA,IAAIC,eAAA,CAAQ,KAAK,CAAA,IAAK,cAAA,EAAgB;AACpC,IAAA,MAAM,kBAAA,GAAqB,IAAI,KAAA,CAAM,KAAA,CAAM,OAAO,CAAA;AAClD,IAAA,kBAAA,CAAmB,IAAA,GAAO,CAAA,oBAAA,EAAuB,KAAA,CAAM,IAAI,CAAA,CAAA;AAC3D,IAAA,kBAAA,CAAmB,KAAA,GAAQ,cAAA;AAG3B,IAAA,QAAA,CAAS,OAAO,kBAAkB,CAAA;AAAA,EACpC;AAEA,EAAA,OAAOC,0BAAA,CAAiB,OAAO,IAAI,CAAA;AACrC;AAoBO,SAAS,kBAEd,QAAA,EAE4C;AAE5C,EAAA,OAAO,CAAC,OAAY,SAAA,KAAyB;AAC3C,IAAA,MAAM,WAAA,GAAc,CAAC,CAAC,QAAA;AACtB,IAAA,MAAM,OAAA,GAAU,qBAAA,CAAsB,KAAA,EAAO,SAAA,EAAW;AAAA,MACtD,SAAA,EAAW,EAAE,OAAA,EAAS,WAAA,EAAa,MAAM,mCAAA;AAAoC,KAC9E,CAAA;AACD,IAAA,IAAI,WAAA,EAAa;AACf,MAAA,QAAA,CAAS,KAAA,EAAO,WAAW,OAAO,CAAA;AAAA,IACpC;AAAA,EACF,CAAA;AACF;;;;;;"}
|
|
@@ -39,16 +39,10 @@ const MEMO_STATICS = {
|
|
|
39
39
|
};
|
|
40
40
|
const ForwardRefType = /* @__PURE__ */ Symbol.for("react.forward_ref");
|
|
41
41
|
const MemoType = /* @__PURE__ */ Symbol.for("react.memo");
|
|
42
|
-
function isMemo(component) {
|
|
43
|
-
return typeof component === "object" && component !== null && component.$$typeof === MemoType;
|
|
44
|
-
}
|
|
45
42
|
const TYPE_STATICS = {};
|
|
46
43
|
TYPE_STATICS[ForwardRefType] = FORWARD_REF_STATICS;
|
|
47
44
|
TYPE_STATICS[MemoType] = MEMO_STATICS;
|
|
48
45
|
function getStatics(component) {
|
|
49
|
-
if (isMemo(component)) {
|
|
50
|
-
return MEMO_STATICS;
|
|
51
|
-
}
|
|
52
46
|
const componentType = component.$$typeof;
|
|
53
47
|
return componentType && TYPE_STATICS[componentType] || REACT_STATICS;
|
|
54
48
|
}
|
|
@@ -78,7 +72,7 @@ function hoistNonReactStatics(targetComponent, sourceComponent, excludelist) {
|
|
|
78
72
|
if (descriptor) {
|
|
79
73
|
try {
|
|
80
74
|
defineProperty(targetComponent, key, descriptor);
|
|
81
|
-
} catch
|
|
75
|
+
} catch {
|
|
82
76
|
}
|
|
83
77
|
}
|
|
84
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hoist-non-react-statics.js","sources":["../../src/hoist-non-react-statics.ts"],"sourcesContent":["/**\n * Inlined implementation of hoist-non-react-statics\n * Original library: https://github.com/mridgway/hoist-non-react-statics\n * License: BSD-3-Clause\n * Copyright 2015, Yahoo! Inc.\n *\n * This is an inlined version to avoid ESM compatibility issues with the original package.\n */\n\nimport type * as React from 'react';\n\n/**\n * React statics that should not be hoisted\n */\nconst REACT_STATICS = {\n childContextTypes: true,\n contextType: true,\n contextTypes: true,\n defaultProps: true,\n displayName: true,\n getDefaultProps: true,\n getDerivedStateFromError: true,\n getDerivedStateFromProps: true,\n mixins: true,\n propTypes: true,\n type: true,\n} as const;\n\n/**\n * Known JavaScript function statics that should not be hoisted\n */\nconst KNOWN_STATICS = {\n name: true,\n length: true,\n prototype: true,\n caller: true,\n callee: true,\n arguments: true,\n arity: true,\n} as const;\n\n/**\n * Statics specific to ForwardRef components\n */\nconst FORWARD_REF_STATICS = {\n $$typeof: true,\n render: true,\n defaultProps: true,\n displayName: true,\n propTypes: true,\n} as const;\n\n/**\n * Statics specific to Memo components\n */\nconst MEMO_STATICS = {\n $$typeof: true,\n compare: true,\n defaultProps: true,\n displayName: true,\n propTypes: true,\n type: true,\n} as const;\n\n/**\n * Inlined react-is utilities\n * We only need to detect ForwardRef and Memo types\n */\nconst ForwardRefType = Symbol.for('react.forward_ref');\nconst MemoType = Symbol.for('react.memo');\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"hoist-non-react-statics.js","sources":["../../src/hoist-non-react-statics.ts"],"sourcesContent":["/**\n * Inlined implementation of hoist-non-react-statics\n * Original library: https://github.com/mridgway/hoist-non-react-statics\n * License: BSD-3-Clause\n * Copyright 2015, Yahoo! Inc.\n *\n * This is an inlined version to avoid ESM compatibility issues with the original package.\n */\n\nimport type * as React from 'react';\n\n/**\n * React statics that should not be hoisted\n */\nconst REACT_STATICS = {\n childContextTypes: true,\n contextType: true,\n contextTypes: true,\n defaultProps: true,\n displayName: true,\n getDefaultProps: true,\n getDerivedStateFromError: true,\n getDerivedStateFromProps: true,\n mixins: true,\n propTypes: true,\n type: true,\n} as const;\n\n/**\n * Known JavaScript function statics that should not be hoisted\n */\nconst KNOWN_STATICS = {\n name: true,\n length: true,\n prototype: true,\n caller: true,\n callee: true,\n arguments: true,\n arity: true,\n} as const;\n\n/**\n * Statics specific to ForwardRef components\n */\nconst FORWARD_REF_STATICS = {\n $$typeof: true,\n render: true,\n defaultProps: true,\n displayName: true,\n propTypes: true,\n} as const;\n\n/**\n * Statics specific to Memo components\n */\nconst MEMO_STATICS = {\n $$typeof: true,\n compare: true,\n defaultProps: true,\n displayName: true,\n propTypes: true,\n type: true,\n} as const;\n\n/**\n * Inlined react-is utilities\n * We only need to detect ForwardRef and Memo types\n */\nconst ForwardRefType = Symbol.for('react.forward_ref');\nconst MemoType = Symbol.for('react.memo');\n\n/**\n * Map of React component types to their specific statics\n */\nconst TYPE_STATICS: Record<symbol, Record<string, boolean>> = {};\nTYPE_STATICS[ForwardRefType] = FORWARD_REF_STATICS;\nTYPE_STATICS[MemoType] = MEMO_STATICS;\n\n/**\n * Get the appropriate statics object for a given component\n */\nfunction getStatics(component: React.ComponentType<unknown>): Record<string, boolean> {\n const componentType = (component as { $$typeof?: symbol }).$$typeof;\n return (componentType && TYPE_STATICS[componentType]) || REACT_STATICS;\n}\n\nconst defineProperty = Object.defineProperty.bind(Object);\nconst getOwnPropertyNames = Object.getOwnPropertyNames.bind(Object);\nconst getOwnPropertySymbols = Object.getOwnPropertySymbols?.bind(Object);\nconst getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor.bind(Object);\nconst getPrototypeOf = Object.getPrototypeOf.bind(Object);\nconst objectPrototype = Object.prototype;\n\n/**\n * Copies non-react specific statics from a child component to a parent component.\n * Similar to Object.assign, but copies all static properties from source to target,\n * excluding React-specific statics and known JavaScript statics.\n *\n * @param targetComponent - The component to copy statics to\n * @param sourceComponent - The component to copy statics from\n * @param excludelist - An optional object of keys to exclude from hoisting\n * @returns The target component with hoisted statics\n */\nexport function hoistNonReactStatics<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends React.ComponentType<any>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n S extends React.ComponentType<any>,\n C extends Record<string, boolean> = Record<string, never>,\n>(targetComponent: T, sourceComponent: S, excludelist?: C): T {\n if (typeof sourceComponent !== 'string') {\n // Don't hoist over string (html) components\n if (objectPrototype) {\n const inheritedComponent = getPrototypeOf(sourceComponent);\n\n if (inheritedComponent && inheritedComponent !== objectPrototype) {\n hoistNonReactStatics(targetComponent, inheritedComponent, excludelist);\n }\n }\n\n let keys: (string | symbol)[] = getOwnPropertyNames(sourceComponent);\n\n if (getOwnPropertySymbols) {\n keys = keys.concat(getOwnPropertySymbols(sourceComponent));\n }\n\n const targetStatics = getStatics(targetComponent);\n const sourceStatics = getStatics(sourceComponent);\n\n for (const key of keys) {\n // Use key directly - String(key) throws for Symbols if minified to '' + key (#18966)\n if (\n !KNOWN_STATICS[key as keyof typeof KNOWN_STATICS] &&\n !excludelist?.[key as keyof C] &&\n !sourceStatics?.[key as string] &&\n !targetStatics?.[key as string] &&\n !getOwnPropertyDescriptor(targetComponent, key) // Don't overwrite existing properties\n ) {\n const descriptor = getOwnPropertyDescriptor(sourceComponent, key);\n\n if (descriptor) {\n try {\n // Avoid failures from read-only properties\n defineProperty(targetComponent, key, descriptor);\n } catch {\n // Silently ignore errors\n }\n }\n }\n }\n }\n\n return targetComponent;\n}\n"],"names":[],"mappings":";;AAcA,MAAM,aAAA,GAAgB;AAAA,EACpB,iBAAA,EAAmB,IAAA;AAAA,EACnB,WAAA,EAAa,IAAA;AAAA,EACb,YAAA,EAAc,IAAA;AAAA,EACd,YAAA,EAAc,IAAA;AAAA,EACd,WAAA,EAAa,IAAA;AAAA,EACb,eAAA,EA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BAAA,CAAyB,eAAA,EAAiB,GAAG,CAAA;AAEhE,QAAA,IAAI,UAAA,EAAY;AACd,UAAA,IAAI;AAEF,YAAA,cAAA,CAAe,eAAA,EAAiB,KAAK,UAAU,CAAA;AAAA,UACjD,CAAA,CAAA,MAAQ;AAAA,UAER;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,eAAA;AACT;;;;"}
|
package/build/cjs/profiler.js
CHANGED
|
@@ -2,8 +2,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const browser = require('@sentry/browser');
|
|
4
4
|
const core = require('@sentry/core');
|
|
5
|
+
const attributes = require('@sentry/conventions/attributes');
|
|
6
|
+
const op = require('@sentry/conventions/op');
|
|
5
7
|
const React = require('react');
|
|
6
|
-
const constants = require('./constants.js');
|
|
7
8
|
const hoistNonReactStatics = require('./hoist-non-react-statics.js');
|
|
8
9
|
|
|
9
10
|
const UNKNOWN_COMPONENT = "unknown";
|
|
@@ -17,8 +18,9 @@ class Profiler extends React.Component {
|
|
|
17
18
|
this._mountSpan = browser.startInactiveSpan({
|
|
18
19
|
name: `<${name}>`,
|
|
19
20
|
onlyIfParent: true,
|
|
20
|
-
op: constants.REACT_MOUNT_OP,
|
|
21
21
|
attributes: {
|
|
22
|
+
// TODO(conventions): Replace `'ui.mount'` with the `ui.mount` span op constant once it is released in `@sentry/conventions`.
|
|
23
|
+
[attributes.SENTRY_OP]: "ui.mount",
|
|
22
24
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.ui.react.profiler",
|
|
23
25
|
"ui.component_name": name
|
|
24
26
|
}
|
|
@@ -39,9 +41,10 @@ class Profiler extends React.Component {
|
|
|
39
41
|
return browser.startInactiveSpan({
|
|
40
42
|
name: `<${this.props.name}>`,
|
|
41
43
|
onlyIfParent: true,
|
|
42
|
-
op: constants.REACT_UPDATE_OP,
|
|
43
44
|
startTime: now,
|
|
44
45
|
attributes: {
|
|
46
|
+
// TODO(conventions): Replace `'ui.update'` with the `ui.update` span op constant once it is released in `@sentry/conventions`.
|
|
47
|
+
[attributes.SENTRY_OP]: "ui.update",
|
|
45
48
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.ui.react.profiler",
|
|
46
49
|
"ui.component_name": this.props.name,
|
|
47
50
|
"ui.react.changed_props": changedProps
|
|
@@ -64,14 +67,14 @@ class Profiler extends React.Component {
|
|
|
64
67
|
const endTimestamp = core.timestampInSeconds();
|
|
65
68
|
const { name, includeRender = true } = this.props;
|
|
66
69
|
if (this._mountSpan && includeRender) {
|
|
67
|
-
const startTime = core.spanToJSON(this._mountSpan).
|
|
70
|
+
const startTime = core.spanToJSON(this._mountSpan).end_timestamp;
|
|
68
71
|
core.withActiveSpan(this._mountSpan, () => {
|
|
69
72
|
const renderSpan = browser.startInactiveSpan({
|
|
70
73
|
onlyIfParent: true,
|
|
71
74
|
name: `<${name}>`,
|
|
72
|
-
op: constants.REACT_RENDER_OP,
|
|
73
75
|
startTime,
|
|
74
76
|
attributes: {
|
|
77
|
+
[attributes.SENTRY_OP]: op.BROWSER_UI_RENDER_SPAN_OP,
|
|
75
78
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.ui.react.profiler",
|
|
76
79
|
"ui.component_name": name
|
|
77
80
|
}
|
|
@@ -111,8 +114,9 @@ function useProfiler(name, options = {
|
|
|
111
114
|
return browser.startInactiveSpan({
|
|
112
115
|
name: `<${name}>`,
|
|
113
116
|
onlyIfParent: true,
|
|
114
|
-
op: constants.REACT_MOUNT_OP,
|
|
115
117
|
attributes: {
|
|
118
|
+
// TODO(conventions): Replace `'ui.mount'` with the `ui.mount` span op constant once it is released in `@sentry/conventions`.
|
|
119
|
+
[attributes.SENTRY_OP]: "ui.mount",
|
|
116
120
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.ui.react.profiler",
|
|
117
121
|
"ui.component_name": name
|
|
118
122
|
}
|
|
@@ -124,14 +128,14 @@ function useProfiler(name, options = {
|
|
|
124
128
|
}
|
|
125
129
|
return () => {
|
|
126
130
|
if (mountSpan && options.hasRenderSpan) {
|
|
127
|
-
const startTime = core.spanToJSON(mountSpan).
|
|
131
|
+
const startTime = core.spanToJSON(mountSpan).end_timestamp;
|
|
128
132
|
const endTimestamp = core.timestampInSeconds();
|
|
129
133
|
const renderSpan = browser.startInactiveSpan({
|
|
130
134
|
name: `<${name}>`,
|
|
131
135
|
onlyIfParent: true,
|
|
132
|
-
op: constants.REACT_RENDER_OP,
|
|
133
136
|
startTime,
|
|
134
137
|
attributes: {
|
|
138
|
+
[attributes.SENTRY_OP]: op.BROWSER_UI_RENDER_SPAN_OP,
|
|
135
139
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.ui.react.profiler",
|
|
136
140
|
"ui.component_name": name
|
|
137
141
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiler.js","sources":["../../src/profiler.tsx"],"sourcesContent":["import { startInactiveSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON, timestampInSeconds, withActiveSpan } from '@sentry/core';\nimport * as React from 'react';\nimport { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from './constants';\nimport { hoistNonReactStatics } from './hoist-non-react-statics';\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 // Component that is being profiled.\n children?: React.ReactNode;\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;\n /**\n * The span that represents the duration of time between shouldComponentUpdate and componentDidUpdate\n */\n protected _updateSpan: Span | undefined;\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 this._mountSpan = startInactiveSpan({\n name: `<${name}>`,\n onlyIfParent: true,\n op: REACT_MOUNT_OP,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',\n 'ui.component_name': name,\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.end();\n }\n }\n\n public shouldComponentUpdate({ updateProps, includeUpdates = true }: ProfilerProps): boolean {\n // Only generate an update span if includeUpdates 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 have 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 potentially very large.\n const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);\n if (changedProps.length > 0) {\n const now = timestampInSeconds();\n this._updateSpan = withActiveSpan(this._mountSpan, () => {\n return startInactiveSpan({\n name: `<${this.props.name}>`,\n onlyIfParent: true,\n op: REACT_UPDATE_OP,\n startTime: now,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',\n 'ui.component_name': this.props.name,\n 'ui.react.changed_props': changedProps,\n },\n });\n });\n }\n }\n\n return true;\n }\n\n public componentDidUpdate(): void {\n if (this._updateSpan) {\n this._updateSpan.end();\n this._updateSpan = undefined;\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 endTimestamp = timestampInSeconds();\n const { name, includeRender = true } = this.props;\n\n if (this._mountSpan && includeRender) {\n const startTime = spanToJSON(this._mountSpan).timestamp;\n withActiveSpan(this._mountSpan, () => {\n const renderSpan = startInactiveSpan({\n onlyIfParent: true,\n name: `<${name}>`,\n op: REACT_RENDER_OP,\n startTime,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',\n 'ui.component_name': name,\n },\n });\n if (renderSpan) {\n // Have to cast to Span because the type of _mountSpan is Span | undefined\n // and not getting narrowed properly\n renderSpan.end(endTimestamp);\n }\n });\n }\n }\n\n public render(): React.ReactNode {\n return this.props.children;\n }\n}\n\n// React.Component default props are defined as static property on the class\nObject.assign(Profiler, {\n defaultProps: {\n disabled: false,\n includeRender: true,\n includeUpdates: true,\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 */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\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' | 'children'>>,\n): React.FC<P> {\n const componentDisplayName =\n 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?.disabled) {\n return undefined;\n }\n\n return startInactiveSpan({\n name: `<${name}>`,\n onlyIfParent: true,\n op: REACT_MOUNT_OP,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',\n 'ui.component_name': name,\n },\n });\n });\n\n React.useEffect(() => {\n if (mountSpan) {\n mountSpan.end();\n }\n\n return (): void => {\n if (mountSpan && options.hasRenderSpan) {\n const startTime = spanToJSON(mountSpan).timestamp;\n const endTimestamp = timestampInSeconds();\n\n const renderSpan = startInactiveSpan({\n name: `<${name}>`,\n onlyIfParent: true,\n op: REACT_RENDER_OP,\n startTime,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',\n 'ui.component_name': name,\n },\n });\n if (renderSpan) {\n // Have to cast to Span because the type of _mountSpan is Span | undefined\n // and not getting narrowed properly\n renderSpan.end(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 { Profiler, useProfiler, withProfiler };\n"],"names":["startInactiveSpan","REACT_MOUNT_OP","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","timestampInSeconds","withActiveSpan","REACT_UPDATE_OP","spanToJSON","REACT_RENDER_OP","hoistNonReactStatics"],"mappings":";;;;;;;;AAOO,MAAM,iBAAA,GAAoB;AAsBjC,MAAM,QAAA,SAAiB,MAAM,SAAA,CAAyB;AAAA,EAW7C,YAAY,KAAA,EAAsB;AACvC,IAAA,KAAA,CAAM,KAAK,CAAA;AACX,IAAA,MAAM,EAAE,IAAA,EAAM,QAAA,GAAW,KAAA,KAAU,IAAA,CAA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M,UAAU,MAAM;AACpB,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,SAAA,CAAU,GAAA,EAAI;AAAA,IAChB;AAEA,IAAA,OAAO,MAAY;AACjB,MAAA,IAAI,SAAA,IAAa,QAAQ,aAAA,EAAe;AACtC,QAAA,MAAM,SAAA,GAAYI,eAAA,CAAW,SAAS,CAAA,CAAE,SAAA;AACxC,QAAA,MAAM,eAAeH,uBAAA,EAAmB;AAExC,QAAA,MAAM,aAAaH,yBAAA,CAAkB;AAAA,UACnC,IAAA,EAAM,IAAI,IAAI,CAAA,CAAA,CAAA;AAAA,UACd,YAAA,EAAc,IAAA;AAAA,UACd,EAAA,EAAIO,yBAAA;AAAA,UACJ,SAAA;AAAA,UACA,UAAA,EAAY;AAAA,YACV,CAACL,qCAAgC,GAAG,wBAAA;AAAA,YACpC,mBAAA,EAAqB;AAAA;AACvB,SACD,CAAA;AACD,QAAA,IAAI,UAAA,EAAY;AAGd,UAAA,UAAA,CAAW,IAAI,YAAY,CAAA;AAAA,QAC7B;AAAA,MACF;AAAA,IACF,CAAA;AAAA,EAGF,CAAA,EAAG,EAAE,CAAA;AACP;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"profiler.js","sources":["../../src/profiler.tsx"],"sourcesContent":["import { startInactiveSpan } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON, timestampInSeconds, withActiveSpan } from '@sentry/core';\nimport { SENTRY_OP } from '@sentry/conventions/attributes';\nimport { BROWSER_UI_RENDER_SPAN_OP } from '@sentry/conventions/op';\nimport * as React from 'react';\nimport { hoistNonReactStatics } from './hoist-non-react-statics';\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 // Component that is being profiled.\n children?: React.ReactNode;\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;\n /**\n * The span that represents the duration of time between shouldComponentUpdate and componentDidUpdate\n */\n protected _updateSpan: Span | undefined;\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 this._mountSpan = startInactiveSpan({\n name: `<${name}>`,\n onlyIfParent: true,\n attributes: {\n // TODO(conventions): Replace `'ui.mount'` with the `ui.mount` span op constant once it is released in `@sentry/conventions`.\n [SENTRY_OP]: 'ui.mount',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',\n 'ui.component_name': name,\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.end();\n }\n }\n\n public shouldComponentUpdate({ updateProps, includeUpdates = true }: ProfilerProps): boolean {\n // Only generate an update span if includeUpdates 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 have 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 potentially very large.\n const changedProps = Object.keys(updateProps).filter(k => updateProps[k] !== this.props.updateProps[k]);\n if (changedProps.length > 0) {\n const now = timestampInSeconds();\n this._updateSpan = withActiveSpan(this._mountSpan, () => {\n return startInactiveSpan({\n name: `<${this.props.name}>`,\n onlyIfParent: true,\n startTime: now,\n attributes: {\n // TODO(conventions): Replace `'ui.update'` with the `ui.update` span op constant once it is released in `@sentry/conventions`.\n [SENTRY_OP]: 'ui.update',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',\n 'ui.component_name': this.props.name,\n 'ui.react.changed_props': changedProps,\n },\n });\n });\n }\n }\n\n return true;\n }\n\n public componentDidUpdate(): void {\n if (this._updateSpan) {\n this._updateSpan.end();\n this._updateSpan = undefined;\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 endTimestamp = timestampInSeconds();\n const { name, includeRender = true } = this.props;\n\n if (this._mountSpan && includeRender) {\n const startTime = spanToJSON(this._mountSpan).end_timestamp;\n withActiveSpan(this._mountSpan, () => {\n const renderSpan = startInactiveSpan({\n onlyIfParent: true,\n name: `<${name}>`,\n startTime,\n attributes: {\n [SENTRY_OP]: BROWSER_UI_RENDER_SPAN_OP,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',\n 'ui.component_name': name,\n },\n });\n if (renderSpan) {\n // Have to cast to Span because the type of _mountSpan is Span | undefined\n // and not getting narrowed properly\n renderSpan.end(endTimestamp);\n }\n });\n }\n }\n\n public render(): React.ReactNode {\n return this.props.children;\n }\n}\n\n// React.Component default props are defined as static property on the class\nObject.assign(Profiler, {\n defaultProps: {\n disabled: false,\n includeRender: true,\n includeUpdates: true,\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 */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\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' | 'children'>>,\n): React.FC<P> {\n const componentDisplayName =\n 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 * @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?.disabled) {\n return undefined;\n }\n\n return startInactiveSpan({\n name: `<${name}>`,\n onlyIfParent: true,\n attributes: {\n // TODO(conventions): Replace `'ui.mount'` with the `ui.mount` span op constant once it is released in `@sentry/conventions`.\n [SENTRY_OP]: 'ui.mount',\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',\n 'ui.component_name': name,\n },\n });\n });\n\n React.useEffect(() => {\n if (mountSpan) {\n mountSpan.end();\n }\n\n return (): void => {\n if (mountSpan && options.hasRenderSpan) {\n const startTime = spanToJSON(mountSpan).end_timestamp;\n const endTimestamp = timestampInSeconds();\n\n const renderSpan = startInactiveSpan({\n name: `<${name}>`,\n onlyIfParent: true,\n startTime,\n attributes: {\n [SENTRY_OP]: BROWSER_UI_RENDER_SPAN_OP,\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.react.profiler',\n 'ui.component_name': name,\n },\n });\n if (renderSpan) {\n // Have to cast to Span because the type of _mountSpan is Span | undefined\n // and not getting narrowed properly\n renderSpan.end(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 { Profiler, useProfiler, withProfiler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AAA,CAAM,SAAS,MAAM;AACvC,IAAA,IAAI,SAAS,QAAA,EAAU;AACrB,MAAA,OAAO,MAAA;AAAA,IACT;AAEA,IAAA,OAAOP,yBAAA,CAAkB;AAAA,MACvB,IAAA,EAAM,IAAI,IAAI,CAAA,CAAA,CAAA;AAAA,MACd,YAAA,EAAc,IAAA;AAAA,MACd,UAAA,EAAY;AAAA;AAAA,QAEV,CAACC,oBAAS,GAAG,UAAA;AAAA,QACb,CAACC,qCAAgC,GAAG,wBAAA;AAAA,QACpC,mBAAA,EAAqB;AAAA;AACvB,KACD,CAAA;AAAA,EACH,CAAC,CAAA;AAED,EAAA,KAAA,CAAM,UAAU,MAAM;AACpB,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,SAAA,CAAU,GAAA,EAAI;AAAA,IAChB;AAEA,IAAA,OAAO,MAAY;AACjB,MAAA,IAAI,SAAA,IAAa,QAAQ,aAAA,EAAe;AACtC,QAAA,MAAM,SAAA,GAAYG,eAAA,CAAW,SAAS,CAAA,CAAE,aAAA;AACxC,QAAA,MAAM,eAAeF,uBAAA,EAAmB;AAExC,QAAA,MAAM,aAAaH,yBAAA,CAAkB;AAAA,UACnC,IAAA,EAAM,IAAI,IAAI,CAAA,CAAA,CAAA;AAAA,UACd,YAAA,EAAc,IAAA;AAAA,UACd,SAAA;AAAA,UACA,UAAA,EAAY;AAAA,YACV,CAACC,oBAAS,GAAGK,4BAAA;AAAA,YACb,CAACJ,qCAAgC,GAAG,wBAAA;AAAA,YACpC,mBAAA,EAAqB;AAAA;AACvB,SACD,CAAA;AACD,QAAA,IAAI,UAAA,EAAY;AAGd,UAAA,UAAA,CAAW,IAAI,YAAY,CAAA;AAAA,QAC7B;AAAA,MACF;AAAA,IACF,CAAA;AAAA,EAGF,CAAA,EAAG,EAAE,CAAA;AACP;;;;;;;"}
|
|
@@ -114,12 +114,12 @@ function processResolvedRoutes(resolvedRoutes, parentRoute, currentLocation = nu
|
|
|
114
114
|
}
|
|
115
115
|
const targetSpan = capturedSpan ?? utils.getActiveRootSpan();
|
|
116
116
|
if (targetSpan) {
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
117
|
+
const { end_timestamp, attributes: attributes$1 } = core.spanToJSON(targetSpan);
|
|
118
|
+
if (end_timestamp) {
|
|
119
119
|
debugBuild.DEBUG_BUILD && core.debug.warn("[React Router] Lazy handler resolved after span ended - skipping update");
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
|
-
const spanOp =
|
|
122
|
+
const spanOp = attributes$1[attributes.SENTRY_OP];
|
|
123
123
|
let location = currentLocation;
|
|
124
124
|
if (!location && !capturedSpan) {
|
|
125
125
|
if (typeof browser.WINDOW !== "undefined") {
|
|
@@ -144,12 +144,11 @@ function processResolvedRoutes(resolvedRoutes, parentRoute, currentLocation = nu
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
function updateNavigationSpan(activeRootSpan, location, allRoutes2, forceUpdate = false, matchRoutes) {
|
|
147
|
-
const
|
|
148
|
-
const currentName = spanJson.description;
|
|
147
|
+
const { name: currentName, end_timestamp, attributes: attributes$1 } = core.spanToJSON(activeRootSpan);
|
|
149
148
|
const hasBeenNamed = activeRootSpan?.__sentry_navigation_name_set__;
|
|
150
149
|
const currentNameHasWildcard = currentName && utils.transactionNameHasWildcard(currentName);
|
|
151
150
|
const shouldUpdate = !hasBeenNamed || forceUpdate || currentNameHasWildcard;
|
|
152
|
-
if (shouldUpdate && !
|
|
151
|
+
if (shouldUpdate && !end_timestamp) {
|
|
153
152
|
const currentBranches = matchRoutes(allRoutes2, location);
|
|
154
153
|
const [name, source] = utils.resolveRouteNameAndSource(
|
|
155
154
|
location,
|
|
@@ -160,7 +159,7 @@ function updateNavigationSpan(activeRootSpan, location, allRoutes2, forceUpdate
|
|
|
160
159
|
_lazyRouteManifest,
|
|
161
160
|
_enableAsyncRouteHandlers
|
|
162
161
|
);
|
|
163
|
-
const currentSource =
|
|
162
|
+
const currentSource = attributes$1[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
|
|
164
163
|
const isImprovement = name && (!currentName || // No current name - always set
|
|
165
164
|
!hasBeenNamed && (currentSource !== "route" || source === "route") || // Not finalized - allow unless downgrading route→url
|
|
166
165
|
currentSource !== "route" && source === "route" || // URL → route upgrade
|
|
@@ -172,25 +171,21 @@ function updateNavigationSpan(activeRootSpan, location, allRoutes2, forceUpdate
|
|
|
172
171
|
activeRootSpan.setAttribute(attributes.URL_TEMPLATE, name);
|
|
173
172
|
}
|
|
174
173
|
if (!utils.transactionNameHasWildcard(name) && source === "route") {
|
|
175
|
-
core.addNonEnumerableProperty(
|
|
176
|
-
activeRootSpan,
|
|
177
|
-
"__sentry_navigation_name_set__",
|
|
178
|
-
true
|
|
179
|
-
);
|
|
174
|
+
core.addNonEnumerableProperty(activeRootSpan, "__sentry_navigation_name_set__", true);
|
|
180
175
|
}
|
|
181
176
|
}
|
|
182
177
|
}
|
|
183
178
|
}
|
|
184
179
|
function setupRouterSubscription(router, routes, version, basename, activeRootSpan) {
|
|
185
180
|
let isInitialPageloadComplete = false;
|
|
186
|
-
let hasSeenPageloadSpan = !!activeRootSpan && core.spanToJSON(activeRootSpan).
|
|
181
|
+
let hasSeenPageloadSpan = !!activeRootSpan && core.spanToJSON(activeRootSpan).attributes[attributes.SENTRY_OP] === "pageload";
|
|
187
182
|
let hasSeenPopAfterPageload = false;
|
|
188
183
|
let scheduledNavigationHandler = null;
|
|
189
184
|
let lastHandledPathname = null;
|
|
190
185
|
router.subscribe((state) => {
|
|
191
186
|
if (!isInitialPageloadComplete) {
|
|
192
187
|
const currentRootSpan = utils.getActiveRootSpan();
|
|
193
|
-
const isCurrentlyInPageload = currentRootSpan && core.spanToJSON(currentRootSpan).
|
|
188
|
+
const isCurrentlyInPageload = currentRootSpan && core.spanToJSON(currentRootSpan).attributes[attributes.SENTRY_OP] === "pageload";
|
|
194
189
|
if (isCurrentlyInPageload) {
|
|
195
190
|
hasSeenPageloadSpan = true;
|
|
196
191
|
} else if (hasSeenPageloadSpan) {
|
|
@@ -254,11 +249,7 @@ function createV6CompatibleWrapCreateBrowserRouter(createRouterFunction, version
|
|
|
254
249
|
const activeRootSpan = utils.getActiveRootSpan();
|
|
255
250
|
const hasPatchRoutesOnNavigation = opts && "patchRoutesOnNavigation" in opts && typeof opts.patchRoutesOnNavigation === "function";
|
|
256
251
|
if (hasPatchRoutesOnNavigation && activeRootSpan) {
|
|
257
|
-
core.addNonEnumerableProperty(
|
|
258
|
-
activeRootSpan,
|
|
259
|
-
"__sentry_may_have_lazy_routes__",
|
|
260
|
-
true
|
|
261
|
-
);
|
|
252
|
+
core.addNonEnumerableProperty(activeRootSpan, "__sentry_may_have_lazy_routes__", true);
|
|
262
253
|
createDeferredLazyRoutePromise(activeRootSpan);
|
|
263
254
|
}
|
|
264
255
|
const wrappedOpts = wrapPatchRoutesOnNavigation(opts, false, activeRootSpan);
|
|
@@ -295,11 +286,7 @@ function createV6CompatibleWrapCreateMemoryRouter(createRouterFunction, version)
|
|
|
295
286
|
const memoryActiveRootSpanEarly = utils.getActiveRootSpan();
|
|
296
287
|
const hasPatchRoutesOnNavigation = opts && "patchRoutesOnNavigation" in opts && typeof opts.patchRoutesOnNavigation === "function";
|
|
297
288
|
if (hasPatchRoutesOnNavigation && memoryActiveRootSpanEarly) {
|
|
298
|
-
core.addNonEnumerableProperty(
|
|
299
|
-
memoryActiveRootSpanEarly,
|
|
300
|
-
"__sentry_may_have_lazy_routes__",
|
|
301
|
-
true
|
|
302
|
-
);
|
|
289
|
+
core.addNonEnumerableProperty(memoryActiveRootSpanEarly, "__sentry_may_have_lazy_routes__", true);
|
|
303
290
|
createDeferredLazyRoutePromise(memoryActiveRootSpanEarly);
|
|
304
291
|
}
|
|
305
292
|
const wrappedOpts = wrapPatchRoutesOnNavigation(opts, true, memoryActiveRootSpanEarly);
|
|
@@ -474,8 +461,8 @@ function wrapPatchRoutesOnNavigation(opts, isMemoryRouter = false, capturedSpan)
|
|
|
474
461
|
}
|
|
475
462
|
}
|
|
476
463
|
const spanJson = activeRootSpan ? core.spanToJSON(activeRootSpan) : void 0;
|
|
477
|
-
if (targetPath && activeRootSpan && spanJson && !spanJson.
|
|
478
|
-
spanJson.
|
|
464
|
+
if (targetPath && activeRootSpan && spanJson && !spanJson.end_timestamp && // Span hasn't ended yet
|
|
465
|
+
spanJson.attributes[attributes.SENTRY_OP] === "navigation") {
|
|
479
466
|
updateNavigationSpan(
|
|
480
467
|
activeRootSpan,
|
|
481
468
|
{ pathname: targetPath, search: "", hash: "", state: null, key: "default" },
|
|
@@ -500,8 +487,8 @@ function wrapPatchRoutesOnNavigation(opts, isMemoryRouter = false, capturedSpan)
|
|
|
500
487
|
}
|
|
501
488
|
}
|
|
502
489
|
const spanJson = activeRootSpan ? core.spanToJSON(activeRootSpan) : void 0;
|
|
503
|
-
if (activeRootSpan && spanJson && !spanJson.
|
|
504
|
-
spanJson.
|
|
490
|
+
if (activeRootSpan && spanJson && !spanJson.end_timestamp && // Span hasn't ended yet
|
|
491
|
+
spanJson.attributes[attributes.SENTRY_OP] === "navigation") {
|
|
505
492
|
const pathname = targetPath;
|
|
506
493
|
if (pathname) {
|
|
507
494
|
updateNavigationSpan(
|
|
@@ -530,7 +517,7 @@ function handleNavigation(opts) {
|
|
|
530
517
|
return;
|
|
531
518
|
}
|
|
532
519
|
const activeRootSpan = utils.getActiveRootSpan();
|
|
533
|
-
if (activeRootSpan && core.spanToJSON(activeRootSpan).
|
|
520
|
+
if (activeRootSpan && core.spanToJSON(activeRootSpan).attributes[attributes.SENTRY_OP] === "pageload" && navigationType === "POP") {
|
|
534
521
|
return;
|
|
535
522
|
}
|
|
536
523
|
if ((navigationType === "PUSH" || navigationType === "POP") && branches) {
|
|
@@ -545,7 +532,7 @@ function handleNavigation(opts) {
|
|
|
545
532
|
);
|
|
546
533
|
const locationKey = computeLocationKey(location);
|
|
547
534
|
const trackedNav = activeNavigationSpans.get(client);
|
|
548
|
-
const trackedSpanHasEnded = trackedNav && !trackedNav.isPlaceholder ? !!core.spanToJSON(trackedNav.span).
|
|
535
|
+
const trackedSpanHasEnded = trackedNav && !trackedNav.isPlaceholder ? !!core.spanToJSON(trackedNav.span).end_timestamp : false;
|
|
549
536
|
const { skip, shouldUpdate } = shouldSkipNavigation(trackedNav, locationKey, name, trackedSpanHasEnded);
|
|
550
537
|
if (skip) {
|
|
551
538
|
if (shouldUpdate && trackedNav) {
|
|
@@ -561,11 +548,7 @@ function handleNavigation(opts) {
|
|
|
561
548
|
if (source === "route") {
|
|
562
549
|
trackedNav.span.setAttribute(attributes.URL_TEMPLATE, name);
|
|
563
550
|
}
|
|
564
|
-
core.addNonEnumerableProperty(
|
|
565
|
-
trackedNav.span,
|
|
566
|
-
"__sentry_navigation_name_set__",
|
|
567
|
-
true
|
|
568
|
-
);
|
|
551
|
+
core.addNonEnumerableProperty(trackedNav.span, "__sentry_navigation_name_set__", true);
|
|
569
552
|
trackedNav.routeName = name;
|
|
570
553
|
debugBuild.DEBUG_BUILD && core.debug.log(`[Tracing] Updated navigation span name from "${oldName}" to "${name}"`);
|
|
571
554
|
}
|
|
@@ -694,7 +677,7 @@ function shouldUpdateWildcardSpanName(currentName, currentSource, newName, newSo
|
|
|
694
677
|
}
|
|
695
678
|
function tryUpdateSpanNameBeforeEnd(span, spanJson, currentName, location, routes, basename, spanType, allRoutes2) {
|
|
696
679
|
try {
|
|
697
|
-
const currentSource = spanJson.
|
|
680
|
+
const currentSource = spanJson.attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
|
|
698
681
|
if (currentSource === "route" && currentName && !utils.transactionNameHasWildcard(currentName)) {
|
|
699
682
|
return;
|
|
700
683
|
}
|
|
@@ -714,7 +697,7 @@ function tryUpdateSpanNameBeforeEnd(span, spanJson, currentName, location, route
|
|
|
714
697
|
_enableAsyncRouteHandlers
|
|
715
698
|
);
|
|
716
699
|
const isImprovement = shouldUpdateWildcardSpanName(currentName, currentSource, name, source, true);
|
|
717
|
-
const spanNotEnded = spanType === "pageload" || !spanJson.
|
|
700
|
+
const spanNotEnded = spanType === "pageload" || !spanJson.end_timestamp;
|
|
718
701
|
if (isImprovement && spanNotEnded) {
|
|
719
702
|
span.updateName(name);
|
|
720
703
|
span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
|
|
@@ -741,13 +724,13 @@ function patchSpanEnd(span, location, routes, basename, spanType) {
|
|
|
741
724
|
endCalled = true;
|
|
742
725
|
const endTimestamp = args.length > 0 ? args[0] : Date.now() / 1e3;
|
|
743
726
|
const spanJson = core.spanToJSON(span);
|
|
744
|
-
const currentName = spanJson.
|
|
745
|
-
const currentSource = spanJson.
|
|
727
|
+
const currentName = spanJson.name;
|
|
728
|
+
const currentSource = spanJson.attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
|
|
746
729
|
const cleanupNavigationSpan = () => {
|
|
747
730
|
const client = core.getClient();
|
|
748
731
|
if (client && spanType === "navigation") {
|
|
749
732
|
const trackedNav = activeNavigationSpans.get(client);
|
|
750
|
-
if (trackedNav
|
|
733
|
+
if (trackedNav?.span === span) {
|
|
751
734
|
activeNavigationSpans.delete(client);
|
|
752
735
|
}
|
|
753
736
|
}
|
|
@@ -777,7 +760,7 @@ function patchSpanEnd(span, location, routes, basename, spanType) {
|
|
|
777
760
|
tryUpdateSpanNameBeforeEnd(
|
|
778
761
|
span,
|
|
779
762
|
updatedSpanJson,
|
|
780
|
-
updatedSpanJson.
|
|
763
|
+
updatedSpanJson.name,
|
|
781
764
|
location,
|
|
782
765
|
routes,
|
|
783
766
|
basename,
|