@datadog/mobile-react-native-navigation 1.2.0 → 1.3.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 (45) hide show
  1. package/README.md +2 -0
  2. package/lib/commonjs/rum/instrumentation/DdRumReactNativeNavigationTracking.js +50 -32
  3. package/lib/commonjs/rum/instrumentation/DdRumReactNativeNavigationTracking.js.map +1 -1
  4. package/lib/module/rum/instrumentation/DdRumReactNativeNavigationTracking.js +51 -30
  5. package/lib/module/rum/instrumentation/DdRumReactNativeNavigationTracking.js.map +1 -1
  6. package/lib/typescript/core/src/DdSdkReactNative.d.ts +7 -3
  7. package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +22 -0
  8. package/lib/typescript/core/src/foundation.d.ts +2 -4
  9. package/lib/typescript/core/src/index.d.ts +5 -3
  10. package/lib/typescript/core/src/logs/DdLogs.d.ts +14 -0
  11. package/lib/typescript/core/src/logs/eventMapper.d.ts +11 -0
  12. package/lib/typescript/core/src/logs/types.d.ts +54 -0
  13. package/lib/typescript/core/src/nativeModulesTypes.d.ts +1 -1
  14. package/lib/typescript/core/src/rum/DdRum.d.ts +36 -0
  15. package/lib/typescript/core/src/rum/eventMappers/actionEventMapper.d.ts +21 -0
  16. package/lib/typescript/core/src/rum/eventMappers/errorEventMapper.d.ts +21 -0
  17. package/lib/typescript/core/src/rum/eventMappers/resourceEventMapper.d.ts +25 -0
  18. package/lib/typescript/core/src/rum/instrumentation/{DdEventsInterceptor.d.ts → interactionTracking/DdEventsInterceptor.d.ts} +0 -0
  19. package/lib/typescript/core/src/rum/instrumentation/{DdRumUserInteractionTracking.d.ts → interactionTracking/DdRumUserInteractionTracking.d.ts} +0 -0
  20. package/lib/typescript/core/src/rum/instrumentation/{EventsInterceptor.d.ts → interactionTracking/EventsInterceptor.d.ts} +0 -0
  21. package/lib/typescript/core/src/rum/instrumentation/{NoOpEventsInterceptor.d.ts → interactionTracking/NoOpEventsInterceptor.d.ts} +0 -0
  22. package/lib/typescript/core/src/rum/instrumentation/{ShallowObjectEqualityChecker.d.ts → interactionTracking/ShallowObjectEqualityChecker.d.ts} +0 -0
  23. package/lib/typescript/core/src/rum/instrumentation/{getJsxRuntime.d.ts → interactionTracking/getJsxRuntime.d.ts} +0 -0
  24. package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +3 -1
  25. package/lib/typescript/core/src/rum/types.d.ts +110 -0
  26. package/lib/typescript/core/src/sdk/AttributesSingleton/AttributesSingleton.d.ts +12 -0
  27. package/lib/typescript/core/src/sdk/AttributesSingleton/types.d.ts +3 -0
  28. package/lib/typescript/core/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/BoundedBuffer.d.ts +0 -0
  29. package/lib/typescript/core/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.d.ts +0 -0
  30. package/lib/typescript/core/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.d.ts +0 -0
  31. package/lib/typescript/core/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.d.ts +0 -0
  32. package/lib/typescript/core/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.d.ts +0 -0
  33. package/lib/typescript/core/src/{DatadogProvider → sdk/DatadogProvider}/DatadogProvider.d.ts +2 -2
  34. package/lib/typescript/core/src/sdk/EventMappers/EventMapper.d.ts +24 -0
  35. package/lib/typescript/core/src/sdk/EventMappers/utils/deepClone.d.ts +10 -0
  36. package/lib/typescript/core/src/sdk/UserInfoSingleton/UserInfoSingleton.d.ts +12 -0
  37. package/lib/typescript/core/src/sdk/UserInfoSingleton/types.d.ts +6 -0
  38. package/lib/typescript/core/src/types.d.ts +0 -139
  39. package/lib/typescript/core/src/version.d.ts +1 -1
  40. package/lib/typescript/react-native-navigation/src/rum/instrumentation/DdRumReactNativeNavigationTracking.d.ts +5 -3
  41. package/package.json +6 -4
  42. package/src/__tests__/rum/instrumentation/DdRumReactNativeNavigationTracking.test.tsx +182 -109
  43. package/src/__tests__/rum/instrumentation/__utils__/AppStateMock.ts +75 -0
  44. package/src/__tests__/rum/instrumentation/__utils__/AppStateMockLegacy.ts +61 -0
  45. package/src/rum/instrumentation/DdRumReactNativeNavigationTracking.tsx +87 -54
package/README.md CHANGED
@@ -22,6 +22,8 @@ yarn add @datadog/mobile-react-native-navigation
22
22
 
23
23
  In order to start tracking your navigation events, simply call the add the following lines before setting up your navigation. You can use the optional `ViewNamePredicate` callback to replace the automatically detected View name with something more relevant to your use case, based on the [`ComponentDidAppearEvent`][3].
24
24
 
