@datadog/mobile-react-navigation 1.3.0 → 1.4.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 (21) hide show
  1. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js +2 -0
  2. package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  3. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js +2 -0
  4. package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
  5. package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +11 -3
  6. package/lib/typescript/core/src/index.d.ts +3 -3
  7. package/lib/typescript/core/src/rum/eventMappers/resourceEventMapper.d.ts +0 -1
  8. package/lib/typescript/core/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts +1 -0
  9. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +2 -1
  10. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +32 -6
  11. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.d.ts +21 -0
  12. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +4 -2
  13. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +6 -1
  14. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +0 -1
  15. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +0 -6
  16. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +0 -1
  17. package/lib/typescript/core/src/rum/types.d.ts +17 -0
  18. package/lib/typescript/core/src/version.d.ts +1 -1
  19. package/package.json +5 -5
  20. package/src/__tests__/rum/instrumentation/DdRumReactNavigationTracking.test.tsx +10 -1
  21. package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +2 -0
@@ -65,6 +65,8 @@ class DdRumReactNavigationTracking {
65
65
  if (this.appStateSubscription) {
66
66
  this.appStateSubscription.remove();
67
67
  } else {
68
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
69
+ // @ts-ignore
68
70
  _reactNative.AppState.removeEventListener('change', DdRumReactNavigationTracking.appStateListener);
69
71
  }
70
72
  }
@@ -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","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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AAAA,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B,gDAYL,gG;;gBAZKA,4B,uCAcL,+C;;gBAdKA,4B,yCAgBL,6K;;gBAhBKA,4B,6BAkBwB,MAAe;AAC5C,MAAIA,4BAA4B,CAACW,mBAA7B,KAAqD,IAAzD,EAA+D;AAC3D,WAAO,KAAP;AACH;;AACD,MAAIX,4BAA4B,CAACW,mBAA7B,CAAiD+B,SAAjD,EAAJ,EAAkE;AAC9D,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,C;;gBA1BQ1C,4B,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 | null;\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);\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,mBADu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ACxD3C,IAAAA,4BAA4B,CAACyB,iBAA7B,CACIzB,4BAA4B,CAACW,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBArCQX,4B,sBAiLL+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 | null;\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 // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\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);\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"]}
@@ -61,6 +61,8 @@ export class DdRumReactNavigationTracking {
61
61
  if (this.appStateSubscription) {
62
62
  this.appStateSubscription.remove();
63
63
  } else {
64
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
65
+ // @ts-ignore
64
66
  AppState.removeEventListener('change', DdRumReactNavigationTracking.appStateListener);
65
67
  }
66
68
  }
@@ -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","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,EADJ;AAGAZ,MAAAA,aAAa,CAACa,WAAd,CAA0B,OAA1B,EAAmCJ,QAAnC;AACAX,MAAAA,4BAA4B,CAACS,mBAA7B,GAAmDP,aAAnD;AACAF,MAAAA,4BAA4B,CAACgB,WAA7B,GAA2CjB,WAAW,CAACkB,gBAAZ,CAC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,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 | null;\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);\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,EAAg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P;AACH,C;;gBArCQT,4B,sBAiLL2B,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 | null;\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 // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\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);\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"]}
@@ -5,12 +5,20 @@ import type { LogEventMapper } from './logs/types';
5
5
  import type { ActionEventMapper } from './rum/eventMappers/actionEventMapper';
6
6
  import type { ErrorEventMapper } from './rum/eventMappers/errorEventMapper';
7
7
  import type { ResourceEventMapper } from './rum/eventMappers/resourceEventMapper';
8
+ import type { FirstPartyHost } from './rum/types';
8
9
  export declare enum VitalsUpdateFrequency {
9
10
  FREQUENT = "FREQUENT",
10
11
  AVERAGE = "AVERAGE",
11
12
  RARE = "RARE",
12
13
  NEVER = "NEVER"
13
14
  }
15
+ export declare type FirstPartyHostsConfiguration = (FirstPartyHost | LegacyFirstPartyHost)[];
16
+ export declare type LegacyFirstPartyHost = string;
17
+ /**
18
+ * Defaults legacy first party hosts format to Datadog first party hosts to keep
19
+ * retro-compatibility before OTel support was introduced.
20
+ */
21
+ export declare const formatFirstPartyHosts: (firstPartyHosts: FirstPartyHostsConfiguration) => FirstPartyHost[];
14
22
  /**
15
23
  * The SDK configuration class.
16
24
  * It will be used to configure the SDK functionality at initialization.
@@ -63,7 +71,7 @@ export declare class DdSdkReactNativeConfiguration {
63
71
  *
64
72
  * Matches domains and subdomains, e.g. `['example.com']` matches `example.com` and `api.example.com`.
65
73
  */
