@depup/sentry__react 10.48.0-depup.0 → 10.67.0-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/README.md +9 -3
  2. package/build/cjs/constants.js +3 -5
  3. package/build/cjs/constants.js.map +1 -1
  4. package/build/cjs/debug-build.js +0 -5
  5. package/build/cjs/debug-build.js.map +1 -1
  6. package/build/cjs/error.js +14 -77
  7. package/build/cjs/error.js.map +1 -1
  8. package/build/cjs/errorboundary.js +22 -77
  9. package/build/cjs/errorboundary.js.map +1 -1
  10. package/build/cjs/hoist-non-react-statics.js +16 -84
  11. package/build/cjs/hoist-non-react-statics.js.map +1 -1
  12. package/build/cjs/index.js +6 -0
  13. package/build/cjs/index.js.map +1 -1
  14. package/build/cjs/isSyntheticEvent.js +10 -0
  15. package/build/cjs/isSyntheticEvent.js.map +1 -0
  16. package/build/cjs/profiler.js +35 -110
  17. package/build/cjs/profiler.js.map +1 -1
  18. package/build/cjs/reactrouter-compat-utils/instrumentation.js +236 -692
  19. package/build/cjs/reactrouter-compat-utils/instrumentation.js.map +1 -1
  20. package/build/cjs/reactrouter-compat-utils/lazy-routes.js +24 -85
  21. package/build/cjs/reactrouter-compat-utils/lazy-routes.js.map +1 -1
  22. package/build/cjs/reactrouter-compat-utils/route-manifest.js +18 -96
  23. package/build/cjs/reactrouter-compat-utils/route-manifest.js.map +1 -1
  24. package/build/cjs/reactrouter-compat-utils/utils.js +82 -193
  25. package/build/cjs/reactrouter-compat-utils/utils.js.map +1 -1
  26. package/build/cjs/reactrouter.compat.js +29 -0
  27. package/build/cjs/reactrouter.compat.js.map +1 -0
  28. package/build/cjs/reactrouter.js +34 -111
  29. package/build/cjs/reactrouter.js.map +1 -1
  30. package/build/cjs/reactrouterv3.js +31 -60
  31. package/build/cjs/reactrouterv3.js.map +1 -1
  32. package/build/cjs/reactrouterv6.js +10 -42
  33. package/build/cjs/reactrouterv6.js.map +1 -1
  34. package/build/cjs/reactrouterv7.js +10 -42
  35. package/build/cjs/reactrouterv7.js.map +1 -1
  36. package/build/cjs/redux.js +61 -90
  37. package/build/cjs/redux.js.map +1 -1
  38. package/build/cjs/sdk.js +15 -10
  39. package/build/cjs/sdk.js.map +1 -1
  40. package/build/cjs/tanstackrouter.js +90 -92
  41. package/build/cjs/tanstackrouter.js.map +1 -1
  42. package/build/esm/constants.js +3 -5
  43. package/build/esm/constants.js.map +1 -1
  44. package/build/esm/debug-build.js +0 -5
  45. package/build/esm/debug-build.js.map +1 -1
  46. package/build/esm/error.js +13 -76
  47. package/build/esm/error.js.map +1 -1
  48. package/build/esm/errorboundary.js +22 -77
  49. package/build/esm/errorboundary.js.map +1 -1
  50. package/build/esm/hoist-non-react-statics.js +16 -84
  51. package/build/esm/hoist-non-react-statics.js.map +1 -1
  52. package/build/esm/index.js +1 -0
  53. package/build/esm/index.js.map +1 -1
  54. package/build/esm/isSyntheticEvent.js +8 -0
  55. package/build/esm/isSyntheticEvent.js.map +1 -0
  56. package/build/esm/package.json +1 -1
  57. package/build/esm/profiler.js +35 -110
  58. package/build/esm/profiler.js.map +1 -1
  59. package/build/esm/reactrouter-compat-utils/instrumentation.js +237 -693
  60. package/build/esm/reactrouter-compat-utils/instrumentation.js.map +1 -1
  61. package/build/esm/reactrouter-compat-utils/lazy-routes.js +24 -85
  62. package/build/esm/reactrouter-compat-utils/lazy-routes.js.map +1 -1
  63. package/build/esm/reactrouter-compat-utils/route-manifest.js +18 -96
  64. package/build/esm/reactrouter-compat-utils/route-manifest.js.map +1 -1
  65. package/build/esm/reactrouter-compat-utils/utils.js +80 -191
  66. package/build/esm/reactrouter-compat-utils/utils.js.map +1 -1
  67. package/build/esm/reactrouter.compat.js +23 -0
  68. package/build/esm/reactrouter.compat.js.map +1 -0
  69. package/build/esm/reactrouter.js +34 -111
  70. package/build/esm/reactrouter.js.map +1 -1
  71. package/build/esm/reactrouterv3.js +29 -58
  72. package/build/esm/reactrouterv3.js.map +1 -1
  73. package/build/esm/reactrouterv6.js +10 -42
  74. package/build/esm/reactrouterv6.js.map +1 -1
  75. package/build/esm/reactrouterv7.js +10 -42
  76. package/build/esm/reactrouterv7.js.map +1 -1
  77. package/build/esm/redux.js +61 -90
  78. package/build/esm/redux.js.map +1 -1
  79. package/build/esm/sdk.js +15 -10
  80. package/build/esm/sdk.js.map +1 -1
  81. package/build/esm/tanstackrouter.js +91 -93
  82. package/build/esm/tanstackrouter.js.map +1 -1
  83. package/build/types/error.d.ts.map +1 -1
  84. package/build/types/index.d.ts +1 -0
  85. package/build/types/index.d.ts.map +1 -1
  86. package/build/types/isSyntheticEvent.d.ts +10 -0
  87. package/build/types/isSyntheticEvent.d.ts.map +1 -0
  88. package/build/types/reactrouter-compat-utils/instrumentation.d.ts +1 -1
  89. package/build/types/reactrouter-compat-utils/instrumentation.d.ts.map +1 -1
  90. package/build/types/reactrouter-compat-utils/utils.d.ts +1 -1
  91. package/build/types/reactrouter-compat-utils/utils.d.ts.map +1 -1
  92. package/build/types/reactrouter.compat.d.ts +42 -0
  93. package/build/types/reactrouter.compat.d.ts.map +1 -0
  94. package/build/types/reactrouter.d.ts.map +1 -1
  95. package/build/types/reactrouterv3.d.ts +1 -1
  96. package/build/types/reactrouterv3.d.ts.map +1 -1
  97. package/build/types/reactrouterv6.d.ts +10 -0
  98. package/build/types/reactrouterv6.d.ts.map +1 -1
  99. package/build/types/reactrouterv7.d.ts +10 -0
  100. package/build/types/reactrouterv7.d.ts.map +1 -1
  101. package/build/types/redux.d.ts +1 -1
  102. package/build/types/redux.d.ts.map +1 -1
  103. package/build/types/sdk.d.ts +1 -1
  104. package/build/types/sdk.d.ts.map +1 -1
  105. package/build/types/tanstackrouter.d.ts +1 -1
  106. package/build/types/tanstackrouter.d.ts.map +1 -1
  107. package/build/types/vendor/tanstackrouter-types.d.ts +2 -1
  108. package/build/types/vendor/tanstackrouter-types.d.ts.map +1 -1
  109. package/build/types-ts3.8/index.d.ts +1 -0
  110. package/build/types-ts3.8/isSyntheticEvent.d.ts +10 -0
  111. package/build/types-ts3.8/reactrouter-compat-utils/instrumentation.d.ts +1 -1
  112. package/build/types-ts3.8/reactrouter-compat-utils/utils.d.ts +1 -1
  113. package/build/types-ts3.8/reactrouter.compat.d.ts +42 -0
  114. package/build/types-ts3.8/reactrouterv3.d.ts +1 -1
  115. package/build/types-ts3.8/reactrouterv6.d.ts +10 -0
  116. package/build/types-ts3.8/reactrouterv7.d.ts +10 -0
  117. package/build/types-ts3.8/redux.d.ts +1 -1
  118. package/build/types-ts3.8/sdk.d.ts +1 -1
  119. package/build/types-ts3.8/tanstackrouter.d.ts +1 -1
  120. package/build/types-ts3.8/vendor/tanstackrouter-types.d.ts +2 -1
  121. package/changes.json +8 -3
  122. package/package.json +18 -8
