@datadog/mobile-react-navigation 1.0.0-rc8 → 1.1.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 (32) 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/DdSdkReactNative.d.ts +2 -0
  6. package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +20 -0
  7. package/lib/typescript/core/src/foundation.d.ts +3 -2
  8. package/lib/typescript/core/src/nativeModulesTypes.d.ts +168 -0
  9. package/lib/typescript/core/src/rum/instrumentation/DdEventsInterceptor.d.ts +0 -15
  10. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +15 -0
  11. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +18 -0
  12. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +6 -0
  13. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +8 -0
  14. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +20 -0
  15. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.d.ts +8 -0
  16. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.d.ts +6 -0
  17. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.d.ts +17 -0
  18. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/URLHostParser.d.ts +6 -0
  19. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +25 -0
  20. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +3 -0
  21. package/lib/typescript/core/src/types.d.ts +42 -7
  22. package/lib/typescript/core/src/version.d.ts +1 -1
  23. package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts +1 -0
  24. package/package.json +4 -4
  25. package/src/__tests__/rum/instrumentation/DdRumReactNavigationTracking.test.tsx +135 -122
  26. package/src/__tests__/rum/instrumentation/__utils__/AppStateMock.ts +35 -16
  27. package/src/__tests__/rum/instrumentation/__utils__/AppStateMockLegacy.ts +61 -0
  28. package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +14 -5
  29. package/lib/typescript/core/src/rum/instrumentation/DdRumResourceTracking.d.ts +0 -40
  30. package/lib/typescript/core/src/rum/instrumentation/DdRumXhr.d.ts +0 -23
  31. package/lib/typescript/core/src/rum/instrumentation/TraceIdentifier.d.ts +0 -1
  32. 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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C,EAEIvB,gCAAawB,IAFjB;;AAIA;AACH;;AAEDjC,QAAAA,4BAA4B,CAACe,qBAA7B,CAAmDc,KAAnD;AACH,OAZD;AAaH;;AACD,WAAO7B,4BAA4B,CAAC0B,6BAApC;AACH;;AAnKqC;;;;gBAA7B1B,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,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,WA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,iBA4BY,MAAM;AACvB,MAAIA,4BAA4B,CAAC2C,uBAA7B,EAAJ,EAA4D;AACxD3C,IAAAA,4BAA4B,CAACyB,iBAA7B,CACIzB,4BAA4B,CAACW,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBArCQX,4B,sBA+KL+B,cADgD,IAE/C;AAAA;;AACD,QAAMa,YAAY,6BAAG5C,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;AAqC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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,Y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4BAA4B,CAACa,qBAA7B,CAAmDa,KAAnD;AACH,OAZD;AAaH;;AACD,WAAO1B,4BAA4B,CAACuB,6BAApC;AACH;;AA5KqC;;gBAA7BvB,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B,gDAYL,gG;;gBAZKA,4B,uCAcL,+C;;gBAdKA,4B,yCAgBL,6K;;gBAhBKA,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"]}
