@datadog/mobile-react-native-navigation 1.0.0-rc3 → 1.0.0-rc6
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.
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumReactNativeNavigationTracking.js +6 -6
- package/lib/commonjs/rum/instrumentation/DdRumReactNativeNavigationTracking.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumReactNativeNavigationTracking.js +6 -6
- package/lib/module/rum/instrumentation/DdRumReactNativeNavigationTracking.js.map +1 -1
- package/lib/typescript/core/src/DdSdkReactNative.d.ts +7 -6
- package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +15 -4
- package/lib/typescript/core/src/InternalLog.d.ts +6 -0
- package/lib/typescript/core/src/SdkVerbosity.d.ts +9 -0
- package/lib/typescript/core/src/TimeProvider.d.ts +20 -0
- package/lib/typescript/core/src/Timer.d.ts +3 -2
- package/lib/typescript/core/src/index.d.ts +3 -2
- package/lib/typescript/core/src/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
- package/lib/typescript/core/src/rum/instrumentation/DdRumErrorTracking.d.ts +3 -2
- package/lib/typescript/core/src/rum/instrumentation/DdRumResourceTracking.d.ts +13 -8
- package/lib/typescript/core/src/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
- package/lib/typescript/core/src/rum/instrumentation/DdRumXhr.d.ts +13 -3
- package/lib/typescript/core/src/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
- package/lib/typescript/core/src/types.d.ts +12 -11
- package/lib/typescript/core/src/version.d.ts +1 -0
- package/lib/typescript/react-native-navigation/src/rum/instrumentation/DdRumReactNativeNavigationTracking.d.ts +3 -3
- package/package.json +4 -4
- package/src/__tests__/rum/instrumentation/DdRumReactNativeNavigationTracking.test.tsx +59 -46
- package/src/index.tsx +4 -1
- package/src/rum/instrumentation/DdRumReactNativeNavigationTracking.tsx +71 -33
- package/lib/typescript/core/src/NativeSdkVerbosity.d.ts +0 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA","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 {
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA","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 {\n DdRumReactNativeNavigationTracking,\n ViewNamePredicate\n} from './rum/instrumentation/DdRumReactNativeNavigationTracking';\n\nexport { DdRumReactNativeNavigationTracking, ViewNamePredicate };\n"]}
|
|
@@ -5,19 +5,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.DdRumReactNativeNavigationTracking = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _mobileReactNative = require("@datadog/mobile-react-native");
|
|
9
9
|
|
|
10
10
|
var _reactNativeNavigation = require("react-native-navigation");
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
|
|
16
16
|
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
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.
|
|
20
|
-
*/
|
|
19
|
+
* Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.
|
|
20
|
+
*/
|
|
21
21
|
class DdRumReactNativeNavigationTracking {
|
|
22
22
|
/**
|
|
23
23
|
* Starts tracking the Navigation and sends a RUM View event every time a root View component appear/disappear.
|
|
@@ -34,7 +34,7 @@ class DdRumReactNativeNavigationTracking {
|
|
|
34
34
|
DdRumReactNativeNavigationTracking.originalCreateElement = original;
|
|
35
35
|
|
|
36
36
|
_react.default.createElement = (element, props, ...children) => {
|
|
37
|
-
if (props && props.componentId
|
|
37
|
+
if (props && props.componentId !== undefined && props.componentId !== null && !DdRumReactNativeNavigationTracking.trackedComponentIds.includes(props.componentId)) {
|
|
38
38
|
const componentId = props.componentId;
|
|
39
39
|
|
|
40
40
|
_reactNativeNavigation.Navigation.events().registerComponentListener({
|
|
@@ -70,7 +70,7 @@ class DdRumReactNativeNavigationTracking {
|
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
if (DdRumReactNativeNavigationTracking.originalCreateElement
|
|
73
|
+
if (DdRumReactNativeNavigationTracking.originalCreateElement !== undefined) {
|
|
74
74
|
_react.default.createElement = DdRumReactNativeNavigationTracking.originalCreateElement;
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -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;;
|
|
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"]}
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["DdRumReactNativeNavigationTracking","ViewNamePredicate"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["DdRumReactNativeNavigationTracking","ViewNamePredicate"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SACIA,kCADJ,EAEIC,iBAFJ,QAGO,0DAHP;AAKA,SAASD,kCAAT,EAA6CC,iBAA7C","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 {\n DdRumReactNativeNavigationTracking,\n ViewNamePredicate\n} from './rum/instrumentation/DdRumReactNativeNavigationTracking';\n\nexport { DdRumReactNativeNavigationTracking, ViewNamePredicate };\n"]}
|
|
@@ -5,13 +5,13 @@ 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 React from 'react';
|
|
9
|
-
import { Navigation } from 'react-native-navigation';
|
|
10
8
|
import { DdRum } from '@datadog/mobile-react-native';
|
|
9
|
+
import { Navigation } from 'react-native-navigation';
|
|
10
|
+
import React from 'react';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.
|
|
14
|
-
*/
|
|
13
|
+
* Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.
|
|
14
|
+
*/
|
|
15
15
|
export class DdRumReactNativeNavigationTracking {
|
|
16
16
|
/**
|
|
17
17
|
* Starts tracking the Navigation and sends a RUM View event every time a root View component appear/disappear.
|
|
@@ -28,7 +28,7 @@ export class DdRumReactNativeNavigationTracking {
|
|
|
28
28
|
DdRumReactNativeNavigationTracking.originalCreateElement = original;
|
|
29
29
|
|
|
30
30
|
React.createElement = (element, props, ...children) => {
|
|
31
|
-
if (props && props.componentId
|
|
31
|
+
if (props && props.componentId !== undefined && props.componentId !== null && !DdRumReactNativeNavigationTracking.trackedComponentIds.includes(props.componentId)) {
|
|
32
32
|
const componentId = props.componentId;
|
|
33
33
|
Navigation.events().registerComponentListener({
|
|
34
34
|
componentDidAppear: event => {
|
|
@@ -61,7 +61,7 @@ export class DdRumReactNativeNavigationTracking {
|
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
if (DdRumReactNativeNavigationTracking.originalCreateElement
|
|
64
|
+
if (DdRumReactNativeNavigationTracking.originalCreateElement !== undefined) {
|
|
65
65
|
React.createElement = DdRumReactNativeNavigationTracking.originalCreateElement;
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdRumReactNativeNavigationTracking.tsx"],"names":["
|
|
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,GAA2DF,QAA3D;;AACAP,IAAAA,KAAK,CAACQ,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,CAACZ,kCAAkC,CAACc,mBAAnC,CAAuDC,QAAvD,CACGL,KAAK,CAACE,WADT,CAJL,EAOE;AACE,cAAMA,WAAW,GAAGF,KAAK,CAACE,WAA1B;AACAd,QAAAA,UAAU,CAACkB,MAAX,GAAoBC,yBAApB,CACI;AACIC,UAAAA,kBAAkB,EACdC,KADgB,IAEf;AAAA;;AACD,kBAAMC,SAAS,GACXpB,kCAAkC,CAACE,iBADvC;AAEA,kBAAMmB,UAAU,iBACZD,SAAS,CAACD,KAAD,EAAQA,KAAK,CAACG,aAAd,CADG,mDAEZH,KAAK,CAACG,aAFV;AAGAzB,YAAAA,KAAK,CAAC0B,SAAN,CAAgBX,WAAhB,EAA6BS,UAA7B;AACH,WAVL;AAWIG,UAAAA,qBAAqB,EAAE,MAAM;AACzB3B,YAAAA,KAAK,CAAC4B,QAAN,CAAeb,WAAf;AACH;AAbL,SADJ,EAgBIA,WAhBJ;AAkBAZ,QAAAA,kCAAkC,CAACc,mBAAnC,CAAuDY,IAAvD,CACId,WADJ;AAGH;;AAED,aAAON,QAAQ,CAACG,OAAD,EAAUC,KAAV,EAAiB,GAAGC,QAApB,CAAf;AACH,KAtCD;;AAuCAX,IAAAA,kCAAkC,CAACK,UAAnC,GAAgD,IAAhD;AACAL,IAAAA,kCAAkC,CAACE,iBAAnC,GAAuDA,iBAAvD;AACH;AAED;AACJ;AACA;;;AACuB,SAAZyB,YAAY,GAAS;AACxB,QAAI,CAAC3B,kCAAkC,CAACK,UAAxC,EAAoD;AAChD;AACH;;AACD,QACIL,kCAAkC,CAACQ,qBAAnC,KACAK,SAFJ,EAGE;AACEd,MAAAA,KAAK,CAACQ,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,10 +1,11 @@
|
|
|
1
|
-
import type { DdSdkReactNativeConfiguration } from
|
|
2
|
-
import type { TrackingConsent } from
|
|
1
|
+
import type { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
|
|
2
|
+
import type { TrackingConsent } from './TrackingConsent';
|
|
3
3
|
/**
|
|
4
4
|
* This class initializes the Datadog SDK, and sets up communication with the server.
|
|
5
5
|
*/
|
|
6
6
|
export declare class DdSdkReactNative {
|
|
7
7
|
private static readonly DD_SOURCE_KEY;
|
|
8
|
+
private static readonly DD_SDK_VERSION;
|
|
8
9
|
private static readonly DD_SERVICE_NAME;
|
|
9
10
|
private static readonly DD_SDK_VERBOSITY_KEY;
|
|
10
11
|
private static readonly DD_NATIVE_VIEW_TRACKING_KEY;
|
|
@@ -17,10 +18,10 @@ export declare class DdSdkReactNative {
|
|
|
17
18
|
private static readonly NATIVE_LONG_TASK_THRESHOLD_MS;
|
|
18
19
|
private static wasInitialized;
|
|
19
20
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
* Initializes the Datadog SDK.
|
|
22
|
+
* @param configuration the configuration for the SDK library
|
|
23
|
+
* @returns a Promise.
|
|
24
|
+
*/
|
|
24
25
|
static initialize(configuration: DdSdkReactNativeConfiguration): Promise<void>;
|
|
25
26
|
/**
|
|
26
27
|
* Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TrackingConsent } from './TrackingConsent';
|
|
2
|
-
import type { NativeSdkVerbosity } from './NativeSdkVerbosity';
|
|
3
1
|
import type { ProxyConfiguration } from './ProxyConfiguration';
|
|
2
|
+
import type { SdkVerbosity } from './SdkVerbosity';
|
|
3
|
+
import { TrackingConsent } from './TrackingConsent';
|
|
4
4
|
/**
|
|
5
5
|
* The SDK configuration class.
|
|
6
6
|
* It will be used to configure the SDK functionality at initialization.
|
|
@@ -14,9 +14,20 @@ export declare class DdSdkReactNativeConfiguration {
|
|
|
14
14
|
readonly trackErrors: boolean;
|
|
15
15
|
readonly trackingConsent: TrackingConsent;
|
|
16
16
|
nativeCrashReportEnabled: boolean;
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.
|
|
19
|
+
*/
|
|
20
|
+
sampleRate?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Percentage of sampled RUM sessions. Range `0`-`100`.
|
|
23
|
+
*/
|
|
24
|
+
sessionSamplingRate: number;
|
|
25
|
+
/**
|
|
26
|
+
* Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
|
|
27
|
+
*/
|
|
28
|
+
resourceTracingSamplingRate: number;
|
|
18
29
|
site: string;
|
|
19
|
-
verbosity:
|
|
30
|
+
verbosity: SdkVerbosity | undefined;
|
|
20
31
|
nativeViewTracking: boolean;
|
|
21
32
|
proxyConfig?: ProxyConfiguration;
|
|
22
33
|
serviceName?: string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Timestamp structure holding the
|
|
3
|
+
*/
|
|
4
|
+
export declare type Timestamp = {
|
|
5
|
+
unix: number;
|
|
6
|
+
react_native: number | null;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Simple class providing timestamps in milliseconds.
|
|
10
|
+
* If available, it will use the `performance.now()` method, and will fallback on `Date.now()` otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare class TimeProvider {
|
|
13
|
+
private canUsePerformanceNow;
|
|
14
|
+
/** Keeps an average offset between the unix time and the provided timestamp. */
|
|
15
|
+
private baseOffset;
|
|
16
|
+
constructor();
|
|
17
|
+
getTimestamp(): Timestamp;
|
|
18
|
+
now(): number;
|
|
19
|
+
private performanceNow;
|
|
20
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { TimeProvider } from './TimeProvider';
|
|
1
2
|
/**
|
|
2
3
|
* Simple timer which records time ticks. Shouldn't be re-used once stopped.
|
|
3
4
|
* All timestamps/durations returned are in milliseconds.
|
|
4
5
|
*/
|
|
5
6
|
export default class Timer {
|
|
7
|
+
private timeProvider;
|
|
6
8
|
private times;
|
|
9
|
+
constructor(timeProvider?: TimeProvider);
|
|
7
10
|
get startTime(): number;
|
|
8
11
|
get stopTime(): number;
|
|
9
12
|
start(): void;
|
|
@@ -14,7 +17,5 @@ export default class Timer {
|
|
|
14
17
|
timeAt(label: string): number;
|
|
15
18
|
reset(): void;
|
|
16
19
|
private durationBetweenTicks;
|
|
17
|
-
private performanceNow;
|
|
18
|
-
private canUsePerformanceNow;
|
|
19
20
|
private checkLabelExists;
|
|
20
21
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
2
1
|
import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
|
|
3
2
|
import { DdSdkReactNative } from './DdSdkReactNative';
|
|
4
3
|
import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
|
|
4
|
+
import { SdkVerbosity } from './SdkVerbosity';
|
|
5
5
|
import { TrackingConsent } from './TrackingConsent';
|
|
6
|
-
|
|
6
|
+
import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
7
|
+
export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, ProxyConfiguration, ProxyType, TrackingConsent, SdkVerbosity };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type EventsInterceptor from './EventsInterceptor';
|
|
2
2
|
export declare const UNKNOWN_TARGET_NAME = "unknown_target";
|
|
3
3
|
export declare class DdEventsInterceptor implements EventsInterceptor {
|
|
4
|
+
static ACTION_EVENT_DROPPED_WARN_MESSAGE: string;
|
|
4
5
|
private debouncingStartedTimestamp;
|
|
5
6
|
interceptOnPress(...args: any[]): void;
|
|
6
7
|
private handleTargetEvent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Provides RUM auto-instrumentation feature to track errors as RUM events.
|
|
3
|
-
*/
|
|
2
|
+
* Provides RUM auto-instrumentation feature to track errors as RUM events.
|
|
3
|
+
*/
|
|
4
4
|
export declare class DdRumErrorTracking {
|
|
5
5
|
private static isTracking;
|
|
6
6
|
private static isInDefaultErrorHandler;
|
|
@@ -12,5 +12,6 @@ export declare class DdRumErrorTracking {
|
|
|
12
12
|
static startTracking(): void;
|
|
13
13
|
static onGlobalError(error: any, isFatal?: boolean): void;
|
|
14
14
|
static onConsoleError(...params: unknown[]): void;
|
|
15
|
+
private static getErrorMessage;
|
|
15
16
|
private static getErrorStackTrace;
|
|
16
17
|
}
|
|
@@ -1,22 +1,27 @@
|
|
|
1
|
+
/// <reference types="react-native" />
|
|
1
2
|
export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
|
|
2
3
|
export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
|
|
3
4
|
export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
|
|
5
|
+
export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
|
|
4
6
|
export declare const ORIGIN_RUM = "rum";
|
|
7
|
+
export declare const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
|
|
8
|
+
export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
|
|
5
9
|
/**
|
|
6
|
-
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
|
|
7
|
-
*/
|
|
10
|
+
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
|
|
11
|
+
*/
|
|
8
12
|
export declare class DdRumResourceTracking {
|
|
9
13
|
private static isTracking;
|
|
14
|
+
private static tracingSamplingRate;
|
|
10
15
|
private static originalXhrOpen;
|
|
11
16
|
private static originalXhrSend;
|
|
12
17
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
static startTracking(): void;
|
|
18
|
+
* Starts tracking resources and sends a RUM Resource event every time a network request is detected.
|
|
19
|
+
*/
|
|
20
|
+
static startTracking(tracingSamplingRate: number): void;
|
|
16
21
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
static startTrackingInternal(xhrType:
|
|
22
|
+
* Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.
|
|
23
|
+
*/
|
|
24
|
+
static startTrackingInternal(xhrType: typeof XMLHttpRequest, tracingSamplingRate: number): void;
|
|
20
25
|
static stopTracking(): void;
|
|
21
26
|
static proxyXhr(xhrType: any): void;
|
|
22
27
|
private static proxyOpen;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Provides RUM auto-instrumentation feature to track user interaction as RUM events.
|
|
3
|
-
* For now we are only covering the "onPress" events.
|
|
4
|
-
*/
|
|
2
|
+
* Provides RUM auto-instrumentation feature to track user interaction as RUM events.
|
|
3
|
+
* For now we are only covering the "onPress" events.
|
|
4
|
+
*/
|
|
5
5
|
export declare class DdRumUserInteractionTracking {
|
|
6
6
|
private static isTracking;
|
|
7
7
|
private static eventsInterceptor;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react-native" />
|
|
2
|
-
import type Timer from
|
|
2
|
+
import type Timer from '../../Timer';
|
|
3
3
|
export interface DdRumXhr extends XMLHttpRequest {
|
|
4
4
|
_datadog_xhr: DdRumXhrContext;
|
|
5
5
|
}
|
|
@@ -8,6 +8,16 @@ export interface DdRumXhrContext {
|
|
|
8
8
|
url: string;
|
|
9
9
|
reported: boolean;
|
|
10
10
|
timer: Timer;
|
|
11
|
-
|
|
12
|
-
traceId: string;
|
|
11
|
+
tracingAttributes: DdRumResourceTracingAttributes;
|
|
13
12
|
}
|
|
13
|
+
export declare type DdRumResourceTracingAttributes = {
|
|
14
|
+
tracingStrategy: 'KEEP';
|
|
15
|
+
traceId: string;
|
|
16
|
+
spanId: string;
|
|
17
|
+
samplingPriorityHeader: '1';
|
|
18
|
+
} | {
|
|
19
|
+
tracingStrategy: 'DISCARD';
|
|
20
|
+
traceId?: void;
|
|
21
|
+
spanId?: void;
|
|
22
|
+
samplingPriorityHeader: '0';
|
|
23
|
+
};
|
|
@@ -74,14 +74,14 @@ export declare type DdTraceType = {
|
|
|
74
74
|
* Start a span, and returns a unique identifier for the span.
|
|
75
75
|
* @param operation: The operation name of the span.
|
|
76
76
|
* @param context: The additional context to send.
|
|
77
|
-
* @param timestampMs: The timestamp when the operation started (in milliseconds).
|
|
77
|
+
* @param timestampMs: The timestamp when the operation started (in milliseconds). If not provided, current timestamp will be used.
|
|
78
78
|
*/
|
|
79
79
|
startSpan(operation: string, context?: object, timestampMs?: number): Promise<string>;
|
|
80
80
|
/**
|
|
81
81
|
* Finish a started span.
|
|
82
82
|
* @param spanId: The unique identifier of the span.
|
|
83
83
|
* @param context: The additional context to send.
|
|
84
|
-
* @param timestampMs: The timestamp when the operation stopped (in milliseconds).
|
|
84
|
+
* @param timestampMs: The timestamp when the operation stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
85
85
|
*/
|
|
86
86
|
finishSpan(spanId: string, context?: object, timestampMs?: number): Promise<void>;
|
|
87
87
|
};
|
|
@@ -94,14 +94,14 @@ export declare type DdRumType = {
|
|
|
94
94
|
* @param key: The view unique key identifier.
|
|
95
95
|
* @param name: The view name.
|
|
96
96
|
* @param context: The additional context to send.
|
|
97
|
-
* @param timestampMs: The timestamp when the view started (in milliseconds).
|
|
97
|
+
* @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
|
|
98
98
|
*/
|
|
99
99
|
startView(key: string, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
100
100
|
/**
|
|
101
101
|
* Stop tracking a RUM View.
|
|
102
102
|
* @param key: The view unique key identifier.
|
|
103
103
|
* @param context: The additional context to send.
|
|
104
|
-
* @param timestampMs: The timestamp when the view stopped (in milliseconds).
|
|
104
|
+
* @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
105
105
|
*/
|
|
106
106
|
stopView(key: string, context?: object, timestampMs?: number): Promise<void>;
|
|
107
107
|
/**
|
|
@@ -109,13 +109,13 @@ export declare type DdRumType = {
|
|
|
109
109
|
* @param type: The action type (tap, scroll, swipe, click, custom).
|
|
110
110
|
* @param name: The action name.
|
|
111
111
|
* @param context: The additional context to send.
|
|
112
|
-
* @param timestampMs: The timestamp when the action started (in milliseconds).
|
|
112
|
+
* @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
|
|
113
113
|
*/
|
|
114
114
|
startAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
115
115
|
/**
|
|
116
116
|
* Stop tracking the ongoing RUM Action.
|
|
117
117
|
* @param context: The additional context to send.
|
|
118
|
-
* @param timestampMs: The timestamp when the action stopped (in milliseconds).
|
|
118
|
+
* @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
119
119
|
*/
|
|
120
120
|
stopAction(context?: object, timestampMs?: number): Promise<void>;
|
|
121
121
|
/**
|
|
@@ -123,7 +123,7 @@ export declare type DdRumType = {
|
|
|
123
123
|
* @param type: The action type (tap, scroll, swipe, click, custom).
|
|
124
124
|
* @param name: The action name.
|
|
125
125
|
* @param context: The additional context to send.
|
|
126
|
-
* @param timestampMs: The timestamp when the action occurred (in milliseconds).
|
|
126
|
+
* @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
127
127
|
*/
|
|
128
128
|
addAction(type: string, name: string, context?: object, timestampMs?: number): Promise<void>;
|
|
129
129
|
/**
|
|
@@ -132,7 +132,7 @@ export declare type DdRumType = {
|
|
|
132
132
|
* @param method: The resource method (GET, POST, …).
|
|
133
133
|
* @param url: The resource url.
|
|
134
134
|
* @param context: The additional context to send.
|
|
135
|
-
* @param timestampMs: The timestamp when the resource started (in milliseconds).
|
|
135
|
+
* @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
|
|
136
136
|
*/
|
|
137
137
|
startResource(key: string, method: string, url: string, context?: object, timestampMs?: number): Promise<void>;
|
|
138
138
|
/**
|
|
@@ -140,17 +140,18 @@ export declare type DdRumType = {
|
|
|
140
140
|
* @param key: The resource unique key identifier.
|
|
141
141
|
* @param statusCode: The resource status code.
|
|
142
142
|
* @param kind: The resource's kind (xhr, document, image, css, font, …).
|
|
143
|
+
* @param size: The resource size in bytes. If size is unknown, use -1.
|
|
143
144
|
* @param context: The additional context to send.
|
|
144
|
-
* @param timestampMs: The timestamp when the resource stopped (in milliseconds).
|
|
145
|
+
* @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
|
|
145
146
|
*/
|
|
146
|
-
stopResource(key: string, statusCode: number, kind: string, context?: object, timestampMs?: number): Promise<void>;
|
|
147
|
+
stopResource(key: string, statusCode: number, kind: string, size?: number, context?: object, timestampMs?: number): Promise<void>;
|
|
147
148
|
/**
|
|
148
149
|
* Add a RUM Error.
|
|
149
150
|
* @param message: The error message.
|
|
150
151
|
* @param source: The error source (network, source, console, logger, …).
|
|
151
152
|
* @param stacktrace: The error stacktrace.
|
|
152
153
|
* @param context: The additional context to send.
|
|
153
|
-
* @param timestampMs: The timestamp when the error occurred (in milliseconds).
|
|
154
|
+
* @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
154
155
|
*/
|
|
155
156
|
addError(message: string, source: string, stacktrace: string, context?: object, timestampMs?: number): Promise<void>;
|
|
156
157
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "1.0.0-rc6";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ComponentDidAppearEvent } from 'react-native-navigation';
|
|
1
|
+
import type { ComponentDidAppearEvent } from 'react-native-navigation';
|
|
2
2
|
export declare type ViewNamePredicate = (event: ComponentDidAppearEvent, trackedName: string) => string;
|
|
3
3
|
/**
|
|
4
|
-
* Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.
|
|
5
|
-
*/
|
|
4
|
+
* Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.
|
|
5
|
+
*/
|
|
6
6
|
export declare class DdRumReactNativeNavigationTracking {
|
|
7
7
|
private static isTracking;
|
|
8
8
|
private static trackedComponentIds;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/mobile-react-native-navigation",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc6",
|
|
4
4
|
"description": "A client-side React Native module to interact with Datadog",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"prepare": "bob build"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@datadog/mobile-react-native": "^1.0.0-
|
|
39
|
+
"@datadog/mobile-react-native": "^1.0.0-rc6",
|
|
40
40
|
"react-native-gesture-handler": "1.10.3",
|
|
41
41
|
"react-native-navigation": "7.13.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@datadog/mobile-react-native": "^1.0.0-beta4",
|
|
45
45
|
"react": ">=16.13.1",
|
|
46
|
-
"react-native": "
|
|
46
|
+
"react-native": ">=0.63.4 <1.0",
|
|
47
47
|
"react-native-navigation": "^7.5.0"
|
|
48
48
|
},
|
|
49
49
|
"jest": {
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
]
|
|
71
71
|
]
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "db2b48ab61c67e64567b91fc5d858473bf64d448"
|
|
74
74
|
}
|
|
@@ -4,39 +4,39 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import React from 'react';
|
|
8
7
|
import { DdRum } from '@datadog/mobile-react-native';
|
|
9
|
-
import { ComponentDidAppearEvent } from 'react-native-navigation';
|
|
10
|
-
import
|
|
8
|
+
import type { ComponentDidAppearEvent } from 'react-native-navigation';
|
|
9
|
+
import React from 'react';
|
|
10
|
+
|
|
11
|
+
import type { ViewNamePredicate } from '../../../rum/instrumentation/DdRumReactNativeNavigationTracking';
|
|
12
|
+
import { DdRumReactNativeNavigationTracking } from '../../../rum/instrumentation/DdRumReactNativeNavigationTracking';
|
|
11
13
|
|
|
12
14
|
jest.mock('@datadog/mobile-react-native', () => {
|
|
13
15
|
return {
|
|
14
16
|
DdRum: {
|
|
15
|
-
startView: jest.fn().mockImplementation(() => {
|
|
16
|
-
stopView: jest.fn().mockImplementation(() => {
|
|
17
|
-
}
|
|
17
|
+
startView: jest.fn().mockImplementation(() => {}),
|
|
18
|
+
stopView: jest.fn().mockImplementation(() => {})
|
|
19
|
+
}
|
|
18
20
|
};
|
|
19
21
|
});
|
|
20
22
|
jest.useFakeTimers();
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
const mockRegisterComponentListener = jest.fn().mockImplementation(() => {});
|
|
23
25
|
jest.mock('react-native-navigation', () => {
|
|
24
26
|
return {
|
|
25
27
|
Navigation: {
|
|
26
28
|
events: jest.fn().mockImplementation(() => {
|
|
27
29
|
return {
|
|
28
30
|
registerComponentListener: mockRegisterComponentListener
|
|
29
|
-
}
|
|
31
|
+
};
|
|
30
32
|
})
|
|
31
33
|
}
|
|
32
|
-
}
|
|
34
|
+
};
|
|
33
35
|
});
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
let originalCreateMethod: Function
|
|
37
|
+
let originalCreateMethod: typeof React.createElement;
|
|
37
38
|
|
|
38
39
|
beforeEach(() => {
|
|
39
|
-
|
|
40
40
|
jest.setTimeout(20000);
|
|
41
41
|
DdRum.startView.mockClear();
|
|
42
42
|
DdRum.stopView.mockClear();
|
|
@@ -44,12 +44,12 @@ beforeEach(() => {
|
|
|
44
44
|
|
|
45
45
|
DdRumReactNativeNavigationTracking['trackedComponentIds'] = [];
|
|
46
46
|
DdRumReactNativeNavigationTracking['isTracking'] = false;
|
|
47
|
-
originalCreateMethod = React.createElement
|
|
48
|
-
})
|
|
47
|
+
originalCreateMethod = React.createElement;
|
|
48
|
+
});
|
|
49
49
|
|
|
50
50
|
afterEach(() => {
|
|
51
|
-
React.createElement = originalCreateMethod
|
|
52
|
-
})
|
|
51
|
+
React.createElement = originalCreateMethod;
|
|
52
|
+
});
|
|
53
53
|
|
|
54
54
|
// Unit tests
|
|
55
55
|
|
|
@@ -58,99 +58,112 @@ it('M not register W props are missing + startTracking()', async () => {
|
|
|
58
58
|
DdRumReactNativeNavigationTracking.startTracking();
|
|
59
59
|
|
|
60
60
|
// WHEN
|
|
61
|
-
|
|
61
|
+
React.createElement('View', null);
|
|
62
62
|
|
|
63
63
|
// THEN
|
|
64
64
|
expect(mockRegisterComponentListener).toBeCalledTimes(0);
|
|
65
|
-
})
|
|
65
|
+
});
|
|
66
66
|
|
|
67
67
|
it('M not register W componentId is missing + startTracking()', async () => {
|
|
68
68
|
// GIVEN
|
|
69
69
|
DdRumReactNativeNavigationTracking.startTracking();
|
|
70
70
|
|
|
71
71
|
// WHEN
|
|
72
|
-
|
|
72
|
+
React.createElement('View', { foo: 'bar' });
|
|
73
73
|
|
|
74
74
|
// THEN
|
|
75
75
|
expect(mockRegisterComponentListener).toBeCalledTimes(0);
|
|
76
|
-
})
|
|
76
|
+
});
|
|
77
77
|
|
|
78
78
|
it('M register only once W startTracking()', async () => {
|
|
79
79
|
// GIVEN
|
|
80
|
-
|
|
80
|
+
const componentId = 'component42';
|
|
81
81
|
DdRumReactNativeNavigationTracking.startTracking();
|
|
82
82
|
|
|
83
83
|
// WHEN
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
React.createElement('View', {
|
|
85
|
+
componentId
|
|
86
|
+
});
|
|
87
|
+
React.createElement('View', {
|
|
88
|
+
componentId,
|
|
89
|
+
something: 'else'
|
|
90
|
+
});
|
|
86
91
|
|
|
87
92
|
// THEN
|
|
88
93
|
expect(mockRegisterComponentListener.mock.calls.length).toBe(1);
|
|
89
|
-
})
|
|
94
|
+
});
|
|
90
95
|
|
|
91
96
|
it('M restore original createElement method W stopTracking()', async () => {
|
|
92
97
|
// GIVEN
|
|
93
|
-
|
|
98
|
+
const componentId = 'component42';
|
|
94
99
|
DdRumReactNativeNavigationTracking.startTracking();
|
|
95
100
|
|
|
96
101
|
// WHEN
|
|
97
102
|
DdRumReactNativeNavigationTracking.stopTracking();
|
|
98
|
-
|
|
103
|
+
React.createElement('View', {
|
|
104
|
+
componentId
|
|
105
|
+
});
|
|
99
106
|
|
|
100
107
|
// THEN
|
|
101
108
|
expect(mockRegisterComponentListener.mock.calls.length).toBe(0);
|
|
102
|
-
})
|
|
109
|
+
});
|
|
103
110
|
|
|
104
111
|
it('M send a RUM ViewEvent W startTracking() componentDidAppear', async () => {
|
|
105
112
|
// GIVEN
|
|
106
|
-
|
|
113
|
+
const componentId = 'component42';
|
|
107
114
|
DdRumReactNativeNavigationTracking.startTracking();
|
|
108
115
|
|
|
109
116
|
// WHEN
|
|
110
|
-
|
|
117
|
+
React.createElement('View', {
|
|
118
|
+
componentId
|
|
119
|
+
});
|
|
111
120
|
const listener = mockRegisterComponentListener.mock.calls[0][0];
|
|
112
|
-
const componentName =
|
|
113
|
-
listener.componentDidAppear({ componentName
|
|
121
|
+
const componentName = 'some-name';
|
|
122
|
+
listener.componentDidAppear({ componentName });
|
|
114
123
|
|
|
115
124
|
// THEN
|
|
116
125
|
expect(DdRum.startView.mock.calls.length).toBe(1);
|
|
117
126
|
expect(DdRum.startView.mock.calls[0][0]).toBe(componentId);
|
|
118
127
|
expect(DdRum.startView.mock.calls[0][1]).toBe(componentName);
|
|
119
128
|
expect(DdRum.startView.mock.calls[0][2]).toBeUndefined();
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
});
|
|
123
130
|
|
|
124
131
|
it('M send a RUM ViewEvent W startTracking() componentDidAppear { custom viewPredicate }', async () => {
|
|
125
132
|
// GIVEN
|
|
126
|
-
|
|
127
|
-
const customViewName =
|
|
128
|
-
const predicate: ViewNamePredicate = function (
|
|
129
|
-
|
|
133
|
+
const componentId = 'component42';
|
|
134
|
+
const customViewName = 'custom_view_name';
|
|
135
|
+
const predicate: ViewNamePredicate = function (
|
|
136
|
+
_event: ComponentDidAppearEvent,
|
|
137
|
+
_trackedName: string
|
|
138
|
+
) {
|
|
139
|
+
return customViewName;
|
|
130
140
|
};
|
|
131
141
|
DdRumReactNativeNavigationTracking.startTracking(predicate);
|
|
132
142
|
|
|
133
143
|
// WHEN
|
|
134
|
-
|
|
144
|
+
React.createElement('View', {
|
|
145
|
+
componentId
|
|
146
|
+
});
|
|
135
147
|
const listener = mockRegisterComponentListener.mock.calls[0][0];
|
|
136
|
-
const componentName =
|
|
137
|
-
listener.componentDidAppear({ componentName
|
|
148
|
+
const componentName = 'some-name';
|
|
149
|
+
listener.componentDidAppear({ componentName });
|
|
138
150
|
|
|
139
151
|
// THEN
|
|
140
152
|
expect(DdRum.startView.mock.calls.length).toBe(1);
|
|
141
153
|
expect(DdRum.startView.mock.calls[0][0]).toBe(componentId);
|
|
142
154
|
expect(DdRum.startView.mock.calls[0][1]).toBe(customViewName);
|
|
143
155
|
expect(DdRum.startView.mock.calls[0][2]).toBeUndefined();
|
|
144
|
-
})
|
|
156
|
+
});
|
|
145
157
|
|
|
146
158
|
it('M send a RUM ViewEvent W startTracking() componentDidDisappear', async () => {
|
|
147
|
-
|
|
148
159
|
// GIVEN
|
|
149
|
-
|
|
160
|
+
const componentId = 'component42';
|
|
150
161
|
DdRumReactNativeNavigationTracking.startTracking();
|
|
151
162
|
|
|
152
163
|
// WHEN
|
|
153
|
-
|
|
164
|
+
React.createElement('View', {
|
|
165
|
+
componentId
|
|
166
|
+
});
|
|
154
167
|
const listener = mockRegisterComponentListener.mock.calls[0][0];
|
|
155
168
|
listener.componentDidDisappear();
|
|
156
169
|
|
|
@@ -158,4 +171,4 @@ it('M send a RUM ViewEvent W startTracking() componentDidDisappear', async () =>
|
|
|
158
171
|
expect(DdRum.stopView.mock.calls.length).toBe(1);
|
|
159
172
|
expect(DdRum.stopView.mock.calls[0][0]).toBe(componentId);
|
|
160
173
|
expect(DdRum.stopView.mock.calls[0][1]).toBeUndefined();
|
|
161
|
-
})
|
|
174
|
+
});
|
package/src/index.tsx
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
DdRumReactNativeNavigationTracking,
|
|
9
|
+
ViewNamePredicate
|
|
10
|
+
} from './rum/instrumentation/DdRumReactNativeNavigationTracking';
|
|
8
11
|
|
|
9
12
|
export { DdRumReactNativeNavigationTracking, ViewNamePredicate };
|
|
@@ -4,58 +4,84 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import React from 'react'
|
|
8
|
-
import { ComponentDidAppearEvent, Navigation } from 'react-native-navigation';
|
|
9
7
|
import { DdRum } from '@datadog/mobile-react-native';
|
|
8
|
+
import type { ComponentDidAppearEvent } from 'react-native-navigation';
|
|
9
|
+
import { Navigation } from 'react-native-navigation';
|
|
10
|
+
import React from 'react';
|
|
10
11
|
|
|
11
|
-
export type ViewNamePredicate = (
|
|
12
|
+
export type ViewNamePredicate = (
|
|
13
|
+
event: ComponentDidAppearEvent,
|
|
14
|
+
trackedName: string
|
|
15
|
+
) => string;
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
|
-
* Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.
|
|
15
|
-
*/
|
|
18
|
+
* Provides RUM integration for the [React Native Navigation](https://wix.github.io/react-native-navigation) API.
|
|
19
|
+
*/
|
|
16
20
|
export class DdRumReactNativeNavigationTracking {
|
|
17
|
-
|
|
18
|
-
private static
|
|
19
|
-
private static
|
|
20
|
-
private static originalCreateElement: any = undefined
|
|
21
|
+
private static isTracking = false;
|
|
22
|
+
private static trackedComponentIds: Array<any> = [];
|
|
23
|
+
private static originalCreateElement: any = undefined;
|
|
21
24
|
|
|
22
25
|
private static viewNamePredicate: ViewNamePredicate;
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* Starts tracking the Navigation and sends a RUM View event every time a root View component appear/disappear.
|
|
26
29
|
*/
|
|
27
|
-
static startTracking(
|
|
30
|
+
static startTracking(
|
|
31
|
+
viewNamePredicate: ViewNamePredicate = function (
|
|
32
|
+
_event: ComponentDidAppearEvent,
|
|
33
|
+
trackedName: string
|
|
34
|
+
) {
|
|
35
|
+
return trackedName;
|
|
36
|
+
}
|
|
37
|
+
): void {
|
|
28
38
|
// extra safety to avoid wrapping more than 1 time this function
|
|
29
39
|
if (DdRumReactNativeNavigationTracking.isTracking) {
|
|
30
|
-
return
|
|
40
|
+
return;
|
|
31
41
|
}
|
|
32
|
-
const original = React.createElement
|
|
33
|
-
DdRumReactNativeNavigationTracking.originalCreateElement = original
|
|
34
|
-
React.createElement = (
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
const original = React.createElement;
|
|
43
|
+
DdRumReactNativeNavigationTracking.originalCreateElement = original;
|
|
44
|
+
React.createElement = (
|
|
45
|
+
element: any,
|
|
46
|
+
props: any,
|
|
47
|
+
...children: any
|
|
48
|
+
): any => {
|
|
49
|
+
if (
|
|
50
|
+
props &&
|
|
51
|
+
props.componentId !== undefined &&
|
|
52
|
+
props.componentId !== null &&
|
|
53
|
+
!DdRumReactNativeNavigationTracking.trackedComponentIds.includes(
|
|
54
|
+
props.componentId
|
|
55
|
+
)
|
|
37
56
|
) {
|
|
38
|
-
const componentId = props.componentId
|
|
57
|
+
const componentId = props.componentId;
|
|
39
58
|
Navigation.events().registerComponentListener(
|
|
40
59
|
{
|
|
41
|
-
componentDidAppear: (
|
|
42
|
-
|
|
43
|
-
|
|
60
|
+
componentDidAppear: (
|
|
61
|
+
event: ComponentDidAppearEvent
|
|
62
|
+
) => {
|
|
63
|
+
const predicate =
|
|
64
|
+
DdRumReactNativeNavigationTracking.viewNamePredicate;
|
|
65
|
+
const screenName =
|
|
66
|
+
predicate(event, event.componentName) ??
|
|
67
|
+
event.componentName;
|
|
44
68
|
DdRum.startView(componentId, screenName);
|
|
45
69
|
},
|
|
46
70
|
componentDidDisappear: () => {
|
|
47
71
|
DdRum.stopView(componentId);
|
|
48
|
-
}
|
|
72
|
+
}
|
|
49
73
|
},
|
|
50
74
|
componentId
|
|
51
75
|
);
|
|
52
|
-
DdRumReactNativeNavigationTracking.trackedComponentIds.push(
|
|
76
|
+
DdRumReactNativeNavigationTracking.trackedComponentIds.push(
|
|
77
|
+
componentId
|
|
78
|
+
);
|
|
53
79
|
}
|
|
54
80
|
|
|
55
|
-
return original(element, props, ...children)
|
|
56
|
-
}
|
|
57
|
-
DdRumReactNativeNavigationTracking.isTracking = true
|
|
58
|
-
DdRumReactNativeNavigationTracking.viewNamePredicate = viewNamePredicate
|
|
81
|
+
return original(element, props, ...children);
|
|
82
|
+
};
|
|
83
|
+
DdRumReactNativeNavigationTracking.isTracking = true;
|
|
84
|
+
DdRumReactNativeNavigationTracking.viewNamePredicate = viewNamePredicate;
|
|
59
85
|
}
|
|
60
86
|
|
|
61
87
|
/**
|
|
@@ -63,13 +89,25 @@ export class DdRumReactNativeNavigationTracking {
|
|
|
63
89
|
*/
|
|
64
90
|
static stopTracking(): void {
|
|
65
91
|
if (!DdRumReactNativeNavigationTracking.isTracking) {
|
|
66
|
-
return
|
|
92
|
+
return;
|
|
67
93
|
}
|
|
68
|
-
if (
|
|
69
|
-
|
|
94
|
+
if (
|
|
95
|
+
DdRumReactNativeNavigationTracking.originalCreateElement !==
|
|
96
|
+
undefined
|
|
97
|
+
) {
|
|
98
|
+
React.createElement =
|
|
99
|
+
DdRumReactNativeNavigationTracking.originalCreateElement;
|
|
70
100
|
}
|
|
71
|
-
DdRumReactNativeNavigationTracking.trackedComponentIds.splice(
|
|
72
|
-
|
|
73
|
-
|
|
101
|
+
DdRumReactNativeNavigationTracking.trackedComponentIds.splice(
|
|
102
|
+
0,
|
|
103
|
+
DdRumReactNativeNavigationTracking.trackedComponentIds.length
|
|
104
|
+
);
|
|
105
|
+
DdRumReactNativeNavigationTracking.isTracking = false;
|
|
106
|
+
DdRumReactNativeNavigationTracking.viewNamePredicate = function (
|
|
107
|
+
_event: ComponentDidAppearEvent,
|
|
108
|
+
trackedName: string
|
|
109
|
+
) {
|
|
110
|
+
return trackedName;
|
|
111
|
+
};
|
|
74
112
|
}
|
|
75
|
-
}
|
|
113
|
+
}
|