@sentry/react-native 7.6.0 → 7.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/RNSentry.podspec +1 -1
  2. package/android/build.gradle +1 -1
  3. package/android/libs/replay-stubs.jar +0 -0
  4. package/android/replay-stubs/build.gradle +1 -1
  5. package/android/src/main/java/io/sentry/react/RNSentryVersion.java +1 -1
  6. package/dist/js/client.d.ts.map +1 -1
  7. package/dist/js/client.js +9 -0
  8. package/dist/js/client.js.map +1 -1
  9. package/dist/js/feedback/FeedbackWidgetProvider.d.ts.map +1 -1
  10. package/dist/js/feedback/FeedbackWidgetProvider.js.map +1 -1
  11. package/dist/js/feedback/integration.d.ts.map +1 -1
  12. package/dist/js/feedback/integration.js.map +1 -1
  13. package/dist/js/index.d.ts +2 -2
  14. package/dist/js/index.d.ts.map +1 -1
  15. package/dist/js/index.js +1 -1
  16. package/dist/js/index.js.map +1 -1
  17. package/dist/js/integrations/default.js +1 -1
  18. package/dist/js/integrations/default.js.map +1 -1
  19. package/dist/js/integrations/expocontext.d.ts.map +1 -1
  20. package/dist/js/integrations/expocontext.js.map +1 -1
  21. package/dist/js/options.d.ts +9 -0
  22. package/dist/js/options.d.ts.map +1 -1
  23. package/dist/js/options.js.map +1 -1
  24. package/dist/js/replay/mobilereplay.d.ts +12 -2
  25. package/dist/js/replay/mobilereplay.d.ts.map +1 -1
  26. package/dist/js/replay/mobilereplay.js +43 -8
  27. package/dist/js/replay/mobilereplay.js.map +1 -1
  28. package/dist/js/tools/sentryMetroSerializer.d.ts.map +1 -1
  29. package/dist/js/tools/sentryMetroSerializer.js +9 -11
  30. package/dist/js/tools/sentryMetroSerializer.js.map +1 -1
  31. package/dist/js/tracing/integrations/nativeFrames.d.ts +2 -1
  32. package/dist/js/tracing/integrations/nativeFrames.d.ts.map +1 -1
  33. package/dist/js/tracing/integrations/nativeFrames.js +68 -25
  34. package/dist/js/tracing/integrations/nativeFrames.js.map +1 -1
  35. package/dist/js/tracing/onSpanEndUtils.d.ts +9 -0
  36. package/dist/js/tracing/onSpanEndUtils.d.ts.map +1 -1
  37. package/dist/js/tracing/onSpanEndUtils.js +52 -12
  38. package/dist/js/tracing/onSpanEndUtils.js.map +1 -1
  39. package/dist/js/tracing/reactnativenavigation.d.ts.map +1 -1
  40. package/dist/js/tracing/reactnativenavigation.js +4 -1
  41. package/dist/js/tracing/reactnativenavigation.js.map +1 -1
  42. package/dist/js/tracing/reactnavigation.d.ts +12 -1
  43. package/dist/js/tracing/reactnavigation.d.ts.map +1 -1
  44. package/dist/js/tracing/reactnavigation.js +51 -12
  45. package/dist/js/tracing/reactnavigation.js.map +1 -1
  46. package/dist/js/tracing/span.d.ts +18 -1
  47. package/dist/js/tracing/span.d.ts.map +1 -1
  48. package/dist/js/tracing/span.js +9 -2
  49. package/dist/js/tracing/span.js.map +1 -1
  50. package/dist/js/tracing/timetodisplay.d.ts.map +1 -1
  51. package/dist/js/tracing/timetodisplay.js +206 -21
  52. package/dist/js/tracing/timetodisplay.js.map +1 -1
  53. package/dist/js/version.d.ts +1 -1
  54. package/dist/js/version.js +1 -1
  55. package/dist/js/version.js.map +1 -1
  56. package/dist/js/wrapper.d.ts.map +1 -1
  57. package/dist/js/wrapper.js +5 -3
  58. package/dist/js/wrapper.js.map +1 -1
  59. package/ios/RNSentryVersion.m +1 -1
  60. package/package.json +13 -13
  61. package/ts3.8/dist/js/index.d.ts +2 -2
  62. package/ts3.8/dist/js/options.d.ts +9 -0
  63. package/ts3.8/dist/js/replay/mobilereplay.d.ts +12 -2
  64. package/ts3.8/dist/js/tracing/integrations/nativeFrames.d.ts +2 -1
  65. package/ts3.8/dist/js/tracing/onSpanEndUtils.d.ts +9 -0
  66. package/ts3.8/dist/js/tracing/reactnavigation.d.ts +12 -1
  67. package/ts3.8/dist/js/tracing/span.d.ts +18 -1
  68. package/ts3.8/dist/js/version.d.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,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IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;YAClE,IAAI,CAAC,GAAG,EAAE,CAAC;SACZ;IACH,CAAC,CAAC,CAAC;IAEH,YAAY;QACV,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,SAAe,EAAE,EAAE;;YACvC,IAAI,SAAS,KAAK,IAAI,EAAE;gBACtB,KAAK,CAAC,GAAG,CAAC,kCAAkC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;gBAChF,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,4DAAI,CAAC;aAC1B;QACH,CAAC,CAAC,CAAC;AACP,CAAC,CAAC","sourcesContent":["import type { Client, Span } from '@sentry/core';\nimport { debug, getSpanDescendants, SPAN_STATUS_ERROR, spanToJSON } from '@sentry/core';\nimport type { AppStateStatus } from 'react-native';\nimport { AppState } from 'react-native';\nimport { isRootSpan, isSentrySpan } from '../utils/span';\n\n/**\n * Hooks on span end event to execute a callback when the span ends.\n */\nexport function onThisSpanEnd(client: Client, span: Span, callback: (span: Span) => void): void {\n client.on('spanEnd', (endedSpan: Span) => {\n if (span !== endedSpan) {\n return;\n }\n callback(endedSpan);\n });\n}\n\nexport const adjustTransactionDuration = (client: Client, span: Span, maxDurationMs: number): void => {\n if (!isRootSpan(span)) {\n debug.warn('Not sampling empty back spans only works for Sentry Transactions (Root Spans).');\n return;\n }\n\n client.on('spanEnd', (endedSpan: Span) => {\n if (endedSpan !== span) {\n return;\n }\n\n const endTimestamp = spanToJSON(span).timestamp;\n const startTimestamp = spanToJSON(span).start_timestamp;\n if (!endTimestamp || !startTimestamp) {\n return;\n }\n\n const diff = endTimestamp - startTimestamp;\n const isOutdatedTransaction = endTimestamp && (diff > maxDurationMs || diff < 0);\n if (isOutdatedTransaction) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'deadline_exceeded' });\n // TODO: check where was used, might be possible to delete\n span.setAttribute('maxTransactionDurationExceeded', 'true');\n }\n });\n};\n\nexport const ignoreEmptyBackNavigation = (client: Client | undefined, span: Span | undefined): void => {\n if (!client) {\n debug.warn('Could not hook on spanEnd event because client is not defined.');\n return;\n }\n\n if (!span) {\n debug.warn('Could not hook on spanEnd event because span is not defined.');\n return;\n }\n\n if (!isRootSpan(span) || !isSentrySpan(span)) {\n debug.warn('Not sampling empty back spans only works for Sentry Transactions (Root Spans).');\n return;\n }\n\n client.on('spanEnd', (endedSpan: Span) => {\n if (endedSpan !== span) {\n return;\n }\n\n if (!spanToJSON(span).data?.['route.has_been_seen']) {\n return;\n }\n\n const children = getSpanDescendants(span);\n const filtered = children.filter(\n child =>\n child.spanContext().spanId !== span.spanContext().spanId &&\n spanToJSON(child).op !== 'ui.load.initial_display' &&\n spanToJSON(child).op !== 'navigation.processing',\n );\n\n if (filtered.length <= 0) {\n // filter children must include at least one span not created by the navigation automatic instrumentation\n debug.log(\n 'Not sampling transaction as route has been seen before. Pass ignoreEmptyBackNavigationTransactions = false to disable this feature.',\n );\n // Route has been seen before and has no child spans.\n span['_sampled'] = false;\n }\n });\n};\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 = (client: Client, span: Span): void => {\n if (!isRootSpan(span) || !isSentrySpan(span)) {\n debug.warn('Not sampling childless spans only works for Sentry Transactions (Root Spans).');\n return;\n }\n\n client.on('spanEnd', (endedSpan: Span) => {\n if (endedSpan !== span) {\n return;\n }\n\n const children = getSpanDescendants(span);\n\n if (children.length <= 1) {\n // Span always has at lest one child, itself\n debug.log(`Not sampling as ${spanToJSON(span).op} transaction has no child spans.`);\n span['_sampled'] = false;\n }\n });\n};\n\n/**\n * Hooks on AppState change to cancel the span if the app goes background.\n */\nexport const cancelInBackground = (client: Client, span: Span): void => {\n const subscription = AppState.addEventListener('change', (newState: AppStateStatus) => {\n if (newState === 'background') {\n debug.log(`Setting ${spanToJSON(span).op} transaction to cancelled because the app is in the background.`);\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'cancelled' });\n span.end();\n }\n });\n\n subscription &&\n client.on('spanEnd', (endedSpan: Span) => {\n if (endedSpan === span) {\n debug.log(`Removing AppState listener for ${spanToJSON(span).op} transaction.`);\n subscription?.remove?.();\n }\n });\n};\n"]}
1
+ {"version":3,"file":"onSpanEndUtils.js","sourceRoot":"","sources":["../../../src/js/tracing/onSpanEndUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAExF,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEzD;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,IAAU,EAAE,QAA8B;IACtF,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,SAAe,EAAE,EAAE;QACvC,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO;SACR;QACD,QAAQ,CAAC,SAAS,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,MAAc,EAAE,IAAU,EAAE,aAAqB,EAAQ,EAAE;IACnG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACrB,KAAK,CAAC,IAAI,CAAC,gFAAgF,CAAC,CAAC;QAC7F,OAAO;KACR;IAED,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,SAAe,EAAE,EAAE;QACvC,IAAI,SAAS,KAAK,IAAI,EAAE;YACtB,OAAO;SACR;QAED,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC;QAChD,MAAM,cAAc,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC;QACxD,IAA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AU,CAAC,IAAI,CAAC,CAAC,EAAE,iEAAiE,CAAC,CAAC;YAC3G,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;YAClE,IAAI,CAAC,GAAG,EAAE,CAAC;SACZ;IACH,CAAC,CAAC,CAAC;IAEH,YAAY;QACV,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,SAAe,EAAE,EAAE;;YACvC,IAAI,SAAS,KAAK,IAAI,EAAE;gBACtB,KAAK,CAAC,GAAG,CAAC,kCAAkC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;gBAChF,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,4DAAI,CAAC;aAC1B;QACH,CAAC,CAAC,CAAC;AACP,CAAC,CAAC","sourcesContent":["import type { Client, Span } from '@sentry/core';\nimport { debug, getSpanDescendants, SPAN_STATUS_ERROR, spanToJSON } from '@sentry/core';\nimport type { AppStateStatus } from 'react-native';\nimport { AppState } from 'react-native';\nimport { isRootSpan, isSentrySpan } from '../utils/span';\n\n/**\n * Hooks on span end event to execute a callback when the span ends.\n */\nexport function onThisSpanEnd(client: Client, span: Span, callback: (span: Span) => void): void {\n client.on('spanEnd', (endedSpan: Span) => {\n if (span !== endedSpan) {\n return;\n }\n callback(endedSpan);\n });\n}\n\nexport const adjustTransactionDuration = (client: Client, span: Span, maxDurationMs: number): void => {\n if (!isRootSpan(span)) {\n debug.warn('Not sampling empty back spans only works for Sentry Transactions (Root Spans).');\n return;\n }\n\n client.on('spanEnd', (endedSpan: Span) => {\n if (endedSpan !== span) {\n return;\n }\n\n const endTimestamp = spanToJSON(span).timestamp;\n const startTimestamp = spanToJSON(span).start_timestamp;\n if (!endTimestamp || !startTimestamp) {\n return;\n }\n\n const diff = endTimestamp - startTimestamp;\n const isOutdatedTransaction = endTimestamp && (diff > maxDurationMs || diff < 0);\n if (isOutdatedTransaction) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'deadline_exceeded' });\n // TODO: check where was used, might be possible to delete\n span.setAttribute('maxTransactionDurationExceeded', 'true');\n }\n });\n};\n\n/**\n * Helper function to filter out auto-instrumentation child spans.\n */\nfunction getMeaningfulChildSpans(span: Span): Span[] {\n const children = getSpanDescendants(span);\n return children.filter(\n child =>\n child.spanContext().spanId !== span.spanContext().spanId &&\n spanToJSON(child).op !== 'ui.load.initial_display' &&\n spanToJSON(child).op !== 'navigation.processing',\n );\n}\n\n/**\n * Generic helper to discard empty navigation spans based on a condition.\n */\nfunction discardEmptyNavigationSpan(\n client: Client | undefined,\n span: Span | undefined,\n shouldDiscardFn: (span: Span) => boolean,\n onDiscardFn: (span: Span) => void,\n): void {\n if (!client) {\n debug.warn('Could not hook on spanEnd event because client is not defined.');\n return;\n }\n\n if (!span) {\n debug.warn('Could not hook on spanEnd event because span is not defined.');\n return;\n }\n\n if (!isRootSpan(span) || !isSentrySpan(span)) {\n debug.warn('Not sampling empty navigation spans only works for Sentry Transactions (Root Spans).');\n return;\n }\n\n client.on('spanEnd', (endedSpan: Span) => {\n if (endedSpan !== span) {\n return;\n }\n\n if (!shouldDiscardFn(span)) {\n return;\n }\n\n const meaningfulChildren = getMeaningfulChildSpans(span);\n if (meaningfulChildren.length <= 0) {\n onDiscardFn(span);\n span['_sampled'] = false;\n }\n });\n}\n\nexport const ignoreEmptyBackNavigation = (client: Client | undefined, span: Span | undefined): void => {\n discardEmptyNavigationSpan(\n client,\n span,\n // Only discard if route has been seen before\n span => spanToJSON(span).data?.['route.has_been_seen'] === true,\n // Log message when discarding\n () => {\n debug.log(\n 'Not sampling transaction as route has been seen before. Pass ignoreEmptyBackNavigationTransactions = false to disable this feature.',\n );\n },\n );\n};\n\n/**\n * Discards empty \"Route Change\" transactions that never received route information.\n * This happens when navigation library emits a route change event but getCurrentRoute() returns undefined.\n * Such transactions don't contain any useful information and should not be sent to Sentry.\n *\n * This function must be called with a reference tracker function that can check if the span\n * was cleared from the integration's tracking (indicating it went through the state listener).\n */\nexport const ignoreEmptyRouteChangeTransactions = (\n client: Client | undefined,\n span: Span | undefined,\n defaultNavigationSpanName: string,\n isSpanStillTracked: () => boolean,\n): void => {\n discardEmptyNavigationSpan(\n client,\n span,\n // Only discard if:\n // 1. Still has default name\n // 2. No route information was set\n // 3. Still being tracked (state listener never called)\n span => {\n const spanJSON = spanToJSON(span);\n return (\n spanJSON.description === defaultNavigationSpanName && !spanJSON.data?.['route.name'] && isSpanStillTracked()\n );\n },\n // Log and record dropped event\n _span => {\n debug.log(`Discarding empty \"${defaultNavigationSpanName}\" transaction that never received route information.`);\n client?.recordDroppedEvent('sample_rate', 'transaction');\n },\n );\n};\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 = (client: Client, span: Span): void => {\n if (!isRootSpan(span) || !isSentrySpan(span)) {\n debug.warn('Not sampling childless spans only works for Sentry Transactions (Root Spans).');\n return;\n }\n\n client.on('spanEnd', (endedSpan: Span) => {\n if (endedSpan !== span) {\n return;\n }\n\n const children = getSpanDescendants(span);\n\n if (children.length <= 1) {\n // Span always has at lest one child, itself\n debug.log(`Not sampling as ${spanToJSON(span).op} transaction has no child spans.`);\n span['_sampled'] = false;\n }\n });\n};\n\n/**\n * Hooks on AppState change to cancel the span if the app goes background.\n */\nexport const cancelInBackground = (client: Client, span: Span): void => {\n const subscription = AppState.addEventListener('change', (newState: AppStateStatus) => {\n if (newState === 'background') {\n debug.log(`Setting ${spanToJSON(span).op} transaction to cancelled because the app is in the background.`);\n span.setStatus({ code: SPAN_STATUS_ERROR, message: 'cancelled' });\n span.end();\n }\n });\n\n subscription &&\n client.on('spanEnd', (endedSpan: Span) => {\n if (endedSpan === span) {\n debug.log(`Removing AppState listener for ${spanToJSON(span).op} transaction.`);\n subscription?.remove?.();\n }\n });\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,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AC9G,uBAAuB,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,GAAG,iBAAiB,CAAC;IAC9F,gCAAgC,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,GAAG,mBAAmB,CAAC;CACzG;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,cAAc,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gCAAgC,+HAK1C,4BAA4B,KAAG,WA0IjC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { addBreadcrumb, getClient, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, spanToJSON, } from '@sentry/core';
2
2
  import { isSentrySpan } from '../utils/span';
3
- import { ignoreEmptyBackNavigation } from './onSpanEndUtils';
3
+ import { ignoreEmptyBackNavigation, ignoreEmptyRouteChangeTransactions } from './onSpanEndUtils';
4
4
  import { SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NATIVE_NAVIGATION } from './origin';
5
5
  import { getReactNativeTracingIntegration } from './reactnativetracing';
6
6
  import { DEFAULT_NAVIGATION_SPAN_NAME, defaultIdleOptions, getDefaultIdleNavigationSpanOptions, startIdleNavigationSpan as startGenericIdleNavigationSpan, } from './span';
@@ -42,6 +42,9 @@ export const reactNativeNavigationIntegration = ({ navigation: optionsNavigation
42
42
  if (ignoreEmptyBackNavigationTransactions) {
43
43
  ignoreEmptyBackNavigation(getClient(), latestNavigationSpan);
44
44
  }
45
+ // Always discard transactions that never receive route information
46
+ const spanToCheck = latestNavigationSpan;
47
+ ignoreEmptyRouteChangeTransactions(getClient(), spanToCheck, DEFAULT_NAVIGATION_SPAN_NAME, () => latestNavigationSpan === spanToCheck);
45
48
  stateChangeTimeout = setTimeout(discardLatestNavigationSpan.bind(this), routeChangeTimeoutMs);
46
49
  };
47
50
  const updateLatestNavigationSpanWithCurrentComponent = (event) => {
@@ -1 +1 @@
1
- {"version":3,"file":"reactnativenavigation.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnativenavigation.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,SAAS,EACT,4BAA4B,EAC5B,gCAAgC,EAChC,gCAAgC,EAChC,UAAU,GACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,mDAAmD,EAAE,MAAM,UAAU,CAAC;AAE/E,OAAO,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,mCAAmC,EACnC,uBAAuB,IAAI,8BAA8B,GAC1D,MAAM,QAAQ,CAAC;AAEhB,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAExD,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAkExC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,EAC/C,UAAU,EAAE,iBAAiB,EAC7B,oBAAoB,GAAG,IAAK,EAC5B,yBAAyB,GAAG,KAAK,EACjC,qCAAqC,GAAG,IAAI,GACf,EAAe,EAAE;IAC9C,MAAM,UAAU,GAAG,iBAAuC,CAAC;IAC3D,IAAI,kBAAkB,GAAa,EAAE,CAAC;IAEtC,IAAI,OAAkD,CAAC;IACvD,IAAI,eAAe,GAAyD,kBAAkB,CAAC;IAE/F,IAAI,kBAA6D,CAAC;IAClE,IAAI,kBAAkB,GAAoC,IAAI,CAAC;IAC/D,IAAI,oBAAsC,CAAC;IAE3C,MAAM,aAAa,GAAG,CAAC,MAAc,EAAQ,EAAE;QAC7C,OAAO,GAAG,gCAAgC,CAAC,MAAM,CAAC,CAAC;QACnD,IAAI,OAAO,E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,CAAC,CAAC;KAC/E;IACD,UAAU,CAAC,MAAM,EAAE,CAAC,mCAAmC,CAAC,8CAA8C,CAAC,CAAC;IAExG,MAAM,qBAAqB,GAAG,CAAC,EAAU,EAAQ,EAAE;QACjD,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE5B,IAAI,kBAAkB,CAAC,MAAM,GAAG,2BAA2B,EAAE;YAC3D,kBAAkB,GAAG,kBAAkB,CAAC,KAAK,CAAC,kBAAkB,CAAC,MAAM,GAAG,2BAA2B,CAAC,CAAC;SACxG;IACH,CAAC,CAAC;IAEF,MAAM,2BAA2B,GAAG,GAAS,EAAE;QAC7C,IAAI,oBAAoB,EAAE;YACxB,IAAI,YAAY,CAAC,oBAAoB,CAAC,EAAE;gBACtC,oBAAoB,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC;aAC1C;YACD,qCAAqC;YACrC,oBAAoB,CAAC,GAAG,EAAE,CAAC;YAC3B,oBAAoB,GAAG,SAAS,CAAC;SAClC;QAED,uBAAuB,EAAE,CAAC;IAC5B,CAAC,CAAC;IAEF,MAAM,uBAAuB,GAAG,GAAS,EAAE;QACzC,IAAI,OAAO,kBAAkB,KAAK,WAAW,EAAE;YAC7C,YAAY,CAAC,kBAAkB,CAAC,CAAC;YACjC,kBAAkB,GAAG,SAAS,CAAC;SAChC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,aAAa;KACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { Client, Integration, Span } from '@sentry/core';\nimport {\n addBreadcrumb,\n getClient,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n} from '@sentry/core';\nimport type { EmitterSubscription } from '../utils/rnlibrariesinterface';\nimport { isSentrySpan } from '../utils/span';\nimport { ignoreEmptyBackNavigation } from './onSpanEndUtils';\nimport { SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NATIVE_NAVIGATION } from './origin';\nimport type { ReactNativeTracingIntegration } from './reactnativetracing';\nimport { getReactNativeTracingIntegration } from './reactnativetracing';\nimport {\n DEFAULT_NAVIGATION_SPAN_NAME,\n defaultIdleOptions,\n getDefaultIdleNavigationSpanOptions,\n startIdleNavigationSpan as startGenericIdleNavigationSpan,\n} from './span';\n\nexport const INTEGRATION_NAME = 'ReactNativeNavigation';\n\nconst NAVIGATION_HISTORY_MAX_SIZE = 200;\n\ninterface ReactNativeNavigationOptions {\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 *\n * @default 1_000 (ms)\n */\n routeChangeTimeoutMs?: number;\n\n /**\n * Instrumentation will create a transaction on tab change.\n * By default only navigation commands create transactions.\n *\n * @default false\n */\n enableTabsInstrumentation?: boolean;\n\n /**\n * Does not sample transactions that are from routes that have been seen any more and don't have any spans.\n * This removes a lot of the clutter as most back navigation transactions are now ignored.\n *\n * @default true\n */\n ignoreEmptyBackNavigationTransactions?: boolean;\n\n /** The React Native Navigation `NavigationDelegate`.\n *\n * ```js\n * import { Navigation } from 'react-native-navigation';\n * ```\n */\n navigation: unknown;\n}\n\ninterface ComponentEvent {\n componentId: string;\n}\n\ntype ComponentType = 'Component' | 'TopBarTitle' | 'TopBarBackground' | 'TopBarButton';\n\nexport interface ComponentWillAppearEvent extends ComponentEvent {\n componentName: string;\n passProps?: Record<string | number | symbol, unknown>;\n componentType: ComponentType;\n}\n\nexport interface EventSubscription {\n remove(): void;\n}\n\nexport interface BottomTabPressedEvent {\n tabIndex: number;\n}\n\nexport interface EventsRegistry {\n registerComponentWillAppearListener(callback: (event: ComponentWillAppearEvent) => void): EmitterSubscription;\n registerCommandListener(callback: (name: string, params: unknown) => void): EventSubscription;\n registerBottomTabPressedListener(callback: (event: BottomTabPressedEvent) => void): EmitterSubscription;\n}\n\nexport interface NavigationDelegate {\n events: () => EventsRegistry;\n}\n\n/**\n * Instrumentation for React Native Navigation. See docs or sample app for usage.\n *\n * How this works:\n * - `_onCommand` is called every time a commands happens and sets an IdleTransaction on the scope without any route context.\n * - `_onComponentWillAppear` is then called AFTER the state change happens due to a dispatch and sets the route context onto the active transaction.\n * - If `_onComponentWillAppear` isn't called within `options.routeChangeTimeoutMs` of the dispatch, then the transaction is not sampled and finished.\n */\nexport const reactNativeNavigationIntegration = ({\n navigation: optionsNavigation,\n routeChangeTimeoutMs = 1_000,\n enableTabsInstrumentation = false,\n ignoreEmptyBackNavigationTransactions = true,\n}: ReactNativeNavigationOptions): Integration => {\n const navigation = optionsNavigation as NavigationDelegate;\n let recentComponentIds: string[] = [];\n\n let tracing: ReactNativeTracingIntegration | undefined;\n let idleSpanOptions: Parameters<typeof startGenericIdleNavigationSpan>[1] = defaultIdleOptions;\n\n let stateChangeTimeout: ReturnType<typeof setTimeout> | undefined;\n let prevComponentEvent: ComponentWillAppearEvent | null = null;\n let latestNavigationSpan: Span | undefined;\n\n const afterAllSetup = (client: Client): void => {\n tracing = getReactNativeTracingIntegration(client);\n if (tracing) {\n idleSpanOptions = {\n finalTimeout: tracing.options.finalTimeoutMs,\n idleTimeout: tracing.options.idleTimeoutMs,\n };\n }\n };\n\n const startIdleNavigationSpan = (): void => {\n if (latestNavigationSpan) {\n discardLatestNavigationSpan();\n }\n\n latestNavigationSpan = startGenericIdleNavigationSpan(\n tracing?.options.beforeStartSpan\n ? tracing.options.beforeStartSpan(getDefaultIdleNavigationSpanOptions())\n : getDefaultIdleNavigationSpanOptions(),\n idleSpanOptions,\n );\n latestNavigationSpan?.setAttribute(\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NATIVE_NAVIGATION,\n );\n if (ignoreEmptyBackNavigationTransactions) {\n ignoreEmptyBackNavigation(getClient(), latestNavigationSpan);\n }\n\n stateChangeTimeout = setTimeout(discardLatestNavigationSpan.bind(this), routeChangeTimeoutMs);\n };\n\n const updateLatestNavigationSpanWithCurrentComponent = (event: ComponentWillAppearEvent): void => {\n if (!latestNavigationSpan) {\n return;\n }\n\n // We ignore actions that pertain to the same screen.\n const isSameComponent = prevComponentEvent && event.componentId === prevComponentEvent.componentId;\n if (isSameComponent) {\n discardLatestNavigationSpan();\n return;\n }\n\n clearStateChangeTimeout();\n\n const routeHasBeenSeen = recentComponentIds.includes(event.componentId);\n\n if (spanToJSON(latestNavigationSpan).description === DEFAULT_NAVIGATION_SPAN_NAME) {\n latestNavigationSpan.updateName(event.componentName);\n }\n latestNavigationSpan.setAttributes({\n // TODO: Should we include pass props? I don't know exactly what it contains, cant find it in the RNavigation docs\n 'route.name': event.componentName,\n 'route.component_id': event.componentId,\n 'route.component_type': event.componentType,\n 'route.has_been_seen': routeHasBeenSeen,\n 'previous_route.name': prevComponentEvent?.componentName,\n 'previous_route.component_id': prevComponentEvent?.componentId,\n 'previous_route.component_type': prevComponentEvent?.componentType,\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n });\n\n tracing?.setCurrentRoute(event.componentName);\n\n addBreadcrumb({\n category: 'navigation',\n type: 'navigation',\n message: `Navigation to ${event.componentName}`,\n data: {\n from: prevComponentEvent?.componentName,\n to: event.componentName,\n },\n });\n\n pushRecentComponentId(event.componentId);\n prevComponentEvent = event;\n latestNavigationSpan = undefined;\n };\n\n navigation.events().registerCommandListener(startIdleNavigationSpan);\n if (enableTabsInstrumentation) {\n navigation.events().registerBottomTabPressedListener(startIdleNavigationSpan);\n }\n navigation.events().registerComponentWillAppearListener(updateLatestNavigationSpanWithCurrentComponent);\n\n const pushRecentComponentId = (id: string): void => {\n recentComponentIds.push(id);\n\n if (recentComponentIds.length > NAVIGATION_HISTORY_MAX_SIZE) {\n recentComponentIds = recentComponentIds.slice(recentComponentIds.length - NAVIGATION_HISTORY_MAX_SIZE);\n }\n };\n\n const discardLatestNavigationSpan = (): void => {\n if (latestNavigationSpan) {\n if (isSentrySpan(latestNavigationSpan)) {\n latestNavigationSpan['_sampled'] = false;\n }\n // TODO: What if it's not SentrySpan?\n latestNavigationSpan.end();\n latestNavigationSpan = undefined;\n }\n\n clearStateChangeTimeout();\n };\n\n const clearStateChangeTimeout = (): void => {\n if (typeof stateChangeTimeout !== 'undefined') {\n clearTimeout(stateChangeTimeout);\n stateChangeTimeout = undefined;\n }\n };\n\n return {\n name: INTEGRATION_NAME,\n afterAllSetup,\n };\n};\n"]}
1
+ {"version":3,"file":"reactnativenavigation.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnativenavigation.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,SAAS,EACT,4BAA4B,EAC5B,gCAAgC,EAChC,gCAAgC,EAChC,UAAU,GACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,kCAAkC,EAAE,MAAM,kBAAkB,CAAC;AACjG,OAAO,EAAE,mDAAmD,EAAE,MAAM,UAAU,CAAC;AAE/E,OAAO,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,mCAAmC,EACnC,uBAAuB,IAAI,8BAA8B,GAC1D,MAAM,QAAQ,CAAC;AAEhB,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAExD,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAkExC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,EAC/C,UAAU,EAAE,iBAAiB,EAC7B,oBAAoB,GAAG,IAAK,EAC5B,yBAAyB,GAAG,KAAK,EACjC,qCAAqC,GAAG,IAAI,GACf,EAAe,EAAE;IAC9C,MAAM,UAAU,GAAG,iBAAuC,CAAC;IAC3D,IAAI,kBAAkB,GAAa,EAAE,CAAC;IAEtC,IAAI,OAAk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kBAAkB,GAAG,SAAS,CAAC;SAChC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,aAAa;KACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { Client, Integration, Span } from '@sentry/core';\nimport {\n addBreadcrumb,\n getClient,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n spanToJSON,\n} from '@sentry/core';\nimport type { EmitterSubscription } from '../utils/rnlibrariesinterface';\nimport { isSentrySpan } from '../utils/span';\nimport { ignoreEmptyBackNavigation, ignoreEmptyRouteChangeTransactions } from './onSpanEndUtils';\nimport { SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NATIVE_NAVIGATION } from './origin';\nimport type { ReactNativeTracingIntegration } from './reactnativetracing';\nimport { getReactNativeTracingIntegration } from './reactnativetracing';\nimport {\n DEFAULT_NAVIGATION_SPAN_NAME,\n defaultIdleOptions,\n getDefaultIdleNavigationSpanOptions,\n startIdleNavigationSpan as startGenericIdleNavigationSpan,\n} from './span';\n\nexport const INTEGRATION_NAME = 'ReactNativeNavigation';\n\nconst NAVIGATION_HISTORY_MAX_SIZE = 200;\n\ninterface ReactNativeNavigationOptions {\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 *\n * @default 1_000 (ms)\n */\n routeChangeTimeoutMs?: number;\n\n /**\n * Instrumentation will create a transaction on tab change.\n * By default only navigation commands create transactions.\n *\n * @default false\n */\n enableTabsInstrumentation?: boolean;\n\n /**\n * Does not sample transactions that are from routes that have been seen any more and don't have any spans.\n * This removes a lot of the clutter as most back navigation transactions are now ignored.\n *\n * @default true\n */\n ignoreEmptyBackNavigationTransactions?: boolean;\n\n /** The React Native Navigation `NavigationDelegate`.\n *\n * ```js\n * import { Navigation } from 'react-native-navigation';\n * ```\n */\n navigation: unknown;\n}\n\ninterface ComponentEvent {\n componentId: string;\n}\n\ntype ComponentType = 'Component' | 'TopBarTitle' | 'TopBarBackground' | 'TopBarButton';\n\nexport interface ComponentWillAppearEvent extends ComponentEvent {\n componentName: string;\n passProps?: Record<string | number | symbol, unknown>;\n componentType: ComponentType;\n}\n\nexport interface EventSubscription {\n remove(): void;\n}\n\nexport interface BottomTabPressedEvent {\n tabIndex: number;\n}\n\nexport interface EventsRegistry {\n registerComponentWillAppearListener(callback: (event: ComponentWillAppearEvent) => void): EmitterSubscription;\n registerCommandListener(callback: (name: string, params: unknown) => void): EventSubscription;\n registerBottomTabPressedListener(callback: (event: BottomTabPressedEvent) => void): EmitterSubscription;\n}\n\nexport interface NavigationDelegate {\n events: () => EventsRegistry;\n}\n\n/**\n * Instrumentation for React Native Navigation. See docs or sample app for usage.\n *\n * How this works:\n * - `_onCommand` is called every time a commands happens and sets an IdleTransaction on the scope without any route context.\n * - `_onComponentWillAppear` is then called AFTER the state change happens due to a dispatch and sets the route context onto the active transaction.\n * - If `_onComponentWillAppear` isn't called within `options.routeChangeTimeoutMs` of the dispatch, then the transaction is not sampled and finished.\n */\nexport const reactNativeNavigationIntegration = ({\n navigation: optionsNavigation,\n routeChangeTimeoutMs = 1_000,\n enableTabsInstrumentation = false,\n ignoreEmptyBackNavigationTransactions = true,\n}: ReactNativeNavigationOptions): Integration => {\n const navigation = optionsNavigation as NavigationDelegate;\n let recentComponentIds: string[] = [];\n\n let tracing: ReactNativeTracingIntegration | undefined;\n let idleSpanOptions: Parameters<typeof startGenericIdleNavigationSpan>[1] = defaultIdleOptions;\n\n let stateChangeTimeout: ReturnType<typeof setTimeout> | undefined;\n let prevComponentEvent: ComponentWillAppearEvent | null = null;\n let latestNavigationSpan: Span | undefined;\n\n const afterAllSetup = (client: Client): void => {\n tracing = getReactNativeTracingIntegration(client);\n if (tracing) {\n idleSpanOptions = {\n finalTimeout: tracing.options.finalTimeoutMs,\n idleTimeout: tracing.options.idleTimeoutMs,\n };\n }\n };\n\n const startIdleNavigationSpan = (): void => {\n if (latestNavigationSpan) {\n discardLatestNavigationSpan();\n }\n\n latestNavigationSpan = startGenericIdleNavigationSpan(\n tracing?.options.beforeStartSpan\n ? tracing.options.beforeStartSpan(getDefaultIdleNavigationSpanOptions())\n : getDefaultIdleNavigationSpanOptions(),\n idleSpanOptions,\n );\n latestNavigationSpan?.setAttribute(\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NATIVE_NAVIGATION,\n );\n if (ignoreEmptyBackNavigationTransactions) {\n ignoreEmptyBackNavigation(getClient(), latestNavigationSpan);\n }\n // Always discard transactions that never receive route information\n const spanToCheck = latestNavigationSpan;\n ignoreEmptyRouteChangeTransactions(\n getClient(),\n spanToCheck,\n DEFAULT_NAVIGATION_SPAN_NAME,\n () => latestNavigationSpan === spanToCheck,\n );\n\n stateChangeTimeout = setTimeout(discardLatestNavigationSpan.bind(this), routeChangeTimeoutMs);\n };\n\n const updateLatestNavigationSpanWithCurrentComponent = (event: ComponentWillAppearEvent): void => {\n if (!latestNavigationSpan) {\n return;\n }\n\n // We ignore actions that pertain to the same screen.\n const isSameComponent = prevComponentEvent && event.componentId === prevComponentEvent.componentId;\n if (isSameComponent) {\n discardLatestNavigationSpan();\n return;\n }\n\n clearStateChangeTimeout();\n\n const routeHasBeenSeen = recentComponentIds.includes(event.componentId);\n\n if (spanToJSON(latestNavigationSpan).description === DEFAULT_NAVIGATION_SPAN_NAME) {\n latestNavigationSpan.updateName(event.componentName);\n }\n latestNavigationSpan.setAttributes({\n // TODO: Should we include pass props? I don't know exactly what it contains, cant find it in the RNavigation docs\n 'route.name': event.componentName,\n 'route.component_id': event.componentId,\n 'route.component_type': event.componentType,\n 'route.has_been_seen': routeHasBeenSeen,\n 'previous_route.name': prevComponentEvent?.componentName,\n 'previous_route.component_id': prevComponentEvent?.componentId,\n 'previous_route.component_type': prevComponentEvent?.componentType,\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n });\n\n tracing?.setCurrentRoute(event.componentName);\n\n addBreadcrumb({\n category: 'navigation',\n type: 'navigation',\n message: `Navigation to ${event.componentName}`,\n data: {\n from: prevComponentEvent?.componentName,\n to: event.componentName,\n },\n });\n\n pushRecentComponentId(event.componentId);\n prevComponentEvent = event;\n latestNavigationSpan = undefined;\n };\n\n navigation.events().registerCommandListener(startIdleNavigationSpan);\n if (enableTabsInstrumentation) {\n navigation.events().registerBottomTabPressedListener(startIdleNavigationSpan);\n }\n navigation.events().registerComponentWillAppearListener(updateLatestNavigationSpanWithCurrentComponent);\n\n const pushRecentComponentId = (id: string): void => {\n recentComponentIds.push(id);\n\n if (recentComponentIds.length > NAVIGATION_HISTORY_MAX_SIZE) {\n recentComponentIds = recentComponentIds.slice(recentComponentIds.length - NAVIGATION_HISTORY_MAX_SIZE);\n }\n };\n\n const discardLatestNavigationSpan = (): void => {\n if (latestNavigationSpan) {\n if (isSentrySpan(latestNavigationSpan)) {\n latestNavigationSpan['_sampled'] = false;\n }\n // TODO: What if it's not SentrySpan?\n latestNavigationSpan.end();\n latestNavigationSpan = undefined;\n }\n\n clearStateChangeTimeout();\n };\n\n const clearStateChangeTimeout = (): void => {\n if (typeof stateChangeTimeout !== 'undefined') {\n clearTimeout(stateChangeTimeout);\n stateChangeTimeout = undefined;\n }\n };\n\n return {\n name: INTEGRATION_NAME,\n afterAllSetup,\n };\n};\n"]}
@@ -35,6 +35,12 @@ interface ReactNavigationIntegrationOptions {
35
35
  * @default false
36
36
  */
37
37
  useDispatchedActionData: boolean;
38
+ /**
39
+ * Whether to use the full paths for navigation routes.
40
+ *
41
+ * @default false
42
+ */
43
+ useFullPathsForNavigationRoutes: boolean;
38
44
  }
39
45
  /**
40
46
  * Instrumentation for React-Navigation V5 and above. See docs or sample app for usage.
@@ -44,7 +50,7 @@ interface ReactNavigationIntegrationOptions {
44
50
  * - `_onStateChange` is then called AFTER the state change happens due to a dispatch and sets the route context onto the active transaction.
45
51
  * - If `_onStateChange` isn't called within `STATE_CHANGE_TIMEOUT_DURATION` of the dispatch, then the transaction is not sampled and finished.
46
52
  */
47
- export declare const reactNavigationIntegration: ({ routeChangeTimeoutMs, enableTimeToInitialDisplay, ignoreEmptyBackNavigationTransactions, enableTimeToInitialDisplayForPreloadedRoutes, useDispatchedActionData, }?: Partial<ReactNavigationIntegrationOptions>) => Integration & {
53
+ export declare const reactNavigationIntegration: ({ routeChangeTimeoutMs, enableTimeToInitialDisplay, ignoreEmptyBackNavigationTransactions, enableTimeToInitialDisplayForPreloadedRoutes, useDispatchedActionData, useFullPathsForNavigationRoutes, }?: Partial<ReactNavigationIntegrationOptions>) => Integration & {
48
54
  /**
49
55
  * Pass the ref to the navigation container to register it to the instrumentation
50
56
  * @param navigationContainerRef Ref to a `NavigationContainer`
@@ -56,6 +62,11 @@ export interface NavigationRoute {
56
62
  name: string;
57
63
  key: string;
58
64
  params?: Record<string, any>;
65
+ state?: NavigationState;
66
+ }
67
+ interface NavigationState {
68
+ index?: number;
69
+ routes: NavigationRoute[];
59
70
  }
60
71
  /**
61
72
  * Returns React Navigation integration of the given client.
@@ -1 +1 @@
1
- {"version":3,"file":"reactnavigation.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAQ,MAAM,cAAc,CAAC;AA+B9D,eAAO,MAAM,gBAAgB,oBAAoB,CAAC;AAIlD,UAAU,iCAAiC;IACzC;;;;;OAKG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAE7B;;;;;OAKG;IACH,0BAA0B,EAAE,OAAO,CAAC;IAEpC;;;;;OAKG;IACH,qCAAqC,EAAE,OAAO,CAAC;IAE/C;;;;;OAKG;IACH,4CAA4C,EAAE,OAAO,CAAC;IAEtD;;;;OAIG;IACH,uBAAuB,EAAE,OAAO,CAAC;CAClC;AAED;;;;;;;GA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AK,CAAC,EAAE,eAAe,CAAC;CACzB;AAED,UAAU,eAAe;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AAQD;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,MAAM,GACb,UAAU,CAAC,OAAO,0BAA0B,CAAC,GAAG,SAAS,CAE3D"}
@@ -3,7 +3,7 @@ import { getAppRegistryIntegration } from '../integrations/appRegistry';
3
3
  import { isSentrySpan } from '../utils/span';
4
4
  import { RN_GLOBAL_OBJ } from '../utils/worldwide';
5
5
  import { NATIVE } from '../wrapper';
6
- import { ignoreEmptyBackNavigation } from './onSpanEndUtils';
6
+ import { ignoreEmptyBackNavigation, ignoreEmptyRouteChangeTransactions } from './onSpanEndUtils';
7
7
  import { SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NAVIGATION } from './origin';
8
8
  import { getReactNativeTracingIntegration } from './reactnativetracing';
9
9
  import { SEMANTIC_ATTRIBUTE_NAVIGATION_ACTION_TYPE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from './semanticAttributes';
@@ -11,6 +11,27 @@ import { DEFAULT_NAVIGATION_SPAN_NAME, defaultIdleOptions, getDefaultIdleNavigat
11
11
  import { addTimeToInitialDisplayFallback } from './timeToDisplayFallback';
12
12
  export const INTEGRATION_NAME = 'ReactNavigation';
13
13
  const NAVIGATION_HISTORY_MAX_SIZE = 200;
14
+ /**
15
+ * Builds a full path from the navigation state by traversing nested navigators.
16
+ * For example, with nested navigators: "Home/Settings/Profile"
17
+ */
18
+ function getPathFromState(state) {
19
+ var _a;
20
+ if (!state) {
21
+ return undefined;
22
+ }
23
+ const routeNames = [];
24
+ let currentState = state;
25
+ while (currentState) {
26
+ const index = (_a = currentState.index) !== null && _a !== void 0 ? _a : 0;
27
+ const route = currentState.routes[index];
28
+ if (route === null || route === void 0 ? void 0 : route.name) {
29
+ routeNames.push(route.name);
30
+ }
31
+ currentState = route === null || route === void 0 ? void 0 : route.state;
32
+ }
33
+ return routeNames.length > 0 ? routeNames.join('/') : undefined;
34
+ }
14
35
  /**
15
36
  * Instrumentation for React-Navigation V5 and above. See docs or sample app for usage.
16
37
  *
@@ -19,7 +40,7 @@ const NAVIGATION_HISTORY_MAX_SIZE = 200;
19
40
  * - `_onStateChange` is then called AFTER the state change happens due to a dispatch and sets the route context onto the active transaction.
20
41
  * - If `_onStateChange` isn't called within `STATE_CHANGE_TIMEOUT_DURATION` of the dispatch, then the transaction is not sampled and finished.
21
42
  */
22
- export const reactNavigationIntegration = ({ routeChangeTimeoutMs = 1000, enableTimeToInitialDisplay = false, ignoreEmptyBackNavigationTransactions = true, enableTimeToInitialDisplayForPreloadedRoutes = false, useDispatchedActionData = false, } = {}) => {
43
+ export const reactNavigationIntegration = ({ routeChangeTimeoutMs = 1000, enableTimeToInitialDisplay = false, ignoreEmptyBackNavigationTransactions = true, enableTimeToInitialDisplayForPreloadedRoutes = false, useDispatchedActionData = false, useFullPathsForNavigationRoutes = false, } = {}) => {
23
44
  let navigationContainer;
24
45
  let tracing;
25
46
  let idleSpanOptions = defaultIdleOptions;
@@ -58,7 +79,7 @@ export const reactNavigationIntegration = ({ routeChangeTimeoutMs = 1000, enable
58
79
  // This ensures runApplication calls after the initial start are correctly traced.
59
80
  // This is used for example when Activity is (re)started on Android.
60
81
  debug.log('[ReactNavigationIntegration] Starting new idle navigation span based on runApplication call.');
61
- startIdleNavigationSpan();
82
+ startIdleNavigationSpan(undefined, true);
62
83
  }
63
84
  });
64
85
  startIdleNavigationSpan();
@@ -115,8 +136,11 @@ export const reactNavigationIntegration = ({ routeChangeTimeoutMs = 1000, enable
115
136
  * To be called on every React-Navigation action dispatch.
116
137
  * It does not name the transaction or populate it with route information. Instead, it waits for the state to fully change
117
138
  * and gets the route information from there, @see updateLatestNavigationSpanWithCurrentRoute
139
+ *
140
+ * @param unknownEvent - The event object that contains navigation action data
141
+ * @param isAppRestart - Whether this span is being started due to an app restart rather than a normal navigation action
118
142
  */
119
- const startIdleNavigationSpan = (unknownEvent) => {
143
+ const startIdleNavigationSpan = (unknownEvent, isAppRestart = false) => {
120
144
  const event = unknownEvent;
121
145
  if (useDispatchedActionData && (event === null || event === void 0 ? void 0 : event.data.noop)) {
122
146
  debug.log(`${INTEGRATION_NAME} Navigation action is a noop, not starting navigation span.`);
@@ -144,12 +168,15 @@ export const reactNavigationIntegration = ({ routeChangeTimeoutMs = 1000, enable
144
168
  }
145
169
  latestNavigationSpan = startGenericIdleNavigationSpan((tracing === null || tracing === void 0 ? void 0 : tracing.options.beforeStartSpan)
146
170
  ? tracing.options.beforeStartSpan(getDefaultIdleNavigationSpanOptions())
147
- : getDefaultIdleNavigationSpanOptions(), idleSpanOptions);
171
+ : getDefaultIdleNavigationSpanOptions(), Object.assign(Object.assign({}, idleSpanOptions), { isAppRestart }));
148
172
  latestNavigationSpan === null || latestNavigationSpan === void 0 ? void 0 : latestNavigationSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NAVIGATION);
149
173
  latestNavigationSpan === null || latestNavigationSpan === void 0 ? void 0 : latestNavigationSpan.setAttribute(SEMANTIC_ATTRIBUTE_NAVIGATION_ACTION_TYPE, navigationActionType);
150
174
  if (ignoreEmptyBackNavigationTransactions) {
151
175
  ignoreEmptyBackNavigation(getClient(), latestNavigationSpan);
152
176
  }
177
+ // Always discard transactions that never receive route information
178
+ const spanToCheck = latestNavigationSpan;
179
+ ignoreEmptyRouteChangeTransactions(getClient(), spanToCheck, DEFAULT_NAVIGATION_SPAN_NAME, () => latestNavigationSpan === spanToCheck);
153
180
  if (enableTimeToInitialDisplay && latestNavigationSpan) {
154
181
  NATIVE.setActiveSpanId(latestNavigationSpan.spanContext().spanId);
155
182
  navigationProcessingSpan = startInactiveSpan({
@@ -190,15 +217,21 @@ export const reactNavigationIntegration = ({ routeChangeTimeoutMs = 1000, enable
190
217
  return undefined;
191
218
  }
192
219
  const routeHasBeenSeen = recentRouteKeys.includes(route.key);
193
- navigationProcessingSpan === null || navigationProcessingSpan === void 0 ? void 0 : navigationProcessingSpan.updateName(`Navigation dispatch to screen ${route.name} mounted`);
220
+ // Get the full navigation path for nested navigators
221
+ let routeName = route.name;
222
+ if (useFullPathsForNavigationRoutes) {
223
+ const navigationState = navigationContainer.getState();
224
+ routeName = getPathFromState(navigationState) || route.name;
225
+ }
226
+ navigationProcessingSpan === null || navigationProcessingSpan === void 0 ? void 0 : navigationProcessingSpan.updateName(`Navigation dispatch to screen ${routeName} mounted`);
194
227
  navigationProcessingSpan === null || navigationProcessingSpan === void 0 ? void 0 : navigationProcessingSpan.setStatus({ code: SPAN_STATUS_OK });
195
228
  navigationProcessingSpan === null || navigationProcessingSpan === void 0 ? void 0 : navigationProcessingSpan.end(stateChangedTimestamp);
196
229
  navigationProcessingSpan = undefined;
197
230
  if (spanToJSON(latestNavigationSpan).description === DEFAULT_NAVIGATION_SPAN_NAME) {
198
- latestNavigationSpan.updateName(route.name);
231
+ latestNavigationSpan.updateName(routeName);
199
232
  }
200
233
  latestNavigationSpan.setAttributes({
201
- 'route.name': route.name,
234
+ 'route.name': routeName,
202
235
  'route.key': route.key,
203
236
  // TODO: filter PII params instead of dropping them all
204
237
  // 'route.params': {},
@@ -215,15 +248,20 @@ export const reactNavigationIntegration = ({ routeChangeTimeoutMs = 1000, enable
215
248
  addBreadcrumb({
216
249
  category: 'navigation',
217
250
  type: 'navigation',
218
- message: `Navigation to ${route.name}`,
251
+ message: `Navigation to ${routeName}`,
219
252
  data: {
220
253
  from: previousRoute === null || previousRoute === void 0 ? void 0 : previousRoute.name,
221
- to: route.name,
254
+ to: routeName,
222
255
  },
223
256
  });
224
- tracing === null || tracing === void 0 ? void 0 : tracing.setCurrentRoute(route.name);
257
+ tracing === null || tracing === void 0 ? void 0 : tracing.setCurrentRoute(routeName);
225
258
  pushRecentRouteKey(route.key);
226
- latestRoute = route;
259
+ if (useFullPathsForNavigationRoutes) {
260
+ latestRoute = Object.assign(Object.assign({}, route), { name: routeName });
261
+ }
262
+ else {
263
+ latestRoute = route;
264
+ }
227
265
  // Clear the latest transaction as it has been handled.
228
266
  latestNavigationSpan = undefined;
229
267
  };
@@ -264,6 +302,7 @@ export const reactNavigationIntegration = ({ routeChangeTimeoutMs = 1000, enable
264
302
  ignoreEmptyBackNavigationTransactions,
265
303
  enableTimeToInitialDisplayForPreloadedRoutes,
266
304
  useDispatchedActionData,
305
+ useFullPathsForNavigationRoutes,
267
306
  },
268
307
  };
269
308
  };
@@ -1 +1 @@
1
- {"version":3,"file":"reactnavigation.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigation.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EACb,KAAK,EACL,SAAS,EACT,aAAa,EACb,4BAA4B,EAC5B,gCAAgC,EAChC,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,4CAA4C,EAAE,MAAM,UAAU,CAAC;AAExE,OAAO,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,yCAAyC,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AACnH,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,mCAAmC,EACnC,uBAAuB,IAAI,8BAA8B,GAC1D,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAE1E,MAAM,CAAC,MAAM,gBAAgB,GAA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;IACxE,MAAM,yBAAyB,GAAG,GAAS,EAAE;QAC3C,IAAI,oBAAoB,EAAE;YACxB,IAAI,YAAY,CAAC,oBAAoB,CAAC,EAAE;gBACtC,oBAAoB,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC;aAC1C;YACD,qCAAqC;YACrC,oBAAoB,CAAC,GAAG,EAAE,CAAC;YAC3B,oBAAoB,GAAG,SAAS,CAAC;SAClC;QACD,IAAI,wBAAwB,EAAE;YAC5B,wBAAwB,GAAG,SAAS,CAAC;SACtC;IACH,CAAC,CAAC;IAEF,MAAM,uBAAuB,GAAG,GAAS,EAAE;QACzC,IAAI,OAAO,kBAAkB,KAAK,WAAW,EAAE;YAC7C,YAAY,CAAC,kBAAkB,CAAC,CAAC;YACjC,kBAAkB,GAAG,SAAS,CAAC;SAChC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,aAAa;QACb,2BAA2B;QAC3B,OAAO,EAAE;YACP,oBAAoB;YACpB,0BAA0B;YAC1B,qCAAqC;YACrC,4CAA4C;YAC5C,uBAAuB;SACxB;KACF,CAAC;AACJ,CAAC,CAAC;AAcF;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAC3C,MAAc;IAEd,OAAO,MAAM,CAAC,oBAAoB,CAAgD,gBAAgB,CAAC,CAAC;AACtG,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport type { Client, Integration, Span } from '@sentry/core';\nimport {\n addBreadcrumb,\n debug,\n getClient,\n isPlainObject,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_OK,\n spanToJSON,\n startInactiveSpan,\n timestampInSeconds,\n} from '@sentry/core';\nimport { getAppRegistryIntegration } from '../integrations/appRegistry';\nimport { isSentrySpan } from '../utils/span';\nimport { RN_GLOBAL_OBJ } from '../utils/worldwide';\nimport type { UnsafeAction } from '../vendor/react-navigation/types';\nimport { NATIVE } from '../wrapper';\nimport { ignoreEmptyBackNavigation } from './onSpanEndUtils';\nimport { SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NAVIGATION } from './origin';\nimport type { ReactNativeTracingIntegration } from './reactnativetracing';\nimport { getReactNativeTracingIntegration } from './reactnativetracing';\nimport { SEMANTIC_ATTRIBUTE_NAVIGATION_ACTION_TYPE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from './semanticAttributes';\nimport {\n DEFAULT_NAVIGATION_SPAN_NAME,\n defaultIdleOptions,\n getDefaultIdleNavigationSpanOptions,\n startIdleNavigationSpan as startGenericIdleNavigationSpan,\n} from './span';\nimport { addTimeToInitialDisplayFallback } from './timeToDisplayFallback';\n\nexport const INTEGRATION_NAME = 'ReactNavigation';\n\nconst NAVIGATION_HISTORY_MAX_SIZE = 200;\n\ninterface ReactNavigationIntegrationOptions {\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 *\n * @default 1_000 (ms)\n */\n routeChangeTimeoutMs: number;\n\n /**\n * Time to initial display measures the time it takes from\n * navigation dispatch to the render of the first frame of the new screen.\n *\n * @default false\n */\n enableTimeToInitialDisplay: boolean;\n\n /**\n * Does not sample transactions that are from routes that have been seen any more and don't have any spans.\n * This removes a lot of the clutter as most back navigation transactions are now ignored.\n *\n * @default true\n */\n ignoreEmptyBackNavigationTransactions: boolean;\n\n /**\n * Enabled measuring Time to Initial Display for routes that are already loaded in memory.\n * (a.k.a., Routes that the navigation integration has already seen.)\n *\n * @default false\n */\n enableTimeToInitialDisplayForPreloadedRoutes: boolean;\n\n /**\n * Whether to use the dispatched action data to populate the transaction metadata.\n *\n * @default false\n */\n useDispatchedActionData: boolean;\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 const reactNavigationIntegration = ({\n routeChangeTimeoutMs = 1_000,\n enableTimeToInitialDisplay = false,\n ignoreEmptyBackNavigationTransactions = true,\n enableTimeToInitialDisplayForPreloadedRoutes = false,\n useDispatchedActionData = false,\n}: Partial<ReactNavigationIntegrationOptions> = {}): Integration & {\n /**\n * Pass the ref to the navigation container to register it to the instrumentation\n * @param navigationContainerRef Ref to a `NavigationContainer`\n */\n registerNavigationContainer: (navigationContainerRef: unknown) => void;\n options: ReactNavigationIntegrationOptions;\n} => {\n let navigationContainer: NavigationContainer | undefined;\n\n let tracing: ReactNativeTracingIntegration | undefined;\n let idleSpanOptions: Parameters<typeof startGenericIdleNavigationSpan>[1] = defaultIdleOptions;\n let latestRoute: NavigationRoute | undefined;\n\n let latestNavigationSpan: Span | undefined;\n let navigationProcessingSpan: Span | undefined;\n\n let initialStateHandled: boolean = false;\n let stateChangeTimeout: ReturnType<typeof setTimeout> | undefined;\n let recentRouteKeys: string[] = [];\n\n if (enableTimeToInitialDisplay) {\n NATIVE.initNativeReactNavigationNewFrameTracking().catch((reason: unknown) => {\n debug.error(`${INTEGRATION_NAME} Failed to initialize native new frame tracking: ${reason}`);\n });\n }\n\n /**\n * Set the initial state and start initial navigation span for the current screen.\n */\n const afterAllSetup = (client: Client): void => {\n tracing = getReactNativeTracingIntegration(client);\n if (tracing) {\n idleSpanOptions = {\n finalTimeout: tracing.options.finalTimeoutMs,\n idleTimeout: tracing.options.idleTimeoutMs,\n };\n }\n\n if (initialStateHandled) {\n // We create an initial state here to ensure a transaction gets created before the first route mounts.\n // This assumes that the Sentry.init() call is made before the first route mounts.\n // If this is not the case, the first transaction will be nameless 'Route Changed'\n return undefined;\n }\n\n getAppRegistryIntegration(client)?.onRunApplication(() => {\n if (initialStateHandled) {\n // To avoid conflict with the initial transaction we check if it was already handled.\n // This ensures runApplication calls after the initial start are correctly traced.\n // This is used for example when Activity is (re)started on Android.\n debug.log('[ReactNavigationIntegration] Starting new idle navigation span based on runApplication call.');\n startIdleNavigationSpan();\n }\n });\n\n startIdleNavigationSpan();\n\n if (!navigationContainer) {\n // This is expected as navigation container is registered after the root component is mounted.\n return undefined;\n }\n\n // Navigation container already registered, just populate with route state\n updateLatestNavigationSpanWithCurrentRoute();\n initialStateHandled = true;\n };\n\n const registerNavigationContainer = (maybeNewNavigationContainer: unknown): void => {\n if (RN_GLOBAL_OBJ.__sentry_rn_v5_registered) {\n debug.log(`${INTEGRATION_NAME} Instrumentation already exists, but registering again...`);\n // In the past we have not allowed re-registering the navigation container to avoid unexpected behavior.\n // But this doesn't work for Android and re-recreating application main activity.\n // Where new navigation container is created and the old one is discarded. We need to re-register to\n // trace the new navigation container navigation.\n }\n\n let newNavigationContainer: NavigationContainer | undefined;\n if (isPlainObject(maybeNewNavigationContainer) && 'current' in maybeNewNavigationContainer) {\n newNavigationContainer = maybeNewNavigationContainer.current as NavigationContainer;\n } else {\n newNavigationContainer = maybeNewNavigationContainer as NavigationContainer;\n }\n\n if (navigationContainer === newNavigationContainer) {\n debug.log(`${INTEGRATION_NAME} Navigation container ref is the same as the one already registered.`);\n return;\n }\n navigationContainer = newNavigationContainer;\n\n if (!navigationContainer) {\n debug.warn(`${INTEGRATION_NAME} Received invalid navigation container ref!`);\n return undefined;\n }\n\n // This action is emitted on every dispatch\n navigationContainer.addListener('__unsafe_action__', startIdleNavigationSpan);\n navigationContainer.addListener('state', updateLatestNavigationSpanWithCurrentRoute);\n RN_GLOBAL_OBJ.__sentry_rn_v5_registered = true;\n\n if (initialStateHandled) {\n return undefined;\n }\n\n if (!latestNavigationSpan) {\n debug.log(`${INTEGRATION_NAME} Navigation container registered, but integration has not been setup yet.`);\n return undefined;\n }\n\n // Navigation Container is registered after the first navigation\n // Initial navigation span was started, after integration setup,\n // so now we populate it with the current route.\n updateLatestNavigationSpanWithCurrentRoute();\n initialStateHandled = true;\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 updateLatestNavigationSpanWithCurrentRoute\n */\n const startIdleNavigationSpan = (unknownEvent?: unknown): void => {\n const event = unknownEvent as UnsafeAction | undefined;\n if (useDispatchedActionData && event?.data.noop) {\n debug.log(`${INTEGRATION_NAME} Navigation action is a noop, not starting navigation span.`);\n return;\n }\n\n const navigationActionType = useDispatchedActionData ? event?.data.action.type : undefined;\n if (\n useDispatchedActionData &&\n navigationActionType &&\n [\n // Process common actions\n 'PRELOAD',\n 'SET_PARAMS',\n // Drawer actions\n 'OPEN_DRAWER',\n 'CLOSE_DRAWER',\n 'TOGGLE_DRAWER',\n ].includes(navigationActionType)\n ) {\n debug.log(`${INTEGRATION_NAME} Navigation action is ${navigationActionType}, not starting navigation span.`);\n return;\n }\n\n if (latestNavigationSpan) {\n debug.log(`${INTEGRATION_NAME} A transaction was detected that turned out to be a noop, discarding.`);\n _discardLatestTransaction();\n clearStateChangeTimeout();\n }\n\n latestNavigationSpan = startGenericIdleNavigationSpan(\n tracing?.options.beforeStartSpan\n ? tracing.options.beforeStartSpan(getDefaultIdleNavigationSpanOptions())\n : getDefaultIdleNavigationSpanOptions(),\n idleSpanOptions,\n );\n latestNavigationSpan?.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NAVIGATION);\n latestNavigationSpan?.setAttribute(SEMANTIC_ATTRIBUTE_NAVIGATION_ACTION_TYPE, navigationActionType);\n if (ignoreEmptyBackNavigationTransactions) {\n ignoreEmptyBackNavigation(getClient(), latestNavigationSpan);\n }\n\n if (enableTimeToInitialDisplay && latestNavigationSpan) {\n NATIVE.setActiveSpanId(latestNavigationSpan.spanContext().spanId);\n navigationProcessingSpan = startInactiveSpan({\n op: 'navigation.processing',\n name: 'Navigation dispatch to navigation cancelled or screen mounted',\n startTime: spanToJSON(latestNavigationSpan).start_timestamp,\n });\n navigationProcessingSpan.setAttribute(\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NAVIGATION,\n );\n }\n\n stateChangeTimeout = setTimeout(_discardLatestTransaction, routeChangeTimeoutMs);\n };\n\n /**\n * To be called AFTER the state has been changed to populate the transaction with the current route.\n */\n const updateLatestNavigationSpanWithCurrentRoute = (): void => {\n const stateChangedTimestamp = timestampInSeconds();\n const previousRoute = latestRoute;\n\n if (!navigationContainer) {\n debug.warn(`${INTEGRATION_NAME} Missing navigation container ref. Route transactions will not be sent.`);\n return undefined;\n }\n\n const route = navigationContainer.getCurrentRoute();\n if (!route) {\n debug.log(`[${INTEGRATION_NAME}] Navigation state changed, but no route is rendered.`);\n return undefined;\n }\n\n if (!latestNavigationSpan) {\n debug.log(\n `[${INTEGRATION_NAME}] Navigation state changed, but navigation transaction was not started on dispatch.`,\n );\n return undefined;\n }\n\n addTimeToInitialDisplayFallback(latestNavigationSpan.spanContext().spanId, NATIVE.getNewScreenTimeToDisplay());\n\n if (previousRoute && previousRoute.key === route.key) {\n debug.log(`[${INTEGRATION_NAME}] Navigation state changed, but route is the same as previous.`);\n pushRecentRouteKey(route.key);\n latestRoute = route;\n\n // Clear the latest transaction as it has been handled.\n latestNavigationSpan = undefined;\n return undefined;\n }\n\n const routeHasBeenSeen = recentRouteKeys.includes(route.key);\n\n navigationProcessingSpan?.updateName(`Navigation dispatch to screen ${route.name} mounted`);\n navigationProcessingSpan?.setStatus({ code: SPAN_STATUS_OK });\n navigationProcessingSpan?.end(stateChangedTimestamp);\n navigationProcessingSpan = undefined;\n\n if (spanToJSON(latestNavigationSpan).description === DEFAULT_NAVIGATION_SPAN_NAME) {\n latestNavigationSpan.updateName(route.name);\n }\n latestNavigationSpan.setAttributes({\n 'route.name': route.name,\n 'route.key': route.key,\n // TODO: filter PII params instead of dropping them all\n // 'route.params': {},\n 'route.has_been_seen': routeHasBeenSeen,\n 'previous_route.name': previousRoute?.name,\n 'previous_route.key': previousRoute?.key,\n // TODO: filter PII params instead of dropping them all\n // 'previous_route.params': {},\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n });\n\n // Clear the timeout so the transaction does not get cancelled.\n clearStateChangeTimeout();\n\n addBreadcrumb({\n category: 'navigation',\n type: 'navigation',\n message: `Navigation to ${route.name}`,\n data: {\n from: previousRoute?.name,\n to: route.name,\n },\n });\n\n tracing?.setCurrentRoute(route.name);\n\n pushRecentRouteKey(route.key);\n latestRoute = route;\n // Clear the latest transaction as it has been handled.\n latestNavigationSpan = undefined;\n };\n\n /** Pushes a recent route key, and removes earlier routes when there is greater than the max length */\n const pushRecentRouteKey = (key: string): void => {\n recentRouteKeys.push(key);\n\n if (recentRouteKeys.length > NAVIGATION_HISTORY_MAX_SIZE) {\n recentRouteKeys = recentRouteKeys.slice(recentRouteKeys.length - NAVIGATION_HISTORY_MAX_SIZE);\n }\n };\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n const _discardLatestTransaction = (): void => {\n if (latestNavigationSpan) {\n if (isSentrySpan(latestNavigationSpan)) {\n latestNavigationSpan['_sampled'] = false;\n }\n // TODO: What if it's not SentrySpan?\n latestNavigationSpan.end();\n latestNavigationSpan = undefined;\n }\n if (navigationProcessingSpan) {\n navigationProcessingSpan = undefined;\n }\n };\n\n const clearStateChangeTimeout = (): void => {\n if (typeof stateChangeTimeout !== 'undefined') {\n clearTimeout(stateChangeTimeout);\n stateChangeTimeout = undefined;\n }\n };\n\n return {\n name: INTEGRATION_NAME,\n afterAllSetup,\n registerNavigationContainer,\n options: {\n routeChangeTimeoutMs,\n enableTimeToInitialDisplay,\n ignoreEmptyBackNavigationTransactions,\n enableTimeToInitialDisplayForPreloadedRoutes,\n useDispatchedActionData,\n },\n };\n};\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: (event?: unknown) => void) => void;\n getCurrentRoute: () => NavigationRoute;\n}\n\n/**\n * Returns React Navigation integration of the given client.\n */\nexport function getReactNavigationIntegration(\n client: Client,\n): ReturnType<typeof reactNavigationIntegration> | undefined {\n return client.getIntegrationByName<ReturnType<typeof reactNavigationIntegration>>(INTEGRATION_NAME);\n}\n"]}
1
+ {"version":3,"file":"reactnavigation.js","sourceRoot":"","sources":["../../../src/js/tracing/reactnavigation.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EACb,KAAK,EACL,SAAS,EACT,aAAa,EACb,4BAA4B,EAC5B,gCAAgC,EAChC,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,kCAAkC,EAAE,MAAM,kBAAkB,CAAC;AACjG,OAAO,EAAE,4CAA4C,EAAE,MAAM,UAAU,CAAC;AAExE,OAAO,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,yCAAyC,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AACnH,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,mCAAmC,EACnC,uBAAuB,IAAI,8BAA8B,GAC1D,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAE1E,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAElD,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAExC;;;GAGG;AACH,SAAS,gBAAgB,CAAC,KAAuB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C,UAAU,CAAC,GAAG,KAAK,CAAC;aAC1C;YACD,qCAAqC;YACrC,oBAAoB,CAAC,GAAG,EAAE,CAAC;YAC3B,oBAAoB,GAAG,SAAS,CAAC;SAClC;QACD,IAAI,wBAAwB,EAAE;YAC5B,wBAAwB,GAAG,SAAS,CAAC;SACtC;IACH,CAAC,CAAC;IAEF,MAAM,uBAAuB,GAAG,GAAS,EAAE;QACzC,IAAI,OAAO,kBAAkB,KAAK,WAAW,EAAE;YAC7C,YAAY,CAAC,kBAAkB,CAAC,CAAC;YACjC,kBAAkB,GAAG,SAAS,CAAC;SAChC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,aAAa;QACb,2BAA2B;QAC3B,OAAO,EAAE;YACP,oBAAoB;YACpB,0BAA0B;YAC1B,qCAAqC;YACrC,4CAA4C;YAC5C,uBAAuB;YACvB,+BAA+B;SAChC;KACF,CAAC;AACJ,CAAC,CAAC;AAqBF;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAC3C,MAAc;IAEd,OAAO,MAAM,CAAC,oBAAoB,CAAgD,gBAAgB,CAAC,CAAC;AACtG,CAAC","sourcesContent":["/* eslint-disable max-lines */\nimport type { Client, Integration, Span } from '@sentry/core';\nimport {\n addBreadcrumb,\n debug,\n getClient,\n isPlainObject,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_OK,\n spanToJSON,\n startInactiveSpan,\n timestampInSeconds,\n} from '@sentry/core';\nimport { getAppRegistryIntegration } from '../integrations/appRegistry';\nimport { isSentrySpan } from '../utils/span';\nimport { RN_GLOBAL_OBJ } from '../utils/worldwide';\nimport type { UnsafeAction } from '../vendor/react-navigation/types';\nimport { NATIVE } from '../wrapper';\nimport { ignoreEmptyBackNavigation, ignoreEmptyRouteChangeTransactions } from './onSpanEndUtils';\nimport { SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NAVIGATION } from './origin';\nimport type { ReactNativeTracingIntegration } from './reactnativetracing';\nimport { getReactNativeTracingIntegration } from './reactnativetracing';\nimport { SEMANTIC_ATTRIBUTE_NAVIGATION_ACTION_TYPE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from './semanticAttributes';\nimport {\n DEFAULT_NAVIGATION_SPAN_NAME,\n defaultIdleOptions,\n getDefaultIdleNavigationSpanOptions,\n startIdleNavigationSpan as startGenericIdleNavigationSpan,\n} from './span';\nimport { addTimeToInitialDisplayFallback } from './timeToDisplayFallback';\n\nexport const INTEGRATION_NAME = 'ReactNavigation';\n\nconst NAVIGATION_HISTORY_MAX_SIZE = 200;\n\n/**\n * Builds a full path from the navigation state by traversing nested navigators.\n * For example, with nested navigators: \"Home/Settings/Profile\"\n */\nfunction getPathFromState(state?: NavigationState): string | undefined {\n if (!state) {\n return undefined;\n }\n\n const routeNames: string[] = [];\n let currentState: NavigationState | undefined = state;\n\n while (currentState) {\n const index: number = currentState.index ?? 0;\n const route: NavigationRoute | undefined = currentState.routes[index];\n if (route?.name) {\n routeNames.push(route.name);\n }\n currentState = route?.state;\n }\n\n return routeNames.length > 0 ? routeNames.join('/') : undefined;\n}\n\ninterface ReactNavigationIntegrationOptions {\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 *\n * @default 1_000 (ms)\n */\n routeChangeTimeoutMs: number;\n\n /**\n * Time to initial display measures the time it takes from\n * navigation dispatch to the render of the first frame of the new screen.\n *\n * @default false\n */\n enableTimeToInitialDisplay: boolean;\n\n /**\n * Does not sample transactions that are from routes that have been seen any more and don't have any spans.\n * This removes a lot of the clutter as most back navigation transactions are now ignored.\n *\n * @default true\n */\n ignoreEmptyBackNavigationTransactions: boolean;\n\n /**\n * Enabled measuring Time to Initial Display for routes that are already loaded in memory.\n * (a.k.a., Routes that the navigation integration has already seen.)\n *\n * @default false\n */\n enableTimeToInitialDisplayForPreloadedRoutes: boolean;\n\n /**\n * Whether to use the dispatched action data to populate the transaction metadata.\n *\n * @default false\n */\n useDispatchedActionData: boolean;\n\n /**\n * Whether to use the full paths for navigation routes.\n *\n * @default false\n */\n useFullPathsForNavigationRoutes: boolean;\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 const reactNavigationIntegration = ({\n routeChangeTimeoutMs = 1_000,\n enableTimeToInitialDisplay = false,\n ignoreEmptyBackNavigationTransactions = true,\n enableTimeToInitialDisplayForPreloadedRoutes = false,\n useDispatchedActionData = false,\n useFullPathsForNavigationRoutes = false,\n}: Partial<ReactNavigationIntegrationOptions> = {}): Integration & {\n /**\n * Pass the ref to the navigation container to register it to the instrumentation\n * @param navigationContainerRef Ref to a `NavigationContainer`\n */\n registerNavigationContainer: (navigationContainerRef: unknown) => void;\n options: ReactNavigationIntegrationOptions;\n} => {\n let navigationContainer: NavigationContainer | undefined;\n\n let tracing: ReactNativeTracingIntegration | undefined;\n let idleSpanOptions: Parameters<typeof startGenericIdleNavigationSpan>[1] = defaultIdleOptions;\n let latestRoute: NavigationRoute | undefined;\n\n let latestNavigationSpan: Span | undefined;\n let navigationProcessingSpan: Span | undefined;\n\n let initialStateHandled: boolean = false;\n let stateChangeTimeout: ReturnType<typeof setTimeout> | undefined;\n let recentRouteKeys: string[] = [];\n\n if (enableTimeToInitialDisplay) {\n NATIVE.initNativeReactNavigationNewFrameTracking().catch((reason: unknown) => {\n debug.error(`${INTEGRATION_NAME} Failed to initialize native new frame tracking: ${reason}`);\n });\n }\n\n /**\n * Set the initial state and start initial navigation span for the current screen.\n */\n const afterAllSetup = (client: Client): void => {\n tracing = getReactNativeTracingIntegration(client);\n if (tracing) {\n idleSpanOptions = {\n finalTimeout: tracing.options.finalTimeoutMs,\n idleTimeout: tracing.options.idleTimeoutMs,\n };\n }\n\n if (initialStateHandled) {\n // We create an initial state here to ensure a transaction gets created before the first route mounts.\n // This assumes that the Sentry.init() call is made before the first route mounts.\n // If this is not the case, the first transaction will be nameless 'Route Changed'\n return undefined;\n }\n\n getAppRegistryIntegration(client)?.onRunApplication(() => {\n if (initialStateHandled) {\n // To avoid conflict with the initial transaction we check if it was already handled.\n // This ensures runApplication calls after the initial start are correctly traced.\n // This is used for example when Activity is (re)started on Android.\n debug.log('[ReactNavigationIntegration] Starting new idle navigation span based on runApplication call.');\n startIdleNavigationSpan(undefined, true);\n }\n });\n\n startIdleNavigationSpan();\n\n if (!navigationContainer) {\n // This is expected as navigation container is registered after the root component is mounted.\n return undefined;\n }\n\n // Navigation container already registered, just populate with route state\n updateLatestNavigationSpanWithCurrentRoute();\n initialStateHandled = true;\n };\n\n const registerNavigationContainer = (maybeNewNavigationContainer: unknown): void => {\n if (RN_GLOBAL_OBJ.__sentry_rn_v5_registered) {\n debug.log(`${INTEGRATION_NAME} Instrumentation already exists, but registering again...`);\n // In the past we have not allowed re-registering the navigation container to avoid unexpected behavior.\n // But this doesn't work for Android and re-recreating application main activity.\n // Where new navigation container is created and the old one is discarded. We need to re-register to\n // trace the new navigation container navigation.\n }\n\n let newNavigationContainer: NavigationContainer | undefined;\n if (isPlainObject(maybeNewNavigationContainer) && 'current' in maybeNewNavigationContainer) {\n newNavigationContainer = maybeNewNavigationContainer.current as NavigationContainer;\n } else {\n newNavigationContainer = maybeNewNavigationContainer as NavigationContainer;\n }\n\n if (navigationContainer === newNavigationContainer) {\n debug.log(`${INTEGRATION_NAME} Navigation container ref is the same as the one already registered.`);\n return;\n }\n navigationContainer = newNavigationContainer;\n\n if (!navigationContainer) {\n debug.warn(`${INTEGRATION_NAME} Received invalid navigation container ref!`);\n return undefined;\n }\n\n // This action is emitted on every dispatch\n navigationContainer.addListener('__unsafe_action__', startIdleNavigationSpan);\n navigationContainer.addListener('state', updateLatestNavigationSpanWithCurrentRoute);\n RN_GLOBAL_OBJ.__sentry_rn_v5_registered = true;\n\n if (initialStateHandled) {\n return undefined;\n }\n\n if (!latestNavigationSpan) {\n debug.log(`${INTEGRATION_NAME} Navigation container registered, but integration has not been setup yet.`);\n return undefined;\n }\n\n // Navigation Container is registered after the first navigation\n // Initial navigation span was started, after integration setup,\n // so now we populate it with the current route.\n updateLatestNavigationSpanWithCurrentRoute();\n initialStateHandled = true;\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 updateLatestNavigationSpanWithCurrentRoute\n *\n * @param unknownEvent - The event object that contains navigation action data\n * @param isAppRestart - Whether this span is being started due to an app restart rather than a normal navigation action\n */\n const startIdleNavigationSpan = (unknownEvent?: unknown, isAppRestart = false): void => {\n const event = unknownEvent as UnsafeAction | undefined;\n if (useDispatchedActionData && event?.data.noop) {\n debug.log(`${INTEGRATION_NAME} Navigation action is a noop, not starting navigation span.`);\n return;\n }\n\n const navigationActionType = useDispatchedActionData ? event?.data.action.type : undefined;\n if (\n useDispatchedActionData &&\n navigationActionType &&\n [\n // Process common actions\n 'PRELOAD',\n 'SET_PARAMS',\n // Drawer actions\n 'OPEN_DRAWER',\n 'CLOSE_DRAWER',\n 'TOGGLE_DRAWER',\n ].includes(navigationActionType)\n ) {\n debug.log(`${INTEGRATION_NAME} Navigation action is ${navigationActionType}, not starting navigation span.`);\n return;\n }\n\n if (latestNavigationSpan) {\n debug.log(`${INTEGRATION_NAME} A transaction was detected that turned out to be a noop, discarding.`);\n _discardLatestTransaction();\n clearStateChangeTimeout();\n }\n\n latestNavigationSpan = startGenericIdleNavigationSpan(\n tracing?.options.beforeStartSpan\n ? tracing.options.beforeStartSpan(getDefaultIdleNavigationSpanOptions())\n : getDefaultIdleNavigationSpanOptions(),\n { ...idleSpanOptions, isAppRestart },\n );\n latestNavigationSpan?.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NAVIGATION);\n latestNavigationSpan?.setAttribute(SEMANTIC_ATTRIBUTE_NAVIGATION_ACTION_TYPE, navigationActionType);\n if (ignoreEmptyBackNavigationTransactions) {\n ignoreEmptyBackNavigation(getClient(), latestNavigationSpan);\n }\n // Always discard transactions that never receive route information\n const spanToCheck = latestNavigationSpan;\n ignoreEmptyRouteChangeTransactions(\n getClient(),\n spanToCheck,\n DEFAULT_NAVIGATION_SPAN_NAME,\n () => latestNavigationSpan === spanToCheck,\n );\n\n if (enableTimeToInitialDisplay && latestNavigationSpan) {\n NATIVE.setActiveSpanId(latestNavigationSpan.spanContext().spanId);\n navigationProcessingSpan = startInactiveSpan({\n op: 'navigation.processing',\n name: 'Navigation dispatch to navigation cancelled or screen mounted',\n startTime: spanToJSON(latestNavigationSpan).start_timestamp,\n });\n navigationProcessingSpan.setAttribute(\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_ORIGIN_AUTO_NAVIGATION_REACT_NAVIGATION,\n );\n }\n\n stateChangeTimeout = setTimeout(_discardLatestTransaction, routeChangeTimeoutMs);\n };\n\n /**\n * To be called AFTER the state has been changed to populate the transaction with the current route.\n */\n const updateLatestNavigationSpanWithCurrentRoute = (): void => {\n const stateChangedTimestamp = timestampInSeconds();\n const previousRoute = latestRoute;\n\n if (!navigationContainer) {\n debug.warn(`${INTEGRATION_NAME} Missing navigation container ref. Route transactions will not be sent.`);\n return undefined;\n }\n\n const route = navigationContainer.getCurrentRoute();\n if (!route) {\n debug.log(`[${INTEGRATION_NAME}] Navigation state changed, but no route is rendered.`);\n return undefined;\n }\n\n if (!latestNavigationSpan) {\n debug.log(\n `[${INTEGRATION_NAME}] Navigation state changed, but navigation transaction was not started on dispatch.`,\n );\n return undefined;\n }\n\n addTimeToInitialDisplayFallback(latestNavigationSpan.spanContext().spanId, NATIVE.getNewScreenTimeToDisplay());\n\n if (previousRoute && previousRoute.key === route.key) {\n debug.log(`[${INTEGRATION_NAME}] Navigation state changed, but route is the same as previous.`);\n pushRecentRouteKey(route.key);\n latestRoute = route;\n\n // Clear the latest transaction as it has been handled.\n latestNavigationSpan = undefined;\n return undefined;\n }\n\n const routeHasBeenSeen = recentRouteKeys.includes(route.key);\n\n // Get the full navigation path for nested navigators\n let routeName = route.name;\n if (useFullPathsForNavigationRoutes) {\n const navigationState = navigationContainer.getState();\n routeName = getPathFromState(navigationState) || route.name;\n }\n\n navigationProcessingSpan?.updateName(`Navigation dispatch to screen ${routeName} mounted`);\n navigationProcessingSpan?.setStatus({ code: SPAN_STATUS_OK });\n navigationProcessingSpan?.end(stateChangedTimestamp);\n navigationProcessingSpan = undefined;\n\n if (spanToJSON(latestNavigationSpan).description === DEFAULT_NAVIGATION_SPAN_NAME) {\n latestNavigationSpan.updateName(routeName);\n }\n latestNavigationSpan.setAttributes({\n 'route.name': routeName,\n 'route.key': route.key,\n // TODO: filter PII params instead of dropping them all\n // 'route.params': {},\n 'route.has_been_seen': routeHasBeenSeen,\n 'previous_route.name': previousRoute?.name,\n 'previous_route.key': previousRoute?.key,\n // TODO: filter PII params instead of dropping them all\n // 'previous_route.params': {},\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component',\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',\n });\n\n // Clear the timeout so the transaction does not get cancelled.\n clearStateChangeTimeout();\n\n addBreadcrumb({\n category: 'navigation',\n type: 'navigation',\n message: `Navigation to ${routeName}`,\n data: {\n from: previousRoute?.name,\n to: routeName,\n },\n });\n\n tracing?.setCurrentRoute(routeName);\n\n pushRecentRouteKey(route.key);\n if (useFullPathsForNavigationRoutes) {\n latestRoute = { ...route, name: routeName };\n } else {\n latestRoute = route;\n }\n // Clear the latest transaction as it has been handled.\n latestNavigationSpan = undefined;\n };\n\n /** Pushes a recent route key, and removes earlier routes when there is greater than the max length */\n const pushRecentRouteKey = (key: string): void => {\n recentRouteKeys.push(key);\n\n if (recentRouteKeys.length > NAVIGATION_HISTORY_MAX_SIZE) {\n recentRouteKeys = recentRouteKeys.slice(recentRouteKeys.length - NAVIGATION_HISTORY_MAX_SIZE);\n }\n };\n\n /** Cancels the latest transaction so it does not get sent to Sentry. */\n const _discardLatestTransaction = (): void => {\n if (latestNavigationSpan) {\n if (isSentrySpan(latestNavigationSpan)) {\n latestNavigationSpan['_sampled'] = false;\n }\n // TODO: What if it's not SentrySpan?\n latestNavigationSpan.end();\n latestNavigationSpan = undefined;\n }\n if (navigationProcessingSpan) {\n navigationProcessingSpan = undefined;\n }\n };\n\n const clearStateChangeTimeout = (): void => {\n if (typeof stateChangeTimeout !== 'undefined') {\n clearTimeout(stateChangeTimeout);\n stateChangeTimeout = undefined;\n }\n };\n\n return {\n name: INTEGRATION_NAME,\n afterAllSetup,\n registerNavigationContainer,\n options: {\n routeChangeTimeoutMs,\n enableTimeToInitialDisplay,\n ignoreEmptyBackNavigationTransactions,\n enableTimeToInitialDisplayForPreloadedRoutes,\n useDispatchedActionData,\n useFullPathsForNavigationRoutes,\n },\n };\n};\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 state?: NavigationState;\n}\n\ninterface NavigationState {\n index?: number;\n routes: NavigationRoute[];\n}\n\ninterface NavigationContainer {\n addListener: (type: string, listener: (event?: unknown) => void) => void;\n getCurrentRoute: () => NavigationRoute;\n getState: () => NavigationState | undefined;\n}\n\n/**\n * Returns React Navigation integration of the given client.\n */\nexport function getReactNavigationIntegration(\n client: Client,\n): ReturnType<typeof reactNavigationIntegration> | undefined {\n return client.getIntegrationByName<ReturnType<typeof reactNavigationIntegration>>(INTEGRATION_NAME);\n}\n"]}
@@ -16,7 +16,24 @@ export declare const defaultIdleOptions: {
16
16
  */
17
17
  idleTimeout: number;
18
18
  };
19
- export declare const startIdleNavigationSpan: (startSpanOption: StartSpanOptions, { finalTimeout, idleTimeout, }?: Partial<typeof defaultIdleOptions>) => Span | undefined;
19
+ export declare const startIdleNavigationSpan: (startSpanOption: StartSpanOptions, { finalTimeout, idleTimeout, isAppRestart, }?: Partial<{
20
+ /**
21
+ * The time that has to pass without any span being created.
22
+ * If this time is exceeded, the idle span will finish.
23
+ *
24
+ * @default 1_000 (ms)
25
+ */
26
+ finalTimeout: number;
27
+ /**
28
+ * The max. time an idle span may run.
29
+ * If this time is exceeded, the idle span will finish no matter what.
30
+ *
31
+ * @default 60_0000 (ms)
32
+ */
33
+ idleTimeout: number;
34
+ }> & {
35
+ isAppRestart?: boolean | undefined;
36
+ }) => Span | undefined;
20
37
  /**
21
38
  * Starts an idle span from `@sentry/core` with React Native application
22
39
  * context awareness.
@@ -1 +1 @@
1
- {"version":3,"file":"span.d.ts","sourceRoot":"","sources":["../../../src/js/tracing/span.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAuBpF,eAAO,MAAM,4BAA4B,iBAAiB,CAAC;AAE3D,eAAO,MAAM,kBAAkB,EAAE;IAC/B;;;;;OAKG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;;;OAKG;IACH,WAAW,EAAE,MAAM,CAAC;CAIrB,CAAC;AAEF,eAAO,MAAM,uBAAuB,oBACjB,gBAAgB,mCAI9B,QAAQ,yBAAyB,CAAC,KACpC,IAAI,GAAG,SAmCT,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,oBACP,gBAAgB;kBACc,MAAM,GAAG,SAAS;iBAAe,MAAM,GAAG,SAAS;MACjG,IAkBF,CAAC;AAEF;;GAEG;AACH,wBAAgB,mCAAmC,IAAI,gBAAgB,CAOtE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE3D;AAED,eAAO,MAAM,gBAAgB,gBAAgB,CAA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AED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAE3D;AAED,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAE9C,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG;IACvC,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAGxE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAM5D;AAED,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAC9C,eAAO,MAAM,qBAAqB,SAAS,CAAC;AAC5C,eAAO,MAAM,2BAA2B,eAAe,CAAC;AAExD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAMxD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAI9D"}
@@ -8,15 +8,22 @@ export const defaultIdleOptions = {
8
8
  idleTimeout: 1000,
9
9
  finalTimeout: 600000,
10
10
  };
11
- export const startIdleNavigationSpan = (startSpanOption, { finalTimeout = defaultIdleOptions.finalTimeout, idleTimeout = defaultIdleOptions.idleTimeout, } = {}) => {
11
+ export const startIdleNavigationSpan = (startSpanOption, { finalTimeout = defaultIdleOptions.finalTimeout, idleTimeout = defaultIdleOptions.idleTimeout, isAppRestart = false, } = {}) => {
12
12
  const client = getClient();
13
13
  if (!client) {
14
14
  debug.warn("[startIdleNavigationSpan] Can't create route change span, missing client.");
15
15
  return undefined;
16
16
  }
17
17
  const activeSpan = getActiveSpan();
18
+ const isActiveSpanInteraction = activeSpan && isRootSpan(activeSpan) && isSentryInteractionSpan(activeSpan);
18
19
  clearActiveSpanFromScope(getCurrentScope());
19
- if (activeSpan && isRootSpan(activeSpan) && isSentryInteractionSpan(activeSpan)) {
20
+ // Don't cancel user interaction spans when starting from runApplication (app restart/reload).
21
+ // This preserves the span context for error capture and replay recording.
22
+ if (isActiveSpanInteraction && isAppRestart) {
23
+ debug.log(`[startIdleNavigationSpan] Not canceling ${spanToJSON(activeSpan).op} transaction because navigation is from app restart - preserving error context.`);
24
+ // Don't end the span - it will timeout naturally and remains available for error/replay processing
25
+ }
26
+ else if (isActiveSpanInteraction) {
20
27
  debug.log(`[startIdleNavigationSpan] Canceling ${spanToJSON(activeSpan).op} transaction because of a new navigation root span.`);
21
28
  activeSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'cancelled' });
22
29
  activeSpan.end();
@@ -1 +1 @@
1
- {"version":3,"file":"span.js","sourceRoot":"","sources":["../../../src/js/tracing/span.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,eAAe,EACf,aAAa,EACb,SAAS,EACT,eAAe,EACf,4BAA4B,EAC5B,gCAAgC,EAChC,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,aAAa,IAAI,iBAAiB,GACnC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EACL,4BAA4B,EAC5B,kCAAkC,EAClC,8BAA8B,GAC/B,MAAM,UAAU,CAAC;AAElB,MAAM,CAAC,MAAM,4BAA4B,GAAG,cAAc,CAAC;AAE3D,MAAM,CAAC,MAAM,kBAAkB,GAgB3B;IACF,WAAW,EAAE,IAAK;IAClB,YAAY,EAAE,MAAO;CACtB,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,eAAiC,EACjC,EACE,YAAY,GAAG,kBAAkB,CAAC,YAAY,EAC9C,WAAW,GAAG,kBAAkB,CAAC,WAAW,MACN,EAAE,EACxB,EAAE;IACpB,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pC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE;YACxB,IAAI,CAAC,YAAY,CAAC,4BAA4B,EAAE,SAAS,CAAC,CAAC;SAC5D;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAC9C,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAC5C,MAAM,CAAC,MAAM,2BAA2B,GAAG,YAAY,CAAC;AAExD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,IAAU,EAAE,EAAE;;QACpC,IAAI,CAAC,CAAA,MAAA,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,0CAAG,gBAAgB,CAAC,CAAA,EAAE;YAC9C,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE,2BAA2B,CAAC,CAAC;SAClE;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAkB;IAClD,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;IACpC,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,qBAAqB,CAAC;IACxD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import type { Client, Scope, Span, SpanJSON, StartSpanOptions } from '@sentry/core';\nimport {\n debug,\n generateTraceId,\n getActiveSpan,\n getClient,\n getCurrentScope,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SentryNonRecordingSpan,\n SPAN_STATUS_ERROR,\n spanToJSON,\n startIdleSpan as coreStartIdleSpan,\n} from '@sentry/core';\nimport { AppState } from 'react-native';\nimport { isRootSpan } from '../utils/span';\nimport { adjustTransactionDuration, cancelInBackground } from './onSpanEndUtils';\nimport {\n SPAN_ORIGIN_AUTO_INTERACTION,\n SPAN_ORIGIN_AUTO_NAVIGATION_CUSTOM,\n SPAN_ORIGIN_MANUAL_INTERACTION,\n} from './origin';\n\nexport const DEFAULT_NAVIGATION_SPAN_NAME = 'Route Change';\n\nexport const defaultIdleOptions: {\n /**\n * The time that has to pass without any span being created.\n * If this time is exceeded, the idle span will finish.\n *\n * @default 1_000 (ms)\n */\n finalTimeout: number;\n\n /**\n * The max. time an idle span may run.\n * If this time is exceeded, the idle span will finish no matter what.\n *\n * @default 60_0000 (ms)\n */\n idleTimeout: number;\n} = {\n idleTimeout: 1_000,\n finalTimeout: 60_0000,\n};\n\nexport const startIdleNavigationSpan = (\n startSpanOption: StartSpanOptions,\n {\n finalTimeout = defaultIdleOptions.finalTimeout,\n idleTimeout = defaultIdleOptions.idleTimeout,\n }: Partial<typeof defaultIdleOptions> = {},\n): Span | undefined => {\n const client = getClient();\n if (!client) {\n debug.warn(\"[startIdleNavigationSpan] Can't create route change span, missing client.\");\n return undefined;\n }\n\n const activeSpan = getActiveSpan();\n clearActiveSpanFromScope(getCurrentScope());\n if (activeSpan && isRootSpan(activeSpan) && isSentryInteractionSpan(activeSpan)) {\n debug.log(\n `[startIdleNavigationSpan] Canceling ${\n spanToJSON(activeSpan).op\n } transaction because of a new navigation root span.`,\n );\n activeSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'cancelled' });\n activeSpan.end();\n }\n\n const finalStartSpanOptions = {\n ...getDefaultIdleNavigationSpanOptions(),\n ...startSpanOption,\n };\n\n const idleSpan = startIdleSpan(finalStartSpanOptions, { finalTimeout, idleTimeout });\n debug.log(\n `[startIdleNavigationSpan] Starting ${finalStartSpanOptions.op || 'unknown op'} transaction \"${\n finalStartSpanOptions.name\n }\" on scope`,\n );\n\n adjustTransactionDuration(client, idleSpan, finalTimeout);\n\n idleSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_ORIGIN_AUTO_NAVIGATION_CUSTOM);\n return idleSpan;\n};\n\n/**\n * Starts an idle span from `@sentry/core` with React Native application\n * context awareness.\n *\n * - Span will be started with new propagation context.\n * - Span will be canceled if the app goes to background.\n */\nexport const startIdleSpan = (\n startSpanOption: StartSpanOptions,\n { finalTimeout, idleTimeout }: { finalTimeout: number | undefined; idleTimeout: number | undefined },\n): Span => {\n const client = getClient();\n if (!client) {\n debug.warn(\"[startIdleSpan] Can't create idle span, missing client.\");\n return new SentryNonRecordingSpan();\n }\n\n const currentAppState = AppState.currentState;\n if (currentAppState === 'background') {\n debug.log(`[startIdleSpan] App is already in background, not starting span for ${startSpanOption.name}`);\n return new SentryNonRecordingSpan();\n }\n\n getCurrentScope().setPropagationContext({ traceId: generateTraceId(), sampleRand: Math.random() });\n\n const span = coreStartIdleSpan(startSpanOption, { finalTimeout, idleTimeout });\n cancelInBackground(client, span);\n return span;\n};\n\n/**\n * Returns the default options for the idle navigation span.\n */\nexport function getDefaultIdleNavigationSpanOptions(): StartSpanOptions {\n return {\n name: DEFAULT_NAVIGATION_SPAN_NAME,\n op: 'navigation',\n forceTransaction: true,\n scope: getCurrentScope(),\n };\n}\n\n/**\n * Checks if the span is a Sentry User Interaction span.\n */\nexport function isSentryInteractionSpan(span: Span): boolean {\n return [SPAN_ORIGIN_AUTO_INTERACTION, SPAN_ORIGIN_MANUAL_INTERACTION].includes(spanToJSON(span).origin || '');\n}\n\nexport const SCOPE_SPAN_FIELD = '_sentrySpan';\n\nexport type ScopeWithMaybeSpan = Scope & {\n [SCOPE_SPAN_FIELD]?: Span;\n};\n\n/**\n * Removes the active span from the scope.\n */\nexport function clearActiveSpanFromScope(scope: ScopeWithMaybeSpan): void {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete scope[SCOPE_SPAN_FIELD];\n}\n\n/**\n * Ensures that all created spans have an operation name.\n */\nexport function addDefaultOpForSpanFrom(client: Client): void {\n client.on('spanStart', (span: Span) => {\n if (!spanToJSON(span).op) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'default');\n }\n });\n}\n\nexport const SPAN_THREAD_NAME = 'thread.name';\nexport const SPAN_THREAD_NAME_MAIN = 'main';\nexport const SPAN_THREAD_NAME_JAVASCRIPT = 'javascript';\n\n/**\n * Adds Javascript thread info to spans.\n * Ref: https://reactnative.dev/architecture/threading-model\n */\nexport function addThreadInfoToSpan(client: Client): void {\n client.on('spanStart', (span: Span) => {\n if (!spanToJSON(span).data?.[SPAN_THREAD_NAME]) {\n span.setAttribute(SPAN_THREAD_NAME, SPAN_THREAD_NAME_JAVASCRIPT);\n }\n });\n}\n\n/**\n * Sets the Main thread info to the span.\n */\nexport function setMainThreadInfo(spanJSON: SpanJSON): SpanJSON {\n spanJSON.data = spanJSON.data || {};\n spanJSON.data[SPAN_THREAD_NAME] = SPAN_THREAD_NAME_MAIN;\n return spanJSON;\n}\n"]}
1
+ {"version":3,"file":"span.js","sourceRoot":"","sources":["../../../src/js/tracing/span.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,eAAe,EACf,aAAa,EACb,SAAS,EACT,eAAe,EACf,4BAA4B,EAC5B,gCAAgC,EAChC,sBAAsB,EACtB,iBAAiB,EACjB,UAAU,EACV,aAAa,IAAI,iBAAiB,GACnC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EACL,4BAA4B,EAC5B,kCAAkC,EAClC,8BAA8B,GAC/B,MAAM,UAAU,CAAC;AAElB,MAAM,CAAC,MAAM,4BAA4B,GAAG,cAAc,CAAC;AAE3D,MAAM,CAAC,MAAM,kBAAkB,GAgB3B;IACF,WAAW,EAAE,IAAK;IAClB,YAAY,EAAE,MAAO;CACtB,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,e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cesContent":["import type { Client, Scope, Span, SpanJSON, StartSpanOptions } from '@sentry/core';\nimport {\n debug,\n generateTraceId,\n getActiveSpan,\n getClient,\n getCurrentScope,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SentryNonRecordingSpan,\n SPAN_STATUS_ERROR,\n spanToJSON,\n startIdleSpan as coreStartIdleSpan,\n} from '@sentry/core';\nimport { AppState } from 'react-native';\nimport { isRootSpan } from '../utils/span';\nimport { adjustTransactionDuration, cancelInBackground } from './onSpanEndUtils';\nimport {\n SPAN_ORIGIN_AUTO_INTERACTION,\n SPAN_ORIGIN_AUTO_NAVIGATION_CUSTOM,\n SPAN_ORIGIN_MANUAL_INTERACTION,\n} from './origin';\n\nexport const DEFAULT_NAVIGATION_SPAN_NAME = 'Route Change';\n\nexport const defaultIdleOptions: {\n /**\n * The time that has to pass without any span being created.\n * If this time is exceeded, the idle span will finish.\n *\n * @default 1_000 (ms)\n */\n finalTimeout: number;\n\n /**\n * The max. time an idle span may run.\n * If this time is exceeded, the idle span will finish no matter what.\n *\n * @default 60_0000 (ms)\n */\n idleTimeout: number;\n} = {\n idleTimeout: 1_000,\n finalTimeout: 60_0000,\n};\n\nexport const startIdleNavigationSpan = (\n startSpanOption: StartSpanOptions,\n {\n finalTimeout = defaultIdleOptions.finalTimeout,\n idleTimeout = defaultIdleOptions.idleTimeout,\n isAppRestart = false,\n }: Partial<typeof defaultIdleOptions> & { isAppRestart?: boolean } = {},\n): Span | undefined => {\n const client = getClient();\n if (!client) {\n debug.warn(\"[startIdleNavigationSpan] Can't create route change span, missing client.\");\n return undefined;\n }\n\n const activeSpan = getActiveSpan();\n const isActiveSpanInteraction = activeSpan && isRootSpan(activeSpan) && isSentryInteractionSpan(activeSpan);\n\n clearActiveSpanFromScope(getCurrentScope());\n\n // Don't cancel user interaction spans when starting from runApplication (app restart/reload).\n // This preserves the span context for error capture and replay recording.\n if (isActiveSpanInteraction && isAppRestart) {\n debug.log(\n `[startIdleNavigationSpan] Not canceling ${\n spanToJSON(activeSpan).op\n } transaction because navigation is from app restart - preserving error context.`,\n );\n // Don't end the span - it will timeout naturally and remains available for error/replay processing\n } else if (isActiveSpanInteraction) {\n debug.log(\n `[startIdleNavigationSpan] Canceling ${\n spanToJSON(activeSpan).op\n } transaction because of a new navigation root span.`,\n );\n activeSpan.setStatus({ code: SPAN_STATUS_ERROR, message: 'cancelled' });\n activeSpan.end();\n }\n\n const finalStartSpanOptions = {\n ...getDefaultIdleNavigationSpanOptions(),\n ...startSpanOption,\n };\n\n const idleSpan = startIdleSpan(finalStartSpanOptions, { finalTimeout, idleTimeout });\n debug.log(\n `[startIdleNavigationSpan] Starting ${finalStartSpanOptions.op || 'unknown op'} transaction \"${\n finalStartSpanOptions.name\n }\" on scope`,\n );\n\n adjustTransactionDuration(client, idleSpan, finalTimeout);\n\n idleSpan.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_ORIGIN_AUTO_NAVIGATION_CUSTOM);\n return idleSpan;\n};\n\n/**\n * Starts an idle span from `@sentry/core` with React Native application\n * context awareness.\n *\n * - Span will be started with new propagation context.\n * - Span will be canceled if the app goes to background.\n */\nexport const startIdleSpan = (\n startSpanOption: StartSpanOptions,\n { finalTimeout, idleTimeout }: { finalTimeout: number | undefined; idleTimeout: number | undefined },\n): Span => {\n const client = getClient();\n if (!client) {\n debug.warn(\"[startIdleSpan] Can't create idle span, missing client.\");\n return new SentryNonRecordingSpan();\n }\n\n const currentAppState = AppState.currentState;\n if (currentAppState === 'background') {\n debug.log(`[startIdleSpan] App is already in background, not starting span for ${startSpanOption.name}`);\n return new SentryNonRecordingSpan();\n }\n\n getCurrentScope().setPropagationContext({ traceId: generateTraceId(), sampleRand: Math.random() });\n\n const span = coreStartIdleSpan(startSpanOption, { finalTimeout, idleTimeout });\n cancelInBackground(client, span);\n return span;\n};\n\n/**\n * Returns the default options for the idle navigation span.\n */\nexport function getDefaultIdleNavigationSpanOptions(): StartSpanOptions {\n return {\n name: DEFAULT_NAVIGATION_SPAN_NAME,\n op: 'navigation',\n forceTransaction: true,\n scope: getCurrentScope(),\n };\n}\n\n/**\n * Checks if the span is a Sentry User Interaction span.\n */\nexport function isSentryInteractionSpan(span: Span): boolean {\n return [SPAN_ORIGIN_AUTO_INTERACTION, SPAN_ORIGIN_MANUAL_INTERACTION].includes(spanToJSON(span).origin || '');\n}\n\nexport const SCOPE_SPAN_FIELD = '_sentrySpan';\n\nexport type ScopeWithMaybeSpan = Scope & {\n [SCOPE_SPAN_FIELD]?: Span;\n};\n\n/**\n * Removes the active span from the scope.\n */\nexport function clearActiveSpanFromScope(scope: ScopeWithMaybeSpan): void {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete scope[SCOPE_SPAN_FIELD];\n}\n\n/**\n * Ensures that all created spans have an operation name.\n */\nexport function addDefaultOpForSpanFrom(client: Client): void {\n client.on('spanStart', (span: Span) => {\n if (!spanToJSON(span).op) {\n span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'default');\n }\n });\n}\n\nexport const SPAN_THREAD_NAME = 'thread.name';\nexport const SPAN_THREAD_NAME_MAIN = 'main';\nexport const SPAN_THREAD_NAME_JAVASCRIPT = 'javascript';\n\n/**\n * Adds Javascript thread info to spans.\n * Ref: https://reactnative.dev/architecture/threading-model\n */\nexport function addThreadInfoToSpan(client: Client): void {\n client.on('spanStart', (span: Span) => {\n if (!spanToJSON(span).data?.[SPAN_THREAD_NAME]) {\n span.setAttribute(SPAN_THREAD_NAME, SPAN_THREAD_NAME_JAVASCRIPT);\n }\n });\n}\n\n/**\n * Sets the Main thread info to the span.\n */\nexport function setMainThreadInfo(spanJSON: SpanJSON): SpanJSON {\n spanJSON.data = spanJSON.data || {};\n spanJSON.data[SPAN_THREAD_NAME] = SPAN_THREAD_NAME_MAIN;\n return spanJSON;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"timetodisplay.d.ts","sourceR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