66
- firstPartyHosts: string[];
74
+ firstPartyHosts: FirstPartyHostsConfiguration;
67
75
  /**
68
76
  * Overrides the reported version of the app.
69
77
  * Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.
@@ -134,7 +142,7 @@ export declare class DdSdkReactNativeConfiguration {
134
142
  export declare type AutoInstrumentationConfiguration = {
135
143
  readonly trackInteractions: boolean;
136
144
  readonly trackResources: boolean;
137
- readonly firstPartyHosts?: string[];
145
+ readonly firstPartyHosts?: FirstPartyHostsConfiguration;
138
146
  readonly resourceTracingSamplingRate?: number;
139
147
  readonly trackErrors: boolean;
140
148
  readonly logEventMapper?: LogEventMapper | null;
@@ -148,7 +156,7 @@ export declare type AutoInstrumentationConfiguration = {
148
156
  export declare type AutoInstrumentationParameters = {
149
157
  readonly trackInteractions: boolean;
150
158
  readonly trackResources: boolean;
151
- readonly firstPartyHosts: string[];
159
+ readonly firstPartyHosts: FirstPartyHostsConfiguration;
152
160
  readonly resourceTracingSamplingRate: number;
153
161
  readonly trackErrors: boolean;
154
162
  readonly logEventMapper: LogEventMapper | null;
@@ -1,4 +1,4 @@
1
- import { DatadogProviderConfiguration, DdSdkReactNativeConfiguration, InitializationMode } from './DdSdkReactNativeConfiguration';
1
+ import { DatadogProviderConfiguration, DdSdkReactNativeConfiguration, InitializationMode, VitalsUpdateFrequency } from './DdSdkReactNativeConfiguration';
2
2
  import { DdSdkReactNative } from './DdSdkReactNative';
3
3
  import { InternalLog } from './InternalLog';
4
4
  import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
@@ -7,6 +7,6 @@ import { TrackingConsent } from './TrackingConsent';
7
7
  import { DdTrace } from './foundation';
8
8
  import { DdLogs } from './logs/DdLogs';
9
9
  import { DdRum } from './rum/DdRum';
10
- import { RumActionType, ErrorSource } from './rum/types';
10
+ import { RumActionType, ErrorSource, PropagatorType } from './rum/types';
11
11
  import { DatadogProvider } from './sdk/DatadogProvider/DatadogProvider';
12
- export { DatadogProvider, DatadogProviderConfiguration, InitializationMode, DdLogs, DdTrace, DdRum, RumActionType, ErrorSource, DdSdkReactNativeConfiguration, DdSdkReactNative, InternalLog, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
12
+ export { DatadogProvider, DatadogProviderConfiguration, InitializationMode, DdLogs, DdTrace, DdRum, RumActionType, ErrorSource, DdSdkReactNativeConfiguration, DdSdkReactNative, InternalLog, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity, VitalsUpdateFrequency, PropagatorType };
@@ -1,4 +1,3 @@
1
- /// <reference types="react-native" />
2
1
  import type { AdditionalEventDataForMapper } from '../../sdk/EventMappers/EventMapper';
3
2
  import { EventMapper } from '../../sdk/EventMappers/EventMapper';
4
3
  import type { ResourceKind } from '../types';
@@ -7,6 +7,7 @@ export declare class DdRumUserInteractionTracking {
7
7
  private static eventsInterceptor;
8
8
  private static originalCreateElement;
9
9
  private static originalMemo;
10
+ private static originalJsx;
10
11
  private static patchCreateElementFunction;
11
12
  /**
12
13
  * Starts tracking user interactions and sends a RUM Action event every time a new interaction was detected.
@@ -1,3 +1,4 @@
1
+ import type { FirstPartyHost } from '../../types';
1
2
  /**
2
3
  * Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
3
4
  */
@@ -9,7 +10,7 @@ export declare class DdRumResourceTracking {
9
10
  */
10
11
  static startTracking({ tracingSamplingRate, firstPartyHosts }: {
11
12
  tracingSamplingRate: number;
12
- firstPartyHosts: string[];
13
+ firstPartyHosts: FirstPartyHost[];
13
14
  }): void;
14
15
  static stopTracking(): void;
15
16
  }
@@ -1,19 +1,45 @@
1
+ import type { PropagatorType } from '../../../types';
1
2
  import type { Hostname } from './firstPartyHosts';
