@datadog/mobile-react-navigation 1.0.0-rc8 → 1.0.0-rc9

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 (26) hide show
  1. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js +11 -4
  2. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  3. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js +11 -3
  4. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  5. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +15 -0
  6. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +18 -0
  7. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +6 -0
  8. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +8 -0
  9. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +19 -0
  10. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.d.ts +8 -0
  11. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.d.ts +6 -0
  12. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.d.ts +17 -0
  13. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/URLHostParser.d.ts +6 -0
  14. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +25 -0
  15. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +3 -0
  16. package/lib/typescript/core/src/version.d.ts +1 -1
  17. package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts +1 -0
  18. package/package.json +3 -3
  19. package/src/__tests__/rum/instrumentation/DdRumReactNavigationTracking.test.tsx +135 -122
  20. package/src/__tests__/rum/instrumentation/__utils__/AppStateMock.ts +35 -16
  21. package/src/__tests__/rum/instrumentation/__utils__/AppStateMockLegacy.ts +61 -0
  22. package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +14 -5
  23. package/lib/typescript/core/src/rum/instrumentation/DdRumResourceTracking.d.ts +0 -40
  24. package/lib/typescript/core/src/rum/instrumentation/DdRumXhr.d.ts +0 -23
  25. package/lib/typescript/core/src/rum/instrumentation/TraceIdentifier.d.ts +0 -1
  26. package/lib/typescript/core/src/rum/instrumentation/URLHostParser.d.ts +0 -6
@@ -37,8 +37,7 @@ class DdRumReactNavigationTracking {
37
37
  navigationRef.addListener('state', listener);
38
38
  DdRumReactNavigationTracking.registeredContainer = navigationRef;
39
39
  DdRumReactNavigationTracking.backHandler = _reactNative.BackHandler.addEventListener('hardwareBackPress', DdRumReactNavigationTracking.onBackPress);
40
-
41
- _reactNative.AppState.addEventListener('change', DdRumReactNavigationTracking.appStateListener);
40
+ this.appStateSubscription = _reactNative.AppState.addEventListener('change', DdRumReactNavigationTracking.appStateListener);
42
41
  }
43
42
  }
