@sentry/react-native 5.3.0 → 5.3.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/CHANGELOG.md +23 -0
- package/RNSentry.podspec +1 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/io/sentry/react/RNSentryModuleImpl.java +13 -0
- package/dist/js/NativeRNSentry.d.ts.map +1 -1
- package/dist/js/NativeRNSentry.js.map +1 -1
- package/dist/js/breadcrumb.d.ts.map +1 -1
- package/dist/js/breadcrumb.js.map +1 -1
- package/dist/js/client.d.ts.map +1 -1
- package/dist/js/client.js +4 -5
- package/dist/js/client.js.map +1 -1
- package/dist/js/index.d.ts +1 -2
- package/dist/js/index.d.ts.map +1 -1
- package/dist/js/index.js +1 -5
- package/dist/js/index.js.map +1 -1
- package/dist/js/integrations/debugsymbolicator.d.ts.map +1 -1
- package/dist/js/integrations/debugsymbolicator.js +1 -3
- package/dist/js/integrations/debugsymbolicator.js.map +1 -1
- package/dist/js/integrations/devicecontext.d.ts.map +1 -1
- package/dist/js/integrations/devicecontext.js +2 -4
- package/dist/js/integrations/devicecontext.js.map +1 -1
- package/dist/js/integrations/eventorigin.js +1 -1
- package/dist/js/integrations/eventorigin.js.map +1 -1
- package/dist/js/integrations/factory.d.ts.map +1 -1
- package/dist/js/integrations/factory.js +3 -1
- package/dist/js/integrations/factory.js.map +1 -1
- package/dist/js/integrations/modulesloader.d.ts.map +1 -1
- package/dist/js/integrations/modulesloader.js.map +1 -1
- package/dist/js/integrations/reactnativeerrorhandlers.d.ts.map +1 -1
- package/dist/js/integrations/reactnativeerrorhandlers.js +2 -2
- package/dist/js/integrations/reactnativeerrorhandlers.js.map +1 -1
- package/dist/js/integrations/reactnativeinfo.d.ts.map +1 -1
- package/dist/js/integrations/reactnativeinfo.js +1 -2
- package/dist/js/integrations/reactnativeinfo.js.map +1 -1
- package/dist/js/integrations/rewriteframes.d.ts.map +1 -1
- package/dist/js/integrations/rewriteframes.js +2 -5
- package/dist/js/integrations/rewriteframes.js.map +1 -1
- package/dist/js/integrations/screenshot.d.ts.map +1 -1
- package/dist/js/integrations/screenshot.js +2 -6
- package/dist/js/integrations/screenshot.js.map +1 -1
- package/dist/js/integrations/sdkinfo.js.map +1 -1
- package/dist/js/integrations/viewhierarchy.js.map +1 -1
- package/dist/js/measurements.d.ts +2 -3
- package/dist/js/measurements.d.ts.map +1 -1
- package/dist/js/measurements.js +5 -8
- package/dist/js/measurements.js.map +1 -1
- package/dist/js/misc.d.ts.map +1 -1
- package/dist/js/misc.js +1 -3
- package/dist/js/misc.js.map +1 -1
- package/dist/js/options.d.ts +6 -6
- package/dist/js/options.d.ts.map +1 -1
- package/dist/js/options.js.map +1 -1
- package/dist/js/scope.d.ts +2 -2
- package/dist/js/scope.d.ts.map +1 -1
- package/dist/js/scope.js +4 -4
- package/dist/js/scope.js.map +1 -1
- package/dist/js/tools/ModulesCollector.d.ts.map +1 -1
- package/dist/js/tools/ModulesCollector.js +3 -7
- package/dist/js/tools/ModulesCollector.js.map +1 -1
- package/dist/js/tools/collectModules.js +1 -3
- package/dist/js/tools/collectModules.js.map +1 -1
- package/dist/js/tracing/gesturetracing.d.ts.map +1 -1
- package/dist/js/tracing/gesturetracing.js +4 -2
- package/dist/js/tracing/gesturetracing.js.map +1 -1
- package/dist/js/tracing/index.d.ts +3 -3
- package/dist/js/tracing/index.d.ts.map +1 -1
- package/dist/js/tracing/index.js +2 -2
- package/dist/js/tracing/index.js.map +1 -1
- package/dist/js/tracing/nativeframes.d.ts +4 -4
- package/dist/js/tracing/nativeframes.d.ts.map +1 -1
- package/dist/js/tracing/nativeframes.js +15 -15
- package/dist/js/tracing/nativeframes.js.map +1 -1
- package/dist/js/tracing/ops.d.ts.map +1 -1
- package/dist/js/tracing/ops.js.map +1 -1
- package/dist/js/tracing/reactnativenavigation.d.ts.map +1 -1
- package/dist/js/tracing/reactnativenavigation.js +4 -11
- package/dist/js/tracing/reactnativenavigation.js.map +1 -1
- package/dist/js/tracing/reactnativetracing.d.ts +2 -2
- package/dist/js/tracing/reactnativetracing.d.ts.map +1 -1
- package/dist/js/tracing/reactnativetracing.js +20 -16
- package/dist/js/tracing/reactnativetracing.js.map +1 -1
- package/dist/js/tracing/reactnavigation.d.ts.map +1 -1
- package/dist/js/tracing/reactnavigation.js.map +1 -1
- package/dist/js/tracing/reactnavigationv4.d.ts.map +1 -1
- package/dist/js/tracing/reactnavigationv4.js +1 -2
- package/dist/js/tracing/reactnavigationv4.js.map +1 -1
- package/dist/js/tracing/routingInstrumentation.d.ts.map +1 -1
- package/dist/js/tracing/routingInstrumentation.js.map +1 -1
- package/dist/js/tracing/stalltracking.d.ts +1 -1
- package/dist/js/tracing/stalltracking.d.ts.map +1 -1
- package/dist/js/tracing/stalltracking.js +9 -17
- package/dist/js/tracing/stalltracking.js.map +1 -1
- package/dist/js/tracing/transaction.d.ts.map +1 -1
- package/dist/js/tracing/transaction.js +2 -1
- package/dist/js/tracing/transaction.js.map +1 -1
- package/dist/js/tracing/types.d.ts.map +1 -1
- package/dist/js/tracing/types.js.map +1 -1
- package/dist/js/tracing/utils.d.ts +1 -1
- package/dist/js/tracing/utils.d.ts.map +1 -1
- package/dist/js/tracing/utils.js.map +1 -1
- package/dist/js/transports/TextEncoder.d.ts.map +1 -1
- package/dist/js/transports/TextEncoder.js.map +1 -1
- package/dist/js/transports/native.d.ts +1 -1
- package/dist/js/transports/native.d.ts.map +1 -1
- package/dist/js/transports/native.js +1 -1
- package/dist/js/transports/native.js.map +1 -1
- package/dist/js/user.d.ts.map +1 -1
- package/dist/js/user.js.map +1 -1
- package/dist/js/utils/envelope.d.ts.map +1 -1
- package/dist/js/utils/envelope.js +5 -2
- package/dist/js/utils/envelope.js.map +1 -1
- package/dist/js/utils/outcome.js +1 -1
- package/dist/js/utils/outcome.js.map +1 -1
- package/dist/js/utils/safe.d.ts.map +1 -1
- package/dist/js/utils/safe.js +1 -3
- package/dist/js/utils/safe.js.map +1 -1
- package/dist/js/vendor/buffer/index.d.ts +1 -1
- package/dist/js/vendor/buffer/index.d.ts.map +1 -1
- package/dist/js/vendor/buffer/index.js +1 -1
- package/dist/js/vendor/buffer/index.js.map +1 -1
- package/dist/js/vendor/buffer/utf8ToBytes.d.ts +0 -5
- package/dist/js/vendor/buffer/utf8ToBytes.d.ts.map +1 -1
- package/dist/js/vendor/buffer/utf8ToBytes.js +29 -16
- package/dist/js/vendor/buffer/utf8ToBytes.js.map +1 -1
- package/dist/js/vendor/index.d.ts +1 -1
- package/dist/js/vendor/index.d.ts.map +1 -1
- package/dist/js/vendor/index.js +1 -1
- package/dist/js/vendor/index.js.map +1 -1
- package/dist/js/version.d.ts +1 -1
- package/dist/js/version.js +1 -1
- package/dist/js/version.js.map +1 -1
- package/dist/js/wrapper.d.ts.map +1 -1
- package/dist/js/wrapper.js +7 -17
- package/dist/js/wrapper.js.map +1 -1
- package/ios/RNSentry.mm +6 -3
- package/package.json +18 -13
- package/sentry.gradle +12 -7
- package/src/js/NativeRNSentry.ts +4 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactnavigation.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAInD,OAAO,EACL,8BAA8B,EAC/B,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAyBxG,MAAM,cAAc,GAA2B;IAC7C,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,8BAA+B,SAAQ,8BAA8B;IAiBhF,YAAmB,UAA2C,EAAE;QAC9D,KAAK,EAAE,CAAC;QAfM,SAAI,GAAW,8BAA8B,CAAC,mBAAmB,CAAC;QAE1E,yBAAoB,GAA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,GAAG,KAAK,CAAC;YACxC,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;SACrC;IACH,CAAC;IAED;;OAEG;IACK,wBAAwB;QAC9B,IAAI,OAAO,IAAI,CAAC,mBAAmB,KAAK,WAAW,EAAE;YACnD,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACvC,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;SACtC;IACH,CAAC;;AApQa,kDAAmB,GAAW,qBAAqB,CAAC;AAuQpE;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,8BAA8B,CAAC;AAE/E,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,IAAI,EAAE,cAAc;IACpB,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE;QACJ,yBAAyB,EACvB,8BAA8B,CAAC,mBAAmB;KACrD;IACD,IAAI,EAAE,EAAE;CACT,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport type { Transaction as TransactionType, TransactionContext } from '@sentry/types';\nimport { logger } from '@sentry/utils';\n\nimport { RN_GLOBAL_OBJ } from '../utils/worldwide';\nimport type {\n OnConfirmRoute,\n TransactionCreator} from './routingInstrumentation';\nimport {\n InternalRoutingInstrumentation\n} from './routingInstrumentation';\nimport type {\n BeforeNavigate,\n ReactNavigationTransactionContext,\n RouteChangeContextData,\n} from './types';\nimport { customTransactionSource, defaultTransactionSource, getBlankTransactionContext } from './utils';\n\nexport interface NavigationRoute {\n name: string;\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params?: Record<string, any>;\n}\n\ninterface NavigationContainer {\n addListener: (type: string, listener: () => void) => void;\n getCurrentRoute: () => NavigationRoute;\n}\n\ninterface ReactNavigationOptions {\n /**\n * How long the instrumentation will wait for the route to mount after a change has been initiated,\n * before the transaction is discarded.\n * Time is in ms.\n *\n * Default: 1000\n */\n routeChangeTimeoutMs: number;\n}\n\nconst defaultOptions: ReactNavigationOptions = {\n routeChangeTimeoutMs: 1000,\n};\n\n/**\n * Instrumentation for React-Navigation V5 and above. See docs or sample app for usage.\n *\n * How this works:\n * - `_onDispatch` is called every time a dispatch happens and sets an IdleTransaction on the scope without any route context.\n * - `_onStateChange` is then called AFTER the state change happens due to a dispatch and sets the route context onto the active transaction.\n * - If `_onStateChange` isn't called within `STATE_CHANGE_TIMEOUT_DURATION` of the dispatch, then the transaction is not sampled and finished.\n */\nexport class ReactNavigationInstrumentation extends InternalRoutingInstrumentation {\n public static instrumentationName: string = 'react-navigation-v5';\n\n public readonly name: string = ReactNavigationInstrumentation.instrumentationName;\n\n private _navigationContainer: NavigationContainer | null = null;\n\n private readonly _maxRecentRouteLen: number = 200;\n\n private _latestRoute?: NavigationRoute;\n private _latestTransaction?: TransactionType;\n private _initialStateHandled: boolean = false;\n private _stateChangeTimeout?: number | undefined;\n private _recentRouteKeys: string[] = [];\n\n private _options: ReactNavigationOptions;\n\n public constructor(options: Partial<ReactNavigationOptions> = {}) {\n super();\n\n this._options = {\n ...defaultOptions,\n ...options,\n };\n }\n\n /**\n * Extends by calling _handleInitialState at the end.\n */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute\n ): void {\n super.registerRoutingInstrumentation(\n listener,\n beforeNavigate,\n onConfirmRoute\n );\n\n // We create an initial state here to ensure a transaction gets created before the first route mounts.\n if (!this._initialStateHandled) {\n this._onDispatch();\n if (this._navigationContainer) {\n // Navigation container already registered, just populate with route state\n this._onStateChange();\n\n this._initialStateHandled = true;\n }\n }\n }\n\n /**\n * Pass the ref to the navigation container to register it to the instrumentation\n * @param navigationContainerRef Ref to a `NavigationContainer`\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n public registerNavigationContainer(navigationContainerRef: any): void {\n /* We prevent duplicate routing instrumentation to be initialized on fast refreshes\n\n Explanation: If the user triggers a fast refresh on the file that the instrumentation is\n initialized in, it will initialize a new instance and will cause undefined behavior.\n */\n if (!RN_GLOBAL_OBJ.__sentry_rn_v5_registered) {\n if ('current' in navigationContainerRef) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n this._navigationContainer = navigationContainerRef.current;\n } else {\n this._navigationContainer = navigationContainerRef;\n }\n\n if (this._navigationContainer) {\n this._navigationContainer.addListener(\n '__unsafe_action__', // This action is emitted on every dispatch\n this._onDispatch.bind(this)\n );\n this._navigationContainer.addListener(\n 'state', // This action is emitted on every state change\n this._onStateChange.bind(this)\n );\n\n if (!this._initialStateHandled) {\n if (this._latestTransaction) {\n // If registerRoutingInstrumentation was called first _onDispatch has already been called\n this._onStateChange();\n\n this._initialStateHandled = true;\n } else {\n logger.log(\n '[ReactNavigationInstrumentation] Navigation container registered, but integration has not been setup yet.'\n );\n }\n }\n\n RN_GLOBAL_OBJ.__sentry_rn_v5_registered = true;\n } else {\n logger.warn(\n '[ReactNavigationInstrumentation] Received invalid navigation container ref!'\n );\n }\n } else {\n logger.log(\n '[ReactNavigationInstrumentation] Instrumentation already exists, but register has been called again, doing nothing.'\n );\n }\n }\n\n /**\n * To be called on every React-Navigation action dispatch.\n * It does not name the transaction or populate it with route information. Instead, it waits for the state to fully change\n * and gets the route information from there, @see _onStateChange\n */\n private _onDispatch(): void {\n if (this._latestTransaction) {\n logger.log(\n '[ReactNavigationInstrumentation] A transaction was detected that turned out to be a noop, discarding.'\n );\n this._discardLatestTransaction();\n this._clearStateChangeTimeout();\n }\n\n this._latestTransaction = this.onRouteWillChange(\n getBlankTransactionContext(\n ReactNavigationInstrumentation.instrumentationName\n )\n );\n\n this._stateChangeTimeout = setTimeout(\n this._discardLatestTransaction.bind(this),\n this._options.routeChangeTimeoutMs\n );\n }\n\n /**\n * To be called AFTER the state has been changed to populate the transaction with the current route.\n */\n private _onStateChange(): void {\n // Use the getCurrentRoute method to be accurate.\n const previousRoute = this._latestRoute;\n\n if (!this._navigationContainer) {\n logger.warn(\n '[ReactNavigationInstrumentation] Missing navigation container ref. Route transactions will not be sent.'\n );\n\n return;\n }\n\n const route = this._navigationContainer.getCurrentRoute();\n\n if (route) {\n if (this._latestTransaction) {\n if (!previousRoute || previousRoute.key !== route.key) {\n const originalContext = this._latestTransaction.toContext() as typeof BLANK_TRANSACTION_CONTEXT;\n const routeHasBeenSeen = this._recentRouteKeys.includes(route.key);\n\n const data: RouteChangeContextData = {\n ...originalContext.data,\n route: {\n name: route.name,\n key: route.key,\n params: route.params ?? {},\n hasBeenSeen: routeHasBeenSeen,\n },\n previousRoute: previousRoute\n ? {\n name: previousRoute.name,\n key: previousRoute.key,\n params: previousRoute.params ?? {},\n }\n : null,\n };\n\n const updatedContext: ReactNavigationTransactionContext = {\n ...originalContext,\n name: route.name,\n tags: {\n ...originalContext.tags,\n 'routing.route.name': route.name,\n },\n data,\n };\n\n const finalContext = this._prepareFinalContext(updatedContext);\n this._latestTransaction.updateWithContext(finalContext);\n\n const isCustomName = updatedContext.name !== finalContext.name;\n this._latestTransaction.setName(\n finalContext.name,\n isCustomName ? customTransactionSource : defaultTransactionSource,\n );\n\n this._onConfirmRoute?.(finalContext);\n }\n\n this._pushRecentRouteKey(route.key);\n this._latestRoute = route;\n\n // Clear the latest transaction as it has been handled.\n this._latestTransaction = undefined;\n }\n }\n }\n\n /** Creates final transaction context before confirmation */\n private _prepareFinalContext(updatedContext: TransactionContext): TransactionContext {\n let finalContext = this._beforeNavigate?.({ ...updatedContext });\n\n // This block is to catch users not returning a transaction context\n if (!finalContext) {\n logger.error(\n `[ReactNavigationInstrumentation] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`\n );\n\n finalContext = {\n ...updatedContext,\n sampled: false,\n };\n }\n\n // Note: finalContext.sampled will be false at this point only if the user sets it to be so in beforeNavigate.\n if (finalContext.sampled === false) {\n logger.log(\n `[ReactNavigationInstrumentation] Will not send transaction \"${finalContext.name}\" due to beforeNavigate.`\n );\n } else {\n // Clear the timeout so the transaction does not get cancelled.\n this._clearStateChangeTimeout();\n }\n\n return finalContext;\n }\n\n /** Pushes a recent route key, and removes earlier routes when there is greater than the max length */\n private _pushRecentRouteKey = (key: string): void => {\n this._recentRouteKeys.push(key);\n\n if (this._recentRouteKeys.length > this._maxRecentRouteLen) {\n this._recentRouteKeys = this._recentRouteKeys.slice(\n this._recentRouteKeys.length - this._maxRecentRouteLen\n );\n }\n };\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _discardLatestTransaction(): void {\n if (this._latestTransaction) {\n this._latestTransaction.sampled = false;\n this._latestTransaction.finish();\n this._latestTransaction = undefined;\n }\n }\n\n /**\n *\n */\n private _clearStateChangeTimeout(): void {\n if (typeof this._stateChangeTimeout !== 'undefined') {\n clearTimeout(this._stateChangeTimeout);\n this._stateChangeTimeout = undefined;\n }\n }\n}\n\n/**\n * Backwards compatibility alias for ReactNavigationInstrumentation\n * @deprecated Use ReactNavigationInstrumentation\n */\nexport const ReactNavigationV5Instrumentation = ReactNavigationInstrumentation;\n\nexport const BLANK_TRANSACTION_CONTEXT = {\n name: 'Route Change',\n op: 'navigation',\n tags: {\n 'routing.instrumentation':\n ReactNavigationInstrumentation.instrumentationName,\n },\n data: {},\n};\n"]}
|
|
1
|
+
{"version":3,"file":"reactnavigation.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAyBxG,MAAM,cAAc,GAA2B;IAC7C,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,8BAA+B,SAAQ,8BAA8B;I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AAY,CAAC;IACtB,CAAC;IAWD,wEAAwE;IAChE,yBAAyB;QAC/B,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC3B,IAAI,CAAC,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC;YACxC,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;SACrC;IACH,CAAC;IAED;;OAEG;IACK,wBAAwB;QAC9B,IAAI,OAAO,IAAI,CAAC,mBAAmB,KAAK,WAAW,EAAE;YACnD,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACvC,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;SACtC;IACH,CAAC;;AA1Pa,kDAAmB,GAAW,qBAAqB,CAAC;AA6PpE;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,8BAA8B,CAAC;AAE/E,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,IAAI,EAAE,cAAc;IACpB,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE;QACJ,yBAAyB,EAAE,8BAA8B,CAAC,mBAAmB;KAC9E;IACD,IAAI,EAAE,EAAE;CACT,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport type { Transaction as TransactionType, TransactionContext } from '@sentry/types';\nimport { logger } from '@sentry/utils';\n\nimport { RN_GLOBAL_OBJ } from '../utils/worldwide';\nimport type { OnConfirmRoute, TransactionCreator } from './routingInstrumentation';\nimport { InternalRoutingInstrumentation } from './routingInstrumentation';\nimport type { BeforeNavigate, ReactNavigationTransactionContext, RouteChangeContextData } from './types';\nimport { customTransactionSource, defaultTransactionSource, getBlankTransactionContext } from './utils';\n\nexport interface NavigationRoute {\n name: string;\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params?: Record<string, any>;\n}\n\ninterface NavigationContainer {\n addListener: (type: string, listener: () => void) => void;\n getCurrentRoute: () => NavigationRoute;\n}\n\ninterface ReactNavigationOptions {\n /**\n * How long the instrumentation will wait for the route to mount after a change has been initiated,\n * before the transaction is discarded.\n * Time is in ms.\n *\n * Default: 1000\n */\n routeChangeTimeoutMs: number;\n}\n\nconst defaultOptions: ReactNavigationOptions = {\n routeChangeTimeoutMs: 1000,\n};\n\n/**\n * Instrumentation for React-Navigation V5 and above. See docs or sample app for usage.\n *\n * How this works:\n * - `_onDispatch` is called every time a dispatch happens and sets an IdleTransaction on the scope without any route context.\n * - `_onStateChange` is then called AFTER the state change happens due to a dispatch and sets the route context onto the active transaction.\n * - If `_onStateChange` isn't called within `STATE_CHANGE_TIMEOUT_DURATION` of the dispatch, then the transaction is not sampled and finished.\n */\nexport class ReactNavigationInstrumentation extends InternalRoutingInstrumentation {\n public static instrumentationName: string = 'react-navigation-v5';\n\n public readonly name: string = ReactNavigationInstrumentation.instrumentationName;\n\n private _navigationContainer: NavigationContainer | null = null;\n\n private readonly _maxRecentRouteLen: number = 200;\n\n private _latestRoute?: NavigationRoute;\n private _latestTransaction?: TransactionType;\n private _initialStateHandled: boolean = false;\n private _stateChangeTimeout?: number | undefined;\n private _recentRouteKeys: string[] = [];\n\n private _options: ReactNavigationOptions;\n\n public constructor(options: Partial<ReactNavigationOptions> = {}) {\n super();\n\n this._options = {\n ...defaultOptions,\n ...options,\n };\n }\n\n /**\n * Extends by calling _handleInitialState at the end.\n */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute,\n ): void {\n super.registerRoutingInstrumentation(listener, beforeNavigate, onConfirmRoute);\n\n // We create an initial state here to ensure a transaction gets created before the first route mounts.\n if (!this._initialStateHandled) {\n this._onDispatch();\n if (this._navigationContainer) {\n // Navigation container already registered, just populate with route state\n this._onStateChange();\n\n this._initialStateHandled = true;\n }\n }\n }\n\n /**\n * Pass the ref to the navigation container to register it to the instrumentation\n * @param navigationContainerRef Ref to a `NavigationContainer`\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n public registerNavigationContainer(navigationContainerRef: any): void {\n /* We prevent duplicate routing instrumentation to be initialized on fast refreshes\n\n Explanation: If the user triggers a fast refresh on the file that the instrumentation is\n initialized in, it will initialize a new instance and will cause undefined behavior.\n */\n if (!RN_GLOBAL_OBJ.__sentry_rn_v5_registered) {\n if ('current' in navigationContainerRef) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n this._navigationContainer = navigationContainerRef.current;\n } else {\n this._navigationContainer = navigationContainerRef;\n }\n\n if (this._navigationContainer) {\n this._navigationContainer.addListener(\n '__unsafe_action__', // This action is emitted on every dispatch\n this._onDispatch.bind(this),\n );\n this._navigationContainer.addListener(\n 'state', // This action is emitted on every state change\n this._onStateChange.bind(this),\n );\n\n if (!this._initialStateHandled) {\n if (this._latestTransaction) {\n // If registerRoutingInstrumentation was called first _onDispatch has already been called\n this._onStateChange();\n\n this._initialStateHandled = true;\n } else {\n logger.log(\n '[ReactNavigationInstrumentation] Navigation container registered, but integration has not been setup yet.',\n );\n }\n }\n\n RN_GLOBAL_OBJ.__sentry_rn_v5_registered = true;\n } else {\n logger.warn('[ReactNavigationInstrumentation] Received invalid navigation container ref!');\n }\n } else {\n logger.log(\n '[ReactNavigationInstrumentation] Instrumentation already exists, but register has been called again, doing nothing.',\n );\n }\n }\n\n /**\n * To be called on every React-Navigation action dispatch.\n * It does not name the transaction or populate it with route information. Instead, it waits for the state to fully change\n * and gets the route information from there, @see _onStateChange\n */\n private _onDispatch(): void {\n if (this._latestTransaction) {\n logger.log(\n '[ReactNavigationInstrumentation] A transaction was detected that turned out to be a noop, discarding.',\n );\n this._discardLatestTransaction();\n this._clearStateChangeTimeout();\n }\n\n this._latestTransaction = this.onRouteWillChange(\n getBlankTransactionContext(ReactNavigationInstrumentation.instrumentationName),\n );\n\n this._stateChangeTimeout = setTimeout(\n this._discardLatestTransaction.bind(this),\n this._options.routeChangeTimeoutMs,\n );\n }\n\n /**\n * To be called AFTER the state has been changed to populate the transaction with the current route.\n */\n private _onStateChange(): void {\n // Use the getCurrentRoute method to be accurate.\n const previousRoute = this._latestRoute;\n\n if (!this._navigationContainer) {\n logger.warn(\n '[ReactNavigationInstrumentation] Missing navigation container ref. Route transactions will not be sent.',\n );\n\n return;\n }\n\n const route = this._navigationContainer.getCurrentRoute();\n\n if (route) {\n if (this._latestTransaction) {\n if (!previousRoute || previousRoute.key !== route.key) {\n const originalContext = this._latestTransaction.toContext() as typeof BLANK_TRANSACTION_CONTEXT;\n const routeHasBeenSeen = this._recentRouteKeys.includes(route.key);\n\n const data: RouteChangeContextData = {\n ...originalContext.data,\n route: {\n name: route.name,\n key: route.key,\n params: route.params ?? {},\n hasBeenSeen: routeHasBeenSeen,\n },\n previousRoute: previousRoute\n ? {\n name: previousRoute.name,\n key: previousRoute.key,\n params: previousRoute.params ?? {},\n }\n : null,\n };\n\n const updatedContext: ReactNavigationTransactionContext = {\n ...originalContext,\n name: route.name,\n tags: {\n ...originalContext.tags,\n 'routing.route.name': route.name,\n },\n data,\n };\n\n const finalContext = this._prepareFinalContext(updatedContext);\n this._latestTransaction.updateWithContext(finalContext);\n\n const isCustomName = updatedContext.name !== finalContext.name;\n this._latestTransaction.setName(\n finalContext.name,\n isCustomName ? customTransactionSource : defaultTransactionSource,\n );\n\n this._onConfirmRoute?.(finalContext);\n }\n\n this._pushRecentRouteKey(route.key);\n this._latestRoute = route;\n\n // Clear the latest transaction as it has been handled.\n this._latestTransaction = undefined;\n }\n }\n }\n\n /** Creates final transaction context before confirmation */\n private _prepareFinalContext(updatedContext: TransactionContext): TransactionContext {\n let finalContext = this._beforeNavigate?.({ ...updatedContext });\n\n // This block is to catch users not returning a transaction context\n if (!finalContext) {\n logger.error(\n `[ReactNavigationInstrumentation] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`,\n );\n\n finalContext = {\n ...updatedContext,\n sampled: false,\n };\n }\n\n // Note: finalContext.sampled will be false at this point only if the user sets it to be so in beforeNavigate.\n if (finalContext.sampled === false) {\n logger.log(\n `[ReactNavigationInstrumentation] Will not send transaction \"${finalContext.name}\" due to beforeNavigate.`,\n );\n } else {\n // Clear the timeout so the transaction does not get cancelled.\n this._clearStateChangeTimeout();\n }\n\n return finalContext;\n }\n\n /** Pushes a recent route key, and removes earlier routes when there is greater than the max length */\n private _pushRecentRouteKey = (key: string): void => {\n this._recentRouteKeys.push(key);\n\n if (this._recentRouteKeys.length > this._maxRecentRouteLen) {\n this._recentRouteKeys = this._recentRouteKeys.slice(this._recentRouteKeys.length - this._maxRecentRouteLen);\n }\n };\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _discardLatestTransaction(): void {\n if (this._latestTransaction) {\n this._latestTransaction.sampled = false;\n this._latestTransaction.finish();\n this._latestTransaction = undefined;\n }\n }\n\n /**\n *\n */\n private _clearStateChangeTimeout(): void {\n if (typeof this._stateChangeTimeout !== 'undefined') {\n clearTimeout(this._stateChangeTimeout);\n this._stateChangeTimeout = undefined;\n }\n }\n}\n\n/**\n * Backwards compatibility alias for ReactNavigationInstrumentation\n * @deprecated Use ReactNavigationInstrumentation\n */\nexport const ReactNavigationV5Instrumentation = ReactNavigationInstrumentation;\n\nexport const BLANK_TRANSACTION_CONTEXT = {\n name: 'Route Change',\n op: 'navigation',\n tags: {\n 'routing.instrumentation': ReactNavigationInstrumentation.instrumentationName,\n },\n data: {},\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactnavigationv4.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigationv4.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIrE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"reactnavigationv4.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigationv4.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIrE,OAAO,KA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jD,OAAO,CAAC,QAAQ,CAA2B;gBAExB,OAAO,GAAE,OAAO,CAAC,wBAAwB,CAAM;IASlE;;OAEG;IACI,8BAA8B,CACnC,QAAQ,EAAE,kBAAkB,EAC5B,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,cAAc,GAC7B,IAAI;IAmBP;;;OAGG;IAEI,oBAAoB,CAAC,eAAe,EAAE,GAAG,GAAG,IAAI;IAmCvD;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAchC;;;OAGG;IACH,OAAO,CAAC,YAAY;IAcpB;;OAEG;IACH,OAAO,CAAC,cAAc;IA4CtB,4DAA4D;IAC5D,OAAO,CAAC,oBAAoB;IAsB5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IA+B9B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAejC,sGAAsG;IACtG,OAAO,CAAC,mBAAmB,CAMzB;IAEF,6EAA6E;IAC7E,OAAO,CAAC,2BAA2B,CAIjC;IAEF,wEAAwE;IACxE,OAAO,CAAC,yBAAyB;CAOlC;AAED,QAAA,MAAM,8BAA8B,EAAE,kBAUrC,CAAC;AAEF,OAAO,EAAE,gCAAgC,EAAE,8BAA8B,EAAE,CAAC"}
|
|
@@ -104,8 +104,7 @@ class ReactNavigationV4Instrumentation extends InternalRoutingInstrumentation {
|
|
|
104
104
|
*/
|
|
105
105
|
_patchRouter() {
|
|
106
106
|
if (this._appContainer) {
|
|
107
|
-
const originalGetStateForAction = this._appContainer._navigation.router
|
|
108
|
-
.getStateForAction;
|
|
107
|
+
const originalGetStateForAction = this._appContainer._navigation.router.getStateForAction;
|
|
109
108
|
this._appContainer._navigation.router.getStateForAction = (action, state) => {
|
|
110
109
|
const newState = originalGetStateForAction(action, state);
|
|
111
110
|
this._onStateChange(newState);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactnavigationv4.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigationv4.ts"],"names":[],"mappings":"AAEA,OAAO,EAA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BAAyB,CAAC,WAAW,CAAC,CAAC;SACpD;QAED,OAAO,WAAgC,CAAC;IAC1C,CAAC;IAoBD,wEAAwE;IAChE,yBAAyB;QAC/B,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC3B,IAAI,CAAC,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC;YACxC,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;SACrC;IACH,CAAC;;AAzSa,oDAAmB,GAAW,qBAAqB,CAAC;AA4SpE,MAAM,8BAA8B,GAAuB;IACzD,IAAI,EAAE,YAAY;IAClB,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE;QACJ,yBAAyB,EACvB,gCAAgC,CAAC,mBAAmB;KACvD;IACD,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE;QACR,MAAM,EAAE,MAAM;KACf;CACF,CAAC;AAEF,OAAO,EAAE,gCAAgC,EAAE,8BAA8B,EAAE,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport type { Transaction, TransactionContext } from '@sentry/types';\nimport { logger } from '@sentry/utils';\n\nimport { RN_GLOBAL_OBJ } from '../utils/worldwide';\nimport type {\n OnConfirmRoute,\n TransactionCreator} from './routingInstrumentation';\nimport {\n InternalRoutingInstrumentation\n} from './routingInstrumentation';\nimport type {\n BeforeNavigate,\n ReactNavigationTransactionContext,\n RouteChangeContextData,\n} from './types';\nimport { customTransactionSource, defaultTransactionSource } from './utils';\n\nexport interface NavigationRouteV4 {\n routeName: string;\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params?: Record<string, any>;\n}\n\nexport interface NavigationStateV4 {\n index: number;\n key: string;\n isTransitioning: boolean;\n routeName?: string;\n routes: (NavigationRouteV4 | NavigationStateV4)[];\n}\n\nexport interface AppContainerInstance {\n _navigation: {\n state: NavigationStateV4;\n router: {\n getStateForAction: (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n action: any,\n state: NavigationStateV4\n ) => NavigationStateV4;\n };\n };\n}\n\ninterface ReactNavigationV4Options {\n /**\n * How long the instrumentation will wait for the route to mount after a change has been initiated,\n * before the transaction is discarded.\n * Time is in ms.\n *\n * Default: 1000\n */\n routeChangeTimeoutMs: number;\n}\n\nconst defaultOptions: ReactNavigationV4Options = {\n routeChangeTimeoutMs: 1000,\n};\n\n/**\n * Instrumentation for React-Navigation V4.\n * Register the app container with `registerAppContainer` to use, or see docs for more details.\n */\nclass ReactNavigationV4Instrumentation extends InternalRoutingInstrumentation {\n public static instrumentationName: string = 'react-navigation-v4';\n\n public readonly name: string = ReactNavigationV4Instrumentation.instrumentationName;\n\n private _appContainer: AppContainerInstance | null = null;\n\n private readonly _maxRecentRouteLen: number = 200;\n\n private _prevRoute?: NavigationRouteV4;\n private _recentRouteKeys: string[] = [];\n\n private _latestTransaction?: Transaction;\n private _initialStateHandled: boolean = false;\n private _stateChangeTimeout?: number | undefined;\n\n private _options: ReactNavigationV4Options;\n\n public constructor(options: Partial<ReactNavigationV4Options> = {}) {\n super();\n\n this._options = {\n ...defaultOptions,\n ...options,\n };\n }\n\n /**\n * Extends by calling _handleInitialState at the end.\n */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute\n ): void {\n super.registerRoutingInstrumentation(\n listener,\n beforeNavigate,\n onConfirmRoute\n );\n\n // Need to handle the initial state as the router patch will only attach transactions on subsequent route changes.\n if (!this._initialStateHandled) {\n this._latestTransaction = this.onRouteWillChange(\n INITIAL_TRANSACTION_CONTEXT_V4\n );\n if (this._appContainer) {\n this._updateLatestTransaction();\n\n this._initialStateHandled = true;\n } else {\n this._stateChangeTimeout = setTimeout(\n this._discardLatestTransaction.bind(this),\n this._options.routeChangeTimeoutMs\n );\n }\n }\n }\n\n /**\n * Pass the ref to the app container to register it to the instrumentation\n * @param appContainerRef Ref to an `AppContainer`\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n public registerAppContainer(appContainerRef: any): void {\n /* We prevent duplicate routing instrumentation to be initialized on fast refreshes\n\n Explanation: If the user triggers a fast refresh on the file that the instrumentation is\n initialized in, it will initialize a new instance and will cause undefined behavior.\n */\n if (!RN_GLOBAL_OBJ.__sentry_rn_v4_registered) {\n if ('current' in appContainerRef) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n this._appContainer = appContainerRef.current;\n } else {\n this._appContainer = appContainerRef;\n }\n\n if (this._appContainer) {\n this._patchRouter();\n\n if (!this._initialStateHandled) {\n if (this._latestTransaction) {\n this._updateLatestTransaction();\n } else {\n logger.log(\n '[ReactNavigationV4Instrumentation] App container registered, but integration has not been setup yet.'\n );\n }\n this._initialStateHandled = true;\n }\n\n RN_GLOBAL_OBJ.__sentry_rn_v4_registered = true;\n } else {\n logger.warn(\n '[ReactNavigationV4Instrumentation] Received invalid app container ref!'\n );\n }\n }\n }\n\n /**\n * Updates the latest transaction with the current state and calls beforeNavigate.\n */\n private _updateLatestTransaction(): void {\n // We can assume the ref is present as this is called from registerAppContainer\n if (this._appContainer && this._latestTransaction) {\n const state = this._appContainer._navigation.state;\n\n if (typeof this._stateChangeTimeout !== 'undefined') {\n clearTimeout(this._stateChangeTimeout);\n this._stateChangeTimeout = undefined;\n }\n\n this._onStateChange(state, true);\n }\n }\n\n /**\n * Patches the react navigation router so we can listen to the route changes and attach the `IdleTransaction` before the\n * new screen is mounted.\n */\n private _patchRouter(): void {\n if (this._appContainer) {\n const originalGetStateForAction = this._appContainer._navigation.router\n .getStateForAction;\n\n this._appContainer._navigation.router.getStateForAction = (\n action,\n state\n ) => {\n const newState = originalGetStateForAction(action, state);\n\n this._onStateChange(newState);\n\n return newState;\n };\n }\n }\n\n /**\n * To be called on navigation state changes and creates the transaction.\n */\n private _onStateChange(\n state: NavigationStateV4 | undefined,\n updateLatestTransaction: boolean = false\n ): void {\n // it's not guaranteed that a state is always produced.\n // see: https://github.com/react-navigation/react-navigation/blob/45d419be93c34e900e8734ce98321ae875ac4997/packages/core/src/routers/SwitchRouter.js?rgh-link-date=2021-09-25T12%3A43%3A36Z#L301\n if (!state || state === undefined) {\n logger.warn(\n '[ReactNavigationV4Instrumentation] onStateChange called without a valid state.'\n );\n\n return;\n }\n\n const currentRoute = this._getCurrentRouteFromState(state);\n\n // If the route is a different key, this is so we ignore actions that pertain to the same screen.\n if (!this._prevRoute || currentRoute.key !== this._prevRoute.key) {\n const originalContext = this._getTransactionContext(\n currentRoute,\n this._prevRoute\n );\n\n let mergedContext = originalContext;\n if (updateLatestTransaction && this._latestTransaction) {\n mergedContext = {\n ...this._latestTransaction.toContext(),\n ...originalContext,\n };\n }\n\n const finalContext = this._prepareFinalContext(mergedContext);\n\n if (updateLatestTransaction && this._latestTransaction) {\n // Update the latest transaction instead of calling onRouteWillChange\n this._latestTransaction.updateWithContext(finalContext);\n const isCustomName = mergedContext.name !== finalContext.name;\n this._latestTransaction.setName(\n finalContext.name,\n isCustomName ? customTransactionSource : defaultTransactionSource,\n );\n } else {\n this._latestTransaction = this.onRouteWillChange(finalContext);\n }\n\n this._onConfirmRoute?.(finalContext);\n\n this._pushRecentRouteKey(currentRoute.key);\n this._prevRoute = currentRoute;\n }\n }\n\n /** Creates final transaction context before confirmation */\n private _prepareFinalContext(mergedContext: TransactionContext): TransactionContext {\n let finalContext = this._beforeNavigate?.({ ...mergedContext });\n\n // This block is to catch users not returning a transaction context\n if (!finalContext) {\n logger.error(\n `[ReactNavigationV4Instrumentation] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`\n );\n\n finalContext = {\n ...mergedContext,\n sampled: false,\n };\n }\n\n if (finalContext.sampled === false) {\n this._onBeforeNavigateNotSampled(finalContext.name);\n }\n\n return finalContext;\n }\n\n /**\n * Gets the transaction context for a `NavigationRouteV4`\n */\n private _getTransactionContext(\n route: NavigationRouteV4,\n previousRoute?: NavigationRouteV4\n ): ReactNavigationTransactionContext {\n const data: RouteChangeContextData = {\n route: {\n name: route.routeName, // Include name here too for use in `beforeNavigate`\n key: route.key,\n params: route.params ?? {},\n hasBeenSeen: this._recentRouteKeys.includes(route.key),\n },\n previousRoute: previousRoute\n ? {\n name: previousRoute.routeName,\n key: previousRoute.key,\n params: previousRoute.params ?? {},\n }\n : null,\n };\n\n return {\n name: route.routeName,\n op: 'navigation',\n tags: {\n 'routing.instrumentation':\n ReactNavigationV4Instrumentation.instrumentationName,\n 'routing.route.name': route.routeName,\n },\n data,\n };\n }\n\n /**\n * Gets the current route given a navigation state\n */\n private _getCurrentRouteFromState(\n state: NavigationStateV4\n ): NavigationRouteV4 {\n const parentRoute = state.routes[state.index];\n\n if (\n 'index' in parentRoute &&\n 'routes' in parentRoute &&\n typeof parentRoute.index === 'number' &&\n Array.isArray(parentRoute.routes)\n ) {\n return this._getCurrentRouteFromState(parentRoute);\n }\n\n return parentRoute as NavigationRouteV4;\n }\n\n /** Pushes a recent route key, and removes earlier routes when there is greater than the max length */\n private _pushRecentRouteKey = (key: string): void => {\n this._recentRouteKeys.push(key);\n\n if (this._recentRouteKeys.length > this._maxRecentRouteLen) {\n this._recentRouteKeys = this._recentRouteKeys.slice(\n this._recentRouteKeys.length - this._maxRecentRouteLen\n );\n }\n };\n\n /** Helper to log a transaction that was not sampled due to beforeNavigate */\n private _onBeforeNavigateNotSampled = (transactionName: string): void => {\n logger.log(\n `[ReactNavigationV4Instrumentation] Will not send transaction \"${transactionName}\" due to beforeNavigate.`\n );\n };\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _discardLatestTransaction(): void {\n if (this._latestTransaction) {\n this._latestTransaction.sampled = false;\n this._latestTransaction.finish();\n this._latestTransaction = undefined;\n }\n }\n}\n\nconst INITIAL_TRANSACTION_CONTEXT_V4: TransactionContext = {\n name: 'App Launch',\n op: 'navigation',\n tags: {\n 'routing.instrumentation':\n ReactNavigationV4Instrumentation.instrumentationName,\n },\n data: {},\n metadata: {\n source: 'view',\n },\n};\n\nexport { ReactNavigationV4Instrumentation, INITIAL_TRANSACTION_CONTEXT_V4 };\n"]}
|
|
1
|
+
{"version":3,"file":"reactnavigationv4.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigationv4.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAyC5E,MAAM,cAAc,GAA6B;IAC/C,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAEF;;;GAGG;AACH,MAAM,gCAAiC,SAAQ,8BAA8B;IAkB3E,YAAmB,UAA6C,EAAE;QAChE,KAAK,EAAE,CAAC;QAhBM,SAAI,GAAW,gCAAgC,CAAC,mBAAmB,CAAC;QAE5E,kBAAa,GAAgC,IAAI,CAAC;QAEzC,uBAAkB,GAAW,GAAG,CAAC;QAG1C,qBAAgB,GAAa,EAAE,CAAC;QAGhC,yBAAoB,GAAY,KAAK,CAAC;QA6O9C,sGAAsG;QAC9F,wBAAmB,GAAG,CAAC,GAAW,EAAQ,EAAE;YAClD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAEhC,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,kBAAkB,EAAE;gBAC1D,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;aAC7G;QACH,CAAC,CAAC;QAEF,6EAA6E;QACrE,gCAA2B,GAAG,CAAC,eAAuB,EAAQ,EAAE;YACtE,MAAM,CAAC,GAAG,CACR,iEAAiE,eAAe,0BAA0B,CAC3G,CAAC;QACJ,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C;QAE9C,IACE,OAAO,IAAI,WAAW;YACtB,QAAQ,IAAI,WAAW;YACvB,OAAO,WAAW,CAAC,KAAK,KAAK,QAAQ;YACrC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,EACjC;YACA,OAAO,IAAI,CAAC,yBAAyB,CAAC,WAAW,CAAC,CAAC;SACpD;QAED,OAAO,WAAgC,CAAC;IAC1C,CAAC;IAkBD,wEAAwE;IAChE,yBAAyB;QAC/B,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC3B,IAAI,CAAC,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC;YACxC,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;SACrC;IACH,CAAC;;AAhRa,oDAAmB,GAAW,qBAAqB,CAAC;AAmRpE,MAAM,8BAA8B,GAAuB;IACzD,IAAI,EAAE,YAAY;IAClB,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE;QACJ,yBAAyB,EAAE,gCAAgC,CAAC,mBAAmB;KAChF;IACD,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE;QACR,MAAM,EAAE,MAAM;KACf;CACF,CAAC;AAEF,OAAO,EAAE,gCAAgC,EAAE,8BAA8B,EAAE,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport type { Transaction, TransactionContext } from '@sentry/types';\nimport { logger } from '@sentry/utils';\n\nimport { RN_GLOBAL_OBJ } from '../utils/worldwide';\nimport type { OnConfirmRoute, TransactionCreator } from './routingInstrumentation';\nimport { InternalRoutingInstrumentation } from './routingInstrumentation';\nimport type { BeforeNavigate, ReactNavigationTransactionContext, RouteChangeContextData } from './types';\nimport { customTransactionSource, defaultTransactionSource } from './utils';\n\nexport interface NavigationRouteV4 {\n routeName: string;\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params?: Record<string, any>;\n}\n\nexport interface NavigationStateV4 {\n index: number;\n key: string;\n isTransitioning: boolean;\n routeName?: string;\n routes: (NavigationRouteV4 | NavigationStateV4)[];\n}\n\nexport interface AppContainerInstance {\n _navigation: {\n state: NavigationStateV4;\n router: {\n getStateForAction: (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n action: any,\n state: NavigationStateV4,\n ) => NavigationStateV4;\n };\n };\n}\n\ninterface ReactNavigationV4Options {\n /**\n * How long the instrumentation will wait for the route to mount after a change has been initiated,\n * before the transaction is discarded.\n * Time is in ms.\n *\n * Default: 1000\n */\n routeChangeTimeoutMs: number;\n}\n\nconst defaultOptions: ReactNavigationV4Options = {\n routeChangeTimeoutMs: 1000,\n};\n\n/**\n * Instrumentation for React-Navigation V4.\n * Register the app container with `registerAppContainer` to use, or see docs for more details.\n */\nclass ReactNavigationV4Instrumentation extends InternalRoutingInstrumentation {\n public static instrumentationName: string = 'react-navigation-v4';\n\n public readonly name: string = ReactNavigationV4Instrumentation.instrumentationName;\n\n private _appContainer: AppContainerInstance | null = null;\n\n private readonly _maxRecentRouteLen: number = 200;\n\n private _prevRoute?: NavigationRouteV4;\n private _recentRouteKeys: string[] = [];\n\n private _latestTransaction?: Transaction;\n private _initialStateHandled: boolean = false;\n private _stateChangeTimeout?: number | undefined;\n\n private _options: ReactNavigationV4Options;\n\n public constructor(options: Partial<ReactNavigationV4Options> = {}) {\n super();\n\n this._options = {\n ...defaultOptions,\n ...options,\n };\n }\n\n /**\n * Extends by calling _handleInitialState at the end.\n */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute,\n ): void {\n super.registerRoutingInstrumentation(listener, beforeNavigate, onConfirmRoute);\n\n // Need to handle the initial state as the router patch will only attach transactions on subsequent route changes.\n if (!this._initialStateHandled) {\n this._latestTransaction = this.onRouteWillChange(INITIAL_TRANSACTION_CONTEXT_V4);\n if (this._appContainer) {\n this._updateLatestTransaction();\n\n this._initialStateHandled = true;\n } else {\n this._stateChangeTimeout = setTimeout(\n this._discardLatestTransaction.bind(this),\n this._options.routeChangeTimeoutMs,\n );\n }\n }\n }\n\n /**\n * Pass the ref to the app container to register it to the instrumentation\n * @param appContainerRef Ref to an `AppContainer`\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types\n public registerAppContainer(appContainerRef: any): void {\n /* We prevent duplicate routing instrumentation to be initialized on fast refreshes\n\n Explanation: If the user triggers a fast refresh on the file that the instrumentation is\n initialized in, it will initialize a new instance and will cause undefined behavior.\n */\n if (!RN_GLOBAL_OBJ.__sentry_rn_v4_registered) {\n if ('current' in appContainerRef) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n this._appContainer = appContainerRef.current;\n } else {\n this._appContainer = appContainerRef;\n }\n\n if (this._appContainer) {\n this._patchRouter();\n\n if (!this._initialStateHandled) {\n if (this._latestTransaction) {\n this._updateLatestTransaction();\n } else {\n logger.log(\n '[ReactNavigationV4Instrumentation] App container registered, but integration has not been setup yet.',\n );\n }\n this._initialStateHandled = true;\n }\n\n RN_GLOBAL_OBJ.__sentry_rn_v4_registered = true;\n } else {\n logger.warn('[ReactNavigationV4Instrumentation] Received invalid app container ref!');\n }\n }\n }\n\n /**\n * Updates the latest transaction with the current state and calls beforeNavigate.\n */\n private _updateLatestTransaction(): void {\n // We can assume the ref is present as this is called from registerAppContainer\n if (this._appContainer && this._latestTransaction) {\n const state = this._appContainer._navigation.state;\n\n if (typeof this._stateChangeTimeout !== 'undefined') {\n clearTimeout(this._stateChangeTimeout);\n this._stateChangeTimeout = undefined;\n }\n\n this._onStateChange(state, true);\n }\n }\n\n /**\n * Patches the react navigation router so we can listen to the route changes and attach the `IdleTransaction` before the\n * new screen is mounted.\n */\n private _patchRouter(): void {\n if (this._appContainer) {\n const originalGetStateForAction = this._appContainer._navigation.router.getStateForAction;\n\n this._appContainer._navigation.router.getStateForAction = (action, state) => {\n const newState = originalGetStateForAction(action, state);\n\n this._onStateChange(newState);\n\n return newState;\n };\n }\n }\n\n /**\n * To be called on navigation state changes and creates the transaction.\n */\n private _onStateChange(state: NavigationStateV4 | undefined, updateLatestTransaction: boolean = false): void {\n // it's not guaranteed that a state is always produced.\n // see: https://github.com/react-navigation/react-navigation/blob/45d419be93c34e900e8734ce98321ae875ac4997/packages/core/src/routers/SwitchRouter.js?rgh-link-date=2021-09-25T12%3A43%3A36Z#L301\n if (!state || state === undefined) {\n logger.warn('[ReactNavigationV4Instrumentation] onStateChange called without a valid state.');\n\n return;\n }\n\n const currentRoute = this._getCurrentRouteFromState(state);\n\n // If the route is a different key, this is so we ignore actions that pertain to the same screen.\n if (!this._prevRoute || currentRoute.key !== this._prevRoute.key) {\n const originalContext = this._getTransactionContext(currentRoute, this._prevRoute);\n\n let mergedContext = originalContext;\n if (updateLatestTransaction && this._latestTransaction) {\n mergedContext = {\n ...this._latestTransaction.toContext(),\n ...originalContext,\n };\n }\n\n const finalContext = this._prepareFinalContext(mergedContext);\n\n if (updateLatestTransaction && this._latestTransaction) {\n // Update the latest transaction instead of calling onRouteWillChange\n this._latestTransaction.updateWithContext(finalContext);\n const isCustomName = mergedContext.name !== finalContext.name;\n this._latestTransaction.setName(\n finalContext.name,\n isCustomName ? customTransactionSource : defaultTransactionSource,\n );\n } else {\n this._latestTransaction = this.onRouteWillChange(finalContext);\n }\n\n this._onConfirmRoute?.(finalContext);\n\n this._pushRecentRouteKey(currentRoute.key);\n this._prevRoute = currentRoute;\n }\n }\n\n /** Creates final transaction context before confirmation */\n private _prepareFinalContext(mergedContext: TransactionContext): TransactionContext {\n let finalContext = this._beforeNavigate?.({ ...mergedContext });\n\n // This block is to catch users not returning a transaction context\n if (!finalContext) {\n logger.error(\n `[ReactNavigationV4Instrumentation] beforeNavigate returned ${finalContext}, return context.sampled = false to not send transaction.`,\n );\n\n finalContext = {\n ...mergedContext,\n sampled: false,\n };\n }\n\n if (finalContext.sampled === false) {\n this._onBeforeNavigateNotSampled(finalContext.name);\n }\n\n return finalContext;\n }\n\n /**\n * Gets the transaction context for a `NavigationRouteV4`\n */\n private _getTransactionContext(\n route: NavigationRouteV4,\n previousRoute?: NavigationRouteV4,\n ): ReactNavigationTransactionContext {\n const data: RouteChangeContextData = {\n route: {\n name: route.routeName, // Include name here too for use in `beforeNavigate`\n key: route.key,\n params: route.params ?? {},\n hasBeenSeen: this._recentRouteKeys.includes(route.key),\n },\n previousRoute: previousRoute\n ? {\n name: previousRoute.routeName,\n key: previousRoute.key,\n params: previousRoute.params ?? {},\n }\n : null,\n };\n\n return {\n name: route.routeName,\n op: 'navigation',\n tags: {\n 'routing.instrumentation': ReactNavigationV4Instrumentation.instrumentationName,\n 'routing.route.name': route.routeName,\n },\n data,\n };\n }\n\n /**\n * Gets the current route given a navigation state\n */\n private _getCurrentRouteFromState(state: NavigationStateV4): NavigationRouteV4 {\n const parentRoute = state.routes[state.index];\n\n if (\n 'index' in parentRoute &&\n 'routes' in parentRoute &&\n typeof parentRoute.index === 'number' &&\n Array.isArray(parentRoute.routes)\n ) {\n return this._getCurrentRouteFromState(parentRoute);\n }\n\n return parentRoute as NavigationRouteV4;\n }\n\n /** Pushes a recent route key, and removes earlier routes when there is greater than the max length */\n private _pushRecentRouteKey = (key: string): void => {\n this._recentRouteKeys.push(key);\n\n if (this._recentRouteKeys.length > this._maxRecentRouteLen) {\n this._recentRouteKeys = this._recentRouteKeys.slice(this._recentRouteKeys.length - this._maxRecentRouteLen);\n }\n };\n\n /** Helper to log a transaction that was not sampled due to beforeNavigate */\n private _onBeforeNavigateNotSampled = (transactionName: string): void => {\n logger.log(\n `[ReactNavigationV4Instrumentation] Will not send transaction \"${transactionName}\" due to beforeNavigate.`,\n );\n };\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n private _discardLatestTransaction(): void {\n if (this._latestTransaction) {\n this._latestTransaction.sampled = false;\n this._latestTransaction.finish();\n this._latestTransaction = undefined;\n }\n }\n}\n\nconst INITIAL_TRANSACTION_CONTEXT_V4: TransactionContext = {\n name: 'App Launch',\n op: 'navigation',\n tags: {\n 'routing.instrumentation': ReactNavigationV4Instrumentation.instrumentationName,\n },\n data: {},\n metadata: {\n source: 'view',\n },\n};\n\nexport { ReactNavigationV4Instrumentation, INITIAL_TRANSACTION_CONTEXT_V4 };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routingInstrumentation.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/routingInstrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,oBAAY,kBAAkB,GAAG,
|
|
1
|
+
{"version":3,"file":"routingInstrumentation.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/routingInstrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,oBAAY,kBAAkB,GAAG,CAAC,OAAO,EAAE,kBAAkB,KAAK,WAAW,GAAG,SAAS,CAAC;AAE1F,oBAAY,cAAc,GAAG,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI,CAAC;AAEnE,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;;;;OAQG;IACH,8BAA8B,CAC5B,QAAQ,EAAE,kBAAkB,EAC5B,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,cAAc,GAC7B,IAAI,CAAC;IACR;;;;;OAKG;IACH,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,GAAG,SAAS,CAAC;CACzE;AAED;;;GAGG;AACH,qBAAa,sBAAuB,YAAW,8BAA8B;IAC3E,OAAc,mBAAmB,EAAE,MAAM,CAAkC;IAE3E,SAAgB,IAAI,EAAE,MAAM,CAA8C;IAE1E,SAAS,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,CAAC;IACrC,SAAS,CAAC,eAAe,CAAC,EAAE,cAAc,CAAC;IAC3C,SAAS,CAAC,eAAe,CAAC,EAAE,cAAc,CAAC;IAC3C,SAAS,CAAC,gBAAgB,CAAC,EAAE,kBAAkB,CAAC;IAEhD,kBAAkB;IACX,8BAA8B,CACnC,QAAQ,EAAE,kBAAkB,EAC5B,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,cAAc,GAC7B,IAAI;IAMP,kBAAkB;IACX,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,GAAG,SAAS;CAS/E;AAED;;GAEG;AACH,qBAAa,8BAA+B,SAAQ,sBAAsB;IACxE,kBAAkB;IACX,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,GAAG,SAAS;CAG/E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routingInstrumentation.js","sourceRoot":"","sources":["../../../src/js/tracing/routingInstrumentation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routingInstrumentation.js","sourceRoot":"","sources":["../../../src/js/tracing/routingInstrumentation.ts"],"names":[],"mappings":"AAqCA;;;GAGG;AACH,MAAM,OAAO,sBAAsB;IAAnC;QAGkB,SAAI,GAAW,sBAAsB,CAAC,mBAAmB,CAAC;IA4B5E,CAAC;IArBC,kBAAkB;IACX,8BAA8B,CACnC,QAA4B,EAC5B,cAA8B,EAC9B,cAA8B;QAE9B,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACtC,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;IACxC,CAAC;IAED,kBAAkB;IACX,iBAAiB,CAAC,OAA2B;;QAClD,MAAM,WAAW,SAAG,IAAI,CAAC,gBAAgB,+CAArB,IAAI,EAAoB,OAAO,CAAC,CAAC;QAErD,IAAI,WAAW,EAAE;YACf,MAAA,IAAI,CAAC,eAAe,+CAApB,IAAI,EAAmB,OAAO,EAAE;SACjC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;;AA7Ba,0CAAmB,GAAW,8BAA8B,CAAC;AAgC7E;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,sBAAsB;IACxE,kBAAkB;IACX,iBAAiB,CAAC,OAA2B;;QAClD,aAAO,IAAI,CAAC,gBAAgB,+CAArB,IAAI,EAAoB,OAAO,EAAE;IAC1C,CAAC;CACF","sourcesContent":["import type { Hub } from '@sentry/core';\nimport type { Transaction, TransactionContext } from '@sentry/types';\n\nimport type { BeforeNavigate } from './types';\n\nexport type TransactionCreator = (context: TransactionContext) => Transaction | undefined;\n\nexport type OnConfirmRoute = (context: TransactionContext) => void;\n\nexport interface RoutingInstrumentationInstance {\n /**\n * Name of the routing instrumentation\n */\n readonly name: string;\n /**\n * Registers a listener that's called on every route change with a `TransactionContext`.\n *\n * Do not overwrite this unless you know what you are doing.\n *\n * @param listener A `RouteListener`\n * @param beforeNavigate BeforeNavigate\n * @param inConfirmRoute OnConfirmRoute\n */\n registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute,\n ): void;\n /**\n * To be called when the route changes, BEFORE the new route mounts.\n * If this is called after a route mounts the child spans will not be correctly attached.\n *\n * @param context A `TransactionContext` used to initialize the transaction.\n */\n onRouteWillChange(context: TransactionContext): Transaction | undefined;\n}\n\n/**\n * Base Routing Instrumentation. Can be used by users to manually instrument custom routers.\n * Pass this to the tracing integration, and call `onRouteWillChange` every time before a route changes.\n */\nexport class RoutingInstrumentation implements RoutingInstrumentationInstance {\n public static instrumentationName: string = 'base-routing-instrumentation';\n\n public readonly name: string = RoutingInstrumentation.instrumentationName;\n\n protected _getCurrentHub?: () => Hub;\n protected _beforeNavigate?: BeforeNavigate;\n protected _onConfirmRoute?: OnConfirmRoute;\n protected _tracingListener?: TransactionCreator;\n\n /** @inheritdoc */\n public registerRoutingInstrumentation(\n listener: TransactionCreator,\n beforeNavigate: BeforeNavigate,\n onConfirmRoute: OnConfirmRoute,\n ): void {\n this._tracingListener = listener;\n this._beforeNavigate = beforeNavigate;\n this._onConfirmRoute = onConfirmRoute;\n }\n\n /** @inheritdoc */\n public onRouteWillChange(context: TransactionContext): Transaction | undefined {\n const transaction = this._tracingListener?.(context);\n\n if (transaction) {\n this._onConfirmRoute?.(context);\n }\n\n return transaction;\n }\n}\n\n/**\n * Internal base routing instrumentation where `_onConfirmRoute` is not called in onRouteWillChange\n */\nexport class InternalRoutingInstrumentation extends RoutingInstrumentation {\n /** @inheritdoc */\n public onRouteWillChange(context: TransactionContext): Transaction | undefined {\n return this._tracingListener?.(context);\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IdleTransaction, Transaction } from '@sentry/
|
|
1
|
+
import type { IdleTransaction, Transaction } from '@sentry/core';
|
|
2
2
|
import type { Measurements, MeasurementUnit } from '@sentry/types';
|
|
3
3
|
import { STALL_COUNT, STALL_LONGEST_TIME, STALL_TOTAL_TIME } from '../measurements';
|
|
4
4
|
export interface StallMeasurements extends Measurements {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stalltracking.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/stalltracking.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAQ,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"stalltracking.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/stalltracking.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAQ,WAAW,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAA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AAO,CAAC,aAAa;IAWrB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAM3B;;OAEG;IACH,OAAO,CAAC,MAAM;IAOd;;;OAGG;IACH,OAAO,CAAC,UAAU;IA0BlB;;OAEG;IACH,OAAO,CAAC,wBAAwB;CAYjC"}
|
|
@@ -82,9 +82,7 @@ export class StallTrackingInstrumentation {
|
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
84
|
const endTimestamp = passedEndTimestamp !== null && passedEndTimestamp !== void 0 ? passedEndTimestamp : transaction.endTimestamp;
|
|
85
|
-
const spans = transaction.spanRecorder
|
|
86
|
-
? transaction.spanRecorder.spans
|
|
87
|
-
: [];
|
|
85
|
+
const spans = transaction.spanRecorder ? transaction.spanRecorder.spans : [];
|
|
88
86
|
const finishedSpanCount = spans.reduce((count, s) => (s !== transaction && s.endTimestamp ? count + 1 : count), 0);
|
|
89
87
|
const trimEnd = transaction.toContext().trimEnd;
|
|
90
88
|
const endWillBeTrimmed = trimEnd && finishedSpanCount > 0;
|
|
@@ -103,9 +101,7 @@ export class StallTrackingInstrumentation {
|
|
|
103
101
|
idle transactions inside `ReactNativeTracing`, which will pass an `endTimestamp`.
|
|
104
102
|
*/
|
|
105
103
|
// There will be cancelled spans, which means that the end won't be trimmed
|
|
106
|
-
const spansWillBeCancelled = spans.some(
|
|
107
|
-
s.startTimestamp < endTimestamp &&
|
|
108
|
-
!s.endTimestamp);
|
|
104
|
+
const spansWillBeCancelled = spans.some(s => s !== transaction && s.startTimestamp < endTimestamp && !s.endTimestamp);
|
|
109
105
|
if (endWillBeTrimmed && !spansWillBeCancelled) {
|
|
110
106
|
// the last span's timestamp will be used.
|
|
111
107
|
if (transactionStats.atTimestamp) {
|
|
@@ -137,10 +133,8 @@ export class StallTrackingInstrumentation {
|
|
|
137
133
|
}
|
|
138
134
|
return;
|
|
139
135
|
}
|
|
140
|
-
transaction.setMeasurement(STALL_COUNT, statsOnFinish.stall_count.value -
|
|
141
|
-
|
|
142
|
-
transaction.setMeasurement(STALL_TOTAL_TIME, statsOnFinish.stall_total_time.value -
|
|
143
|
-
transactionStats.atStart.stall_total_time.value, transactionStats.atStart.stall_total_time.unit);
|
|
136
|
+
transaction.setMeasurement(STALL_COUNT, statsOnFinish.stall_count.value - transactionStats.atStart.stall_count.value, transactionStats.atStart.stall_count.unit);
|
|
137
|
+
transaction.setMeasurement(STALL_TOTAL_TIME, statsOnFinish.stall_total_time.value - transactionStats.atStart.stall_total_time.value, transactionStats.atStart.stall_total_time.unit);
|
|
144
138
|
transaction.setMeasurement(STALL_LONGEST_TIME, statsOnFinish.stall_longest_time.value, statsOnFinish.stall_longest_time.unit);
|
|
145
139
|
}
|
|
146
140
|
/**
|
|
@@ -149,11 +143,9 @@ export class StallTrackingInstrumentation {
|
|
|
149
143
|
_markSpanFinish(transaction, spanEndTimestamp) {
|
|
150
144
|
const previousStats = this._statsByTransaction.get(transaction);
|
|
151
145
|
if (previousStats) {
|
|
152
|
-
if (Math.abs(timestampInSeconds() - spanEndTimestamp) >
|
|
153
|
-
MARGIN_OF_ERROR_SECONDS) {
|
|
146
|
+
if (Math.abs(timestampInSeconds() - spanEndTimestamp) > MARGIN_OF_ERROR_SECONDS) {
|
|
154
147
|
logger.log('[StallTracking] Span end not logged due to end timestamp being outside the margin of error from now.');
|
|
155
|
-
if (previousStats.atTimestamp &&
|
|
156
|
-
previousStats.atTimestamp.timestamp < spanEndTimestamp) {
|
|
148
|
+
if (previousStats.atTimestamp && previousStats.atTimestamp.timestamp < spanEndTimestamp) {
|
|
157
149
|
// We also need to delete the stat for the last span, as the transaction would be trimmed to this span not the last one.
|
|
158
150
|
this._statsByTransaction.set(transaction, Object.assign(Object.assign({}, previousStats), { atTimestamp: null }));
|
|
159
151
|
}
|
|
@@ -175,7 +167,8 @@ export class StallTrackingInstrumentation {
|
|
|
175
167
|
stall_count: { value: this._stallCount, unit: 'none' },
|
|
176
168
|
stall_total_time: { value: this._totalStallTime, unit: 'millisecond' },
|
|
177
169
|
stall_longest_time: {
|
|
178
|
-
value: (_b = (_a = this._statsByTransaction.get(transaction)) === null || _a === void 0 ? void 0 : _a.longestStallTime) !== null && _b !== void 0 ? _b : 0,
|
|
170
|
+
value: (_b = (_a = this._statsByTransaction.get(transaction)) === null || _a === void 0 ? void 0 : _a.longestStallTime) !== null && _b !== void 0 ? _b : 0,
|
|
171
|
+
unit: 'millisecond',
|
|
179
172
|
},
|
|
180
173
|
};
|
|
181
174
|
}
|
|
@@ -225,8 +218,7 @@ export class StallTrackingInstrumentation {
|
|
|
225
218
|
var _a;
|
|
226
219
|
const now = timestampInSeconds() * 1000;
|
|
227
220
|
const totalTimeTaken = now - this._lastIntervalMs;
|
|
228
|
-
if (totalTimeTaken >=
|
|
229
|
-
LOOP_TIMEOUT_INTERVAL_MS + this._minimumStallThreshold) {
|
|
221
|
+
if (totalTimeTaken >= LOOP_TIMEOUT_INTERVAL_MS + this._minimumStallThreshold) {
|
|
230
222
|
const stallTime = totalTimeTaken - LOOP_TIMEOUT_INTERVAL_MS;
|
|
231
223
|
this._stallCount += 1;
|
|
232
224
|
this._totalStallTime += stallTime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stalltracking.js","sourceRoot":"","sources":["../../../src/js/tracing/stalltracking.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAgBpF,8BAA8B;AAC9B,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,wEAAwE;AACxE,MAAM,wBAAwB,GAAG,EAAE,CAAC;AACpC,qIAAqI;AACrI,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,OAAO,4BAA4B;IA0BvC,YACE,UAAgC,EAAE,qBAAqB,EAAE,EAAE,EAAE;QA1BxD,eAAU,GAAY,KAAK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,CAAC,CAAC,CAAC;aACpC;SACF;IACH,CAAC;CACF","sourcesContent":["/* eslint-disable max-lines */\nimport type { IdleTransaction, Span, Transaction } from '@sentry/tracing';\nimport type { Measurements, MeasurementUnit } from '@sentry/types';\nimport { logger, timestampInSeconds } from '@sentry/utils';\n\nimport { STALL_COUNT, STALL_LONGEST_TIME, STALL_TOTAL_TIME } from '../measurements';\n\nexport interface StallMeasurements extends Measurements {\n [STALL_COUNT]: { value: number, unit: MeasurementUnit };\n [STALL_TOTAL_TIME]: { value: number, unit: MeasurementUnit };\n [STALL_LONGEST_TIME]: { value: number, unit: MeasurementUnit };\n}\n\nexport type StallTrackingOptions = {\n /**\n * How long in milliseconds an event loop iteration can be delayed for before being considered a \"stall.\"\n * @default 100\n */\n minimumStallThreshold: number;\n};\n\n/** Margin of error of 20ms */\nconst MARGIN_OF_ERROR_SECONDS = 0.02;\n/** How long between each iteration in the event loop tracker timeout */\nconst LOOP_TIMEOUT_INTERVAL_MS = 50;\n/** Limit for how many transactions the stall tracker will track at a time to prevent leaks due to transactions not being finished */\nconst MAX_RUNNING_TRANSACTIONS = 10;\n\n/**\n * Stall measurement tracker inspired by the `JSEventLoopWatchdog` used internally in React Native:\n * https://github.com/facebook/react-native/blob/006f5afe120c290a37cf6ff896748fbc062bf7ed/Libraries/Interaction/JSEventLoopWatchdog.js\n *\n * However, we modified the interval implementation to instead have a fixed loop timeout interval of `LOOP_TIMEOUT_INTERVAL_MS`.\n * We then would consider that iteration a stall when the total time for that interval to run is greater than `LOOP_TIMEOUT_INTERVAL_MS + minimumStallThreshold`\n */\nexport class StallTrackingInstrumentation {\n public isTracking: boolean = false;\n\n private _minimumStallThreshold: number;\n\n /** Total amount of time of all stalls that occurred during the current tracking session */\n private _totalStallTime: number = 0;\n /** Total number of stalls that occurred during the current tracking session */\n private _stallCount: number = 0;\n\n /** The last timestamp the iteration ran in milliseconds */\n private _lastIntervalMs: number = 0;\n private _timeout: ReturnType<typeof setTimeout> | null = null;\n\n private _statsByTransaction: Map<\n Transaction,\n {\n longestStallTime: number;\n atStart: StallMeasurements;\n atTimestamp: {\n timestamp: number;\n stats: StallMeasurements;\n } | null;\n }\n > = new Map();\n\n public constructor(\n options: StallTrackingOptions = { minimumStallThreshold: 50 }\n ) {\n this._minimumStallThreshold = options.minimumStallThreshold;\n }\n\n /**\n * @inheritDoc\n * Not used for this integration. Instead call `registerTransactionStart` to start tracking.\n */\n public setupOnce(): void {\n // Do nothing.\n }\n\n /**\n * Register a transaction as started. Starts stall tracking if not already running.\n * @returns A finish method that returns the stall measurements.\n */\n public onTransactionStart(transaction: Transaction): void {\n if (this._statsByTransaction.has(transaction)) {\n logger.error(\n '[StallTracking] Tried to start stall tracking on a transaction already being tracked. Measurements might be lost.'\n );\n\n return;\n }\n\n this._startTracking();\n this._statsByTransaction.set(transaction, {\n longestStallTime: 0,\n atTimestamp: null,\n atStart: this._getCurrentStats(transaction),\n });\n this._flushLeakedTransactions();\n\n if (transaction.spanRecorder) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalAdd = transaction.spanRecorder.add;\n\n transaction.spanRecorder.add = (span: Span): void => {\n originalAdd.apply(transaction.spanRecorder, [span]);\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalSpanFinish = span.finish;\n\n span.finish = (endTimestamp?: number) => {\n // We let the span determine its own end timestamp as well in case anything gets changed upstream\n originalSpanFinish.apply(span, [endTimestamp]);\n\n // The span should set a timestamp, so this would be defined.\n if (span.endTimestamp) {\n this._markSpanFinish(transaction, span.endTimestamp);\n }\n };\n };\n }\n }\n\n /**\n * Logs a transaction as finished.\n * Stops stall tracking if no more transactions are running.\n * @returns The stall measurements\n */\n public onTransactionFinish(\n transaction: Transaction | IdleTransaction,\n passedEndTimestamp?: number\n ): void {\n const transactionStats = this._statsByTransaction.get(transaction);\n\n if (!transactionStats) {\n // Transaction has been flushed out somehow, we return null.\n logger.log(\n '[StallTracking] Stall measurements were not added to transaction due to exceeding the max count.'\n );\n\n this._statsByTransaction.delete(transaction);\n this._shouldStopTracking();\n\n return;\n }\n\n const endTimestamp = passedEndTimestamp ?? transaction.endTimestamp;\n\n const spans = transaction.spanRecorder\n ? transaction.spanRecorder.spans\n : [];\n const finishedSpanCount = spans.reduce(\n (count, s) => (s !== transaction && s.endTimestamp ? count + 1 : count),\n 0\n );\n\n const trimEnd = transaction.toContext().trimEnd;\n const endWillBeTrimmed = trimEnd && finishedSpanCount > 0;\n\n /*\n This is not safe in the case that something changes upstream, but if we're planning to move this over to @sentry/javascript anyways,\n we can have this temporarily for now.\n */\n const isIdleTransaction = 'activities' in transaction;\n\n let statsOnFinish: StallMeasurements | undefined;\n if (endTimestamp && isIdleTransaction) {\n /*\n There is different behavior regarding child spans in a normal transaction and an idle transaction. In normal transactions,\n the child spans that aren't finished will be dumped, while in an idle transaction they're cancelled and finished.\n\n Note: `endTimestamp` will always be defined if this is called on an idle transaction finish. This is because we only instrument\n idle transactions inside `ReactNativeTracing`, which will pass an `endTimestamp`.\n */\n\n // There will be cancelled spans, which means that the end won't be trimmed\n const spansWillBeCancelled = spans.some(\n (s) =>\n s !== transaction &&\n s.startTimestamp < endTimestamp &&\n !s.endTimestamp\n );\n\n if (endWillBeTrimmed && !spansWillBeCancelled) {\n // the last span's timestamp will be used.\n\n if (transactionStats.atTimestamp) {\n statsOnFinish = transactionStats.atTimestamp.stats;\n }\n } else {\n // this endTimestamp will be used.\n statsOnFinish = this._getCurrentStats(transaction);\n }\n } else if (endWillBeTrimmed) {\n // If `trimEnd` is used, and there is a span to trim to. If there isn't, then the transaction should use `endTimestamp` or generate one.\n if (transactionStats.atTimestamp) {\n statsOnFinish = transactionStats.atTimestamp.stats;\n }\n } else if (!endTimestamp) {\n statsOnFinish = this._getCurrentStats(transaction);\n }\n\n this._statsByTransaction.delete(transaction);\n this._shouldStopTracking();\n\n if (!statsOnFinish) {\n if (typeof endTimestamp !== 'undefined') {\n logger.log(\n '[StallTracking] Stall measurements not added due to `endTimestamp` being set.'\n );\n } else if (trimEnd) {\n logger.log(\n '[StallTracking] Stall measurements not added due to `trimEnd` being set but we could not determine the stall measurements at that time.'\n );\n }\n\n return;\n }\n\n transaction.setMeasurement(STALL_COUNT,\n statsOnFinish.stall_count.value -\n transactionStats.atStart.stall_count.value,\n transactionStats.atStart.stall_count.unit);\n\n transaction.setMeasurement(STALL_TOTAL_TIME,\n statsOnFinish.stall_total_time.value -\n transactionStats.atStart.stall_total_time.value,\n transactionStats.atStart.stall_total_time.unit);\n\n transaction.setMeasurement(STALL_LONGEST_TIME,\n statsOnFinish.stall_longest_time.value,\n statsOnFinish.stall_longest_time.unit);\n }\n\n /**\n * Logs the finish time of the span for use in `trimEnd: true` transactions.\n */\n private _markSpanFinish(\n transaction: Transaction,\n spanEndTimestamp: number\n ): void {\n const previousStats = this._statsByTransaction.get(transaction);\n if (previousStats) {\n if (\n Math.abs(timestampInSeconds() - spanEndTimestamp) >\n MARGIN_OF_ERROR_SECONDS\n ) {\n logger.log(\n '[StallTracking] Span end not logged due to end timestamp being outside the margin of error from now.'\n );\n\n if (\n previousStats.atTimestamp &&\n previousStats.atTimestamp.timestamp < spanEndTimestamp\n ) {\n // We also need to delete the stat for the last span, as the transaction would be trimmed to this span not the last one.\n this._statsByTransaction.set(transaction, {\n ...previousStats,\n atTimestamp: null,\n });\n }\n } else {\n this._statsByTransaction.set(transaction, {\n ...previousStats,\n atTimestamp: {\n timestamp: spanEndTimestamp,\n stats: this._getCurrentStats(transaction),\n },\n });\n }\n }\n }\n\n /**\n * Get the current stats for a transaction at a given time.\n */\n private _getCurrentStats(transaction: Transaction): StallMeasurements {\n return {\n stall_count: { value: this._stallCount, unit: 'none' },\n stall_total_time: { value: this._totalStallTime, unit: 'millisecond' },\n stall_longest_time: {\n value: this._statsByTransaction.get(transaction)?.longestStallTime ?? 0, unit: 'millisecond'\n },\n };\n }\n\n /**\n * Start tracking stalls\n */\n private _startTracking(): void {\n if (!this.isTracking) {\n this.isTracking = true;\n this._lastIntervalMs = Math.floor(timestampInSeconds() * 1000);\n\n this._iteration();\n }\n }\n\n /**\n * Stops the stall tracking interval and calls reset().\n */\n private _stopTracking(): void {\n this.isTracking = false;\n\n if (this._timeout !== null) {\n clearTimeout(this._timeout);\n this._timeout = null;\n }\n\n this._reset();\n }\n\n /**\n * Will stop tracking if there are no more transactions.\n */\n private _shouldStopTracking(): void {\n if (this._statsByTransaction.size === 0) {\n this._stopTracking();\n }\n }\n\n /**\n * Clears all the collected stats\n */\n private _reset(): void {\n this._stallCount = 0;\n this._totalStallTime = 0;\n this._lastIntervalMs = 0;\n this._statsByTransaction.clear();\n }\n\n /**\n * Iteration of the stall tracking interval. Measures how long the timer strayed from its expected time of running, and how\n * long the stall is for.\n */\n private _iteration(): void {\n const now = timestampInSeconds() * 1000;\n const totalTimeTaken = now - this._lastIntervalMs;\n\n if (\n totalTimeTaken >=\n LOOP_TIMEOUT_INTERVAL_MS + this._minimumStallThreshold\n ) {\n const stallTime = totalTimeTaken - LOOP_TIMEOUT_INTERVAL_MS;\n this._stallCount += 1;\n this._totalStallTime += stallTime;\n\n for (const [transaction, value] of this._statsByTransaction.entries()) {\n const longestStallTime = Math.max(\n value.longestStallTime ?? 0,\n stallTime\n );\n\n this._statsByTransaction.set(transaction, {\n ...value,\n longestStallTime,\n });\n }\n }\n\n this._lastIntervalMs = now;\n\n if (this.isTracking) {\n this._timeout = setTimeout(\n this._iteration.bind(this),\n LOOP_TIMEOUT_INTERVAL_MS\n );\n }\n }\n\n /**\n * Deletes leaked transactions (Earliest transactions when we have more than MAX_RUNNING_TRANSACTIONS transactions.)\n */\n private _flushLeakedTransactions(): void {\n if (this._statsByTransaction.size > MAX_RUNNING_TRANSACTIONS) {\n let counter = 0;\n const len = this._statsByTransaction.size - MAX_RUNNING_TRANSACTIONS;\n const transactions = this._statsByTransaction.keys();\n for (const t of transactions) {\n if (counter >= len) break;\n counter += 1;\n this._statsByTransaction.delete(t);\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file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,CAAC,IAAI,CAAC,EAAE,wBAAwB,CAAC,CAAC;SAClF;IACH,CAAC;IAED;;OAEG;IACK,wBAAwB;QAC9B,IAAI,IAAI,CAAC,mBAAmB,CAAC,IAAI,GAAG,wBAAwB,EAAE;YAC5D,IAAI,OAAO,GAAG,CAAC,CAAC;YAChB,MAAM,GAAG,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,GAAG,wBAAwB,CAAC;YACrE,MAAM,YAAY,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC;YACrD,KAAK,MAAM,CAAC,IAAI,YAAY,EAAE;gBAC5B,IAAI,OAAO,IAAI,GAAG;oBAAE,MAAM;gBAC1B,OAAO,IAAI,CAAC,CAAC;gBACb,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;aACpC;SACF;IACH,CAAC;CACF","sourcesContent":["/* eslint-disable max-lines */\nimport type { IdleTransaction, Span, Transaction } from '@sentry/core';\nimport type { Measurements, MeasurementUnit } from '@sentry/types';\nimport { logger, timestampInSeconds } from '@sentry/utils';\n\nimport { STALL_COUNT, STALL_LONGEST_TIME, STALL_TOTAL_TIME } from '../measurements';\n\nexport interface StallMeasurements extends Measurements {\n [STALL_COUNT]: { value: number; unit: MeasurementUnit };\n [STALL_TOTAL_TIME]: { value: number; unit: MeasurementUnit };\n [STALL_LONGEST_TIME]: { value: number; unit: MeasurementUnit };\n}\n\nexport type StallTrackingOptions = {\n /**\n * How long in milliseconds an event loop iteration can be delayed for before being considered a \"stall.\"\n * @default 100\n */\n minimumStallThreshold: number;\n};\n\n/** Margin of error of 20ms */\nconst MARGIN_OF_ERROR_SECONDS = 0.02;\n/** How long between each iteration in the event loop tracker timeout */\nconst LOOP_TIMEOUT_INTERVAL_MS = 50;\n/** Limit for how many transactions the stall tracker will track at a time to prevent leaks due to transactions not being finished */\nconst MAX_RUNNING_TRANSACTIONS = 10;\n\n/**\n * Stall measurement tracker inspired by the `JSEventLoopWatchdog` used internally in React Native:\n * https://github.com/facebook/react-native/blob/006f5afe120c290a37cf6ff896748fbc062bf7ed/Libraries/Interaction/JSEventLoopWatchdog.js\n *\n * However, we modified the interval implementation to instead have a fixed loop timeout interval of `LOOP_TIMEOUT_INTERVAL_MS`.\n * We then would consider that iteration a stall when the total time for that interval to run is greater than `LOOP_TIMEOUT_INTERVAL_MS + minimumStallThreshold`\n */\nexport class StallTrackingInstrumentation {\n public isTracking: boolean = false;\n\n private _minimumStallThreshold: number;\n\n /** Total amount of time of all stalls that occurred during the current tracking session */\n private _totalStallTime: number = 0;\n /** Total number of stalls that occurred during the current tracking session */\n private _stallCount: number = 0;\n\n /** The last timestamp the iteration ran in milliseconds */\n private _lastIntervalMs: number = 0;\n private _timeout: ReturnType<typeof setTimeout> | null = null;\n\n private _statsByTransaction: Map<\n Transaction,\n {\n longestStallTime: number;\n atStart: StallMeasurements;\n atTimestamp: {\n timestamp: number;\n stats: StallMeasurements;\n } | null;\n }\n > = new Map();\n\n public constructor(options: StallTrackingOptions = { minimumStallThreshold: 50 }) {\n this._minimumStallThreshold = options.minimumStallThreshold;\n }\n\n /**\n * @inheritDoc\n * Not used for this integration. Instead call `registerTransactionStart` to start tracking.\n */\n public setupOnce(): void {\n // Do nothing.\n }\n\n /**\n * Register a transaction as started. Starts stall tracking if not already running.\n * @returns A finish method that returns the stall measurements.\n */\n public onTransactionStart(transaction: Transaction): void {\n if (this._statsByTransaction.has(transaction)) {\n logger.error(\n '[StallTracking] Tried to start stall tracking on a transaction already being tracked. Measurements might be lost.',\n );\n\n return;\n }\n\n this._startTracking();\n this._statsByTransaction.set(transaction, {\n longestStallTime: 0,\n atTimestamp: null,\n atStart: this._getCurrentStats(transaction),\n });\n this._flushLeakedTransactions();\n\n if (transaction.spanRecorder) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalAdd = transaction.spanRecorder.add;\n\n transaction.spanRecorder.add = (span: Span): void => {\n originalAdd.apply(transaction.spanRecorder, [span]);\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalSpanFinish = span.finish;\n\n span.finish = (endTimestamp?: number) => {\n // We let the span determine its own end timestamp as well in case anything gets changed upstream\n originalSpanFinish.apply(span, [endTimestamp]);\n\n // The span should set a timestamp, so this would be defined.\n if (span.endTimestamp) {\n this._markSpanFinish(transaction, span.endTimestamp);\n }\n };\n };\n }\n }\n\n /**\n * Logs a transaction as finished.\n * Stops stall tracking if no more transactions are running.\n * @returns The stall measurements\n */\n public onTransactionFinish(transaction: Transaction | IdleTransaction, passedEndTimestamp?: number): void {\n const transactionStats = this._statsByTransaction.get(transaction);\n\n if (!transactionStats) {\n // Transaction has been flushed out somehow, we return null.\n logger.log('[StallTracking] Stall measurements were not added to transaction due to exceeding the max count.');\n\n this._statsByTransaction.delete(transaction);\n this._shouldStopTracking();\n\n return;\n }\n\n const endTimestamp = passedEndTimestamp ?? transaction.endTimestamp;\n\n const spans = transaction.spanRecorder ? transaction.spanRecorder.spans : [];\n const finishedSpanCount = spans.reduce((count, s) => (s !== transaction && s.endTimestamp ? count + 1 : count), 0);\n\n const trimEnd = transaction.toContext().trimEnd;\n const endWillBeTrimmed = trimEnd && finishedSpanCount > 0;\n\n /*\n This is not safe in the case that something changes upstream, but if we're planning to move this over to @sentry/javascript anyways,\n we can have this temporarily for now.\n */\n const isIdleTransaction = 'activities' in transaction;\n\n let statsOnFinish: StallMeasurements | undefined;\n if (endTimestamp && isIdleTransaction) {\n /*\n There is different behavior regarding child spans in a normal transaction and an idle transaction. In normal transactions,\n the child spans that aren't finished will be dumped, while in an idle transaction they're cancelled and finished.\n\n Note: `endTimestamp` will always be defined if this is called on an idle transaction finish. This is because we only instrument\n idle transactions inside `ReactNativeTracing`, which will pass an `endTimestamp`.\n */\n\n // There will be cancelled spans, which means that the end won't be trimmed\n const spansWillBeCancelled = spans.some(\n s => s !== transaction && s.startTimestamp < endTimestamp && !s.endTimestamp,\n );\n\n if (endWillBeTrimmed && !spansWillBeCancelled) {\n // the last span's timestamp will be used.\n\n if (transactionStats.atTimestamp) {\n statsOnFinish = transactionStats.atTimestamp.stats;\n }\n } else {\n // this endTimestamp will be used.\n statsOnFinish = this._getCurrentStats(transaction);\n }\n } else if (endWillBeTrimmed) {\n // If `trimEnd` is used, and there is a span to trim to. If there isn't, then the transaction should use `endTimestamp` or generate one.\n if (transactionStats.atTimestamp) {\n statsOnFinish = transactionStats.atTimestamp.stats;\n }\n } else if (!endTimestamp) {\n statsOnFinish = this._getCurrentStats(transaction);\n }\n\n this._statsByTransaction.delete(transaction);\n this._shouldStopTracking();\n\n if (!statsOnFinish) {\n if (typeof endTimestamp !== 'undefined') {\n logger.log('[StallTracking] Stall measurements not added due to `endTimestamp` being set.');\n } else if (trimEnd) {\n logger.log(\n '[StallTracking] Stall measurements not added due to `trimEnd` being set but we could not determine the stall measurements at that time.',\n );\n }\n\n return;\n }\n\n transaction.setMeasurement(\n STALL_COUNT,\n statsOnFinish.stall_count.value - transactionStats.atStart.stall_count.value,\n transactionStats.atStart.stall_count.unit,\n );\n\n transaction.setMeasurement(\n STALL_TOTAL_TIME,\n statsOnFinish.stall_total_time.value - transactionStats.atStart.stall_total_time.value,\n transactionStats.atStart.stall_total_time.unit,\n );\n\n transaction.setMeasurement(\n STALL_LONGEST_TIME,\n statsOnFinish.stall_longest_time.value,\n statsOnFinish.stall_longest_time.unit,\n );\n }\n\n /**\n * Logs the finish time of the span for use in `trimEnd: true` transactions.\n */\n private _markSpanFinish(transaction: Transaction, spanEndTimestamp: number): void {\n const previousStats = this._statsByTransaction.get(transaction);\n if (previousStats) {\n if (Math.abs(timestampInSeconds() - spanEndTimestamp) > MARGIN_OF_ERROR_SECONDS) {\n logger.log(\n '[StallTracking] Span end not logged due to end timestamp being outside the margin of error from now.',\n );\n\n if (previousStats.atTimestamp && previousStats.atTimestamp.timestamp < spanEndTimestamp) {\n // We also need to delete the stat for the last span, as the transaction would be trimmed to this span not the last one.\n this._statsByTransaction.set(transaction, {\n ...previousStats,\n atTimestamp: null,\n });\n }\n } else {\n this._statsByTransaction.set(transaction, {\n ...previousStats,\n atTimestamp: {\n timestamp: spanEndTimestamp,\n stats: this._getCurrentStats(transaction),\n },\n });\n }\n }\n }\n\n /**\n * Get the current stats for a transaction at a given time.\n */\n private _getCurrentStats(transaction: Transaction): StallMeasurements {\n return {\n stall_count: { value: this._stallCount, unit: 'none' },\n stall_total_time: { value: this._totalStallTime, unit: 'millisecond' },\n stall_longest_time: {\n value: this._statsByTransaction.get(transaction)?.longestStallTime ?? 0,\n unit: 'millisecond',\n },\n };\n }\n\n /**\n * Start tracking stalls\n */\n private _startTracking(): void {\n if (!this.isTracking) {\n this.isTracking = true;\n this._lastIntervalMs = Math.floor(timestampInSeconds() * 1000);\n\n this._iteration();\n }\n }\n\n /**\n * Stops the stall tracking interval and calls reset().\n */\n private _stopTracking(): void {\n this.isTracking = false;\n\n if (this._timeout !== null) {\n clearTimeout(this._timeout);\n this._timeout = null;\n }\n\n this._reset();\n }\n\n /**\n * Will stop tracking if there are no more transactions.\n */\n private _shouldStopTracking(): void {\n if (this._statsByTransaction.size === 0) {\n this._stopTracking();\n }\n }\n\n /**\n * Clears all the collected stats\n */\n private _reset(): void {\n this._stallCount = 0;\n this._totalStallTime = 0;\n this._lastIntervalMs = 0;\n this._statsByTransaction.clear();\n }\n\n /**\n * Iteration of the stall tracking interval. Measures how long the timer strayed from its expected time of running, and how\n * long the stall is for.\n */\n private _iteration(): void {\n const now = timestampInSeconds() * 1000;\n const totalTimeTaken = now - this._lastIntervalMs;\n\n if (totalTimeTaken >= LOOP_TIMEOUT_INTERVAL_MS + this._minimumStallThreshold) {\n const stallTime = totalTimeTaken - LOOP_TIMEOUT_INTERVAL_MS;\n this._stallCount += 1;\n this._totalStallTime += stallTime;\n\n for (const [transaction, value] of this._statsByTransaction.entries()) {\n const longestStallTime = Math.max(value.longestStallTime ?? 0, stallTime);\n\n this._statsByTransaction.set(transaction, {\n ...value,\n longestStallTime,\n });\n }\n }\n\n this._lastIntervalMs = now;\n\n if (this.isTracking) {\n this._timeout = setTimeout(this._iteration.bind(this), LOOP_TIMEOUT_INTERVAL_MS);\n }\n }\n\n /**\n * Deletes leaked transactions (Earliest transactions when we have more than MAX_RUNNING_TRANSACTIONS transactions.)\n */\n private _flushLeakedTransactions(): void {\n if (this._statsByTransaction.size > MAX_RUNNING_TRANSACTIONS) {\n let counter = 0;\n const len = this._statsByTransaction.size - MAX_RUNNING_TRANSACTIONS;\n const transactions = this._statsByTransaction.keys();\n for (const t of transactions) {\n if (counter >= len) break;\n counter += 1;\n this._statsByTransaction.delete(t);\n }\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/transaction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/transaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAGvF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,oBASpC,CAAC"}
|
|
@@ -4,7 +4,8 @@ import { logger } from '@sentry/utils';
|
|
|
4
4
|
* To avoid side effects of other callbacks this should be hooked as the last callback.
|
|
5
5
|
*/
|
|
6
6
|
export const onlySampleIfChildSpans = (transaction) => {
|
|
7
|
-
const spansCount = transaction.spanRecorder &&
|
|
7
|
+
const spansCount = transaction.spanRecorder &&
|
|
8
|
+
transaction.spanRecorder.spans.filter(span => span.spanId !== transaction.spanId).length;
|
|
8
9
|
if (!spansCount || spansCount <= 0) {
|
|
9
10
|
logger.log(`Not sampling as ${transaction.op} transaction has no child spans.`);
|
|
10
11
|
transaction.sampled = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/js/tracing/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAyB,
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/js/tracing/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAyB,CAAC,WAA4B,EAAQ,EAAE;IACjG,MAAM,UAAU,GACd,WAAW,CAAC,YAAY;QACxB,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;IAE3F,IAAI,CAAC,UAAU,IAAI,UAAU,IAAI,CAAC,EAAE;QAClC,MAAM,CAAC,GAAG,CAAC,mBAAmB,WAAW,CAAC,EAAE,kCAAkC,CAAC,CAAC;QAChF,WAAW,CAAC,OAAO,GAAG,KAAK,CAAC;KAC7B;AACH,CAAC,CAAC","sourcesContent":["import type { IdleTransaction } from '@sentry/core';\nimport type { BeforeFinishCallback } from '@sentry/core/types/tracing/idletransaction';\nimport { logger } from '@sentry/utils';\n\n/**\n * Idle Transaction callback to only sample transactions with child spans.\n * To avoid side effects of other callbacks this should be hooked as the last callback.\n */\nexport const onlySampleIfChildSpans: BeforeFinishCallback = (transaction: IdleTransaction): void => {\n const spansCount =\n transaction.spanRecorder &&\n transaction.spanRecorder.spans.filter(span => span.spanId !== transaction.spanId).length;\n\n if (!spansCount || spansCount <= 0) {\n logger.log(`Not sampling as ${transaction.op} transaction has no child spans.`);\n transaction.sampled = false;\n }\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,MAAM,WAAW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;IACT,KAAK,EAAE;QACL,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QACvB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,OAAO,CAAC;KACtB,CAAC;CACH,CAAC;AAEF,MAAM,WAAW,iCAAkC,SAAQ,kBAAkB;IAC3E,IAAI,EAAE;QACJ,yBAAyB,EAAE,MAAM,CAAC;QAClC,oBAAoB,EAAE,MAAM,CAAC;KAC9B,CAAC;IACF,IAAI,EAAE,sBAAsB,CAAC;CAC9B;AAED,oBAAY,cAAc,GAAG,CAAC,OAAO,EAAE,kBAAkB,KAAK,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/js/tracing/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TransactionContext } from '@sentry/types';\n\nexport interface ReactNavigationRoute {\n name: string;\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params: Record<string, any>;\n}\n\nexport interface ReactNavigationCurrentRoute extends ReactNavigationRoute {\n hasBeenSeen: boolean;\n}\n\nexport type RouteChangeContextData = {\n previousRoute?: {\n [key: string]: unknown;\n name: string;\n } | null;\n route: {\n [key: string]: unknown;\n name: string;\n hasBeenSeen: boolean;\n };\n};\n\nexport interface ReactNavigationTransactionContext extends TransactionContext {\n tags: {\n 'routing.instrumentation': string;\n 'routing.route.name': string;\n };\n data: RouteChangeContextData;\n}\n\nexport type BeforeNavigate = (
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/js/tracing/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TransactionContext } from '@sentry/types';\n\nexport interface ReactNavigationRoute {\n name: string;\n key: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n params: Record<string, any>;\n}\n\nexport interface ReactNavigationCurrentRoute extends ReactNavigationRoute {\n hasBeenSeen: boolean;\n}\n\nexport type RouteChangeContextData = {\n previousRoute?: {\n [key: string]: unknown;\n name: string;\n } | null;\n route: {\n [key: string]: unknown;\n name: string;\n hasBeenSeen: boolean;\n };\n};\n\nexport interface ReactNavigationTransactionContext extends TransactionContext {\n tags: {\n 'routing.instrumentation': string;\n 'routing.route.name': string;\n };\n data: RouteChangeContextData;\n}\n\nexport type BeforeNavigate = (context: TransactionContext) => TransactionContext;\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IdleTransaction, Span, Transaction } from '@sentry/
|
|
1
|
+
import type { IdleTransaction, Span, Transaction } from '@sentry/core';
|
|
2
2
|
import type { TransactionContext, TransactionSource } from '@sentry/types';
|
|
3
3
|
export declare const defaultTransactionSource: TransactionSource;
|
|
4
4
|
export declare const customTransactionSource: TransactionSource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAG3E,eAAO,MAAM,wBAAwB,EAAE,iBAA+B,CAAC;AACvE,eAAO,MAAM,uBAAuB,EAAE,iBAA4B,CAAC;AAEnE,eAAO,MAAM,0BAA0B,sCAYtC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAI5C;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,eAAe,EAC5B,YAAY,EAAE,MAAM,GACnB,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAElD;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,IAAI,GACpD,IAAI,CAkBN;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEtD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/js/tracing/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,CAAC,MAAM,wBAAwB,GAAsB,WAAW,CAAC;AACvE,MAAM,CAAC,MAAM,uBAAuB,GAAsB,QAAQ,CAAC;AAEnE,MAAM,CAAC,MAAM,0BAA0B,GAAG,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/js/tracing/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,CAAC,MAAM,wBAAwB,GAAsB,WAAW,CAAC;AACvE,MAAM,CAAC,MAAM,uBAAuB,GAAsB,QAAQ,CAAC;AAEnE,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,IAAY,EAAsB,EAAE;IAC7E,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,EAAE,EAAE,YAAY;QAChB,IAAI,EAAE;YACJ,yBAAyB,EAAE,IAAI;SAChC;QACD,IAAI,EAAE,EAAE;QACR,QAAQ,EAAE;YACR,MAAM,EAAE,wBAAwB;SACjC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAE5C,MAAM,sBAAsB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AAE1C;;GAEG;AACH,MAAM,UAAU,yBAAyB,CACvC,aAAqB,EACr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transaction } from '@sentry/core';\nimport type { TransactionContext, TransactionSource } from '@sentry/types';\nimport { timestampInSeconds } from '@sentry/utils';\n\nexport const defaultTransactionSource: TransactionSource = 'component';\nexport const customTransactionSource: TransactionSource = 'custom';\n\nexport const getBlankTransactionContext = (name: string): TransactionContext => {\n return {\n name: 'Route Change',\n op: 'navigation',\n tags: {\n 'routing.instrumentation': name,\n },\n data: {},\n metadata: {\n source: defaultTransactionSource,\n },\n };\n};\n\n/**\n * A margin of error of 50ms is allowed for the async native bridge call.\n * Anything larger would reduce the accuracy of our frames measurements.\n */\nexport const MARGIN_OF_ERROR_SECONDS = 0.05;\n\nconst timeOriginMilliseconds = Date.now();\n\n/**\n *\n */\nexport function adjustTransactionDuration(\n maxDurationMs: number,\n transaction: IdleTransaction,\n endTimestamp: number,\n): void {\n const diff = endTimestamp - transaction.startTimestamp;\n const isOutdatedTransaction = endTimestamp && (diff > maxDurationMs || diff < 0);\n if (isOutdatedTransaction) {\n transaction.setStatus('deadline_exceeded');\n transaction.setTag('maxTransactionDurationExceeded', 'true');\n }\n}\n\n/**\n * Returns the timestamp where the JS global scope was initialized.\n */\nexport function getTimeOriginMilliseconds(): number {\n return timeOriginMilliseconds;\n}\n\n/**\n * Calls the callback every time a child span of the transaction is finished.\n */\nexport function instrumentChildSpanFinish(\n transaction: Transaction,\n callback: (span: Span, endTimestamp?: number) => void,\n): void {\n if (transaction.spanRecorder) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalAdd = transaction.spanRecorder.add;\n\n transaction.spanRecorder.add = (span: Span): void => {\n originalAdd.apply(transaction.spanRecorder, [span]);\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalSpanFinish = span.finish;\n\n span.finish = (endTimestamp?: number) => {\n originalSpanFinish.apply(span, [endTimestamp]);\n\n callback(span, endTimestamp);\n };\n };\n }\n}\n\n/**\n * Determines if the timestamp is now or within the specified margin of error from now.\n */\nexport function isNearToNow(timestamp: number): boolean {\n return Math.abs(timestampInSeconds() - timestamp) <= MARGIN_OF_ERROR_SECONDS;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextEncoder.d.ts","sourceRoot":"","sources":["../../../src/js/transports/TextEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAIzD,eAAO,MAAM,mBAAmB,2BAS/B,
|
|
1
|
+
{"version":3,"file":"TextEncoder.d.ts","sourceRoot":"","sources":["../../../src/js/transports/TextEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAIzD,eAAO,MAAM,mBAAmB,2BAS/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextEncoder.js","sourceRoot":"","sources":["../../../src/js/transports/TextEncoder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAwB,EAAE;IAC3D,MAAM,WAAW,GAAG;QAClB,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;YACvB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;YAChD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,QAAQ,EAAE,OAAO;KAClB,CAAC;IACF,OAAO,WAAW,CAAC;AACrB,CAAC,
|
|
1
|
+
{"version":3,"file":"TextEncoder.js","sourceRoot":"","sources":["../../../src/js/transports/TextEncoder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAwB,EAAE;IAC3D,MAAM,WAAW,GAAG;QAClB,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;YACvB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;YAChD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,QAAQ,EAAE,OAAO;KAClB,CAAC;IACF,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC","sourcesContent":["import type { TextEncoderInternal } from '@sentry/types';\n\nimport { utf8ToBytes } from '../vendor';\n\nexport const makeUtf8TextEncoder = (): TextEncoderInternal => {\n const textEncoder = {\n encode: (text: string) => {\n const bytes = new Uint8Array(utf8ToBytes(text));\n return bytes;\n },\n encoding: 'utf-8',\n };\n return textEncoder;\n};\n"]}
|
|
@@ -33,7 +33,7 @@ export declare function makeNativeTransport(options?: BaseNativeTransportOptions
|
|
|
33
33
|
/**
|
|
34
34
|
* Creates a Native Transport factory if the native transport is available.
|
|
35
35
|
*/
|
|
36
|
-
export declare function makeNativeTransportFactory({ enableNative }: {
|
|
36
|
+
export declare function makeNativeTransportFactory({ enableNative, }: {
|
|
37
37
|
enableNative?: boolean;
|
|
38
38
|
}): typeof makeNativeTransport | null;
|
|
39
39
|
//# sourceMappingURL=native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/js/transports/native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAKnD,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,oBAAY,mBAAmB,GAAG,oBAAoB,
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../../src/js/transports/native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAKnD,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,oBAAY,mBAAmB,GAAG,oBAAoB,CAAC;AAEvD,MAAM,WAAW,0BAA0B;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,4CAA4C;AAC5C,qBAAa,eAAgB,YAAW,SAAS;IAC/C,4CAA4C;IAC5C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;gBAE7B,OAAO,GAAE,0BAA+B;IAI3D;;;;OAIG;IACI,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC;IAIlD;;;;;;;OAOG;IACI,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC;CAGrD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,0BAA+B,GAAG,eAAe,CAE7F;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,YAAY,GACb,EAAE;IACD,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,GAAG,OAAO,mBAAmB,GAAG,IAAI,CAKpC"}
|
|
@@ -35,7 +35,7 @@ export function makeNativeTransport(options = {}) {
|
|
|
35
35
|
/**
|
|
36
36
|
* Creates a Native Transport factory if the native transport is available.
|
|
37
37
|
*/
|
|
38
|
-
export function makeNativeTransportFactory({ enableNative }) {
|
|
38
|
+
export function makeNativeTransportFactory({ enableNative, }) {
|
|
39
39
|
if (enableNative && NATIVE.isNativeAvailable()) {
|
|
40
40
|
return makeNativeTransport;
|
|
41
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.js","sourceRoot":"","sources":["../../../src/js/transports/native.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAQtC,4CAA4C;AAC5C,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,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAAsC,EAAE;IAC1E,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,EACzC,YAAY,GAGb;IACC,IAAI,YAAY,IAAI,MAAM,CAAC,iBAAiB,EAAE,EAAE;QAC9C,OAAO,mBAAmB,CAAC;KAC5B;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { BaseTransportOptions, Envelope, Transport } from '@sentry/types';\nimport type { PromiseBuffer } from '@sentry/utils';\nimport { makePromiseBuffer } from '@sentry/utils';\n\nimport { NATIVE } from '../wrapper';\n\nexport const DEFAULT_BUFFER_SIZE = 30;\n\nexport type BaseNativeTransport = BaseTransportOptions;\n\nexport interface BaseNativeTransportOptions {\n bufferSize?: number;\n}\n\n/** Native Transport class implementation */\nexport class NativeTransport implements Transport {\n /** A simple buffer holding all requests. */\n protected readonly _buffer: PromiseBuffer<void>;\n\n public constructor(options: BaseNativeTransportOptions = {}) {\n this._buffer = makePromiseBuffer(options.bufferSize || DEFAULT_BUFFER_SIZE);\n }\n\n /**\n * Sends the envelope to the Store endpoint in Sentry.\n *\n * @param envelope Envelope that should be sent to Sentry.\n */\n public send(envelope: Envelope): PromiseLike<void> {\n return this._buffer.add(() => NATIVE.sendEnvelope(envelope));\n }\n\n /**\n * Wait for all envelopes to be sent or the timeout to expire, whichever comes first.\n *\n * @param timeout Maximum time in ms the transport should wait for envelopes to be flushed. Omitting this parameter will\n * cause the transport to wait until all events are sent before resolving the promise.\n * @returns A promise that will resolve with `true` if all events are sent before the timeout, or `false` if there are\n * still events in the queue when the timeout is reached.\n */\n public flush(timeout?: number): PromiseLike<boolean> {\n return this._buffer.drain(timeout);\n }\n}\n\n/**\n * Creates a Native Transport.\n */\nexport function makeNativeTransport(options: BaseNativeTransportOptions = {}): NativeTransport {\n return new NativeTransport(options);\n}\n\n/**\n * Creates a Native Transport factory if the native transport is available.\n */\nexport function makeNativeTransportFactory({\n enableNative,\n}: {\n enableNative?: boolean;\n}): typeof makeNativeTransport | null {\n if (enableNative && NATIVE.isNativeAvailable()) {\n return makeNativeTransport;\n }\n return null;\n}\n"]}
|
package/dist/js/user.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/js/user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,iFAAiF;AACjF,oBAAY,gBAAgB,GAAG;KAAG,CAAC,IAAI,MAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS;
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/js/user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,iFAAiF;AACjF,oBAAY,gBAAgB,GAAG;KAAG,CAAC,IAAI,MAAM,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS;CAAE,CAAC"}
|
package/dist/js/user.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/js/user.ts"],"names":[],"mappings":"","sourcesContent":["import type { User } from '@sentry/types';\n\n/** Requires all the keys defined on User interface to be present on an object */\nexport type RequiredKeysUser = { [P in keyof Required<User>]: User[P] | undefined
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/js/user.ts"],"names":[],"mappings":"","sourcesContent":["import type { User } from '@sentry/types';\n\n/** Requires all the keys defined on User interface to be present on an object */\nexport type RequiredKeysUser = { [P in keyof Required<User>]: User[P] | undefined };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../../src/js/utils/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../../src/js/utils/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAoB,MAAM,eAAe,CAAC;AAG/G,eAAO,MAAM,MAAM,IAAI,CAAC;AACxB,eAAO,MAAM,KAAK,IAAI,CAAC;AAEvB;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,YAAY,EACtB,EACE,QAAQ,EACR,MAAM,EACN,GAAG,GACJ,EAAE;IACD,QAAQ,EAAE,WAAW,GAAG,SAAS,CAAC;IAClC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,GAAG,EAAE,aAAa,GAAG,SAAS,CAAC;CAChC,GACA,aAAa,CAgBf"}
|