@@ -1,56 +1,24 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const instrumentation = require('./reactrouter-compat-utils/instrumentation.js');
4
- require('@sentry/core');
4
+ require('@sentry/core/browser');
5
5
  require('@sentry/browser');
6
+ require('@sentry/core');
6
7
 
7
- /**
8
- * A browser tracing integration that uses React Router v7 to instrument navigations.
9
- * Expects `useEffect`, `useLocation`, `useNavigationType`, `createRoutesFromChildren` and `matchRoutes` to be passed as options.
10
- */
11
- function reactRouterV7BrowserTracingIntegration(
12
- options,
13
- ) {
14
- return instrumentation.createReactRouterV6CompatibleTracingIntegration(options, '7');
8
+ function reactRouterV7BrowserTracingIntegration(options) {
9
+ return instrumentation.createReactRouterV6CompatibleTracingIntegration(options, "7");
15
10
  }
16
-
17
- /**
18
- * A higher-order component that adds Sentry routing instrumentation to a React Router v7 Route component.
19
- * This is used to automatically capture route changes as transactions.
20
- */
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
11
  function withSentryReactRouterV7Routing(routes) {
23
- return instrumentation.createV6CompatibleWithSentryReactRouterRouting(routes, '7');
12
+ return instrumentation.createV6CompatibleWithSentryReactRouterRouting(routes, "7");
24
13
  }
25
-
26
- /**
27
- * A wrapper function that adds Sentry routing instrumentation to a React Router v7 createBrowserRouter function.
28
- * This is used to automatically capture route changes as transactions when using the createBrowserRouter API.
29
- */
30
- function wrapCreateBrowserRouterV7
31
-
32
- (createRouterFunction) {
33
- return instrumentation.createV6CompatibleWrapCreateBrowserRouter(createRouterFunction, '7');
14
+ function wrapCreateBrowserRouterV7(createRouterFunction) {
15
+ return instrumentation.createV6CompatibleWrapCreateBrowserRouter(createRouterFunction, "7");
34
16
  }
35
-
36
- /**
37
- * A wrapper function that adds Sentry routing instrumentation to a React Router v7 createMemoryRouter function.
38
- * This is used to automatically capture route changes as transactions when using the createMemoryRouter API.
39
- * The difference between createBrowserRouter and createMemoryRouter is that with createMemoryRouter,
40
- * optional `initialEntries` are also taken into account.
41
- */
42
- function wrapCreateMemoryRouterV7
43
-
44
- (createMemoryRouterFunction) {
45
- return instrumentation.createV6CompatibleWrapCreateMemoryRouter(createMemoryRouterFunction, '7');
17
+ function wrapCreateMemoryRouterV7(createMemoryRouterFunction) {
18
+ return instrumentation.createV6CompatibleWrapCreateMemoryRouter(createMemoryRouterFunction, "7");
46
19
  }
47
-
48
- /**
49
- * A wrapper function that adds Sentry routing instrumentation to a React Router v7 useRoutes hook.
50
- * This is used to automatically capture route changes as transactions when using the useRoutes hook.
51
- */
52
20
  function wrapUseRoutesV7(origUseRoutes) {
53
- return instrumentation.createV6CompatibleWrapUseRoutes(origUseRoutes, '7');
21
+ return instrumentation.createV6CompatibleWrapUseRoutes(origUseRoutes, "7");
54
22
  }
55
23
 
56
24
  exports.reactRouterV7BrowserTracingIntegration = reactRouterV7BrowserTracingIntegration;
@@ -1 +1 @@
1
- {"version":3,"file":"reactrouterv7.js","sources":["../../src/reactrouterv7.tsx"],"sourcesContent":["// React Router v7 uses the same integration as v6\nimport type { browserTracingIntegration } from '@sentry/browser';\nimport type { Integration } from '@sentry/core';\nimport type { ReactRouterOptions } from './reactrouter-compat-utils';\nimport {\n createReactRouterV6CompatibleTracingIntegration,\n createV6CompatibleWithSentryReactRouterRouting,\n createV6CompatibleWrapCreateBrowserRouter,\n createV6CompatibleWrapCreateMemoryRouter,\n createV6CompatibleWrapUseRoutes,\n} from './reactrouter-compat-utils';\nimport type { CreateRouterFunction, Router, RouterState, UseRoutes } from './types';\n\n/**\n * A browser tracing integration that uses React Router v7 to instrument navigations.\n * Expects `useEffect`, `useLocation`, `useNavigationType`, `createRoutesFromChildren` and `matchRoutes` to be passed as options.\n */\nexport function reactRouterV7BrowserTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0] & ReactRouterOptions,\n): Integration {\n return createReactRouterV6CompatibleTracingIntegration(options, '7');\n}\n\n/**\n * A higher-order component that adds Sentry routing instrumentation to a React Router v7 Route component.\n * This is used to automatically capture route changes as transactions.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withSentryReactRouterV7Routing<P extends Record<string, any>, R extends React.FC<P>>(routes: R): R {\n return createV6CompatibleWithSentryReactRouterRouting<P, R>(routes, '7');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v7 createBrowserRouter function.\n * This is used to automatically capture route changes as transactions when using the createBrowserRouter API.\n */\nexport function wrapCreateBrowserRouterV7<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n return createV6CompatibleWrapCreateBrowserRouter(createRouterFunction, '7');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v7 createMemoryRouter function.\n * This is used to automatically capture route changes as transactions when using the createMemoryRouter API.\n * The difference between createBrowserRouter and createMemoryRouter is that with createMemoryRouter,\n * optional `initialEntries` are also taken into account.\n */\nexport function wrapCreateMemoryRouterV7<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createMemoryRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n return createV6CompatibleWrapCreateMemoryRouter(createMemoryRouterFunction, '7');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v7 useRoutes hook.\n * This is used to automatically capture route changes as transactions when using the useRoutes hook.\n */\nexport function wrapUseRoutesV7(origUseRoutes: UseRoutes): UseRoutes {\n return createV6CompatibleWrapUseRoutes(origUseRoutes, '7');\n}\n"],"names":["createReactRouterV6CompatibleTracingIntegration","createV6CompatibleWithSentryReactRouterRouting","createV6CompatibleWrapCreateBrowserRouter","createV6CompatibleWrapCreateMemoryRouter","createV6CompatibleWrapUseRoutes"],"mappings":";;;;;;AAaA;AACA;AACA;AACA;AACO,SAAS,sCAAsC;AACtD,EAAE,OAAO;AACT,EAAe;AACf,EAAE,OAAOA,+DAA+C,CAAC,OAAO,EAAE,GAAG,CAAC;AACtE;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,8BAA8B,CAAuD,MAAM,EAAQ;AACnH,EAAE,OAAOC,8DAA8C,CAAO,MAAM,EAAE,GAAG,CAAC;AAC1E;;AAEA;AACA;AACA;AACA;AACO,SAAS;;AAGhB,CAAE,oBAAoB,EAAgF;AACtG,EAAE,OAAOC,yDAAyC,CAAC,oBAAoB,EAAE,GAAG,CAAC;AAC7E;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS;;AAGhB,CAAE,0BAA0B,EAAgF;AAC5G,EAAE,OAAOC,wDAAwC,CAAC,0BAA0B,EAAE,GAAG,CAAC;AAClF;;AAEA;AACA;AACA;AACA;AACO,SAAS,eAAe,CAAC,aAAa,EAAwB;AACrE,EAAE,OAAOC,+CAA+B,CAAC,aAAa,EAAE,GAAG,CAAC;AAC5D;;;;;;;;"}
1
+ {"version":3,"file":"reactrouterv7.js","sources":["../../src/reactrouterv7.tsx"],"sourcesContent":["// React Router v7 uses the same integration as v6\nimport type { browserTracingIntegration } from '@sentry/browser';\nimport type { Integration } from '@sentry/core';\nimport type { ReactRouterOptions } from './reactrouter-compat-utils';\nimport {\n createReactRouterV6CompatibleTracingIntegration,\n createV6CompatibleWithSentryReactRouterRouting,\n createV6CompatibleWrapCreateBrowserRouter,\n createV6CompatibleWrapCreateMemoryRouter,\n createV6CompatibleWrapUseRoutes,\n} from './reactrouter-compat-utils';\nimport type { CreateRouterFunction, Router, RouterState, UseRoutes } from './types';\n\n/**\n * A browser tracing integration that uses React Router v7 to instrument navigations.\n * Expects `useEffect`, `useLocation`, `useNavigationType`, `createRoutesFromChildren` and `matchRoutes` to be passed as options.\n *\n * @deprecated Use `reactRouterBrowserTracingIntegration` instead.\n */\nexport function reactRouterV7BrowserTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0] & ReactRouterOptions,\n): Integration {\n return createReactRouterV6CompatibleTracingIntegration(options, '7');\n}\n\n/**\n * A higher-order component that adds Sentry routing instrumentation to a React Router v7 Route component.\n * This is used to automatically capture route changes as transactions.\n *\n * @deprecated Use `wrapReactRouterRouting` instead.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function withSentryReactRouterV7Routing<P extends Record<string, any>, R extends React.FC<P>>(routes: R): R {\n return createV6CompatibleWithSentryReactRouterRouting<P, R>(routes, '7');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v7 createBrowserRouter function.\n * This is used to automatically capture route changes as transactions when using the createBrowserRouter API.\n *\n * @deprecated Use `wrapCreateBrowserRouter` instead.\n */\nexport function wrapCreateBrowserRouterV7<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n return createV6CompatibleWrapCreateBrowserRouter(createRouterFunction, '7');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v7 createMemoryRouter function.\n * This is used to automatically capture route changes as transactions when using the createMemoryRouter API.\n * The difference between createBrowserRouter and createMemoryRouter is that with createMemoryRouter,\n * optional `initialEntries` are also taken into account.\n *\n * @deprecated Use `wrapCreateMemoryRouter` instead.\n */\nexport function wrapCreateMemoryRouterV7<\n TState extends RouterState = RouterState,\n TRouter extends Router<TState> = Router<TState>,\n>(createMemoryRouterFunction: CreateRouterFunction<TState, TRouter>): CreateRouterFunction<TState, TRouter> {\n return createV6CompatibleWrapCreateMemoryRouter(createMemoryRouterFunction, '7');\n}\n\n/**\n * A wrapper function that adds Sentry routing instrumentation to a React Router v7 useRoutes hook.\n * This is used to automatically capture route changes as transactions when using the useRoutes hook.\n *\n * @deprecated Use `wrapUseRoutes` instead.\n */\nexport function wrapUseRoutesV7(origUseRoutes: UseRoutes): UseRoutes {\n return createV6CompatibleWrapUseRoutes(origUseRoutes, '7');\n}\n"],"names":["createReactRouterV6CompatibleTracingIntegration","createV6CompatibleWithSentryReactRouterRouting","createV6CompatibleWrapCreateBrowserRouter","createV6CompatibleWrapCreateMemoryRouter","createV6CompatibleWrapUseRoutes"],"mappings":";;;;;;;AAmBO,SAAS,uCACd,OAAA,EACa;AACb,EAAA,OAAOA,+DAAA,CAAgD,SAAS,GAAG,CAAA;AACrE;AASO,SAAS,+BAAqF,MAAA,EAAc;AACjH,EAAA,OAAOC,8DAAA,CAAqD,QAAQ,GAAG,CAAA;AACzE;AAQO,SAAS,0BAGd,oBAAA,EAAoG;AACpG,EAAA,OAAOC,yDAAA,CAA0C,sBAAsB,GAAG,CAAA;AAC5E;AAUO,SAAS,yBAGd,0BAAA,EAA0G;AAC1G,EAAA,OAAOC,wDAAA,CAAyC,4BAA4B,GAAG,CAAA;AACjF;AAQO,SAAS,gBAAgB,aAAA,EAAqC;AACnE,EAAA,OAAOC,+CAAA,CAAgC,eAAe,GAAG,CAAA;AAC3D;;;;;;;;"}
@@ -1,105 +1,76 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const core = require('@sentry/core');
4
-
5
- const ACTION_BREADCRUMB_CATEGORY = 'redux.action';
6
- const ACTION_BREADCRUMB_TYPE = 'info';
3
+ const browser = require('@sentry/core/browser');
7
4
 
5
+ const ACTION_BREADCRUMB_CATEGORY = "redux.action";
6
+ const ACTION_BREADCRUMB_TYPE = "info";
8
7
  const defaultOptions = {
9
8
  attachReduxState: true,
10
- actionTransformer: action => action,
11
- stateTransformer: state => state || null,
9
+ actionTransformer: (action) => action,
10
+ stateTransformer: (state) => state || null
12
11
  };
13
-
14
- /**
15
- * Creates an enhancer that would be passed to Redux's createStore to log actions and the latest state to Sentry.
16
- *
17
- * @param enhancerOptions Options to pass to the enhancer
18
- */
19
12
  function createReduxEnhancer(enhancerOptions) {
20
- // Note: We return an any type as to not have type conflicts.
21
13
  const options = {
22
14
  ...defaultOptions,
23
- ...enhancerOptions,
15
+ ...enhancerOptions
24
16
  };
25
-
26
- return (next) =>
27
- (reducer, initialState) => {
28
- options.attachReduxState &&
29
- core.getGlobalScope().addEventProcessor((event, hint) => {
30
- try {
17
+ return (next) => (reducer, initialState) => {
18
+ options.attachReduxState && browser.getGlobalScope().addEventProcessor((event, hint) => {
19
+ try {
20
+ if (event.type === void 0 && event.contexts.state.state.type === "redux") {
21
+ hint.attachments = [
22
+ ...hint.attachments || [],
31
23
  // @ts-expect-error try catch to reduce bundle size
32
- if (event.type === undefined && event.contexts.state.state.type === 'redux') {
33
- hint.attachments = [
34
- ...(hint.attachments || []),
35
- // @ts-expect-error try catch to reduce bundle size
36
- { filename: 'redux_state.json', data: JSON.stringify(event.contexts.state.state.value) },
37
- ];
38
- }
39
- } catch {
40
- // empty
41
- }
42
- return event;
43
- });
44
-
45
- function sentryWrapReducer(reducer) {
46
- return (state, action) => {
47
- const newState = reducer(state, action);
48
-
49
- const scope = core.getCurrentScope();
50
-
51
- /* Action breadcrumbs */
52
- const transformedAction = options.actionTransformer(action);
53
- if (typeof transformedAction !== 'undefined' && transformedAction !== null) {
54
- core.addBreadcrumb({
55
- category: ACTION_BREADCRUMB_CATEGORY,
56
- data: transformedAction,
57
- type: ACTION_BREADCRUMB_TYPE,
58
- });
59
- }
60
-
61
- /* Set latest state to scope */
62
- const transformedState = options.stateTransformer(newState);
63
- if (typeof transformedState !== 'undefined' && transformedState !== null) {
64
- const client = core.getClient();
65
- const options = client?.getOptions();
66
- const normalizationDepth = options?.normalizeDepth || 3; // default state normalization depth to 3
67
-
68
- // Set the normalization depth of the redux state to the configured `normalizeDepth` option or a sane number as a fallback
69
- const newStateContext = { state: { type: 'redux', value: transformedState } };
70
- core.addNonEnumerableProperty(
71
- newStateContext,
72
- '__sentry_override_normalization_depth__',
73
- 3 + // 3 layers for `state.value.transformedState`
74
- normalizationDepth, // rest for the actual state
75
- );
76
-
77
- scope.setContext('state', newStateContext);
78
- } else {
79
- scope.setContext('state', null);
80
- }
81
-
82
- /* Allow user to configure scope with latest state */
83
- const { configureScopeWithState } = options;
84
- if (typeof configureScopeWithState === 'function') {
85
- configureScopeWithState(scope, newState);
86
- }
87
-
88
- return newState;
89
- };
24
+ { filename: "redux_state.json", data: JSON.stringify(event.contexts.state.state.value) }
25
+ ];
26
+ }
27
+ } catch {
90
28
  }
91
-
92
- const store = next(sentryWrapReducer(reducer), initialState);
93
-
94
- // eslint-disable-next-line @typescript-eslint/unbound-method
95
- store.replaceReducer = new Proxy(store.replaceReducer, {
96
- apply: function (target, thisArg, args) {
97
- target.apply(thisArg, [sentryWrapReducer(args[0])]);
98
- },
99
- });
100
-
101
- return store;
102
- };
29
+ return event;
30
+ });
31
+ function sentryWrapReducer(reducer2) {
32
+ return (state, action) => {
33
+ const newState = reducer2(state, action);
34
+ const scope = browser.getCurrentScope();
35
+ const transformedAction = options.actionTransformer(action);
36
+ if (typeof transformedAction !== "undefined" && transformedAction !== null) {
37
+ browser.addBreadcrumb({
38
+ category: ACTION_BREADCRUMB_CATEGORY,
39
+ data: transformedAction,
40
+ type: ACTION_BREADCRUMB_TYPE
41
+ });
42
+ }
43
+ const transformedState = options.stateTransformer(newState);
44
+ if (typeof transformedState !== "undefined" && transformedState !== null) {
45
+ const client = browser.getClient();
46
+ const options2 = client?.getOptions();
47
+ const normalizationDepth = options2?.normalizeDepth || 3;
48
+ const newStateContext = { state: { type: "redux", value: transformedState } };
49
+ browser.setNormalizationDepthOverrideHint(
50
+ newStateContext,
51
+ 3 + // 3 layers for `state.value.transformedState`
52
+ normalizationDepth
53
+ // rest for the actual state
54
+ );
55
+ scope.setContext("state", newStateContext);
56
+ } else {
57
+ scope.setContext("state", null);
58
+ }
59
+ const { configureScopeWithState } = options;
60
+ if (typeof configureScopeWithState === "function") {
61
+ configureScopeWithState(scope, newState);
62
+ }
63
+ return newState;
64
+ };
65
+ }
66
+ const store = next(sentryWrapReducer(reducer), initialState);
67
+ store.replaceReducer = new Proxy(store.replaceReducer, {
68
+ apply: function(target, thisArg, args) {
69
+ target.apply(thisArg, [sentryWrapReducer(args[0])]);
70
+ }
71
+ });
72
+ return store;
73
+ };
103
74
  }
104
75
 
105
76
  exports.createReduxEnhancer = createReduxEnhancer;
@@ -1 +1 @@
1
- {"version":3,"file":"redux.js","sources":["../../src/redux.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Scope } from '@sentry/core';\nimport { addBreadcrumb, addNonEnumerableProperty, getClient, getCurrentScope, getGlobalScope } from '@sentry/core';\n\ninterface Action<T = any> {\n type: T;\n}\n\ninterface AnyAction extends Action {\n [extraProps: string]: any;\n}\n\ntype Reducer<S = any, A extends Action = AnyAction> = (state: S | undefined, action: A) => S;\n\ntype Dispatch<A extends Action = AnyAction> = <T extends A>(action: T, ...extraArgs: any[]) => T;\n\ntype ExtendState<State, Extension> = [Extension] extends [never] ? State : State & Extension;\n\ntype Unsubscribe = () => void;\n\ninterface Store<S = any, A extends Action = AnyAction, StateExt = never, Ext = Record<string, unknown>> {\n dispatch: Dispatch<A>;\n getState(): S;\n subscribe(listener: () => void): Unsubscribe;\n replaceReducer<NewState, NewActions extends Action>(\n nextReducer: Reducer<NewState, NewActions>,\n ): Store<ExtendState<NewState, StateExt>, NewActions, StateExt, Ext> & Ext;\n}\n\ndeclare const $CombinedState: unique symbol;\n\ntype CombinedState<S> = { readonly [$CombinedState]?: undefined } & S;\n\ntype PreloadedState<S> =\n Required<S> extends {\n [$CombinedState]: undefined;\n }\n ? S extends CombinedState<infer S1>\n ? { [K in keyof S1]?: S1[K] extends Record<string, unknown> ? PreloadedState<S1[K]> : S1[K] }\n : never\n : { [K in keyof S]: S[K] extends string | number | boolean | symbol ? S[K] : PreloadedState<S[K]> };\n\ntype StoreEnhancerStoreCreator<Ext = Record<string, unknown>, StateExt = never> = <\n S = any,\n A extends Action = AnyAction,\n>(\n reducer: Reducer<S, A>,\n preloadedState?: PreloadedState<S>,\n) => Store<ExtendState<S, StateExt>, A, StateExt, Ext> & Ext;\n\nexport interface SentryEnhancerOptions<S = any> {\n /**\n * Redux state in attachments or not.\n * @default true\n */\n attachReduxState?: boolean;\n\n /**\n * Transforms the state before attaching it to an event.\n * Use this to remove any private data before sending it to Sentry.\n * Return null to not attach the state.\n */\n stateTransformer(state: S | undefined): (S & any) | null;\n /**\n * Transforms the action before sending it as a breadcrumb.\n * Use this to remove any private data before sending it to Sentry.\n * Return null to not send the breadcrumb.\n */\n actionTransformer(action: AnyAction): AnyAction | null;\n /**\n * Called on every state update, configure the Sentry Scope with the redux state.\n */\n configureScopeWithState?(scope: Scope, state: S): void;\n}\n\nconst ACTION_BREADCRUMB_CATEGORY = 'redux.action';\nconst ACTION_BREADCRUMB_TYPE = 'info';\n\nconst defaultOptions: SentryEnhancerOptions = {\n attachReduxState: true,\n actionTransformer: action => action,\n stateTransformer: state => state || null,\n};\n\n/**\n * Creates an enhancer that would be passed to Redux's createStore to log actions and the latest state to Sentry.\n *\n * @param enhancerOptions Options to pass to the enhancer\n */\nfunction createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>): any {\n // Note: We return an any type as to not have type conflicts.\n const options = {\n ...defaultOptions,\n ...enhancerOptions,\n };\n\n return (next: StoreEnhancerStoreCreator): StoreEnhancerStoreCreator =>\n <S = any, A extends Action = AnyAction>(reducer: Reducer<S, A>, initialState?: PreloadedState<S>) => {\n options.attachReduxState &&\n getGlobalScope().addEventProcessor((event, hint) => {\n try {\n // @ts-expect-error try catch to reduce bundle size\n if (event.type === undefined && event.contexts.state.state.type === 'redux') {\n hint.attachments = [\n ...(hint.attachments || []),\n // @ts-expect-error try catch to reduce bundle size\n { filename: 'redux_state.json', data: JSON.stringify(event.contexts.state.state.value) },\n ];\n }\n } catch {\n // empty\n }\n return event;\n });\n\n function sentryWrapReducer(reducer: Reducer<S, A>): Reducer<S, A> {\n return (state, action): S => {\n const newState = reducer(state, action);\n\n const scope = getCurrentScope();\n\n /* Action breadcrumbs */\n const transformedAction = options.actionTransformer(action);\n if (typeof transformedAction !== 'undefined' && transformedAction !== null) {\n addBreadcrumb({\n category: ACTION_BREADCRUMB_CATEGORY,\n data: transformedAction,\n type: ACTION_BREADCRUMB_TYPE,\n });\n }\n\n /* Set latest state to scope */\n const transformedState = options.stateTransformer(newState);\n if (typeof transformedState !== 'undefined' && transformedState !== null) {\n const client = getClient();\n const options = client?.getOptions();\n const normalizationDepth = options?.normalizeDepth || 3; // default state normalization depth to 3\n\n // Set the normalization depth of the redux state to the configured `normalizeDepth` option or a sane number as a fallback\n const newStateContext = { state: { type: 'redux', value: transformedState } };\n addNonEnumerableProperty(\n newStateContext,\n '__sentry_override_normalization_depth__',\n 3 + // 3 layers for `state.value.transformedState`\n normalizationDepth, // rest for the actual state\n );\n\n scope.setContext('state', newStateContext);\n } else {\n scope.setContext('state', null);\n }\n\n /* Allow user to configure scope with latest state */\n const { configureScopeWithState } = options;\n if (typeof configureScopeWithState === 'function') {\n configureScopeWithState(scope, newState);\n }\n\n return newState;\n };\n }\n\n const store = next(sentryWrapReducer(reducer), initialState);\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n store.replaceReducer = new Proxy(store.replaceReducer, {\n apply: function (target, thisArg, args) {\n target.apply(thisArg, [sentryWrapReducer(args[0])]);\n },\n });\n\n return store;\n };\n}\n\nexport { createReduxEnhancer };\n"],"names":["getGlobalScope","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AE,QAAQ,CAAC;AACpD,UAAU;;AAEV,UAAU,OAAO,QAAQ;AACzB,QAAQ,CAAC;AACT,MAAM;;AAEN,MAAM,MAAM,KAAA,GAAQ,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC;;AAElE;AACA,MAAM,KAAK,CAAC,cAAA,GAAiB,IAAI,KAAK,CAAC,KAAK,CAAC,cAAc,EAAE;AAC7D,QAAQ,KAAK,EAAE,UAAU,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AAChD,UAAU,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,QAAQ,CAAC;AACT,OAAO,CAAC;;AAER,MAAM,OAAO,KAAK;AAClB,IAAI,CAAC;AACL;;;;"}
1
+ {"version":3,"file":"redux.js","sources":["../../src/redux.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Scope } from '@sentry/core/browser';\nimport {\n addBreadcrumb,\n getClient,\n getCurrentScope,\n getGlobalScope,\n setNormalizationDepthOverrideHint,\n} from '@sentry/core/browser';\n\ninterface Action<T = any> {\n type: T;\n}\n\ninterface AnyAction extends Action {\n [extraProps: string]: any;\n}\n\ntype Reducer<S = any, A extends Action = AnyAction> = (state: S | undefined, action: A) => S;\n\ntype Dispatch<A extends Action = AnyAction> = <T extends A>(action: T, ...extraArgs: any[]) => T;\n\ntype ExtendState<State, Extension> = [Extension] extends [never] ? State : State & Extension;\n\ntype Unsubscribe = () => void;\n\ninterface Store<S = any, A extends Action = AnyAction, StateExt = never, Ext = Record<string, unknown>> {\n dispatch: Dispatch<A>;\n getState(): S;\n subscribe(listener: () => void): Unsubscribe;\n replaceReducer<NewState, NewActions extends Action>(\n nextReducer: Reducer<NewState, NewActions>,\n ): Store<ExtendState<NewState, StateExt>, NewActions, StateExt, Ext> & Ext;\n}\n\ndeclare const $CombinedState: unique symbol;\n\ntype CombinedState<S> = { readonly [$CombinedState]?: undefined } & S;\n\ntype PreloadedState<S> =\n Required<S> extends {\n [$CombinedState]: undefined;\n }\n ? S extends CombinedState<infer S1>\n ? { [K in keyof S1]?: S1[K] extends Record<string, unknown> ? PreloadedState<S1[K]> : S1[K] }\n : never\n : { [K in keyof S]: S[K] extends string | number | boolean | symbol ? S[K] : PreloadedState<S[K]> };\n\ntype StoreEnhancerStoreCreator<Ext = Record<string, unknown>, StateExt = never> = <\n S = any,\n A extends Action = AnyAction,\n>(\n reducer: Reducer<S, A>,\n preloadedState?: PreloadedState<S>,\n) => Store<ExtendState<S, StateExt>, A, StateExt, Ext> & Ext;\n\nexport interface SentryEnhancerOptions<S = any> {\n /**\n * Redux state in attachments or not.\n * @default true\n */\n attachReduxState?: boolean;\n\n /**\n * Transforms the state before attaching it to an event.\n * Use this to remove any private data before sending it to Sentry.\n * Return null to not attach the state.\n */\n stateTransformer(state: S | undefined): (S & any) | null;\n /**\n * Transforms the action before sending it as a breadcrumb.\n * Use this to remove any private data before sending it to Sentry.\n * Return null to not send the breadcrumb.\n */\n actionTransformer(action: AnyAction): AnyAction | null;\n /**\n * Called on every state update, configure the Sentry Scope with the redux state.\n */\n configureScopeWithState?(scope: Scope, state: S): void;\n}\n\nconst ACTION_BREADCRUMB_CATEGORY = 'redux.action';\nconst ACTION_BREADCRUMB_TYPE = 'info';\n\nconst defaultOptions: SentryEnhancerOptions = {\n attachReduxState: true,\n actionTransformer: action => action,\n stateTransformer: state => state || null,\n};\n\n/**\n * Creates an enhancer that would be passed to Redux's createStore to log actions and the latest state to Sentry.\n *\n * @param enhancerOptions Options to pass to the enhancer\n */\nfunction createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>): any {\n // Note: We return an any type as to not have type conflicts.\n const options = {\n ...defaultOptions,\n ...enhancerOptions,\n };\n\n return (next: StoreEnhancerStoreCreator): StoreEnhancerStoreCreator =>\n <S = any, A extends Action = AnyAction>(reducer: Reducer<S, A>, initialState?: PreloadedState<S>) => {\n options.attachReduxState &&\n getGlobalScope().addEventProcessor((event, hint) => {\n try {\n // @ts-expect-error try catch to reduce bundle size\n if (event.type === undefined && event.contexts.state.state.type === 'redux') {\n hint.attachments = [\n ...(hint.attachments || []),\n // @ts-expect-error try catch to reduce bundle size\n { filename: 'redux_state.json', data: JSON.stringify(event.contexts.state.state.value) },\n ];\n }\n } catch {\n // empty\n }\n return event;\n });\n\n function sentryWrapReducer(reducer: Reducer<S, A>): Reducer<S, A> {\n return (state, action): S => {\n const newState = reducer(state, action);\n\n const scope = getCurrentScope();\n\n /* Action breadcrumbs */\n const transformedAction = options.actionTransformer(action);\n if (typeof transformedAction !== 'undefined' && transformedAction !== null) {\n addBreadcrumb({\n category: ACTION_BREADCRUMB_CATEGORY,\n data: transformedAction,\n type: ACTION_BREADCRUMB_TYPE,\n });\n }\n\n /* Set latest state to scope */\n const transformedState = options.stateTransformer(newState);\n if (typeof transformedState !== 'undefined' && transformedState !== null) {\n const client = getClient();\n const options = client?.getOptions();\n const normalizationDepth = options?.normalizeDepth || 3; // default state normalization depth to 3\n\n // Set the normalization depth of the redux state to the configured `normalizeDepth` option or a sane number as a fallback\n const newStateContext = { state: { type: 'redux', value: transformedState } };\n setNormalizationDepthOverrideHint(\n newStateContext,\n 3 + // 3 layers for `state.value.transformedState`\n normalizationDepth, // rest for the actual state\n );\n\n scope.setContext('state', newStateContext);\n } else {\n scope.setContext('state', null);\n }\n\n /* Allow user to configure scope with latest state */\n const { configureScopeWithState } = options;\n if (typeof configureScopeWithState === 'function') {\n configureScopeWithState(scope, newState);\n }\n\n return newState;\n };\n }\n\n const store = next(sentryWrapReducer(reducer), initialState);\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n store.replaceReducer = new Proxy(store.replaceReducer, {\n apply: function (target, thisArg, args) {\n target.apply(thisArg, [sentryWrapReducer(args[0])]);\n },\n });\n\n return store;\n };\n}\n\nexport { createReduxEnhancer };\n"],"names":["getGlobalScope","reducer","getC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AiB,IAAI,KAAA,CAAM,KAAA,CAAM,cAAA,EAAgB;AAAA,MACrD,KAAA,EAAO,SAAU,MAAA,EAAQ,OAAA,EAAS,IAAA,EAAM;AACtC,QAAA,MAAA,CAAO,KAAA,CAAM,SAAS,CAAC,iBAAA,CAAkB,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAAA,MACpD;AAAA,KACD,CAAA;AAED,IAAA,OAAO,KAAA;AAAA,EACT,CAAA;AACJ;;;;"}
package/build/cjs/sdk.js CHANGED
@@ -1,20 +1,25 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const browser = require('@sentry/browser');
4
- const core = require('@sentry/core');
3
+ const browser$1 = require('@sentry/browser');
4
+ const browser = require('@sentry/core/browser');
5
5
  const React = require('react');
6
+ const isSyntheticEvent = require('./isSyntheticEvent.js');
6
7
 
7
- /**
8
- * Inits the React SDK
9
- */
10
8
  function init(options) {
11
9
  const opts = {
12
- ...options,
10
+ ...options
13
11
  };
14
-
15
- core.applySdkMetadata(opts, 'react');
16
- browser.setContext('react', { version: React.version });
17
- return browser.init(opts);
12
+ browser.applySdkMetadata(opts, "react");
13
+ browser$1.setContext("react", { version: React.version });
14
+ const client = browser$1.init(opts);
15
+ browser.setNormalizeStringifier(normalizeStringifyValue);
16
+ return client;
17
+ }
18
+ function normalizeStringifyValue(value) {
19
+ if (isSyntheticEvent.isSyntheticEvent(value)) {
20
+ return "[SyntheticEvent]";
21
+ }
22
+ return browser$1.normalizeStringifyValue(value);
18
23
  }
19
24
 
20
25
  exports.init = init;
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.js","sources":["../../src/sdk.ts"],"sourcesContent":["import type { BrowserOptions } from '@sentry/browser';\nimport { init as browserInit, setContext } from '@sentry/browser';\nimport type { Client } from '@sentry/core';\nimport { applySdkMetadata } from '@sentry/core';\nimport { version } from 'react';\n\n/**\n * Inits the React SDK\n */\nexport function init(options: BrowserOptions): Client | undefined {\n const opts = {\n ...options,\n };\n\n applySdkMetadata(opts, 'react');\n setContext('react', { version });\n return browserInit(opts);\n}\n"],"names":["applySdkMetadata","setContext","version","browserInit"],"mappings":";;;;;;AAMA;AACA;AACA;AACO,SAAS,IAAI,CAAC,OAAO,EAAsC;AAClE,EAAE,MAAM,OAAO;AACf,IAAI,GAAG,OAAO;AACd,GAAG;;AAEH,EAAEA,qBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC;AACjC,EAAEC,kBAAU,CAAC,OAAO,EAAE,WAAEC,aAAA,EAAS,CAAC;AAClC,EAAE,OAAOC,YAAW,CAAC,IAAI,CAAC;AAC1B;;;;"}
1
+ {"version":3,"file":"sdk.js","sources":["../../src/sdk.ts"],"sourcesContent":["import type { BrowserOptions } from '@sentry/browser';\nimport {\n init as browserInit,\n normalizeStringifyValue as browserNormalizeStringifyValue,\n setContext,\n} from '@sentry/browser';\nimport type { Client } from '@sentry/core/browser';\nimport { applySdkMetadata, setNormalizeStringifier } from '@sentry/core/browser';\nimport { version } from 'react';\nimport { isSyntheticEvent } from './isSyntheticEvent';\n\n/**\n * Inits the React SDK\n */\nexport function init(options: BrowserOptions): Client | undefined {\n const opts = {\n ...options,\n };\n\n applySdkMetadata(opts, 'react');\n setContext('react', { version });\n const client = browserInit(opts);\n\n // Add react-specific stringification\n setNormalizeStringifier(normalizeStringifyValue);\n\n return client;\n}\n\nfunction normalizeStringifyValue(value: Exclude<unknown, string | number | boolean | null>): string | undefined {\n if (isSyntheticEvent(value)) {\n return '[SyntheticEvent]';\n }\n return browserNormalizeStringifyValue(value);\n}\n"],"names":["applySdkMetadata","setContext","version","browserInit","setNormalizeStringifier","isSyntheticEvent","browserNormalizeStringifyValue"],"mappings":";;;;;;;AAcO,SAAS,KAAK,OAAA,EAA6C;AAChE,EAAA,MAAM,IAAA,GAAO;AAAA,IACX,GAAG;AAAA,GACL;AAEA,EAAAA,wBAAA,CAAiB,MAAM,OAAO,CAAA;AAC9B,EAAAC,oBAAA,CAAW,OAAA,EAAS,WAAEC,aAAA,EAAS,CAAA;AAC/B,EAAA,MAAM,MAAA,GAASC,eAAY,IAAI,CAAA;AAG/B,EAAAC,+BAAA,CAAwB,uBAAuB,CAAA;AAE/C,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,wBAAwB,KAAA,EAA+E;AAC9G,EAAA,IAAIC,iCAAA,CAAiB,KAAK,CAAA,EAAG;AAC3B,IAAA,OAAO,kBAAA;AAAA,EACT;AACA,EAAA,OAAOC,kCAA+B,KAAK,CAAA;AAC7C;;;;"}
@@ -1,132 +1,130 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
3
  const browser = require('@sentry/browser');
4
- const core = require('@sentry/core');
4
+ const browser$1 = require('@sentry/core/browser');
5
+ const attributes = require('@sentry/conventions/attributes');
5
6
 
6
- /**
7
- * A custom browser tracing integration for TanStack Router.
8
- *
9
- * The minimum compatible version of `@tanstack/react-router` is `1.64.0`.
10
- *
11
- * @param router A TanStack Router `Router` instance that should be used for routing instrumentation.
12
- * @param options Sentry browser tracing configuration.
13
- */
14
- function tanstackRouterBrowserTracingIntegration(
15
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
- router, // This is `any` because we don't want any type mismatches if TanStack Router changes their types
17
- options = {},
18
- ) {
7
+ function tanstackRouterBrowserTracingIntegration(router, options = {}) {
19
8
  const castRouterInstance = router;
20
-
21
9
  const browserTracingIntegrationInstance = browser.browserTracingIntegration({
22
10
  ...options,
23
11
  instrumentNavigation: false,
24
- instrumentPageLoad: false,
12
+ instrumentPageLoad: false
25
13
  });
26
-
27
14
  const { instrumentPageLoad = true, instrumentNavigation = true } = options;
28
-
29
15
  return {
30
16
  ...browserTracingIntegrationInstance,
31
17
  afterAllSetup(client) {
32
18
  browserTracingIntegrationInstance.afterAllSetup(client);
33
-
19
+ const resolveRouteMatch = (pathname, search) => {
20
+ const matchedRoutes = castRouterInstance.matchRoutes(pathname, search, {
21
+ preload: false,
22
+ throwOnError: false
23
+ });
24
+ const lastMatch = matchedRoutes[matchedRoutes.length - 1];
25
+ return lastMatch?.routeId !== "__root__" ? lastMatch : void 0;
26
+ };
27
+ const applyRouteMatch = (span, match, toLocation, fallbackName) => {
28
+ span.updateName(match ? match.routeId : fallbackName);
29
+ span.setAttribute(browser$1.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, match ? "route" : "url");
30
+ span.setAttributes({
31
+ ...match && { [attributes.URL_TEMPLATE]: match.routeId },
32
+ ...locationToSpanUrlAttributes(castRouterInstance, toLocation),
33
+ ...routeMatchToParamSpanAttributes(match)
34
+ });
35
+ };
34
36
  const initialWindowLocation = browser.WINDOW.location;
35
37
  if (instrumentPageLoad && initialWindowLocation) {
36
- const matchedRoutes = castRouterInstance.matchRoutes(
38
+ const routeMatch = resolveRouteMatch(
37
39
  initialWindowLocation.pathname,
38
- castRouterInstance.options.parseSearch(initialWindowLocation.search),
39
- { preload: false, throwOnError: false },
40
+ castRouterInstance.options.parseSearch(initialWindowLocation.search)
40
41
  );
41
-
42
- const lastMatch = matchedRoutes[matchedRoutes.length - 1];
43
- // If we only match __root__, we ended up not matching any route at all, so
44
- // we fall back to the pathname.
45
- const routeMatch = lastMatch?.routeId !== '__root__' ? lastMatch : undefined;
46
-
47
- browser.startBrowserTracingPageLoadSpan(client, {
42
+ const pageloadSpan = browser.startBrowserTracingPageLoadSpan(client, {
48
43
  name: routeMatch ? routeMatch.routeId : initialWindowLocation.pathname,
49
44
  attributes: {
50
- [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'pageload',
51
- [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.pageload.react.tanstack_router',
52
- [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: routeMatch ? 'route' : 'url',
53
- ...routeMatchToParamSpanAttributes(routeMatch),
54
- },
45
+ [browser$1.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "pageload",
46
+ [browser$1.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.pageload.react.tanstack_router",
47
+ [browser$1.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: routeMatch ? "route" : "url",
48
+ ...routeMatch && { [attributes.URL_TEMPLATE]: routeMatch.routeId },
49
+ ...routeMatchToParamSpanAttributes(routeMatch)
50
+ }
51
+ });
52
+ const unsubscribePageloadResolved = castRouterInstance.subscribe("onResolved", (onResolvedArgs) => {
53
+ unsubscribePageloadResolved();
54
+ if (!pageloadSpan) {
55
+ return;
56
+ }
57
+ const { toLocation } = onResolvedArgs;
58
+ const resolvedMatch = resolveRouteMatch(toLocation.pathname, toLocation.search);
59
+ applyRouteMatch(pageloadSpan, resolvedMatch, toLocation, toLocation.pathname);
55
60
  });
56
61
  }
57
-
58
62
  if (instrumentNavigation) {
59
- // The onBeforeNavigate hook is called at the very beginning of a navigation and is only called once per navigation, even when the user is redirected
60
- castRouterInstance.subscribe('onBeforeNavigate', onBeforeNavigateArgs => {
61
- // onBeforeNavigate is called during pageloads. We can avoid creating navigation spans by:
62
- // 1. Checking if there's no fromLocation (initial pageload)
63
- // 2. Comparing the states of the to and from arguments
64
- if (
65
- !onBeforeNavigateArgs.fromLocation ||
66
- onBeforeNavigateArgs.toLocation.state === onBeforeNavigateArgs.fromLocation.state
67
- ) {
63
+ let inFlightNavigationSpan;
64
+ castRouterInstance.subscribe("onBeforeLoad", (onBeforeLoadArgs) => {
65
+ const { toLocation, fromLocation } = onBeforeLoadArgs;
66
+ if (!fromLocation || toLocation.state === fromLocation.state) {
68
67
  return;
69
68
  }
70
-
71
- const matchedRoutesOnBeforeNavigate = castRouterInstance.matchRoutes(
72
- onBeforeNavigateArgs.toLocation.pathname,
73
- onBeforeNavigateArgs.toLocation.search,
74
- { preload: false, throwOnError: false },
75
- );
76
-
77
- const onBeforeNavigateLastMatch = matchedRoutesOnBeforeNavigate[matchedRoutesOnBeforeNavigate.length - 1];
78
- const onBeforeNavigateRouteMatch =
79
- onBeforeNavigateLastMatch?.routeId !== '__root__' ? onBeforeNavigateLastMatch : undefined;
80
-
81
- const navigationLocation = browser.WINDOW.location;
82
- const navigationSpan = browser.startBrowserTracingNavigationSpan(client, {
83
- name: onBeforeNavigateRouteMatch ? onBeforeNavigateRouteMatch.routeId : navigationLocation.pathname,
84
- attributes: {
85
- [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
86
- [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.react.tanstack_router',
87
- [core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: onBeforeNavigateRouteMatch ? 'route' : 'url',
88
- },
89
- });
90
-
91
- // In case the user is redirected during navigation we want to update the span with the right value.
92
- const unsubscribeOnResolved = castRouterInstance.subscribe('onResolved', onResolvedArgs => {
93
- unsubscribeOnResolved();
94
- if (navigationSpan) {
95
- const matchedRoutesOnResolved = castRouterInstance.matchRoutes(
96
- onResolvedArgs.toLocation.pathname,
97
- onResolvedArgs.toLocation.search,
98
- { preload: false, throwOnError: false },
99
- );
100
-
101
- const onResolvedLastMatch = matchedRoutesOnResolved[matchedRoutesOnResolved.length - 1];
102
- const onResolvedRouteMatch =
103
- onResolvedLastMatch?.routeId !== '__root__' ? onResolvedLastMatch : undefined;
104
-
105
- if (onResolvedRouteMatch) {
106
- navigationSpan.updateName(onResolvedRouteMatch.routeId);
107
- navigationSpan.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
108
- navigationSpan.setAttributes(routeMatchToParamSpanAttributes(onResolvedRouteMatch));
69
+ const routeMatch = resolveRouteMatch(toLocation.pathname, toLocation.search);
70
+ const fallbackName = browser.WINDOW.location?.pathname || toLocation.pathname;
71
+ if (inFlightNavigationSpan) {
72
+ applyRouteMatch(inFlightNavigationSpan, routeMatch, toLocation, fallbackName);
73
+ return;
74
+ }
75
+ inFlightNavigationSpan = browser.startBrowserTracingNavigationSpan(
76
+ client,
77
+ {
78
+ name: routeMatch ? routeMatch.routeId : fallbackName,
79
+ attributes: {
80
+ [browser$1.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "navigation",
81
+ [browser$1.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: "auto.navigation.react.tanstack_router",
82
+ [browser$1.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: routeMatch ? "route" : "url",
83
+ ...routeMatch && { [attributes.URL_TEMPLATE]: routeMatch.routeId },
84
+ ...routeMatchToParamSpanAttributes(routeMatch)
109
85
  }
110
- }
111
- });
86
+ },
87
+ { url: locationToAbsoluteUrl(castRouterInstance, toLocation) }
88
+ );
89
+ });
90
+ castRouterInstance.subscribe("onResolved", (onResolvedArgs) => {
91
+ const span = inFlightNavigationSpan;
92
+ inFlightNavigationSpan = void 0;
93
+ if (!span) {
94
+ return;
95
+ }
96
+ const { toLocation } = onResolvedArgs;
97
+ const resolvedMatch = resolveRouteMatch(toLocation.pathname, toLocation.search);
98
+ if (resolvedMatch) {
99
+ applyRouteMatch(span, resolvedMatch, toLocation, browser.WINDOW.location?.pathname || toLocation.pathname);
100
+ }
112
101
  });
113
102
  }
114
- },
103
+ }
104
+ };
105
+ }
106
+ function locationToAbsoluteUrl(router, location) {
107
+ const search = router.options.stringifySearch?.(location.search) ?? "";
108
+ const pathWithSearch = `${location.pathname}${search && search !== "?" ? search : ""}`;
109
+ return browser.getAbsoluteUrl(pathWithSearch);
110
+ }
111
+ function locationToSpanUrlAttributes(router, location) {
112
+ const absoluteUrl = locationToAbsoluteUrl(router, location);
113
+ return {
114
+ [attributes.URL_PATH]: location.pathname,
115
+ [attributes.URL_FULL]: absoluteUrl
115
116
  };
116
117
  }
117
-
118
118
  function routeMatchToParamSpanAttributes(match) {
119
119
  if (!match) {
120
120
  return {};
121
121
  }
122
-
123
122
  const paramAttributes = {};
124
123
  Object.entries(match.params).forEach(([key, value]) => {
125
- paramAttributes[`url.path.params.${key}`] = value; // TODO(v11): remove attribute which does not adhere to Sentry's semantic convention
126
- paramAttributes[`url.path.parameter.${key}`] = value;
127
- paramAttributes[`params.${key}`] = value; // params.[key] is an alias
124
+ paramAttributes[`url.path.params.${key}`] = value;
125
+ paramAttributes[`${attributes.URL_PATH_PARAMETER_KEY_BASE}.${key}`] = value;
126
+ paramAttributes[`${attributes.PARAMS_KEY_BASE}.${key}`] = value;
128
127
  });
129
-
130
128
  return paramAttributes;
131
129
  }
132
130