44
43
  /**
@@ -59,9 +58,15 @@ class DdRumReactNavigationTracking {
59
58
  DdRumReactNavigationTracking.viewNamePredicate = function (_route, trackedName) {
60
59
  return trackedName;
61
60
  };
62
- }
61
+ } // For versions of React Native below 0.65, addEventListener does not return a subscription.
62
+ // We have to call AppState.removeEventListener instead.
63
+
63
64
 
64
- _reactNative.AppState.removeEventListener('change', DdRumReactNavigationTracking.appStateListener);
65
+ if (this.appStateSubscription) {
66
+ this.appStateSubscription.remove();
67
+ } else {
68
+ _reactNative.AppState.removeEventListener('change', DdRumReactNavigationTracking.appStateListener);
69
+ }
65
70
  }
66
71
 
67
72
  static handleRouteNavigation(route, appStateStatus = undefined) {
@@ -121,6 +126,8 @@ _defineProperty(DdRumReactNavigationTracking, "viewNamePredicate", void 0);
121
126
 
122
127
  _defineProperty(DdRumReactNavigationTracking, "backHandler", void 0);
123
128
 
129
+ _defineProperty(DdRumReactNavigationTracking, "appStateSubscription", void 0);
130
+
124
131
  _defineProperty(DdRumReactNavigationTracking, "ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE", 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.');
125
132
 
126
133
  _defineProperty(DdRumReactNavigationTracking, "NULL_NAVIGATION_REF_ERROR_MESSAGE", 'Cannot track views with a null navigationRef.');
@@ -1 +1 @@
1
- {"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","InternalLog","log","NULL_NAVIGATION_REF_ERROR_MESSAGE","SdkVerbosity","ERROR","registeredContainer","NAVIGATION_REF_IN_USE_ERROR_MESSAGE","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","backHandler","BackHandler","addEventListener","onBackPress","AppState","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","predicate","screenName","name","DdRum","stopView","startView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;;;;;;AAMA;;AAEA;;;;AAqBA;AACA;AACA;AACO,MAAMA,4BAAN,CAAmC;AAqCtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACrBC,aADqB,EAErBC,iBAAoC,GAAG,UACnCC,MADmC,EAEnCC,WAFmC,EAGrC;AACE,WAAOA,WAAP;AACH,GAPoB,EAQjB;AACJ,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBI,qCAAYC,GAAZ,CACIP,4BAA4B,CAACQ,iCADjC,EAEIC,gCAAaC,KAFjB;;AAIA;AACH;;AAED,QACIV,4BAA4B,CAACW,mBAA7B,IAAoD,IAApD,IACA,KAAKA,mBAAL,KAA6BT,aAFjC,EAGE;AACEI,qCAAYC,GAAZ,CACIP,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,uCAYL,+C;;gBAZKA,4B,yCAcL,6K;;gBAdKA,4B,6BAgBwB,MAAe;AAC5C,MAAIA,4BAA4B,CAACW,mBAA7B,KAAqD,IAAzD,EAA+D;AAC3D,WAAO,KAAP;AACH;;AACD,MAAIX,4BAA4B,CAACW,mBAA7B,CAAiD8B,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBAxBQzC,4B,iBA0BY,MAAM;AACvB,MAAIA,4BAA4B,CAAC0C,uBAA7B,EAAJ,EAA4D;AACxD1C,IAAAA,4BAA4B,CAACwB,iBAA7B,CACIxB,4BAA4B,CAACW,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBAnCQX,4B,sBAsKL8B,cADgD,IAE/C;AAAA;;AACD,QAAMa,YAAY,6BAAG3C,4BAA4B,CAACW,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAI2B,YAAY,KAAKZ,SAAjB,IAA8BY,YAAY,KAAK,IAAnD,EAAyD;AACrDrC,mCAAYC,GAAZ,CACK,4EAA2EuB,cAAe,gDAD/F,EAEIrB,gCAAaC,KAFjB;;AAIA;AACH;;AAEDV,EAAAA,4BAA4B,CAACe,qBAA7B,CACI4B,YADJ,EAEIb,cAFJ;AAIH,C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRum, SdkVerbosity, InternalLog } from '@datadog/mobile-react-native';\nimport type { AppStateStatus, NativeEventSubscription } from 'react-native';\nimport { AppState, BackHandler } from 'react-native';\n\nimport type {\n NavigationContainerRef,\n Route,\n NavigationListener\n} from './react-navigation';\n\n// AppStateStatus can have values:\n// 'active' - The app is running in the foreground\n// 'background' - The app is running in the background. The user is either in another app or on the home screen\n// 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.\n// 'unknown' [iOS] - Initial value until the current app state is determined\n// 'extension' [iOS] - The app is running as an app extension\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null;\n\nexport type ViewNamePredicate = (\n route: Route<string, any | undefined>,\n trackedName: string\n) => string;\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n private static registeredContainer: NavigationContainerRef | null;\n\n private static navigationStateChangeListener: NavigationListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n private static backHandler: NativeEventSubscription | null;\n\n static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =\n 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';\n static NULL_NAVIGATION_REF_ERROR_MESSAGE =\n 'Cannot track views with a null navigationRef.';\n static NAVIGATION_REF_IN_USE_ERROR_MESSAGE =\n 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.';\n\n static isAppExitingOnBackPress = (): boolean => {\n if (DdRumReactNavigationTracking.registeredContainer === null) {\n return false;\n }\n if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {\n return false;\n }\n return true;\n };\n\n static onBackPress = () => {\n if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {\n DdRumReactNavigationTracking.stopTrackingViews(\n DdRumReactNavigationTracking.registeredContainer\n );\n }\n // We always return false so we make sure the react-navigation callback is called.\n // See https://reactnative.dev/docs/backhandler\n return false;\n };\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n if (navigationRef == null) {\n InternalLog.log(\n DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n if (\n DdRumReactNavigationTracking.registeredContainer != null &&\n this.registeredContainer !== navigationRef\n ) {\n InternalLog.log(\n DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(\n navigationRef.getCurrentRoute()\n );\n navigationRef.addListener('state', listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener(\n 'hardwareBackPress',\n DdRumReactNavigationTracking.onBackPress\n );\n AppState.addEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(\n navigationRef: NavigationContainerRef | null\n ): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\n 'state',\n DdRumReactNavigationTracking.navigationStateChangeListener\n );\n DdRumReactNavigationTracking.backHandler?.remove();\n DdRumReactNavigationTracking.backHandler = null;\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n };\n }\n AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined,\n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route === undefined || route === null) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n // RUMM-1400 in some cases the route seem to be undefined\n return;\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (\n appStateStatus === 'active' ||\n appStateStatus === undefined\n ) {\n // case when app goes into foreground,\n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (\n DdRumReactNavigationTracking.navigationStateChangeListener == null\n ) {\n DdRumReactNavigationTracking.navigationStateChangeListener = () => {\n const route = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n\n if (route === undefined) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static appStateListener: AppStateListener = (\n appStateStatus: AppStateStatus\n ) => {\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute === undefined || currentRoute === null) {\n InternalLog.log(\n `We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(\n currentRoute,\n appStateStatus\n );\n };\n}\n"]}
1
+ {"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","InternalLog","log","NULL_NAVIGATION_REF_ERROR_MESSAGE","SdkVerbosity","ERROR","registeredContainer","NAVIGATION_REF_IN_USE_ERROR_MESSAGE","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","backHandler","BackHandler","addEventListener","onBackPress","appStateSubscription","AppState","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","predicate","screenName","name","DdRum","stopView","startView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;;;;;;AAMA;;AAEA;;;;AAqBA;AACA;AACA;AACO,MAAMA,4BAAN,CAAmC;AAuCtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACrBC,aADqB,EAErBC,iBAAoC,GAAG,UACnCC,MADmC,EAEnCC,WAFmC,EAGrC;AACE,WAAOA,WAAP;AACH,GAPoB,EAQjB;AACJ,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBI,qCAAYC,GAAZ,CACIP,4BAA4B,CAACQ,iCADjC,EAEIC,gCAAaC,KAFjB;;AAIA;AACH;;AAED,QACIV,4BAA4B,CAACW,mBAA7B,IAAoD,IAApD,IACA,KAAKA,mBAAL,KAA6BT,aAFjC,EAGE;AACEI,qCAAYC,GAAZ,CACIP,4BAA4B,CAACY,mCADjC,EAEIH,gCAAaC,KAFjB;AAIH,KARD,MAQO,IAAIV,4BAA4B,CAACW,mBAA7B,IAAoD,IAAxD,EAA8D;AACjEX,MAAAA,4BAA4B,CAACG,iBAA7B,GAAiDA,iBAAjD;AACA,YAAMU,QAAQ,GAAGb,4BAA4B,CAACc,oCAA7B,EAAjB;AACAd,MAAAA,4BAA4B,CAACe,qBAA7B,CACIb,aAAa,CAACc,eAAd,EADJ;AAGAd,MAAAA,aAAa,CAACe,WAAd,CAA0B,OAA1B,EAAmCJ,QAAnC;AACAb,MAAAA,4BAA4B,CAACW,mBAA7B,GAAmDT,aAAnD;AACAF,MAAAA,4BAA4B,CAACkB,WAA7B,GAA2CC,yBAAYC,gBAAZ,CACvC,mBADuC,EAEvCpB,4BAA4B,CAACqB,WAFU,CAA3C;AAIA,WAAKC,oBAAL,GAA4BC,sBAASH,gBAAT,CACxB,QADwB,EAExBpB,4BAA4B,CAACwB,gBAFL,CAA5B;AAIH;AACJ;AAED;AACJ;AACA;AACA;;;AAC4B,SAAjBC,iBAAiB,CACpBvB,aADoB,EAEhB;A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C,4BAA4B,CAACW,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAI4B,YAAY,KAAKZ,SAAjB,IAA8BY,YAAY,KAAK,IAAnD,EAAyD;AACrDtC,mCAAYC,GAAZ,CACK,4EAA2EwB,cAAe,gDAD/F,EAEItB,gCAAaC,KAFjB;;AAIA;AACH;;AAEDV,EAAAA,4BAA4B,CAACe,qBAA7B,CACI6B,YADJ,EAEIb,cAFJ;AAIH,C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRum, SdkVerbosity, InternalLog } from '@datadog/mobile-react-native';\nimport type { AppStateStatus, NativeEventSubscription } from 'react-native';\nimport { AppState, BackHandler } from 'react-native';\n\nimport type {\n NavigationContainerRef,\n Route,\n NavigationListener\n} from './react-navigation';\n\n// AppStateStatus can have values:\n// 'active' - The app is running in the foreground\n// 'background' - The app is running in the background. The user is either in another app or on the home screen\n// 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.\n// 'unknown' [iOS] - Initial value until the current app state is determined\n// 'extension' [iOS] - The app is running as an app extension\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null;\n\nexport type ViewNamePredicate = (\n route: Route<string, any | undefined>,\n trackedName: string\n) => string;\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n private static registeredContainer: NavigationContainerRef | null;\n\n private static navigationStateChangeListener: NavigationListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n private static backHandler: NativeEventSubscription | null;\n\n private static appStateSubscription?: NativeEventSubscription;\n\n static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =\n 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';\n static NULL_NAVIGATION_REF_ERROR_MESSAGE =\n 'Cannot track views with a null navigationRef.';\n static NAVIGATION_REF_IN_USE_ERROR_MESSAGE =\n 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.';\n\n static isAppExitingOnBackPress = (): boolean => {\n if (DdRumReactNavigationTracking.registeredContainer === null) {\n return false;\n }\n if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {\n return false;\n }\n return true;\n };\n\n static onBackPress = () => {\n if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {\n DdRumReactNavigationTracking.stopTrackingViews(\n DdRumReactNavigationTracking.registeredContainer\n );\n }\n // We always return false so we make sure the react-navigation callback is called.\n // See https://reactnative.dev/docs/backhandler\n return false;\n };\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n if (navigationRef == null) {\n InternalLog.log(\n DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n if (\n DdRumReactNavigationTracking.registeredContainer != null &&\n this.registeredContainer !== navigationRef\n ) {\n InternalLog.log(\n DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(\n navigationRef.getCurrentRoute()\n );\n navigationRef.addListener('state', listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener(\n 'hardwareBackPress',\n DdRumReactNavigationTracking.onBackPress\n );\n this.appStateSubscription = AppState.addEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(\n navigationRef: NavigationContainerRef | null\n ): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\n 'state',\n DdRumReactNavigationTracking.navigationStateChangeListener\n );\n DdRumReactNavigationTracking.backHandler?.remove();\n DdRumReactNavigationTracking.backHandler = null;\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n };\n }\n\n // For versions of React Native below 0.65, addEventListener does not return a subscription.\n // We have to call AppState.removeEventListener instead.\n if (this.appStateSubscription) {\n this.appStateSubscription.remove();\n } else {\n AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined,\n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route === undefined || route === null) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n // RUMM-1400 in some cases the route seem to be undefined\n return;\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (\n appStateStatus === 'active' ||\n appStateStatus === undefined\n ) {\n // case when app goes into foreground,\n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (\n DdRumReactNavigationTracking.navigationStateChangeListener == null\n ) {\n DdRumReactNavigationTracking.navigationStateChangeListener = () => {\n const route = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n\n if (route === undefined) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static appStateListener: AppStateListener = (\n appStateStatus: AppStateStatus\n ) => {\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute === undefined || currentRoute === null) {\n InternalLog.log(\n `We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(\n currentRoute,\n appStateStatus\n );\n };\n}\n"]}
@@ -33,7 +33,7 @@ export class DdRumReactNavigationTracking {
33
33
  navigationRef.addListener('state', listener);
34
34
  DdRumReactNavigationTracking.registeredContainer = navigationRef;
35
35
  DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener('hardwareBackPress', DdRumReactNavigationTracking.onBackPress);
36
- AppState.addEventListener('change', DdRumReactNavigationTracking.appStateListener);
36
+ this.appStateSubscription = AppState.addEventListener('change', DdRumReactNavigationTracking.appStateListener);
37
37
  }
38
38
  }
39
39
  /**
@@ -54,9 +54,15 @@ export class DdRumReactNavigationTracking {
54
54
  DdRumReactNavigationTracking.viewNamePredicate = function (_route, trackedName) {
55
55
  return trackedName;
56
56
  };
57
- }
57
+ } // For versions of React Native below 0.65, addEventListener does not return a subscription.
58
+ // We have to call AppState.removeEventListener instead.
59
+
58
60
 
59
- AppState.removeEventListener('change', DdRumReactNavigationTracking.appStateListener);
61
+ if (this.appStateSubscription) {
62
+ this.appStateSubscription.remove();
63
+ } else {
64
+ AppState.removeEventListener('change', DdRumReactNavigationTracking.appStateListener);
65
+ }
60
66
  }
61
67
 
62
68
  static handleRouteNavigation(route, appStateStatus = undefined) {
@@ -112,6 +118,8 @@ _defineProperty(DdRumReactNavigationTracking, "viewNamePredicate", void 0);
112
118
 
113
119
  _defineProperty(DdRumReactNavigationTracking, "backHandler", void 0);
114
120
 
121
+ _defineProperty(DdRumReactNavigationTracking, "appStateSubscription", void 0);
122
+
115
123
  _defineProperty(DdRumReactNavigationTracking, "ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE", 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.');
116
124
 
117
125
  _defineProperty(DdRumReactNavigationTracking, "NULL_NAVIGATION_REF_ERROR_MESSAGE", 'Cannot track views with a null navigationRef.');
@@ -1 +1 @@
1
- {"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRum","SdkVerbosity","InternalLog","AppState","BackHandler","DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","log","NULL_NAVIGATION_REF_ERROR_MESSAGE","ERROR","registeredContainer","NAVIGATION_REF_IN_USE_ERROR_MESSAGE","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","backHandler","addEventListener","onBackPress","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","predicate","screenName","name","stopView","startView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,EAAgBC,YAAhB,EAA8BC,WAA9B,QAAiD,8BAAjD;AAEA,SAASC,QAAT,EAAmBC,WAAnB,QAAsC,cAAtC;;AAqBA;AACA;AACA;AACA,OAAO,MAAMC,4BAAN,CAAmC;AAqCtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACrBC,aADqB,EAErBC,iBAAoC,GAAG,UACnCC,MADmC,EAEnCC,WAFmC,EAGrC;AACE,WAAOA,WAAP;AACH,GAPoB,EAQjB;AACJ,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBL,MAAAA,WAAW,CAACS,GAAZ,CACIN,4BAA4B,CAACO,iCADjC,EAEIX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IhC,YAAY,CAACiC,IAFjB;AAIA;AACH;;AAED7B,QAAAA,4BAA4B,CAACa,qBAA7B,CAAmDY,KAAnD;AACH,OAZD;AAaH;;AACD,WAAOzB,4BAA4B,CAACsB,6BAApC;AACH;;AAnKqC;;gBAA7BtB,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B,gDAUL,gG;;gBAVKA,4B,uCAYL,+C;;gBAZKA,4B,yCAcL,6K;;gBAdKA,4B,6BAgBwB,MAAe;AAC5C,MAAIA,4BAA4B,CAACS,mBAA7B,KAAqD,IAAzD,EAA+D;AAC3D,WAAO,KAAP;AACH;;AACD,MAAIT,4BAA4B,CAACS,mBAA7B,CAAiD2B,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBAxBQpC,4B,iBA0BY,MAAM;AACvB,MAAIA,4BAA4B,CAACqC,uBAA7B,EAAJ,EAA4D;AACxDrC,IAAAA,4BAA4B,CAACoB,iBAA7B,CACIpB,4BAA4B,CAACS,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBAnCQT,4B,sBAsKL0B,cADgD,IAE/C;AAAA;;AACD,QAAMY,YAAY,6BAAGtC,4BAA4B,CAACS,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAIwB,YAAY,KAAKX,SAAjB,IAA8BW,YAAY,KAAK,IAAnD,EAAyD;AACrDzC,IAAAA,WAAW,CAACS,GAAZ,CACK,4EAA2EoB,cAAe,gDAD/F,EAEI9B,YAAY,CAACY,KAFjB;AAIA;AACH;;AAEDR,EAAAA,4BAA4B,CAACa,qBAA7B,CACIyB,YADJ,EAEIZ,cAFJ;AAIH,C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRum, SdkVerbosity, InternalLog } from '@datadog/mobile-react-native';\nimport type { AppStateStatus, NativeEventSubscription } from 'react-native';\nimport { AppState, BackHandler } from 'react-native';\n\nimport type {\n NavigationContainerRef,\n Route,\n NavigationListener\n} from './react-navigation';\n\n// AppStateStatus can have values:\n// 'active' - The app is running in the foreground\n// 'background' - The app is running in the background. The user is either in another app or on the home screen\n// 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.\n// 'unknown' [iOS] - Initial value until the current app state is determined\n// 'extension' [iOS] - The app is running as an app extension\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null;\n\nexport type ViewNamePredicate = (\n route: Route<string, any | undefined>,\n trackedName: string\n) => string;\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n private static registeredContainer: NavigationContainerRef | null;\n\n private static navigationStateChangeListener: NavigationListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n private static backHandler: NativeEventSubscription | null;\n\n static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =\n 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';\n static NULL_NAVIGATION_REF_ERROR_MESSAGE =\n 'Cannot track views with a null navigationRef.';\n static NAVIGATION_REF_IN_USE_ERROR_MESSAGE =\n 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.';\n\n static isAppExitingOnBackPress = (): boolean => {\n if (DdRumReactNavigationTracking.registeredContainer === null) {\n return false;\n }\n if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {\n return false;\n }\n return true;\n };\n\n static onBackPress = () => {\n if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {\n DdRumReactNavigationTracking.stopTrackingViews(\n DdRumReactNavigationTracking.registeredContainer\n );\n }\n // We always return false so we make sure the react-navigation callback is called.\n // See https://reactnative.dev/docs/backhandler\n return false;\n };\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n if (navigationRef == null) {\n InternalLog.log(\n DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n if (\n DdRumReactNavigationTracking.registeredContainer != null &&\n this.registeredContainer !== navigationRef\n ) {\n InternalLog.log(\n DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(\n navigationRef.getCurrentRoute()\n );\n navigationRef.addListener('state', listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener(\n 'hardwareBackPress',\n DdRumReactNavigationTracking.onBackPress\n );\n AppState.addEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(\n navigationRef: NavigationContainerRef | null\n ): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\n 'state',\n DdRumReactNavigationTracking.navigationStateChangeListener\n );\n DdRumReactNavigationTracking.backHandler?.remove();\n DdRumReactNavigationTracking.backHandler = null;\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n };\n }\n AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined,\n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route === undefined || route === null) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n // RUMM-1400 in some cases the route seem to be undefined\n return;\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (\n appStateStatus === 'active' ||\n appStateStatus === undefined\n ) {\n // case when app goes into foreground,\n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (\n DdRumReactNavigationTracking.navigationStateChangeListener == null\n ) {\n DdRumReactNavigationTracking.navigationStateChangeListener = () => {\n const route = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n\n if (route === undefined) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static appStateListener: AppStateListener = (\n appStateStatus: AppStateStatus\n ) => {\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute === undefined || currentRoute === null) {\n InternalLog.log(\n `We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(\n currentRoute,\n appStateStatus\n );\n };\n}\n"]}
1
+ {"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRum","SdkVerbosity","InternalLog","AppState","BackHandler","DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","log","NULL_NAVIGATION_REF_ERROR_MESSAGE","ERROR","registeredContainer","NAVIGATION_REF_IN_USE_ERROR_MESSAGE","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","backHandler","addEventListener","onBackPress","appStateSubscription","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","predicate","screenName","name","stopView","startView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,EAAgBC,YAAhB,EAA8BC,WAA9B,QAAiD,8BAAjD;AAEA,SAASC,QAAT,EAAmBC,WAAnB,QAAsC,cAAtC;;AAqBA;AACA;AACA;AACA,OAAO,MAAMC,4BAAN,CAAmC;AAuCtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACrBC,aADqB,EAErBC,iBAAoC,GAAG,UACnCC,MADmC,EAEnCC,WAFmC,EAGrC;AACE,WAAOA,WAAP;AACH,GAPoB,EAQjB;AACJ,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBL,MAAAA,WAAW,CAACS,GAAZ,CACIN,4BAA4B,CAACO,iCADjC,EAEIX,YAAY,CAACY,KAFjB;AAIA;AACH;;AAED,QACIR,4BAA4B,CAACS,mBAA7B,IAAoD,IAApD,IACA,KAAKA,mBAAL,KAA6BP,aAFjC,EAGE;AACEL,MAAAA,WAAW,CAACS,GAAZ,CACIN,4BAA4B,CAACU,mCADjC,EAEId,YAAY,CAACY,KAFjB;AAIH,KARD,MAQO,IAAIR,4BAA4B,CAACS,mBAA7B,IAAoD,IAAxD,EAA8D;AACjET,MAAAA,4BAA4B,CAACG,iBAA7B,GAAiDA,iBAAjD;AACA,YAAMQ,QAAQ,GAAGX,4BAA4B,CAACY,oCAA7B,EAAjB;AACAZ,MAAAA,4BAA4B,CAACa,qBAA7B,CACIX,aAAa,CAACY,eAAd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A,4B,6BAkBwB,MAAe;AAC5C,MAAIA,4BAA4B,CAACS,mBAA7B,KAAqD,IAAzD,EAA+D;AAC3D,WAAO,KAAP;AACH;;AACD,MAAIT,4BAA4B,CAACS,mBAA7B,CAAiD4B,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBA1BQrC,4B,iBA4BY,MAAM;AACvB,MAAIA,4BAA4B,CAACsC,uBAA7B,EAAJ,EAA4D;AACxDtC,IAAAA,4BAA4B,CAACqB,iBAA7B,CACIrB,4BAA4B,CAACS,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBArCQT,4B,sBA+KL2B,cADgD,IAE/C;AAAA;;AACD,QAAMY,YAAY,6BAAGvC,4BAA4B,CAACS,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAIyB,YAAY,KAAKX,SAAjB,IAA8BW,YAAY,KAAK,IAAnD,EAAyD;AACrD1C,IAAAA,WAAW,CAACS,GAAZ,CACK,4EAA2EqB,cAAe,gDAD/F,EAEI/B,YAAY,CAACY,KAFjB;AAIA;AACH;;AAEDR,EAAAA,4BAA4B,CAACa,qBAA7B,CACI0B,YADJ,EAEIZ,cAFJ;AAIH,C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRum, SdkVerbosity, InternalLog } from '@datadog/mobile-react-native';\nimport type { AppStateStatus, NativeEventSubscription } from 'react-native';\nimport { AppState, BackHandler } from 'react-native';\n\nimport type {\n NavigationContainerRef,\n Route,\n NavigationListener\n} from './react-navigation';\n\n// AppStateStatus can have values:\n// 'active' - The app is running in the foreground\n// 'background' - The app is running in the background. The user is either in another app or on the home screen\n// 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.\n// 'unknown' [iOS] - Initial value until the current app state is determined\n// 'extension' [iOS] - The app is running as an app extension\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null;\n\nexport type ViewNamePredicate = (\n route: Route<string, any | undefined>,\n trackedName: string\n) => string;\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n private static registeredContainer: NavigationContainerRef | null;\n\n private static navigationStateChangeListener: NavigationListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n private static backHandler: NativeEventSubscription | null;\n\n private static appStateSubscription?: NativeEventSubscription;\n\n static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =\n 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';\n static NULL_NAVIGATION_REF_ERROR_MESSAGE =\n 'Cannot track views with a null navigationRef.';\n static NAVIGATION_REF_IN_USE_ERROR_MESSAGE =\n 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.';\n\n static isAppExitingOnBackPress = (): boolean => {\n if (DdRumReactNavigationTracking.registeredContainer === null) {\n return false;\n }\n if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {\n return false;\n }\n return true;\n };\n\n static onBackPress = () => {\n if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {\n DdRumReactNavigationTracking.stopTrackingViews(\n DdRumReactNavigationTracking.registeredContainer\n );\n }\n // We always return false so we make sure the react-navigation callback is called.\n // See https://reactnative.dev/docs/backhandler\n return false;\n };\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n if (navigationRef == null) {\n InternalLog.log(\n DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n if (\n DdRumReactNavigationTracking.registeredContainer != null &&\n this.registeredContainer !== navigationRef\n ) {\n InternalLog.log(\n DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(\n navigationRef.getCurrentRoute()\n );\n navigationRef.addListener('state', listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener(\n 'hardwareBackPress',\n DdRumReactNavigationTracking.onBackPress\n );\n this.appStateSubscription = AppState.addEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(\n navigationRef: NavigationContainerRef | null\n ): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\n 'state',\n DdRumReactNavigationTracking.navigationStateChangeListener\n );\n DdRumReactNavigationTracking.backHandler?.remove();\n DdRumReactNavigationTracking.backHandler = null;\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n };\n }\n\n // For versions of React Native below 0.65, addEventListener does not return a subscription.\n // We have to call AppState.removeEventListener instead.\n if (this.appStateSubscription) {\n this.appStateSubscription.remove();\n } else {\n AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined,\n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route === undefined || route === null) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n // RUMM-1400 in some cases the route seem to be undefined\n return;\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (\n appStateStatus === 'active' ||\n appStateStatus === undefined\n ) {\n // case when app goes into foreground,\n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (\n DdRumReactNavigationTracking.navigationStateChangeListener == null\n ) {\n DdRumReactNavigationTracking.navigationStateChangeListener = () => {\n const route = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n\n if (route === undefined) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static appStateListener: AppStateListener = (\n appStateStatus: AppStateStatus\n ) => {\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute === undefined || currentRoute === null) {\n InternalLog.log(\n `We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(\n currentRoute,\n appStateStatus\n );\n };\n}\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
3
+ */
4
+ export declare class DdRumResourceTracking {
5
+ private static isTracking;
6
+ private static requestProxy;
7
+ /**
8
+ * Starts tracking resources and sends a RUM Resource event every time a network request is detected.
9
+ */
10
+ static startTracking({ tracingSamplingRate, firstPartyHosts }: {
11
+ tracingSamplingRate: number;
12
+ firstPartyHosts: string[];
13
+ }): void;
14
+ static stopTracking(): void;
15
+ }
@@ -0,0 +1,18 @@
1
+ import type { Hostname } from './firstPartyHosts';
2
+ export declare type DdRumResourceTracingAttributes = {
3
+ tracingStrategy: 'KEEP';
4
+ traceId: string;
5
+ spanId: string;
6
+ samplingPriorityHeader: '1';
7
+ } | {
8
+ tracingStrategy: 'DISCARD';
9
+ traceId?: void;
10
+ spanId?: void;
11
+ samplingPriorityHeader: '0';
12
+ };
13
+ export declare const getTracingAttributes: ({ hostname, firstPartyHostsRegex, tracingSamplingRate }: {
14
+ hostname: Hostname | null;
15
+ firstPartyHostsRegex: RegExp;
16
+ tracingSamplingRate: number;
17
+ }) => DdRumResourceTracingAttributes;
18
+ export declare function generateTraceId(): string;
@@ -0,0 +1,6 @@
1
+ export declare type Hostname = {
2
+ _type: 'Hostname';
3
+ } & string;
4
+ export declare const NO_MATCH_REGEX: RegExp;
5
+ export declare const firstPartyHostsRegexBuilder: (firstPartyHosts: string[]) => RegExp;
6
+ export declare const isHostFirstParty: (hostname: Hostname, firstPartyHostsRegex: RegExp) => boolean;
@@ -0,0 +1,8 @@
1
+ export interface RequestProxyOptions {
2
+ tracingSamplingRate: number;
3
+ firstPartyHostsRegex: RegExp;
4
+ }
5
+ export declare abstract class RequestProxy {
6
+ abstract onTrackingStart: (context: RequestProxyOptions) => void;
7
+ abstract onTrackingStop: () => void;
8
+ }
@@ -0,0 +1,19 @@
1
+ import type { DdRumResourceTracingAttributes } from '../distributedTracing';
2
+ export interface RUMResource {
3
+ key: string;
4
+ request: {
5
+ method: string;
6
+ url: string;
7
+ kind: string;
8
+ };
9
+ tracingAttributes: DdRumResourceTracingAttributes;
10
+ response: {
11
+ statusCode: number;
12
+ size: number;
13
+ };
14
+ timings: {
15
+ startTime: number;
16
+ stopTime: number;
17
+ responseStartTime?: number;
18
+ };
19
+ }
@@ -0,0 +1,8 @@
1
+ import type { RUMResource } from '../../domain/interfaces/RumResource';
2
+ declare type ResourceMapper = (resource: RUMResource) => RUMResource | null;
3
+ export declare class ResourceReporter {
4
+ private mappers;
5
+ constructor(resourceMappers: ResourceMapper[]);
6
+ reportResource: (resource: RUMResource) => void;
7
+ }
8
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { RUMResource } from '../../domain/interfaces/RumResource';
2
+ /**
3
+ * Filters RN symbolicate calls and Expo logs calls that happen only in dev.
4
+ * @param resource RUMResource
5
+ */
6
+ export declare const filterDevResource: (resource: RUMResource) => RUMResource | null;
@@ -0,0 +1,17 @@
1
+ interface Timing {
2
+ /**
3
+ * Time relative (absolute in case of iOS) to some point, in ns.
4
+ */
5
+ startTime: number;
6
+ /**
7
+ * Duration in ns.
8
+ */
9
+ duration: number;
10
+ }
11
+ interface ResourceTimings {
12
+ firstByte: Timing;
13
+ download: Timing;
14
+ fetch: Timing;
15
+ }
16
+ export declare function createTimings(startTime: number, responseStartTime: number, responseEndTime: number): ResourceTimings;
17
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { Hostname } from '../domain/firstPartyHosts';
2
+ /**
3
+ * Returns the host from an URL.
4
+ * @returns the host (without the port) or null if could not cast the URL as host
5
+ */
6
+ export declare const URLHostParser: (url: string) => Hostname | null;
@@ -0,0 +1,25 @@
1
+ /// <reference types="react-native" />
2
+ import type { RequestProxyOptions } from '../domain/interfaces/RequestProxy';
3
+ import { RequestProxy } from '../domain/interfaces/RequestProxy';
4
+ import type { ResourceReporter } from './DatadogRumResource/ResourceReporter';
5
+ export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
6
+ export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
7
+ export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
8
+ export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
9
+ export declare const ORIGIN_RUM = "rum";
10
+ interface XHRProxyProviders {
11
+ xhrType: typeof XMLHttpRequest;
12
+ resourceReporter: ResourceReporter;
13
+ }
14
+ /**
15
+ * Proxies XMLHTTPRequest to track resources.
16
+ */
17
+ export declare class XHRProxy extends RequestProxy {
18
+ private providers;
19
+ private static originalXhrOpen;
20
+ private static originalXhrSend;
21
+ constructor(providers: XHRProxyProviders);
22
+ onTrackingStart: (context: RequestProxyOptions) => void;
23
+ onTrackingStop: () => void;
24
+ }
25
+ export {};
@@ -0,0 +1,3 @@
1
+ /// <reference types="react-native" />
2
+ export declare const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
3
+ export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
@@ -1 +1 @@
1
- export declare const version = "1.0.0-rc8";
1
+ export declare const version = "1.0.0-rc9";
@@ -8,6 +8,7 @@ export declare class DdRumReactNavigationTracking {
8
8
  private static navigationStateChangeListener;
9
9
  private static viewNamePredicate;
10
10
  private static backHandler;
11
+ private static appStateSubscription?;
11
12
  static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE: string;
12
13
  static NULL_NAVIGATION_REF_ERROR_MESSAGE: string;
13
14
  static NAVIGATION_REF_IN_USE_ERROR_MESSAGE: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-navigation",
3
- "version": "1.0.0-rc8",
3
+ "version": "1.0.0-rc9",
4
4
  "description": "A client-side React Native module to interact with Datadog",
5
5
  "keywords": [
6
6
  "datadog",
@@ -36,7 +36,7 @@
36
36
  "prepare": "bob build"
37
37
  },
38
38
  "devDependencies": {
39
- "@datadog/mobile-react-native": "^1.0.0-rc8",
39
+ "@datadog/mobile-react-native": "^1.0.0-rc9",
40
40
  "@react-navigation/native-v5": "npm:@react-navigation/native@5.9.2",
41
41
  "@react-navigation/native-v6": "npm:@react-navigation/native@6.0.9",
42
42
  "@react-navigation/stack-v5": "npm:@react-navigation/stack@5.14.2",
@@ -77,5 +77,5 @@
77
77
  ]
78
78
  ]