@@ -9,6 +9,8 @@ export declare class DdSdkReactNative {
9
9
  private static readonly DD_SERVICE_NAME;
10
10
  private static readonly DD_SDK_VERBOSITY_KEY;
11
11
  private static readonly DD_NATIVE_VIEW_TRACKING_KEY;
12
+ private static readonly DD_VERSION;
13
+ private static readonly DD_VERSION_SUFFIX;
12
14
  private static readonly DD_PROXY_TYPE_KEY;
13
15
  private static readonly DD_PROXY_ADDRESS_KEY;
14
16
  private static readonly DD_PROXY_PORT_KEY;
@@ -32,6 +32,26 @@ export declare class DdSdkReactNativeConfiguration {
32
32
  proxyConfig?: ProxyConfiguration;
33
33
  serviceName?: string;
34
34
  firstPartyHosts: string[];
35
+ /**
36
+ * Overrides the reported version of the app.
37
+ * Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.
38
+ * Other special characters are converted to underscores.
39
+ *
40
+ * See https://docs.datadoghq.com/getting_started/tagging/#define-tags for more information on the format.
41
+ *
42
+ * Make sure you set it correctly, as it will have to match the one specified during the upload of your source maps and other mapping files.
43
+ */
44
+ version?: string;
45
+ /**
46
+ * Add a suffix to the reported version of the app.
47
+ * Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.
48
+ * Other special characters are converted to underscores.
49
+ *
50
+ * See https://docs.datadoghq.com/getting_started/tagging/#define-tags for more information on the format.
51
+ *
52
+ * A dash (`-`) will be automatically added between the version and the suffix
53
+ */
54
+ versionSuffix?: string;
35
55
  additionalConfig: {
36
56
  [k: string]: any;
37
57
  };
@@ -1,5 +1,6 @@
1
- import { DdSdkConfiguration, DdSdkType, DdLogsType, DdTraceType, DdRumType } from './types';
2
- declare const DdSdk: DdSdkType;
1
+ import { DdSdkConfiguration, DdLogsType, DdTraceType, DdRumType } from './types';
2
+ import type { DdNativeSdkType } from './nativeModulesTypes';
3
+ declare const DdSdk: DdNativeSdkType;
3
4
  declare const DdLogs: DdLogsType;
4
5
  declare const DdTrace: DdTraceType;
5
6
  declare const DdRum: DdRumType;
@@ -0,0 +1,168 @@
1
+ /**
2
+ * A configuration object to initialize Datadog's features.
3
+ */
4
+ export declare class DdNativeSdkConfiguration {
5
+ readonly clientToken: string;
6
+ readonly env: string;
7
+ readonly applicationId: string;
8
+ readonly nativeCrashReportEnabled: boolean;
9
+ readonly sampleRate: number;
10
+ readonly site: string;
11
+ readonly trackingConsent: string;
12
+ readonly additionalConfig: object;
13
+ constructor(clientToken: string, env: string, applicationId: string, nativeCrashReportEnabled: boolean, sampleRate: number, site: string, trackingConsent: string, additionalConfig: object);
14
+ }
15
+ /**
16
+ * The entry point to initialize Datadog's features.
17
+ */
18
+ export declare type DdNativeSdkType = {
19
+ /**
20
+ * Initializes Datadog's features.
21
+ * @param configuration: The configuration to use.
22
+ */
23
+ initialize(configuration: DdNativeSdkConfiguration): Promise<void>;
24
+ /**
25
+ * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
26
+ * @param attributes: The global context attributes.
27
+ */
28
+ setAttributes(attributes: object): Promise<void>;
29
+ /**
30
+ * Set the user information.
31
+ * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
32
+ */
33
+ setUser(user: object): Promise<void>;
34
+ /**
35
+ * Set the tracking consent regarding the data collection.
36
+ * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
37
+ */
38
+ setTrackingConsent(trackingConsent: string): Promise<void>;
39
+ };
40
+ /**
41
+ * The entry point to use Datadog's Logs feature.
42
+ */
43
+ export declare type DdNativeLogsType = {
44
+ /**
45
+ * Send a log with level debug.
46
+ * @param message: The message to send.
47
+ * @param context: The additional context to send.
48
+ */
49
+ debug(message: string, context?: object): Promise<void>;
50
+ /**
51
+ * Send a log with level info.
52
+ * @param message: The message to send.
53
+ * @param context: The additional context to send.
54
+ */
55
+ info(message: string, context?: object): Promise<void>;
56
+ /**
57
+ * Send a log with level warn.
58
+ * @param message: The message to send.
59
+ * @param context: The additional context to send.
60
+ */
61
+ warn(message: string, context?: object): Promise<void>;
62
+ /**
63
+ * Send a log with level error.
64
+ * @param message: The message to send.
65
+ * @param context: The additional context to send.
66
+ */
67
+ error(message: string, context?: object): Promise<void>;
68
+ };
69
+ /**
70
+ * The entry point to use Datadog's Trace feature.
71
+ */
72
+ export declare type DdNativeTraceType = {
73
+ /**
74
+ * Start a span, and returns a unique identifier for the span.
75
+ * @param operation: The operation name of the span.
76
+ * @param context: The additional context to send.
77
+ * @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
78
+ */
79
+ startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;
80
+ /**
81
+ * Finish a started span.
82
+ * @param spanId: The unique identifier of the span.
83
+ * @param context: The additional context to send.
84
+ * @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
85
+ */
86
+ finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;
87
+ };
88
+ /**
89
+ * The entry point to use Datadog's RUM feature.
90
+ */
91
+ export declare type DdNativeRumType = {
92
+ /**
93
+ * Start tracking a RUM View.
94
+ * @param key: The view unique key identifier.
95
+ * @param name: The view name.
96
+ * @param context: The additional context to send.
97
+ * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
98
+ */
99
+ startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;
100
+ /**
101
+ * Stop tracking a RUM View.
102
+ * @param key: The view unique key identifier.
103
+ * @param context: The additional context to send.
104
+ * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
105
+ */
106
+ stopView(key: string, context?: object, timestampMs?: number): Promise<void>;
107
+ /**
108
+ * Start tracking a RUM Action.
109
+ * @param type: The action type (tap, scroll, swipe, back, custom).
110
+ * @param name: The action name.
111
+ * @param context: The additional context to send.
112
+ * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
113
+ */
114
+ startAction(type: ActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
115
+ /**
116
+ * Stop tracking the ongoing RUM Action.
117
+ * @param type: The action type (tap, scroll, swipe, back, custom).
118
+ * @param name: The action name.
119
+ * @param context: The additional context to send.
120
+ * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
121
+ */
122
+ stopAction(type: ActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
123
+ /**
124
+ * Add a RUM Action.
125
+ * @param type: The action type (tap, scroll, swipe, back, custom).
126
+ * @param name: The action name.
127
+ * @param context: The additional context to send.
128
+ * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
129
+ */
130
+ addAction(type: ActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
131
+ /**
132
+ * Start tracking a RUM Resource.
133
+ * @param key: The resource unique key identifier.
134
+ * @param method: The resource method (GET, POST, …).
135
+ * @param url: The resource url.
136
+ * @param context: The additional context to send.
137
+ * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
138
+ */
139
+ startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;
140
+ /**
141
+ * Stop tracking a RUM Resource.
142
+ * @param key: The resource unique key identifier.
143
+ * @param statusCode: The resource status code.
144
+ * @param kind: The resource's kind (xhr, document, image, css, font, …).
145
+ * @param size: The resource size in bytes. If size is unknown, use -1.
146
+ * @param context: The additional context to send.
147
+ * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
148
+ */
149
+ stopResource(key: string, statusCode: number, kind: ResourceKind, size?: number, context?: object, timestampMs?: number): Promise<void>;
150
+ /**
151
+ * Add a RUM Error.
152
+ * @param message: The error message.
153
+ * @param source: The error source (network, source, console, webview, custom).
154
+ * @param stacktrace: The error stacktrace.
155
+ * @param context: The additional context to send.
156
+ * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
157
+ */
158
+ addError(message: string, source: ErrorSource, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;
159
+ /**
160
+ * Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.
161
+ * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.
162
+ */
163
+ addTiming(name: string): Promise<void>;
164
+ };
165
+ declare type ActionType = 'TAP' | 'SCROLL' | 'SWIPE' | 'BACK' | 'CUSTOM';
166
+ declare type ResourceKind = 'image' | 'xhr' | 'beacon' | 'css' | 'document' | 'fetch' | 'font' | 'js' | 'media' | 'other' | 'native';
167
+ declare type ErrorSource = 'NETWORK' | 'SOURCE' | 'CONSOLE' | 'WEBVIEW' | 'CUSTOM';
168
+ export {};
@@ -9,18 +9,3 @@ export declare class DdEventsInterceptor implements EventsInterceptor {
9
9
  private resolveElementTypeName;
10
10
  private findClosestActionLabel;
11
11
  }
12
- /**
13
- * Describe the type of a RUM Action.
14
- */
15
- export declare enum RumActionType {
16
- /** User tapped on a widget. */
17
- TAP = "TAP",
18
- /** User scrolled a view. */
19
- SCROLL = "SCROLL",
20
- /** User swiped on a view. */
21
- SWIPE = "SWIPE",
22
- /** User clicked on a widget (not used on Mobile). */
23
- CLICK = "CLICK",
24
- /** A custom action. */
25
- CUSTOM = "CUSTOM"
26
- }
@@ -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,20 @@
1
+ import type { ResourceKind } from '../../../../../../../core/src/types';
2
+ import type { DdRumResourceTracingAttributes } from '../distributedTracing';
3
+ export interface RUMResource {
4
+ key: string;
5
+ request: {
6
+ method: string;
7
+ url: string;
8
+ kind: ResourceKind;
9
+ };
10
+ tracingAttributes: DdRumResourceTracingAttributes;
11
+ response: {
12
+ statusCode: number;
13
+ size: number;
14
+ };
15
+ timings: {
16
+ startTime: number;
17
+ stopTime: number;
18
+ responseStartTime?: number;
19
+ };
20
+ }
@@ -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;