3
+ import type { RegexMap } from './interfaces/RequestProxy';
2
4
  export declare type DdRumResourceTracingAttributes = {
3
5
  tracingStrategy: 'KEEP';
4
- traceId: string;
5
- spanId: string;
6
- samplingPriorityHeader: '1';
6
+ traceId: TraceId;
7
+ spanId: SpanId;
8
+ samplingPriorityHeader: '1' | '0';
7
9
  rulePsr: number;
10
+ propagatorTypes: PropagatorType[];
8
11
  } | {
9
12
  tracingStrategy: 'DISCARD';
10
13
  traceId?: void;
11
14
  spanId?: void;
12
15
  samplingPriorityHeader: '0';
13
16
  };
14
- export declare const getTracingAttributes: ({ hostname, firstPartyHostsRegex, tracingSamplingRate }: {
17
+ export declare const getTracingAttributes: ({ hostname, firstPartyHostsRegexMap, tracingSamplingRate }: {
15
18
  hostname: Hostname | null;
16
- firstPartyHostsRegex: RegExp;
19
+ firstPartyHostsRegexMap: RegexMap;
17
20
  tracingSamplingRate: number;
18
21
  }) => DdRumResourceTracingAttributes;
19
- export declare function generateTraceId(): string;
22
+ /**
23
+ * Using branded types will ensure we don't accidentally use
24
+ * traceId for spanId when generating headers.
25
+ */
26
+ export declare type TraceId = TraceIdentifier & {
27
+ _brand: 'traceId';
28
+ };
29
+ export declare type SpanId = TraceIdentifier & {
30
+ _brand: 'spanId';
31
+ };
32
+ export declare class TraceIdentifier {
33
+ private low;
34
+ private high;
35
+ constructor();
36
+ toString: (radix: number) => string;
37
+ /**
38
+ * This function pads the trace with `0`.
39
+ * It should not be used with a `length` lower than the trace, as we return the full trace in this case.
40
+ * @param radix radix for the trace
41
+ * @param length minimum length
42
+ * @returns padded string
43
+ */
44
+ toPaddedString: (radix: number, length: number) => string;
45
+ }
@@ -0,0 +1,21 @@
1
+ import type { DdRumResourceTracingAttributes } from './distributedTracing';
2
+ export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
3
+ /**
4
+ * Datadog headers
5
+ */
6
+ export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
7
+ export declare const ORIGIN_RUM = "rum";
8
+ export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
9
+ export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
10
+ /**
11
+ * OTel headers
12
+ */
13
+ export declare const TRACECONTEXT_HEADER_KEY = "traceparent";
14
+ export declare const B3_HEADER_KEY = "b3";
15
+ export declare const B3_MULTI_TRACE_ID_HEADER_KEY = "X-B3-TraceId";
16
+ export declare const B3_MULTI_SPAN_ID_HEADER_KEY = "X-B3-SpanId";
17
+ export declare const B3_MULTI_SAMPLED_HEADER_KEY = "X-B3-Sampled";
18
+ export declare const getTracingHeaders: (tracingAttributes: DdRumResourceTracingAttributes) => {
19
+ header: string;
20
+ value: string;
21
+ }[];
@@ -1,6 +1,8 @@
1
+ import type { FirstPartyHost, PropagatorType } from '../../../types';
2
+ import type { RegexMap } from './interfaces/RequestProxy';
1
3
  export declare type Hostname = {
2
4
  _type: 'Hostname';
3
5
  } & string;
4
6
  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;
7
+ export declare const firstPartyHostsRegexMapBuilder: (firstPartyHosts: FirstPartyHost[]) => RegexMap;
8
+ export declare const getPropagatorsForHost: (hostname: Hostname, firstPartyHostsRegexMap: RegexMap) => PropagatorType[] | null;
@@ -1,7 +1,12 @@
1
+ import type { PropagatorType } from '../../../../types';
1
2
  export interface RequestProxyOptions {
2
3
  tracingSamplingRate: number;
3
- firstPartyHostsRegex: RegExp;
4
+ firstPartyHostsRegexMap: RegexMap;
4
5
  }
6
+ export declare type RegexMap = {
7
+ regex: RegExp;
8
+ propagatorType: PropagatorType;
9
+ }[];
5
10
  export declare abstract class RequestProxy {
6
11
  abstract onTrackingStart: (context: RequestProxyOptions) => void;
7
12
  abstract onTrackingStop: () => void;
@@ -1,4 +1,3 @@
1
- /// <reference types="react-native" />
2
1
  import type { ResourceKind } from '../../../../types';
3
2
  import type { DdRumResourceTracingAttributes } from '../distributedTracing';
4
3
  export interface RUMResource {
@@ -1,12 +1,6 @@
1
- /// <reference types="react-native" />
2
1
  import type { RequestProxyOptions } from '../domain/interfaces/RequestProxy';
3
2
  import { RequestProxy } from '../domain/interfaces/RequestProxy';
4
3
  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
4
  interface XHRProxyProviders {
11
5
  xhrType: typeof XMLHttpRequest;
12
6
  resourceReporter: ResourceReporter;
@@ -1,3 +1,2 @@
1
- /// <reference types="react-native" />
2
1
  export declare const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
3
2
  export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
@@ -108,3 +108,20 @@ export declare enum ErrorSource {
108
108
  WEBVIEW = "WEBVIEW",
109
109
  CUSTOM = "CUSTOM"
110
110
  }
111
+ /**
112
+ * Type of instrumentation on the host.
113
+ * - DATADOG: Datadog’s propagator (`x-datadog-*`)
114
+ * - TRACECONTEXT: W3C Trace Context (`traceparent`)
115
+ * - B3: B3 single header (`b3`)
116
+ * - B3MULTI: B3 multiple headers (`X-B3-*`)
117
+ */
118
+ export declare enum PropagatorType {
119
+ DATADOG = "datadog",
120
+ TRACECONTEXT = "tracecontext",
121
+ B3 = "b3",
122
+ B3MULTI = "b3multi"
123
+ }
124
+ export declare type FirstPartyHost = {
125
+ match: string;
126
+ propagatorTypes: PropagatorType[];
127
+ };
@@ -1 +1 @@
1
- export declare const version = "1.3.0";
1
+ export declare const version = "1.4.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datadog/mobile-react-navigation",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "A client-side React Native module to interact with Datadog",
5
5
  "keywords": [
6
6
  "datadog",
@@ -36,9 +36,9 @@
36
36
  "prepare": "rm -rf lib && yarn bob build"
37
37
  },
38
38
  "devDependencies": {
39
- "@datadog/mobile-react-native": "^1.3.0",
40
- "@react-navigation/native-v5": "npm:@react-navigation/native@5.9.2",
41
- "@react-navigation/native-v6": "npm:@react-navigation/native@6.0.9",
39
+ "@datadog/mobile-react-native": "^1.4.0",
40
+ "@react-navigation/native-v5": "npm:@react-navigation/native@5.9.8",
41
+ "@react-navigation/native-v6": "npm:@react-navigation/native@6.1.2",
42
42
  "@react-navigation/stack-v5": "npm:@react-navigation/stack@5.14.2",
43
43
  "@react-navigation/stack-v6": "npm:@react-navigation/stack@6.2.1",
44
44
  "@testing-library/react-native": "7.0.2",
@@ -77,5 +77,5 @@
77
77
  ]
78
78
  ]
79
79
  },
80
- "gitHead": "16a9d318f9882dc85339b9b59045157d1bc62e7b"
80
+ "gitHead": "cc9c7937cecfd48720ec46852c24965f4a00bab4"
81
81
  }
@@ -38,6 +38,16 @@ jest.mock(
38
38
  () => mockBackHandler
39
39
  );
40
40
 
41
+ /**
42
+ * Fix for @react-navigation/native v5 which calls the `Linking.removeEventListener` API
43
+ * which has been removed in RN 0.71.
44
+ */
45
+ jest.mock('react-native', () => {
46
+ const reactNative = jest.requireActual('react-native');
47
+ reactNative.Linking.removeEventListener = jest.fn();
48
+ return reactNative;
49
+ });
50
+
41
51
  jest.mock('@datadog/mobile-react-native', () => {
42
52
  return {
43
53
  DdRum: {
@@ -59,7 +69,6 @@ jest.mock('@datadog/mobile-react-native', () => {
59
69
 
60
70
  // Silence the warning https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
61
71
  jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
62
- jest.useFakeTimers();
63
72
 
64
73
  beforeEach(() => {
65
74
  mocked(InternalLog.log).mockClear();
@@ -145,6 +145,8 @@ export class DdRumReactNavigationTracking {
145
145
  if (this.appStateSubscription) {
146
146
  this.appStateSubscription.remove();
147
147
  } else {
148
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
149
+ // @ts-ignore
148
150
  AppState.removeEventListener(
149
151
  'change',
150
152
  DdRumReactNavigationTracking.appStateListener