79
79
  },
80
- "gitHead": "67456f90ac95007f8f99beb065ccbf6ec9a6f478"
80
+ "gitHead": "552457ced3fc826cb42120402eb9e98f80228890"
81
81
  }
@@ -15,6 +15,7 @@ import React, { createRef } from 'react';
15
15
  import type { ViewNamePredicate } from '../../../rum/instrumentation/DdRumReactNavigationTracking';
16
16
  import { DdRumReactNavigationTracking } from '../../../rum/instrumentation/DdRumReactNavigationTracking';
17
17
 
18
+ import { AppStateMockLegacy } from './__utils__/AppStateMockLegacy';
18
19
  import { AppStateMock } from './__utils__/AppStateMock';
19
20
  import {
20
21
  FakeNavigator1 as FakeNavigator1v5,
@@ -56,16 +57,8 @@ jest.mock('@datadog/mobile-react-native', () => {
56
57
  };
57
58
  });
58
59
 
59
- const appStateMock = new AppStateMock();
60
- mocked(AppState.addEventListener).mockImplementation(
61
- appStateMock.addEventListener
62
- );
63
- mocked(AppState.removeEventListener).mockImplementation(
64
- appStateMock.removeEventListener
65
- );
66
-
67
60
  // Silence the warning https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
68
- jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
61
+ jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
69
62
  jest.useFakeTimers();