25
+ Returning `null` in the `ViewNamePredicate` prevents the new RUM View from being created. The previous RUM View remains active.
26
+
25
27
  ```js
26
28
  import { DdRumReactNativeNavigationTracking, ViewNamePredicate } from '@datadog/mobile-react-native-navigation';
27
29
  import { ComponentDidAppearEvent } from 'react-native-navigation';
@@ -9,9 +9,7 @@ var _mobileReactNative = require("@datadog/mobile-react-native");
9
9
 
10
10
  var _reactNativeNavigation = require("react-native-navigation");
11
11
 
12
- var _react = _interopRequireDefault(require("react"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ var _reactNative = require("react-native");
15
13
 
16
14
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
15
 
@@ -30,35 +28,22 @@ class DdRumReactNativeNavigationTracking {
30
28
  return;
31
29
  }
32
30
 
33
- const original = _react.default.createElement;
34
- DdRumReactNativeNavigationTracking.originalCreateElement = original;
35
-
36
- _react.default.createElement = (element, props, ...children) => {
37
- if (props && props.componentId !== undefined && props.componentId !== null && !DdRumReactNativeNavigationTracking.trackedComponentIds.includes(props.componentId)) {
38
- const componentId = props.componentId;
39
-
40
- _reactNativeNavigation.Navigation.events().registerComponentListener({
41
- componentDidAppear: event => {
42
- var _predicate;
31
+ DdRumReactNativeNavigationTracking.eventSubscription = _reactNativeNavigation.Navigation.events().registerComponentDidAppearListener(event => {
32
+ const predicate = DdRumReactNativeNavigationTracking.viewNamePredicate;
33
+ const screenName = predicate(event, event.componentName);
43
34
 
44
- const predicate = DdRumReactNativeNavigationTracking.viewNamePredicate;
45
- const screenName = (_predicate = predicate(event, event.componentName)) !== null && _predicate !== void 0 ? _predicate : event.componentName;
35
+ if (screenName !== null) {
36
+ _mobileReactNative.DdRum.startView(event.componentId, screenName);
46
37
 
47
- _mobileReactNative.DdRum.startView(componentId, screenName);
48
- },
49
- componentDidDisappear: () => {
50
- _mobileReactNative.DdRum.stopView(componentId);
51
- }
52
- }, componentId);
53
-
54
- DdRumReactNativeNavigationTracking.trackedComponentIds.push(componentId);
38
+ DdRumReactNativeNavigationTracking.lastView = {
39
+ key: event.componentId,
40
+ name: screenName
41
+ };
55
42
  }
56
-
57
- return original(element, props, ...children);
58
- };
59
-
43
+ });
60
44
  DdRumReactNativeNavigationTracking.isTracking = true;
61
45
  DdRumReactNativeNavigationTracking.viewNamePredicate = viewNamePredicate;
46
+ this.appStateSubscription = _reactNative.AppState.addEventListener('change', DdRumReactNativeNavigationTracking.appStateListener);
62
47
  }
63
48
  /**
64
49
  * Stops tracking Navigation.
@@ -70,11 +55,19 @@ class DdRumReactNativeNavigationTracking {
70
55
  return;
71
56
  }
72
57
 
73
- if (DdRumReactNativeNavigationTracking.originalCreateElement !== undefined) {
74
- _react.default.createElement = DdRumReactNativeNavigationTracking.originalCreateElement;
58
+ if (DdRumReactNativeNavigationTracking.eventSubscription) {
59
+ DdRumReactNativeNavigationTracking.eventSubscription.remove();
60
+ } // For versions of React Native below 0.65, addEventListener does not return a subscription.
61
+ // We have to call AppState.removeEventListener instead.
62
+
63
+
64
+ if (this.appStateSubscription) {
65
+ this.appStateSubscription.remove();
66
+ } else {
67
+ _reactNative.AppState.removeEventListener('change', DdRumReactNativeNavigationTracking.appStateListener);
75
68
  }
76
69
 
77
- DdRumReactNativeNavigationTracking.trackedComponentIds.splice(0, DdRumReactNativeNavigationTracking.trackedComponentIds.length);
70
+ DdRumReactNativeNavigationTracking.lastView = undefined;
78
71
  DdRumReactNativeNavigationTracking.isTracking = false;
79
72
 
80
73
  DdRumReactNativeNavigationTracking.viewNamePredicate = function (_event, trackedName) {
@@ -88,9 +81,34 @@ exports.DdRumReactNativeNavigationTracking = DdRumReactNativeNavigationTracking;
88
81
 
89
82
  _defineProperty(DdRumReactNativeNavigationTracking, "isTracking", false);
90
83
 
91
- _defineProperty(DdRumReactNativeNavigationTracking, "trackedComponentIds", []);
84
+ _defineProperty(DdRumReactNativeNavigationTracking, "eventSubscription", undefined);
92
85
 
93
- _defineProperty(DdRumReactNativeNavigationTracking, "originalCreateElement", undefined);
86
+ _defineProperty(DdRumReactNativeNavigationTracking, "appStateSubscription", void 0);
94
87
 
95
88
  _defineProperty(DdRumReactNativeNavigationTracking, "viewNamePredicate", void 0);
89
+
90
+ _defineProperty(DdRumReactNativeNavigationTracking, "lastView", 'tracking_not_started');
91
+
92
+ _defineProperty(DdRumReactNativeNavigationTracking, "appStateListener", appStateStatus => {
93
+ const lastView = DdRumReactNativeNavigationTracking.lastView;
94
+
95
+ if (lastView === undefined) {
96
+ _mobileReactNative.InternalLog.log(`We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`, _mobileReactNative.SdkVerbosity.ERROR);
97
+
98
+ return;
99
+ }
100
+
101
+ if (lastView === 'tracking_not_started') {
102
+ // Do nothing as no view has been tracked already
103
+ return;
104
+ }
105
+
106
+ if (appStateStatus === 'background') {
107
+ _mobileReactNative.DdRum.stopView(lastView.key);
108
+ } else if (appStateStatus === 'active' || appStateStatus === undefined) {
109
+ // case when app goes into foreground,
110
+ // in that case navigation listener won't be called
111
+ _mobileReactNative.DdRum.startView(lastView.key, lastView.name);
112
+ }
113
+ });
96
114
  //# sourceMappingURL=DdRumReactNativeNavigationTracking.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["DdRumReactNativeNavigationTracking.tsx"],"names":["DdRumReactNativeNavigationTracking","startTracking","viewNamePredicate","_event","trackedName","isTracking","original","React","createElement","originalCreateElement","element","props","children","componentId","undefined","trackedComponentIds","includes","Navigation","events","registerComponentListener","componentDidAppear","event","predicate","screenName","componentName","DdRum","startView","componentDidDisappear","stopView","push","stopTracking","splice","length"],"mappings":";;;;;;;AAMA;;AAEA;;AACA;;;;;;AAOA;AACA;AACA;AACO,MAAMA,kCAAN,CAAyC;AAO5C;AACJ;AACA;AACwB,SAAbC,aAAa,CAChBC,iBAAoC,GAAG,UACnCC,MADmC,EAEnCC,WAFmC,EAGrC;AACE,WAAOA,WAAP;AACH,GANe,EAOZ;AACJ;AACA,QAAIJ,kCAAkC,CAACK,UAAvC,EAAmD;AAC/C;AACH;;AACD,UAAMC,QAAQ,GAAGC,eAAMC,aAAvB;AACAR,IAAAA,kCAAkC,CAACS,qBAAnC,GAA2DH,QAA3D;;AACAC,mBAAMC,aAAN,GAAsB,CAClBE,OADkB,EAElBC,KAFkB,EAGlB,GAAGC,QAHe,KAIZ;AACN,UACID,KAAK,IACLA,KAAK,CAACE,WAAN,KAAsBC,SADtB,IAEAH,KAAK,CAACE,WAAN,KAAsB,IAFtB,IAGA,CAACb,kCAAkC,CAACe,mBAAnC,CAAuDC,QAAvD,CACGL,KAAK,CAACE,WADT,CAJL,EAOE;AACE,cAAMA,WAAW,GAAGF,KAAK,CAACE,WAA1B;;AACAI,0CAAWC,MAAX,GAAoBC,yBAApB,CACI;AACIC,UAAAA,kBAAkB,EACdC,KADgB,IAEf;AAAA;;AACD,kBAAMC,SAAS,GACXtB,kCAAkC,CAACE,iBADvC;AAEA,kBAAMqB,UAAU,iBACZD,SAAS,CAACD,KAAD,EAAQA,KAAK,CAACG,aAAd,CADG,mDAEZH,KAAK,CAACG,aAFV;;AAGAC,qCAAMC,SAAN,CAAgBb,WAAhB,EAA6BU,UAA7B;AACH,WAVL;AAWII,UAAAA,qBAAqB,EAAE,MAAM;AACzBF,qCAAMG,QAAN,CAAef,WAAf;AACH;AAbL,SADJ,EAgBIA,WAhBJ;;AAkBAb,QAAAA,kCAAkC,CAACe,mBAAnC,CAAuDc,IAAvD,CACIhB,WADJ;AAGH;;AAED,aAAOP,QAAQ,CAACI,OAAD,EAAUC,KAAV,EAAiB,GAAGC,QAApB,CAAf;AACH,KAtCD;;AAuCAZ,IAAAA,kCAAkC,CAACK,UAAnC,GAAgD,IAAhD;AACAL,IAAAA,kCAAkC,CAACE,iBAAnC,GAAuDA,iBAAvD;AACH;AAED;AACJ;AACA;;;AACuB,SAAZ4B,YAAY,GAAS;AACxB,QAAI,CAAC9B,kCAAkC,CAACK,UAAxC,EAAoD;AAChD;AACH;;AACD,QACIL,kCAAkC,CAACS,qBAAnC,KACAK,SAFJ,EAGE;AACEP,qBAAMC,aAAN,GACIR,kCAAkC,CAACS,qBADvC;AAEH;;AACDT,IAAAA,kCAAkC,CAACe,mBAAnC,CAAuDgB,MAAvD,CACI,CADJ,EAEI/B,kCAAkC,CAACe,mBAAnC,CAAuDiB,MAF3D;AAIAhC,IAAAA,kCAAkC,CAACK,UAAnC,GAAgD,KAAhD;;AACAL,IAAAA,kCAAkC,CAACE,iBAAnC,GAAuD,UACnDC,MADmD,EAEnDC,WAFmD,EAGrD;AACE,aAAOA,WAAP;AACH,KALD;AAMH;;AA5F2C;;;;gBAAnCJ,kC,gBACmB,K;;gBADnBA,kC,yBAEwC,E;;gBAFxCA,kC,2BAGmCc,S;;gBAHnCd,kC","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 } from '@datadog/mobile-react-native';\nimport type { ComponentDidAppearEvent } from 'react-native-navigation';\nimport { Navigation } from 'react-native-navigation';\nimport React from 'react';\n\nexport type ViewNamePredicate = (\n event: ComponentDidAppearEvent,\n trackedName: string\n) => string;\n\n/**\n * Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.\n */\nexport class DdRumReactNativeNavigationTracking {\n private static isTracking = false;\n private static trackedComponentIds: Array<any> = [];\n private static originalCreateElement: any = undefined;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n /**\n * Starts tracking the Navigation and sends a RUM View event every time a root View component appear/disappear.\n */\n static startTracking(\n viewNamePredicate: ViewNamePredicate = function (\n _event: ComponentDidAppearEvent,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n // extra safety to avoid wrapping more than 1 time this function\n if (DdRumReactNativeNavigationTracking.isTracking) {\n return;\n }\n const original = React.createElement;\n DdRumReactNativeNavigationTracking.originalCreateElement = original;\n React.createElement = (\n element: any,\n props: any,\n ...children: any\n ): any => {\n if (\n props &&\n props.componentId !== undefined &&\n props.componentId !== null &&\n !DdRumReactNativeNavigationTracking.trackedComponentIds.includes(\n props.componentId\n )\n ) {\n const componentId = props.componentId;\n Navigation.events().registerComponentListener(\n {\n componentDidAppear: (\n event: ComponentDidAppearEvent\n ) => {\n const predicate =\n DdRumReactNativeNavigationTracking.viewNamePredicate;\n const screenName =\n predicate(event, event.componentName) ??\n event.componentName;\n DdRum.startView(componentId, screenName);\n },\n componentDidDisappear: () => {\n DdRum.stopView(componentId);\n }\n },\n componentId\n );\n DdRumReactNativeNavigationTracking.trackedComponentIds.push(\n componentId\n );\n }\n\n return original(element, props, ...children);\n };\n DdRumReactNativeNavigationTracking.isTracking = true;\n DdRumReactNativeNavigationTracking.viewNamePredicate = viewNamePredicate;\n }\n\n /**\n * Stops tracking Navigation.\n */\n static stopTracking(): void {\n if (!DdRumReactNativeNavigationTracking.isTracking) {\n return;\n }\n if (\n DdRumReactNativeNavigationTracking.originalCreateElement !==\n undefined\n ) {\n React.createElement =\n DdRumReactNativeNavigationTracking.originalCreateElement;\n }\n DdRumReactNativeNavigationTracking.trackedComponentIds.splice(\n 0,\n DdRumReactNativeNavigationTracking.trackedComponentIds.length\n );\n DdRumReactNativeNavigationTracking.isTracking = false;\n DdRumReactNativeNavigationTracking.viewNamePredicate = function (\n _event: ComponentDidAppearEvent,\n trackedName: string\n ) {\n return trackedName;\n };\n }\n}\n"]}
1
+ {"version":3,"sources":["DdRumReactNativeNavigationTracking.tsx"],"names":["DdRumReactNativeNavigationTracking","startTracking","viewNamePredicate","_event","trackedName","isTracking","eventSubscription","Navigation","events","registerComponentDidAppearListener","event","predicate","screenName","componentName","DdRum","startView","componentId","lastView","key","name","appStateSubscription","AppState","addEventListener","appStateListener","stopTracking","remove","removeEventListener","undefined","appStateStatus","InternalLog","log","SdkVerbosity","ERROR","stopView"],"mappings":";;;;;;;AAMA;;AAEA;;AAMA;;;;AAeA;AACA;AACA;AACO,MAAMA,kCAAN,CAAyC;AAe5C;AACJ;AACA;AACwB,SAAbC,aAAa,CAChBC,iBAAoC,GAAG,UACnCC,MADmC,EAEnCC,WAFmC,EAGrC;AACE,WAAOA,WAAP;AACH,GANe,EAOZ;AACJ;AACA,QAAIJ,kCAAkC,CAACK,UAAvC,EAAmD;AAC/C;AACH;;AAEDL,IAAAA,kCAAkC,CAACM,iBAAnC,GAAuDC,kCAAWC,MAAX,GAAoBC,kCAApB,CAClDC,KAAD,IAAoC;AAChC,YAAMC,SAAS,GACXX,kCAAkC,CAACE,iBADvC;AAEA,YAAMU,UAAU,GAAGD,SAAS,CAACD,KAAD,EAAQA,KAAK,CAACG,aAAd,CAA5B;;AACA,UAAID,UAAU,KAAK,IAAnB,EAAyB;AACrBE,iCAAMC,SAAN,CAAgBL,KAAK,CAACM,WAAtB,EAAmCJ,UAAnC;;AACAZ,QAAAA,kCAAkC,CAACiB,QAAnC,GAA8C;AAC1CC,UAAAA,GAAG,EAAER,KAAK,CAACM,WAD+B;AAE1CG,UAAAA,IAAI,EAAEP;AAFoC,SAA9C;AAIH;AACJ,KAZkD,CAAvD;AAeAZ,IAAAA,kCAAkC,CAACK,UAAnC,GAAgD,IAAhD;AACAL,IAAAA,kCAAkC,CAACE,iBAAnC,GAAuDA,iB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,cAAc,KAAKD,SAFhB,EAGL;AACE;AACA;AACAb,6BAAMC,SAAN,CAAgBE,QAAQ,CAACC,GAAzB,EAA8BD,QAAQ,CAACE,IAAvC;AACH;AACJ,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, InternalLog, SdkVerbosity } from '@datadog/mobile-react-native';\nimport type { ComponentDidAppearEvent } from 'react-native-navigation';\nimport { Navigation } from 'react-native-navigation';\nimport type {\n AppStateStatus,\n EmitterSubscription,\n NativeEventSubscription\n} from 'react-native';\nimport { AppState } from 'react-native';\n\nexport type ViewNamePredicate = (\n event: ComponentDidAppearEvent,\n trackedName: string\n) => string | null;\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\n/**\n * Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.\n */\nexport class DdRumReactNativeNavigationTracking {\n private static isTracking = false;\n private static eventSubscription:\n | EmitterSubscription\n | undefined = undefined;\n private static appStateSubscription?: NativeEventSubscription;\n\n private static viewNamePredicate: ViewNamePredicate;\n private static lastView?:\n | {\n key: string;\n name: string;\n }\n | 'tracking_not_started' = 'tracking_not_started';\n\n /**\n * Starts tracking the Navigation and sends a RUM View event every time a root View component appear/disappear.\n */\n static startTracking(\n viewNamePredicate: ViewNamePredicate = function (\n _event: ComponentDidAppearEvent,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n // extra safety to avoid wrapping more than 1 time this function\n if (DdRumReactNativeNavigationTracking.isTracking) {\n return;\n }\n\n DdRumReactNativeNavigationTracking.eventSubscription = Navigation.events().registerComponentDidAppearListener(\n (event: ComponentDidAppearEvent) => {\n const predicate =\n DdRumReactNativeNavigationTracking.viewNamePredicate;\n const screenName = predicate(event, event.componentName);\n if (screenName !== null) {\n DdRum.startView(event.componentId, screenName);\n DdRumReactNativeNavigationTracking.lastView = {\n key: event.componentId,\n name: screenName\n };\n }\n }\n );\n\n DdRumReactNativeNavigationTracking.isTracking = true;\n DdRumReactNativeNavigationTracking.viewNamePredicate = viewNamePredicate;\n this.appStateSubscription = AppState.addEventListener(\n 'change',\n DdRumReactNativeNavigationTracking.appStateListener\n );\n }\n\n /**\n * Stops tracking Navigation.\n */\n static stopTracking(): void {\n if (!DdRumReactNativeNavigationTracking.isTracking) {\n return;\n }\n if (DdRumReactNativeNavigationTracking.eventSubscription) {\n DdRumReactNativeNavigationTracking.eventSubscription.remove();\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 DdRumReactNativeNavigationTracking.appStateListener\n );\n }\n\n DdRumReactNativeNavigationTracking.lastView = undefined;\n DdRumReactNativeNavigationTracking.isTracking = false;\n DdRumReactNativeNavigationTracking.viewNamePredicate = function (\n _event: ComponentDidAppearEvent,\n trackedName: string\n ) {\n return trackedName;\n };\n }\n\n private static appStateListener: AppStateListener = (\n appStateStatus: AppStateStatus\n ) => {\n const lastView = DdRumReactNativeNavigationTracking.lastView;\n if (lastView === undefined) {\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 if (lastView === 'tracking_not_started') {\n // Do nothing as no view has been tracked already\n return;\n }\n\n if (appStateStatus === 'background') {\n DdRum.stopView(lastView.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(lastView.key, lastView.name);\n }\n };\n}\n"]}
@@ -5,9 +5,9 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
5
5
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
6
6
  * Copyright 2016-Present Datadog, Inc.
7
7
  */
8
- import { DdRum } from '@datadog/mobile-react-native';
8
+ import { DdRum, InternalLog, SdkVerbosity } from '@datadog/mobile-react-native';
9
9
  import { Navigation } from 'react-native-navigation';
10
- import React from 'react';
10
+ import { AppState } from 'react-native';
11
11
 
12
12
  /**
13
13
  * Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.
@@ -24,32 +24,21 @@ export class DdRumReactNativeNavigationTracking {
24
24
  return;
25
25
  }
26
26
 
27
- const original = React.createElement;
28
- DdRumReactNativeNavigationTracking.originalCreateElement = original;
29
-
30
- React.createElement = (element, props, ...children) => {
31
- if (props && props.componentId !== undefined && props.componentId !== null && !DdRumReactNativeNavigationTracking.trackedComponentIds.includes(props.componentId)) {
32
- const componentId = props.componentId;
33
- Navigation.events().registerComponentListener({
34
- componentDidAppear: event => {
35
- var _predicate;
36
-
37
- const predicate = DdRumReactNativeNavigationTracking.viewNamePredicate;
38
- const screenName = (_predicate = predicate(event, event.componentName)) !== null && _predicate !== void 0 ? _predicate : event.componentName;
39
- DdRum.startView(componentId, screenName);
40
- },
41
- componentDidDisappear: () => {
42
- DdRum.stopView(componentId);
43
- }
44
- }, componentId);
45
- DdRumReactNativeNavigationTracking.trackedComponentIds.push(componentId);
46
- }
47
-
48
- return original(element, props, ...children);
49
- };
27
+ DdRumReactNativeNavigationTracking.eventSubscription = Navigation.events().registerComponentDidAppearListener(event => {
28
+ const predicate = DdRumReactNativeNavigationTracking.viewNamePredicate;
29
+ const screenName = predicate(event, event.componentName);
50
30
 
31
+ if (screenName !== null) {
32
+ DdRum.startView(event.componentId, screenName);
33
+ DdRumReactNativeNavigationTracking.lastView = {
34
+ key: event.componentId,
35
+ name: screenName
36
+ };
37
+ }
38
+ });
51
39
  DdRumReactNativeNavigationTracking.isTracking = true;
52
40
  DdRumReactNativeNavigationTracking.viewNamePredicate = viewNamePredicate;
41
+ this.appStateSubscription = AppState.addEventListener('change', DdRumReactNativeNavigationTracking.appStateListener);
53
42
  }
54
43
  /**
55
44
  * Stops tracking Navigation.
@@ -61,11 +50,19 @@ export class DdRumReactNativeNavigationTracking {
61
50
  return;
62
51
  }
63
52
 
64
- if (DdRumReactNativeNavigationTracking.originalCreateElement !== undefined) {
65
- React.createElement = DdRumReactNativeNavigationTracking.originalCreateElement;
53
+ if (DdRumReactNativeNavigationTracking.eventSubscription) {
54
+ DdRumReactNativeNavigationTracking.eventSubscription.remove();
55
+ } // For versions of React Native below 0.65, addEventListener does not return a subscription.
56
+ // We have to call AppState.removeEventListener instead.
57
+
58
+
59
+ if (this.appStateSubscription) {
60
+ this.appStateSubscription.remove();
61
+ } else {
62
+ AppState.removeEventListener('change', DdRumReactNativeNavigationTracking.appStateListener);
66
63
  }
67
64
 
68
- DdRumReactNativeNavigationTracking.trackedComponentIds.splice(0, DdRumReactNativeNavigationTracking.trackedComponentIds.length);
65
+ DdRumReactNativeNavigationTracking.lastView = undefined;
69
66
  DdRumReactNativeNavigationTracking.isTracking = false;
70
67
 
71
68
  DdRumReactNativeNavigationTracking.viewNamePredicate = function (_event, trackedName) {
@@ -77,9 +74,33 @@ export class DdRumReactNativeNavigationTracking {
77
74
 
78
75
  _defineProperty(DdRumReactNativeNavigationTracking, "isTracking", false);
79
76
 
80
- _defineProperty(DdRumReactNativeNavigationTracking, "trackedComponentIds", []);
77
+ _defineProperty(DdRumReactNativeNavigationTracking, "eventSubscription", undefined);
81
78
 
82
- _defineProperty(DdRumReactNativeNavigationTracking, "originalCreateElement", undefined);
79
+ _defineProperty(DdRumReactNativeNavigationTracking, "appStateSubscription", void 0);
83
80
 
84
81
  _defineProperty(DdRumReactNativeNavigationTracking, "viewNamePredicate", void 0);
82
+
83
+ _defineProperty(DdRumReactNativeNavigationTracking, "lastView", 'tracking_not_started');
84
+
85
+ _defineProperty(DdRumReactNativeNavigationTracking, "appStateListener", appStateStatus => {
86
+ const lastView = DdRumReactNativeNavigationTracking.lastView;
87
+
88
+ if (lastView === undefined) {
89
+ InternalLog.log(`We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`, SdkVerbosity.ERROR);
90
+ return;
91
+ }
92
+
93
+ if (lastView === 'tracking_not_started') {
94
+ // Do nothing as no view has been tracked already
95
+ return;
96
+ }
97
+
98
+ if (appStateStatus === 'background') {
99
+ DdRum.stopView(lastView.key);
100
+ } else if (appStateStatus === 'active' || appStateStatus === undefined) {
101
+ // case when app goes into foreground,
102
+ // in that case navigation listener won't be called
103
+ DdRum.startView(lastView.key, lastView.name);
104
+ }
105
+ });
85
106
  //# sourceMappingURL=DdRumReactNativeNavigationTracking.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["DdRumReactNativeNavigationTracking.tsx"],"names":["DdRum","Navigation","React","DdRumReactNativeNavigationTracking","startTracking","viewNamePredicate","_event","trackedName","isTracking","original","createElement","originalCreateElement","element","props","children","componentId","undefined","trackedComponentIds","includes","events","registerComponentListener","componentDidAppear","event","predicate","screenName","componentName","startView","componentDidDisappear","stopView","push","stopTracking","splice","length"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,QAAsB,8BAAtB;AAEA,SAASC,UAAT,QAA2B,yBAA3B;AACA,OAAOC,KAAP,MAAkB,OAAlB;;AAOA;AACA;AACA;AACA,OAAO,MAAMC,kCAAN,CAAyC;AAO5C;AACJ;AACA;AACwB,SAAbC,aAAa,CAChBC,iBAAoC,GAAG,UACnCC,MADmC,EAEnCC,WAFmC,EAGrC;AACE,WAAOA,WAAP;AACH,GANe,EAOZ;AACJ;AACA,QAAIJ,kCAAkC,CAACK,UAAvC,EAAmD;AAC/C;AACH;;AACD,UAAMC,QAAQ,GAAGP,KAAK,CAACQ,aAAvB;AACAP,IAAAA,kCAAkC,CAACQ,qBAAnC,GAA2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aAAN,GACIP,kCAAkC,CAACQ,qBADvC;AAEH;;AACDR,IAAAA,kCAAkC,CAACc,mBAAnC,CAAuDc,MAAvD,CACI,CADJ,EAEI5B,kCAAkC,CAACc,mBAAnC,CAAuDe,MAF3D;AAIA7B,IAAAA,kCAAkC,CAACK,UAAnC,GAAgD,KAAhD;;AACAL,IAAAA,kCAAkC,CAACE,iBAAnC,GAAuD,UACnDC,MADmD,EAEnDC,WAFmD,EAGrD;AACE,aAAOA,WAAP;AACH,KALD;AAMH;;AA5F2C;;gBAAnCJ,kC,gBACmB,K;;gBADnBA,kC,yBAEwC,E;;gBAFxCA,kC,2BAGmCa,S;;gBAHnCb,kC","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 } from '@datadog/mobile-react-native';\nimport type { ComponentDidAppearEvent } from 'react-native-navigation';\nimport { Navigation } from 'react-native-navigation';\nimport React from 'react';\n\nexport type ViewNamePredicate = (\n event: ComponentDidAppearEvent,\n trackedName: string\n) => string;\n\n/**\n * Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.\n */\nexport class DdRumReactNativeNavigationTracking {\n private static isTracking = false;\n private static trackedComponentIds: Array<any> = [];\n private static originalCreateElement: any = undefined;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n /**\n * Starts tracking the Navigation and sends a RUM View event every time a root View component appear/disappear.\n */\n static startTracking(\n viewNamePredicate: ViewNamePredicate = function (\n _event: ComponentDidAppearEvent,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n // extra safety to avoid wrapping more than 1 time this function\n if (DdRumReactNativeNavigationTracking.isTracking) {\n return;\n }\n const original = React.createElement;\n DdRumReactNativeNavigationTracking.originalCreateElement = original;\n React.createElement = (\n element: any,\n props: any,\n ...children: any\n ): any => {\n if (\n props &&\n props.componentId !== undefined &&\n props.componentId !== null &&\n !DdRumReactNativeNavigationTracking.trackedComponentIds.includes(\n props.componentId\n )\n ) {\n const componentId = props.componentId;\n Navigation.events().registerComponentListener(\n {\n componentDidAppear: (\n event: ComponentDidAppearEvent\n ) => {\n const predicate =\n DdRumReactNativeNavigationTracking.viewNamePredicate;\n const screenName =\n predicate(event, event.componentName) ??\n event.componentName;\n DdRum.startView(componentId, screenName);\n },\n componentDidDisappear: () => {\n DdRum.stopView(componentId);\n }\n },\n componentId\n );\n DdRumReactNativeNavigationTracking.trackedComponentIds.push(\n componentId\n );\n }\n\n return original(element, props, ...children);\n };\n DdRumReactNativeNavigationTracking.isTracking = true;\n DdRumReactNativeNavigationTracking.viewNamePredicate = viewNamePredicate;\n }\n\n /**\n * Stops tracking Navigation.\n */\n static stopTracking(): void {\n if (!DdRumReactNativeNavigationTracking.isTracking) {\n return;\n }\n if (\n DdRumReactNativeNavigationTracking.originalCreateElement !==\n undefined\n ) {\n React.createElement =\n DdRumReactNativeNavigationTracking.originalCreateElement;\n }\n DdRumReactNativeNavigationTracking.trackedComponentIds.splice(\n 0,\n DdRumReactNativeNavigationTracking.trackedComponentIds.length\n );\n DdRumReactNativeNavigationTracking.isTracking = false;\n DdRumReactNativeNavigationTracking.viewNamePredicate = function (\n _event: ComponentDidAppearEvent,\n trackedName: string\n ) {\n return trackedName;\n };\n }\n}\n"]}
1
+ {"version":3,"sources":["DdRumReactNativeNavigationTracking.tsx"],"names":["DdRum","InternalLog","SdkVerbosity","Navigation","AppState","DdRumReactNativeNavigationTracking","startTracking","viewNamePredicate","_event","trackedName","isTracking","eventSubscription","events","registerComponentDidAppearListener","event","predicate","screenName","componentName","startView","componentId","lastView","key","name","appStateSubscription","addEventListener","appStateListener","stopTracking","remove","removeEventListener","undefined","appStateStatus","log","ERROR","stopView"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,EAAgBC,WAAhB,EAA6BC,YAA7B,QAAiD,8BAAjD;AAEA,SAASC,UAAT,QAA2B,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AKJ,oBAAT,EAA+B;AAC3B,WAAKA,oBAAL,CAA0BI,MAA1B;AACH,KAFD,MAEO;AACHvB,MAAAA,QAAQ,CAACwB,mBAAT,CACI,QADJ,EAEIvB,kCAAkC,CAACoB,gBAFvC;AAIH;;AAEDpB,IAAAA,kCAAkC,CAACe,QAAnC,GAA8CS,SAA9C;AACAxB,IAAAA,kCAAkC,CAACK,UAAnC,GAAgD,KAAhD;;AACAL,IAAAA,kCAAkC,CAACE,iBAAnC,GAAuD,UACnDC,MADmD,EAEnDC,WAFmD,EAGrD;AACE,aAAOA,WAAP;AACH,KALD;AAMH;;AAnF2C;;gBAAnCJ,kC,gBACmB,K;;gBADnBA,kC,uBAISwB,S;;gBAJTxB,kC;;gBAAAA,kC;;gBAAAA,kC,cAasB,sB;;gBAbtBA,kC,sBAsFLyB,cADgD,IAE/C;AACD,QAAMV,QAAQ,GAAGf,kCAAkC,CAACe,QAApD;;AACA,MAAIA,QAAQ,KAAKS,SAAjB,EAA4B;AACxB5B,IAAAA,WAAW,CAAC8B,GAAZ,CACK,4EAA2ED,cAAe,gDAD/F,EAEI5B,YAAY,CAAC8B,KAFjB;AAIA;AACH;;AAED,MAAIZ,QAAQ,KAAK,sBAAjB,EAAyC;AACrC;AACA;AACH;;AAED,MAAIU,cAAc,KAAK,YAAvB,EAAqC;AACjC9B,IAAAA,KAAK,CAACiC,QAAN,CAAeb,QAAQ,CAACC,GAAxB;AACH,GAFD,MAEO,IACHS,cAAc,KAAK,QAAnB,IACAA,cAAc,KAAKD,SAFhB,EAGL;AACE;AACA;AACA7B,IAAAA,KAAK,CAACkB,SAAN,CAAgBE,QAAQ,CAACC,GAAzB,EAA8BD,QAAQ,CAACE,IAAvC;AACH;AACJ,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, InternalLog, SdkVerbosity } from '@datadog/mobile-react-native';\nimport type { ComponentDidAppearEvent } from 'react-native-navigation';\nimport { Navigation } from 'react-native-navigation';\nimport type {\n AppStateStatus,\n EmitterSubscription,\n NativeEventSubscription\n} from 'react-native';\nimport { AppState } from 'react-native';\n\nexport type ViewNamePredicate = (\n event: ComponentDidAppearEvent,\n trackedName: string\n) => string | null;\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\n/**\n * Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.\n */\nexport class DdRumReactNativeNavigationTracking {\n private static isTracking = false;\n private static eventSubscription:\n | EmitterSubscription\n | undefined = undefined;\n private static appStateSubscription?: NativeEventSubscription;\n\n private static viewNamePredicate: ViewNamePredicate;\n private static lastView?:\n | {\n key: string;\n name: string;\n }\n | 'tracking_not_started' = 'tracking_not_started';\n\n /**\n * Starts tracking the Navigation and sends a RUM View event every time a root View component appear/disappear.\n */\n static startTracking(\n viewNamePredicate: ViewNamePredicate = function (\n _event: ComponentDidAppearEvent,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n // extra safety to avoid wrapping more than 1 time this function\n if (DdRumReactNativeNavigationTracking.isTracking) {\n return;\n }\n\n DdRumReactNativeNavigationTracking.eventSubscription = Navigation.events().registerComponentDidAppearListener(\n (event: ComponentDidAppearEvent) => {\n const predicate =\n DdRumReactNativeNavigationTracking.viewNamePredicate;\n const screenName = predicate(event, event.componentName);\n if (screenName !== null) {\n DdRum.startView(event.componentId, screenName);\n DdRumReactNativeNavigationTracking.lastView = {\n key: event.componentId,\n name: screenName\n };\n }\n }\n );\n\n DdRumReactNativeNavigationTracking.isTracking = true;\n DdRumReactNativeNavigationTracking.viewNamePredicate = viewNamePredicate;\n this.appStateSubscription = AppState.addEventListener(\n 'change',\n DdRumReactNativeNavigationTracking.appStateListener\n );\n }\n\n /**\n * Stops tracking Navigation.\n */\n static stopTracking(): void {\n if (!DdRumReactNativeNavigationTracking.isTracking) {\n return;\n }\n if (DdRumReactNativeNavigationTracking.eventSubscription) {\n DdRumReactNativeNavigationTracking.eventSubscription.remove();\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 DdRumReactNativeNavigationTracking.appStateListener\n );\n }\n\n DdRumReactNativeNavigationTracking.lastView = undefined;\n DdRumReactNativeNavigationTracking.isTracking = false;\n DdRumReactNativeNavigationTracking.viewNamePredicate = function (\n _event: ComponentDidAppearEvent,\n trackedName: string\n ) {\n return trackedName;\n };\n }\n\n private static appStateListener: AppStateListener = (\n appStateStatus: AppStateStatus\n ) => {\n const lastView = DdRumReactNativeNavigationTracking.lastView;\n if (lastView === undefined) {\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 if (lastView === 'tracking_not_started') {\n // Do nothing as no view has been tracked already\n return;\n }\n\n if (appStateStatus === 'background') {\n DdRum.stopView(lastView.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(lastView.key, lastView.name);\n }\n };\n}\n"]}
@@ -1,6 +1,8 @@
1
1
  import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
2
2
  import type { DatadogProviderConfiguration, PartialInitializationConfiguration, AutoInstrumentationConfiguration } from './DdSdkReactNativeConfiguration';
3
3
  import type { TrackingConsent } from './TrackingConsent';
4
+ import type { Attributes } from './sdk/AttributesSingleton/types';
5
+ import type { UserInfo } from './sdk/UserInfoSingleton/types';
4
6
  /**
5
7
  * This class initializes the Datadog SDK, and sets up communication with the server.
6
8
  */
@@ -10,6 +12,7 @@ export declare class DdSdkReactNative {
10
12
  private static readonly DD_SERVICE_NAME;
11
13
  private static readonly DD_SDK_VERBOSITY_KEY;
12
14
  private static readonly DD_NATIVE_VIEW_TRACKING_KEY;
15
+ private static readonly DD_NATIVE_INTERACTION_TRACKING_KEY;
13
16
  private static readonly DD_VERSION;
14
17
  private static readonly DD_VERSION_SUFFIX;
15
18
  private static readonly DD_PROXY_TYPE_KEY;
@@ -40,17 +43,18 @@ export declare class DdSdkReactNative {
40
43
  */
41
44
  static _initializeFromDatadogProviderWithConfigurationAsync: (configuration: PartialInitializationConfiguration) => Promise<void>;
42
45
  /**
43
- * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
46
+ * Adds a set of attributes to the global context attached with all future Logs, Spans and RUM events.
47
+ * To remove an attribute, set it to `undefined` in a call to `setAttributes`.
44
48
  * @param attributes: The global context attributes.
45
49
  * @returns a Promise.
46
50
  */
47
- static setAttributes(attributes: object): Promise<void>;
51
+ static setAttributes(attributes: Attributes): Promise<void>;
48
52
  /**
49
53
  * Set the user information.
50
54
  * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
51
55
  * @returns a Promise.
52
56
  */
53
- static setUser(user: object): Promise<void>;
57
+ static setUser(user: UserInfo): Promise<void>;
54
58
  /**
55
59
  * Set the tracking consent regarding the data collection.
56
60
  * @param trackingConsent: One of TrackingConsent values.
@@ -1,6 +1,10 @@
1
1
  import type { ProxyConfiguration } from './ProxyConfiguration';
2
2
  import type { SdkVerbosity } from './SdkVerbosity';
3
3
  import { TrackingConsent } from './TrackingConsent';
4
+ import type { LogEventMapper } from './logs/types';
5
+ import type { ActionEventMapper } from './rum/eventMappers/actionEventMapper';
6
+ import type { ErrorEventMapper } from './rum/eventMappers/errorEventMapper';
7
+ import type { ResourceEventMapper } from './rum/eventMappers/resourceEventMapper';
4
8
  export declare enum VitalsUpdateFrequency {
5
9
  FREQUENT = "FREQUENT",
6
10
  AVERAGE = "AVERAGE",
@@ -46,6 +50,11 @@ export declare class DdSdkReactNativeConfiguration {
46
50
  * Set to `true` if you use a custom navigation system relying on native views.
47
51
  */
48
52
  nativeViewTracking: boolean;
53
+ /**
54
+ * Enables native interaction tracking.
55
+ * Set to `true` if you want to track interactions on native screens.
56
+ */
57
+ nativeInteractionTracking: boolean;
49
58
  proxyConfig?: ProxyConfiguration;
50
59
  serviceName?: string;
51
60
  /**
@@ -109,6 +118,10 @@ export declare class DdSdkReactNativeConfiguration {
109
118
  * Sets the preferred frequency for collecting mobile vitals.
110
119
  */
111
120
  vitalsUpdateFrequency: VitalsUpdateFrequency;
121
+ logEventMapper: LogEventMapper | null;
122
+ errorEventMapper: ErrorEventMapper | null;
123
+ resourceEventMapper: ResourceEventMapper | null;
124
+ actionEventMapper: ActionEventMapper | null;
112
125
  additionalConfig: {
113
126
  [k: string]: any;
114
127
  };
@@ -124,6 +137,10 @@ export declare type AutoInstrumentationConfiguration = {
124
137
  readonly firstPartyHosts?: string[];
125
138
  readonly resourceTracingSamplingRate?: number;
126
139
  readonly trackErrors: boolean;
140
+ readonly logEventMapper?: LogEventMapper | null;
141
+ readonly errorEventMapper?: ErrorEventMapper | null;
142
+ readonly resourceEventMapper?: ResourceEventMapper | null;
143
+ readonly actionEventMapper?: ActionEventMapper | null;
127
144
  };
128
145
  /**
129
146
  * Parameters needed to start auto instrumentation. Includes default values.
@@ -134,6 +151,10 @@ export declare type AutoInstrumentationParameters = {
134
151
  readonly firstPartyHosts: string[];
135
152
  readonly resourceTracingSamplingRate: number;
136
153
  readonly trackErrors: boolean;
154
+ readonly logEventMapper: LogEventMapper | null;
155
+ readonly errorEventMapper: ErrorEventMapper | null;
156
+ readonly resourceEventMapper: ResourceEventMapper | null;
157
+ readonly actionEventMapper: ActionEventMapper | null;
137
158
  };
138
159
  /**
139
160
  * We could use `Proxy` instead of this function, but `Proxy` is not available on
@@ -148,6 +169,7 @@ export declare type PartialInitializationConfiguration = {
148
169
  readonly site?: string;
149
170
  readonly verbosity?: SdkVerbosity | undefined;
150
171
  readonly nativeViewTracking?: boolean;
172
+ readonly nativeInteractionTracking?: boolean;
151
173
  readonly proxyConfig?: ProxyConfiguration;
152
174
  readonly serviceName?: string;
153
175
  readonly version?: string;
@@ -1,7 +1,5 @@
1
- import { DdSdkConfiguration, DdLogsType, DdTraceType, DdRumType } from './types';
1
+ import { DdSdkConfiguration, DdTraceType } from './types';
2
2
  import type { DdNativeSdkType } from './nativeModulesTypes';
3
3
  declare const DdSdk: DdNativeSdkType;
4
- declare const DdLogs: DdLogsType;
5
4
  declare const DdTrace: DdTraceType;
6
- declare const DdRum: DdRumType;
7
- export { DdSdkConfiguration, DdSdk, DdLogs, DdTrace, DdRum };
5
+ export { DdSdkConfiguration, DdSdk, DdTrace };
@@ -1,10 +1,12 @@
1
- import { DatadogProvider } from './DatadogProvider/DatadogProvider';
2
1
  import { DatadogProviderConfiguration, DdSdkReactNativeConfiguration, InitializationMode } from './DdSdkReactNativeConfiguration';
3
2
  import { DdSdkReactNative } from './DdSdkReactNative';
4
3
  import { InternalLog } from './InternalLog';
5
4
  import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
6
5
  import { SdkVerbosity } from './SdkVerbosity';
7
6
  import { TrackingConsent } from './TrackingConsent';
8
- import { DdLogs, DdTrace, DdRum } from './foundation';
9
- import { RumActionType, ErrorSource } from './types';
7
+ import { DdTrace } from './foundation';
8
+ import { DdLogs } from './logs/DdLogs';
9
+ import { DdRum } from './rum/DdRum';
10
+ import { RumActionType, ErrorSource } from './rum/types';
11
+ import { DatadogProvider } from './sdk/DatadogProvider/DatadogProvider';
10
12
  export { DatadogProvider, DatadogProviderConfiguration, InitializationMode, DdLogs, DdTrace, DdRum, RumActionType, ErrorSource, DdSdkReactNativeConfiguration, DdSdkReactNative, InternalLog, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
@@ -0,0 +1,14 @@
1
+ import type { DdLogsType, LogEventMapper } from './types';
2
+ declare class DdLogsWrapper implements DdLogsType {
3
+ private nativeLogs;
4
+ private logEventMapper;
5
+ debug(message: string, context?: object): Promise<void>;
6
+ info(message: string, context?: object): Promise<void>;
7
+ warn(message: string, context?: object): Promise<void>;
8
+ error(message: string, context?: object): Promise<void>;
9
+ private log;
10
+ registerLogEventMapper(logEventMapper: LogEventMapper): void;
11
+ unregisterLogEventMapper(): void;
12
+ }
13
+ export declare const DdLogs: DdLogsWrapper;
14
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { Attributes } from '../sdk/AttributesSingleton/types';
2
+ import { EventMapper } from '../sdk/EventMappers/EventMapper';
3
+ import type { UserInfo } from '../sdk/UserInfoSingleton/types';
4
+ import type { LogEvent, LogEventMapper, NativeLog, RawLog } from './types';
5
+ export declare const formatLogEventToNativeLog: (logEvent: LogEvent) => NativeLog;
6
+ export declare const formatRawLogToNativeEvent: (rawLog: RawLog) => NativeLog;
7
+ export declare const formatRawLogToLogEvent: (rawLog: RawLog, additionalInformation: {
8
+ userInfo: UserInfo;
9
+ attributes: Attributes;
10
+ }) => LogEvent;
11
+ export declare const generateEventMapper: (logEventMapper: LogEventMapper | undefined) => EventMapper<RawLog, LogEvent, NativeLog>;
@@ -0,0 +1,54 @@
1
+ import type { UserInfo } from '../sdk/UserInfoSingleton/types';
2
+ /**
3
+ * The entry point to use Datadog's Logs feature.
4
+ */
5
+ export declare type DdLogsType = {
6
+ /**
7
+ * Send a log with level debug.
8
+ * @param message: The message to send.
9
+ * @param context: The additional context to send.
10
+ */
11
+ debug(message: string, context?: object): Promise<void>;
12
+ /**
13
+ * Send a log with level info.
14
+ * @param message: The message to send.
15
+ * @param context: The additional context to send.
16
+ */
17
+ info(message: string, context?: object): Promise<void>;
18
+ /**
19
+ * Send a log with level warn.
20
+ * @param message: The message to send.
21
+ * @param context: The additional context to send.
22
+ */
23
+ warn(message: string, context?: object): Promise<void>;
24
+ /**
25
+ * Send a log with level error.
26
+ * @param message: The message to send.
27
+ * @param context: The additional context to send.
28
+ */
29
+ error(message: string, context?: object): Promise<void>;
30
+ };
31
+ /**
32
+ * Log input from developers
33
+ */
34
+ export declare type RawLog = {
35
+ message: string;
36
+ context: object;
37
+ status: LogStatus;
38
+ };
39
+ /**
40
+ * Log input for native SDKs
41
+ */
42
+ export declare type NativeLog = {
43
+ message: string;
44
+ context: object;
45
+ };
46
+ export declare type LogStatus = 'debug' | 'info' | 'warn' | 'error';
47
+ export declare type LogEvent = {
48
+ message: string;
49
+ context: object;
50
+ readonly status: LogStatus;
51
+ readonly userInfo: UserInfo;
52
+ readonly attributes?: object;
53
+ };
54
+ export declare type LogEventMapper = (logEvent: LogEvent) => LogEvent | null;
@@ -30,7 +30,7 @@ export declare type DdNativeSdkType = {
30
30
  * Set the user information.
31
31
  * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).
32
32
  */
33
- setUser(user: object): Promise<void>;
33
+ setUser(user: object): Promise<object>;
34
34
  /**
35
35
  * Set the tracking consent regarding the data collection.
36
36
  * @param trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
@@ -0,0 +1,36 @@
1
+ import type { GestureResponderEvent } from 'react-native';
2
+ import type { ActionEventMapper } from './eventMappers/actionEventMapper';
3
+ import type { ErrorEventMapper } from './eventMappers/errorEventMapper';
4
+ import type { ResourceEventMapper } from './eventMappers/resourceEventMapper';
5
+ import type { DdRumType, RumActionType, ResourceKind, ErrorSource } from './types';
6
+ declare class DdRumWrapper implements DdRumType {
7
+ private nativeRum;
8
+ private lastActionData?;
9
+ private errorEventMapper;
10
+ private resourceEventMapper;
11
+ private actionEventMapper;
12
+ startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;
13
+ stopView(key: string, context?: object, timestampMs?: number): Promise<void>;
14
+ startAction(type: RumActionType, name: string, context?: object, timestampMs?: number): Promise<void>;
15
+ stopAction(...args: [
16
+ type: RumActionType,
17
+ name: string,
18
+ context?: object,
19
+ timestampMs?: number
20
+ ] | [context?: object, timestampMs?: number]): Promise<void>;
21
+ private callNativeStopAction;
22
+ private getStopActionNativeCallArgs;
23
+ addAction(type: RumActionType, name: string, context?: object, timestampMs?: number, actionContext?: GestureResponderEvent): Promise<void>;
24
+ startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;
25
+ stopResource(key: string, statusCode: number, kind: ResourceKind, size?: number, context?: object, timestampMs?: number, resourceContext?: XMLHttpRequest): Promise<void>;
26
+ addError(message: string, source: ErrorSource, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;
27
+ addTiming(name: string): Promise<void>;
28
+ registerErrorEventMapper(errorEventMapper: ErrorEventMapper): void;
29
+ unregisterErrorEventMapper(): void;
30
+ registerResourceEventMapper(resourceEventMapper: ResourceEventMapper): void;
31
+ unregisterResourceEventMapper(): void;
32
+ registerActionEventMapper(actionEventMapper: ActionEventMapper): void;
33
+ unregisterActionEventMapper(): void;
34
+ }
35
+ export declare const DdRum: DdRumWrapper;
36
+ export {};
@@ -0,0 +1,21 @@
1
+ import type { GestureResponderEvent } from 'react-native';
2
+ import type { AdditionalEventDataForMapper } from '../../sdk/EventMappers/EventMapper';
3
+ import { EventMapper } from '../../sdk/EventMappers/EventMapper';
4
+ import type { RumActionType } from '../types';
5
+ declare type RawAction = {
6
+ readonly type: RumActionType;
7
+ readonly name: string;
8
+ context: object;
9
+ readonly timestampMs: number;
10
+ actionContext?: GestureResponderEvent;
11
+ };
12
+ declare type ActionEvent = RawAction & AdditionalEventDataForMapper;
13
+ declare type NativeAction = {
14
+ type: RumActionType;
15
+ name: string;
16
+ context: object;
17
+ timestampMs: number;
18
+ };
19
+ export declare type ActionEventMapper = (event: ActionEvent) => ActionEvent | null;
20
+ export declare const generateActionEventMapper: (eventMapper: ActionEventMapper | undefined) => EventMapper<RawAction, ActionEvent, NativeAction>;
21
+ export {};