70
63
 
71
64
  beforeEach(() => {
@@ -74,8 +67,6 @@ beforeEach(() => {
74
67
  mocked(DdRum.startView).mockClear();
75
68
  mocked(DdRum.stopView).mockClear();
76
69
  mocked(AppState.addEventListener).mockClear();
77
- mocked(AppState.removeEventListener).mockClear();
78
- appStateMock.removeAllListeners();
79
70
  mocked(BackHandler.exitApp).mockClear();
80
71
 
81
72
  // @ts-ignore
@@ -339,117 +330,139 @@ describe.each([
339
330
  });
340
331
  });
341
332
 
342
- describe('AppState listener', () => {
343
- it('registers and unregisters AppState', async () => {
344
- // GIVEN
345
- const navigationRef1 = createRef<any>();
346
- render(<FakeNavigator1 navigationRef={navigationRef1} />);
347
- const navigationRef2 = createRef<any>();
348
- render(<FakeNavigator2 navigationRef={navigationRef2} />);
349
-
350
- // WHEN
351
- DdRumReactNavigationTracking.startTrackingViews(
352
- navigationRef1.current
353
- );
354
- DdRumReactNavigationTracking.stopTrackingViews(
355
- navigationRef1.current
356
- );
357
- DdRumReactNavigationTracking.startTrackingViews(
358
- navigationRef2.current
359
- );
360
-
361
- // THEN
362
- expect(AppState.addEventListener).toHaveBeenCalledTimes(2);
363
- expect(AppState.removeEventListener).toHaveBeenCalledTimes(1);
364
-
365
- // WHEN we go in background mode
366
- appStateMock.changeValue('background');
367
-
368
- // THEN the listener is only called once
369
- expect(DdRum.stopView).toHaveBeenCalledTimes(1);
370
- });
371
-
372
- it('does not log AppState changes when tracking is stopped', async () => {
373
- // GIVEN
374
- const navigationRef = createRef<any>();
375
- render(<FakeNavigator1 navigationRef={navigationRef} />);
376
-
377
- // WHEN
378
- DdRumReactNavigationTracking.startTrackingViews(
379
- navigationRef.current
380
- );
381
- DdRumReactNavigationTracking.stopTrackingViews(
382
- navigationRef.current
383
- );
384
- appStateMock.changeValue('background');
385
-
386
- // THEN
387
- expect(DdRum.stopView).not.toHaveBeenCalled();
388
- expect(InternalLog.log).not.toHaveBeenCalledWith(
389
- 'We could not determine the route when changing the application state to: background. No RUM View event will be sent in this case.',
390
- 'error'
391
- );
392
- });
393
-
394
- it('stops active view when app goes into background', async () => {
395
- // GIVEN
396
- const navigationRef = createRef<any>();
397
- render(<FakeNavigator1 navigationRef={navigationRef} />);
398
-
399
- DdRumReactNavigationTracking.startTrackingViews(
400
- navigationRef.current
401
- );
402
-
403
- // WHEN
404
- appStateMock.changeValue('background');
405
-
406
- // THEN
407
- expect(DdRum.stopView).toHaveBeenCalledTimes(1);
408
- expect(DdRum.stopView).toHaveBeenCalledWith(
409
- navigationRef.current?.getCurrentRoute()?.key
410
- );
411
- expect(
412
- typeof navigationRef.current?.getCurrentRoute()?.key
413
- ).toBe('string');
414
- });
415
-
416
- it('starts last view when app goes into foreground', async () => {
417
- // GIVEN
418
- const navigationRef = createRef<any>();
419
- render(<FakeNavigator1 navigationRef={navigationRef} />);
420
-
421
- DdRumReactNavigationTracking.startTrackingViews(
422
- navigationRef.current
423
- );
424
-
425
- // WHEN
426
- appStateMock.changeValue('background');
427
- appStateMock.changeValue('active');
428
-
429
- // THEN
430
- expect(DdRum.stopView).toHaveBeenCalledTimes(1);
431
- expect(DdRum.startView).toHaveBeenCalledTimes(2);
432
- });
433
-
434
- it('does not stop view when no navigator attached', async () => {
435
- // GIVEN
436
- const navigationRef = createRef<any>();
437
- render(<FakeNavigator1 navigationRef={navigationRef} />);
438
-
439
- DdRumReactNavigationTracking.startTrackingViews(
440
- navigationRef.current
441
- );
442
- DdRumReactNavigationTracking.stopTrackingViews(
443
- navigationRef.current
444
- );
445
-
446
- // WHEN
447
- appStateMock.changeValue('background');
448
-
449
- // THEN
450
- expect(DdRum.stopView).not.toHaveBeenCalled();
451
- });
452
- });
333
+ describe.each([
334
+ ['react-native 0.63-0.64', AppStateMockLegacy],
335
+ ['react-native 0.65+', AppStateMock]
336
+ ])(
337
+ 'AppState listener on %s',
338
+ (reactNativeVersion, AppStateMockVersion) => {
339
+ let appStateMock;
340
+ beforeEach(() => {
341
+ appStateMock = new AppStateMockVersion();
342
+ mocked(AppState.addEventListener).mockImplementation(
343
+ // @ts-ignore
344
+ appStateMock.addEventListener
345
+ );
346
+ // @ts-ignore
347
+ if (appStateMock.removeEventListener) {
348
+ AppState.removeEventListener = jest.fn(
349
+ appStateMock.removeEventListener
350
+ );
351
+ }
352
+ });
353
+ it('registers and unregisters AppState', async () => {
354
+ // GIVEN
355
+ const navigationRef1 = createRef<any>();
356
+ render(<FakeNavigator1 navigationRef={navigationRef1} />);
357
+ const navigationRef2 = createRef<any>();
358
+ render(<FakeNavigator2 navigationRef={navigationRef2} />);
359
+
360
+ // WHEN
361
+ DdRumReactNavigationTracking.startTrackingViews(
362
+ navigationRef1.current
363
+ );
364
+ DdRumReactNavigationTracking.stopTrackingViews(
365
+ navigationRef1.current
366
+ );
367
+ expect(appStateMock.listeners.change).toHaveLength(0);
368
+
369
+ DdRumReactNavigationTracking.startTrackingViews(
370
+ navigationRef2.current
371
+ );
372
+
373
+ // THEN
374
+ expect(AppState.addEventListener).toHaveBeenCalledTimes(2);
375
+ expect(appStateMock.listeners.change).toHaveLength(1);
376
+
377
+ // WHEN we go in background mode
378
+ appStateMock.changeValue('background');
379
+
380
+ // THEN the listener is only called once
381
+ expect(DdRum.stopView).toHaveBeenCalledTimes(1);
382
+ });
383
+
384
+ it('does not log AppState changes when tracking is stopped', async () => {
385
+ // GIVEN
386
+ const navigationRef = createRef<any>();
387
+ render(<FakeNavigator1 navigationRef={navigationRef} />);
388
+
389
+ // WHEN
390
+ DdRumReactNavigationTracking.startTrackingViews(
391
+ navigationRef.current
392
+ );
393
+ DdRumReactNavigationTracking.stopTrackingViews(
394
+ navigationRef.current
395
+ );
396
+ appStateMock.changeValue('background');
397
+
398
+ // THEN
399
+ expect(DdRum.stopView).not.toHaveBeenCalled();
400
+ expect(InternalLog.log).not.toHaveBeenCalledWith(
401
+ 'We could not determine the route when changing the application state to: background. No RUM View event will be sent in this case.',
402
+ 'error'
403
+ );
404
+ });
405
+
406
+ it('stops active view when app goes into background', async () => {
407
+ // GIVEN
408
+ const navigationRef = createRef<any>();
409
+ render(<FakeNavigator1 navigationRef={navigationRef} />);
410
+
411
+ DdRumReactNavigationTracking.startTrackingViews(
412
+ navigationRef.current
413
+ );
414
+
415
+ // WHEN
416
+ appStateMock.changeValue('background');
417
+
418
+ // THEN
419
+ expect(DdRum.stopView).toHaveBeenCalledTimes(1);
420
+ expect(DdRum.stopView).toHaveBeenCalledWith(
421
+ navigationRef.current?.getCurrentRoute()?.key
422
+ );
423
+ expect(
424
+ typeof navigationRef.current?.getCurrentRoute()?.key
425
+ ).toBe('string');
426
+ });
427
+
428
+ it('starts last view when app goes into foreground', async () => {
429
+ // GIVEN
430
+ const navigationRef = createRef<any>();
431
+ render(<FakeNavigator1 navigationRef={navigationRef} />);
432
+
433
+ DdRumReactNavigationTracking.startTrackingViews(
434
+ navigationRef.current
435
+ );
436
+
437
+ // WHEN
438
+ appStateMock.changeValue('background');
439
+ appStateMock.changeValue('active');
440
+
441
+ // THEN
442
+ expect(DdRum.stopView).toHaveBeenCalledTimes(1);
443
+ expect(DdRum.startView).toHaveBeenCalledTimes(2);
444
+ });
445
+
446
+ it('does not stop view when no navigator attached', async () => {
447
+ // GIVEN
448
+ const navigationRef = createRef<any>();
449
+ render(<FakeNavigator1 navigationRef={navigationRef} />);
450
+
451
+ DdRumReactNavigationTracking.startTrackingViews(
452
+ navigationRef.current
453
+ );
454
+ DdRumReactNavigationTracking.stopTrackingViews(
455
+ navigationRef.current
456
+ );
457
+
458
+ // WHEN
459
+ appStateMock.changeValue('background');
460
+
461
+ // THEN
462
+ expect(DdRum.stopView).not.toHaveBeenCalled();
463
+ });
464
+ }
465
+ );
453
466
 
454
467
  describe('Android back handler', () => {
455
468
  it('does not send an error when the app closes with Android back button', async () => {
@@ -4,44 +4,63 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import type { AppStateEvent, AppStateStatus } from 'react-native';
7
+ import type {
8
+ AppStateEvent,
9
+ AppStateStatus,
10
+ NativeEventSubscription
11
+ } from 'react-native';
8
12
 
9
13
  type handler = (type: AppStateStatus) => void;
10
14
 
11
15
  export class AppStateMock {
12
- private handlers: { [eventType: string]: handler[] } = {};
16
+ private listeners: {
17
+ [eventType: string]: {
18
+ callback: handler;
19
+ subscription: NativeEventSubscription;
20
+ }[];
21
+ } = {};
13
22
 
14
23
  addEventListener = (type: AppStateEvent, callback: handler) => {
15
- if (!this.handlers[type]) {
16
- this.handlers[type] = [];
24
+ if (!this.listeners[type]) {
25
+ this.listeners[type] = [];
17
26
  }
18
- this.handlers[type].push(callback);
27
+ const subscription = {
28
+ remove: () => this.removeListeners(type, callback)
29
+ };
30
+ this.listeners[type].push({
31
+ callback,
32
+ subscription
33
+ });
34
+
35
+ return subscription;
19
36
  };
20
37
 
21
- removeEventListener = (type: string, callback: handler) => {
22
- if (!this.handlers[type]) {
38
+ private removeListeners = (type: string, callback: handler) => {
39
+ if (!this.listeners[type]) {
23
40
  return;
24
41
  }
25
- const callbackIndex = this.handlers[type].indexOf(callback);
42
+ const callbackIndex = this.listeners[type].findIndex(
43
+ handler => handler.callback === callback
44
+ );
26
45
  if (callbackIndex === -1) {
27
46
  return;
28
47
  }
29
- this.handlers[type] = [
30
- ...this.handlers[type].slice(0, callbackIndex),
31
- ...this.handlers[type].slice(
48
+ this.listeners[type] = [
49
+ ...this.listeners[type].slice(0, callbackIndex),
50
+ ...this.listeners[type].slice(
32
51
  callbackIndex + 1,
33
- this.handlers[type].length
52
+ this.listeners[type].length
34
53
  )
35
54
  ];
36
55
  };
37
56
 
38
57
  changeValue = (value: AppStateStatus) => {
39
- if (!this.handlers.change) {
58
+ if (!this.listeners.change) {
40
59
  return;
41
60
  }
42
- this.handlers.change.forEach(callback => {
61
+ this.listeners.change.forEach(handler => {
43
62
  try {
44
- callback(value);
63
+ handler.callback(value);
45
64
  } catch (e) {
46
65
  console.warn(
47
66
  `Failure while executing callback for value ${value}`
@@ -51,6 +70,6 @@ export class AppStateMock {
51
70
  };
52
71
 
53
72
  removeAllListeners = () => {
54
- this.handlers = {};
73
+ this.listeners = {};
55
74
  };
56
75
  }
@@ -0,0 +1,61 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ import type { AppStateEvent, AppStateStatus } from 'react-native';
8
+
9
+ type handler = (type: AppStateStatus) => void;
10
+
11
+ /**
12
+ * This is a mock of legacy implementation of AppState (up until RN 0.65).
13
+ * In the new version, removeEventListener has been deprecated and addEventListener
14
+ * now returns a subscription.
15
+ */
16
+ export class AppStateMockLegacy {
17
+ private listeners: { [eventType: string]: handler[] } = {};
18
+
19
+ addEventListener = (type: AppStateEvent, callback: handler) => {
20
+ if (!this.listeners[type]) {
21
+ this.listeners[type] = [];
22
+ }
23
+ this.listeners[type].push(callback);
24
+ };
25
+
26
+ removeEventListener = (type: string, callback: handler) => {
27
+ if (!this.listeners[type]) {
28
+ return;
29
+ }
30
+ const callbackIndex = this.listeners[type].indexOf(callback);
31
+ if (callbackIndex === -1) {
32
+ return;
33
+ }
34
+ this.listeners[type] = [
35
+ ...this.listeners[type].slice(0, callbackIndex),
36
+ ...this.listeners[type].slice(
37
+ callbackIndex + 1,
38
+ this.listeners[type].length
39
+ )
40
+ ];
41
+ };
42
+
43
+ changeValue = (value: AppStateStatus) => {
44
+ if (!this.listeners.change) {
45
+ return;
46
+ }
47
+ this.listeners.change.forEach(callback => {
48
+ try {
49
+ callback(value);
50
+ } catch (e) {
51
+ console.warn(
52
+ `Failure while executing callback for value ${value}`
53
+ );
54
+ }
55
+ });
56
+ };
57
+
58
+ removeAllListeners = () => {
59
+ this.listeners = {};
60
+ };
61
+ }
@@ -39,6 +39,8 @@ export class DdRumReactNavigationTracking {
39
39
 
40
40
  private static backHandler: NativeEventSubscription | null;
41
41
 
42
+ private static appStateSubscription?: NativeEventSubscription;
43
+
42
44
  static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =
43
45
  'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';
44
46
  static NULL_NAVIGATION_REF_ERROR_MESSAGE =
@@ -108,7 +110,7 @@ export class DdRumReactNavigationTracking {
108
110
  'hardwareBackPress',
109
111
  DdRumReactNavigationTracking.onBackPress
110
112
  );
111
- AppState.addEventListener(
113
+ this.appStateSubscription = AppState.addEventListener(
112
114
  'change',
113
115
  DdRumReactNavigationTracking.appStateListener
114
116
  );
@@ -137,10 +139,17 @@ export class DdRumReactNavigationTracking {
137
139
  return trackedName;
138
140
  };
139
141
  }
140
- AppState.removeEventListener(
141
- 'change',
142
- DdRumReactNavigationTracking.appStateListener
143
- );
142
+
143
+ // For versions of React Native below 0.65, addEventListener does not return a subscription.
144
+ // We have to call AppState.removeEventListener instead.
145
+ if (this.appStateSubscription) {
146
+ this.appStateSubscription.remove();
147
+ } else {
148
+ AppState.removeEventListener(
149
+ 'change',
150
+ DdRumReactNavigationTracking.appStateListener
151
+ );
152
+ }
144
153
  }
145
154
 
146
155
  private static handleRouteNavigation(
@@ -1,40 +0,0 @@
1
- /// <reference types="react-native" />
2
- import type { DdRumResourceTracingAttributes } from './DdRumXhr';
3
- export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
4
- export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
5
- export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
6
- export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
7
- export declare const ORIGIN_RUM = "rum";
8
- export declare const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
9
- export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
10
- /**
11
- * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
12
- */
13
- export declare class DdRumResourceTracking {
14
- private static isTracking;
15
- private static tracingSamplingRate;
16
- private static firstPartyHostsRegex;
17
- private static originalXhrOpen;
18
- private static originalXhrSend;
19
- /**
20
- * Starts tracking resources and sends a RUM Resource event every time a network request is detected.
21
- */
22
- static startTracking({ tracingSamplingRate, firstPartyHosts }: {
23
- tracingSamplingRate: number;
24
- firstPartyHosts: string[];
25
- }): void;
26
- /**
27
- * Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.
28
- */
29
- static startTrackingInternal(xhrType: typeof XMLHttpRequest, { tracingSamplingRate, firstPartyHosts }: {
30
- tracingSamplingRate: number;
31
- firstPartyHosts: string[];
32
- }): void;
33
- static stopTracking(): void;
34
- static getTracingAttributes(url: string): DdRumResourceTracingAttributes;
35
- static proxyXhr(xhrType: any): void;
36
- private static proxyOpen;
37
- private static proxySend;
38
- private static proxyOnReadyStateChange;
39
- private static reportXhr;
40
- }
@@ -1,23 +0,0 @@
1
- /// <reference types="react-native" />
2
- import type Timer from '../../Timer';
3
- export interface DdRumXhr extends XMLHttpRequest {
4
- _datadog_xhr: DdRumXhrContext;
5
- }
6
- export interface DdRumXhrContext {
7
- method: string;
8
- url: string;
9
- reported: boolean;
10
- timer: Timer;
11
- tracingAttributes: DdRumResourceTracingAttributes;
12
- }
13
- export declare type DdRumResourceTracingAttributes = {
14
- tracingStrategy: 'KEEP';
15
- traceId: string;
16
- spanId: string;
17
- samplingPriorityHeader: '1';
18
- } | {
19
- tracingStrategy: 'DISCARD';
20
- traceId?: void;
21
- spanId?: void;
22
- samplingPriorityHeader: '0';
23
- };
@@ -1 +0,0 @@
1
- export declare function generateTraceId(): string;
@@ -1,6 +0,0 @@
1
- /**
2
- * Returns the host from an URL.
3
- * @returns the host (without the port)
4
- * @throws if URL is not well formatted
5
- */
6
- export declare const URLHostParser: (url: string) => string;