@datadog/mobile-react-native-navigation 1.0.0-rc5 → 1.0.0-rc8
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 +10 -16
- 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 +10 -16
- package/lib/module/rum/instrumentation/DdRumReactNativeNavigationTracking.js.map +1 -1
- package/lib/typescript/core/src/DdSdkReactNative.d.ts +6 -6
- package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +15 -3
- package/lib/typescript/core/src/InternalLog.d.ts +5 -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 +4 -3
- package/lib/typescript/core/src/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
- package/lib/typescript/core/src/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
- package/lib/typescript/core/src/rum/instrumentation/DdRumResourceTracking.d.ts +19 -9
- 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/rum/instrumentation/URLHostParser.d.ts +6 -0
- package/lib/typescript/core/src/version.d.ts +1 -1
- package/lib/typescript/react-native-navigation/src/rum/instrumentation/DdRumReactNativeNavigationTracking.d.ts +3 -3
- package/package.json +3 -3
- package/src/__tests__/rum/instrumentation/DdRumReactNativeNavigationTracking.test.tsx +59 -46
- package/src/index.tsx +4 -1
- package/src/rum/instrumentation/DdRumReactNativeNavigationTracking.tsx +71 -33
|
@@ -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,28 +5,26 @@ 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.
|
|
24
24
|
*/
|
|
25
|
-
static startTracking() {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
|
|
25
|
+
static startTracking(viewNamePredicate = function (_event, trackedName) {
|
|
26
|
+
return trackedName;
|
|
27
|
+
}) {
|
|
30
28
|
// extra safety to avoid wrapping more than 1 time this function
|
|
31
29
|
if (DdRumReactNativeNavigationTracking.isTracking) {
|
|
32
30
|
return;
|
|
@@ -35,8 +33,8 @@ class DdRumReactNativeNavigationTracking {
|
|
|
35
33
|
const original = _react.default.createElement;
|
|
36
34
|
DdRumReactNativeNavigationTracking.originalCreateElement = original;
|
|
37
35
|
|
|
38
|
-
_react.default.createElement =
|
|
39
|
-
if (props && props.componentId
|
|
36
|
+
_react.default.createElement = (element, props, ...children) => {
|
|
37
|
+
if (props && props.componentId !== undefined && props.componentId !== null && !DdRumReactNativeNavigationTracking.trackedComponentIds.includes(props.componentId)) {
|
|
40
38
|
const componentId = props.componentId;
|
|
41
39
|
|
|
42
40
|
_reactNativeNavigation.Navigation.events().registerComponentListener({
|
|
@@ -56,10 +54,6 @@ class DdRumReactNativeNavigationTracking {
|
|
|
56
54
|
DdRumReactNativeNavigationTracking.trackedComponentIds.push(componentId);
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
60
|
-
children[_key - 2] = arguments[_key];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
57
|
return original(element, props, ...children);
|
|
64
58
|
};
|
|
65
59
|
|
|
@@ -76,7 +70,7 @@ class DdRumReactNativeNavigationTracking {
|
|
|
76
70
|
return;
|
|
77
71
|
}
|
|
78
72
|
|
|
79
|
-
if (DdRumReactNativeNavigationTracking.originalCreateElement
|
|
73
|
+
if (DdRumReactNativeNavigationTracking.originalCreateElement !== undefined) {
|
|
80
74
|
_react.default.createElement = DdRumReactNativeNavigationTracking.originalCreateElement;
|
|
81
75
|
}
|
|
82
76
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdRumReactNativeNavigationTracking.tsx"],"names":["DdRumReactNativeNavigationTracking","startTracking","viewNamePredicate","_event","trackedName","isTracking","original","React","createElement","originalCreateElement","element","props","componentId","undefined","trackedComponentIds","includes","Navigation","events","registerComponentListener","componentDidAppear","event","predicate","screenName","componentName","DdRum","startView","componentDidDisappear","stopView","push","
|
|
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,22 +5,20 @@ 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.
|
|
18
18
|
*/
|
|
19
|
-
static startTracking() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
|
|
19
|
+
static startTracking(viewNamePredicate = function (_event, trackedName) {
|
|
20
|
+
return trackedName;
|
|
21
|
+
}) {
|
|
24
22
|
// extra safety to avoid wrapping more than 1 time this function
|
|
25
23
|
if (DdRumReactNativeNavigationTracking.isTracking) {
|
|
26
24
|
return;
|
|
@@ -29,8 +27,8 @@ export class DdRumReactNativeNavigationTracking {
|
|
|
29
27
|
const original = React.createElement;
|
|
30
28
|
DdRumReactNativeNavigationTracking.originalCreateElement = original;
|
|
31
29
|
|
|
32
|
-
React.createElement =
|
|
33
|
-
if (props && props.componentId
|
|
30
|
+
React.createElement = (element, props, ...children) => {
|
|
31
|
+
if (props && props.componentId !== undefined && props.componentId !== null && !DdRumReactNativeNavigationTracking.trackedComponentIds.includes(props.componentId)) {
|
|
34
32
|
const componentId = props.componentId;
|
|
35
33
|
Navigation.events().registerComponentListener({
|
|
36
34
|
componentDidAppear: event => {
|
|
@@ -47,10 +45,6 @@ export class DdRumReactNativeNavigationTracking {
|
|
|
47
45
|
DdRumReactNativeNavigationTracking.trackedComponentIds.push(componentId);
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
51
|
-
children[_key - 2] = arguments[_key];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
48
|
return original(element, props, ...children);
|
|
55
49
|
};
|
|
56
50
|
|
|
@@ -67,7 +61,7 @@ export class DdRumReactNativeNavigationTracking {
|
|
|
67
61
|
return;
|
|
68
62
|
}
|
|
69
63
|
|
|
70
|
-
if (DdRumReactNativeNavigationTracking.originalCreateElement
|
|
64
|
+
if (DdRumReactNativeNavigationTracking.originalCreateElement !== undefined) {
|
|
71
65
|
React.createElement = DdRumReactNativeNavigationTracking.originalCreateElement;
|
|
72
66
|
}
|
|
73
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,5 +1,5 @@
|
|
|
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
|
*/
|
|
@@ -18,10 +18,10 @@ export declare class DdSdkReactNative {
|
|
|
18
18
|
private static readonly NATIVE_LONG_TASK_THRESHOLD_MS;
|
|
19
19
|
private static wasInitialized;
|
|
20
20
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
* Initializes the Datadog SDK.
|
|
22
|
+
* @param configuration the configuration for the SDK library
|
|
23
|
+
* @returns a Promise.
|
|
24
|
+
*/
|
|
25
25
|
static initialize(configuration: DdSdkReactNativeConfiguration): Promise<void>;
|
|
26
26
|
/**
|
|
27
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 { SdkVerbosity } from './SdkVerbosity';
|
|
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,12 +14,24 @@ 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
30
|
verbosity: SdkVerbosity | undefined;
|
|
20
31
|
nativeViewTracking: boolean;
|
|
21
32
|
proxyConfig?: ProxyConfiguration;
|
|
22
33
|
serviceName?: string;
|
|
34
|
+
firstPartyHosts: string[];
|
|
23
35
|
additionalConfig: {
|
|
24
36
|
[k: string]: any;
|
|
25
37
|
};
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { SdkVerbosity } from './SdkVerbosity';
|
|
2
|
+
/**
|
|
3
|
+
* /!\ DO NOT USE THIS IN YOUR APP /!\\
|
|
4
|
+
*
|
|
5
|
+
* This logger is only for debugging the Datadog SDK.
|
|
6
|
+
*/
|
|
2
7
|
export declare class InternalLog {
|
|
3
8
|
private static levelMap;
|
|
4
9
|
static verbosity: SdkVerbosity | undefined;
|
|
@@ -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,7 +1,8 @@
|
|
|
1
|
-
import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
2
1
|
import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
|
|
3
2
|
import { DdSdkReactNative } from './DdSdkReactNative';
|
|
3
|
+
import { InternalLog } from './InternalLog';
|
|
4
4
|
import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
|
|
5
|
-
import { TrackingConsent } from './TrackingConsent';
|
|
6
5
|
import { SdkVerbosity } from './SdkVerbosity';
|
|
7
|
-
|
|
6
|
+
import { TrackingConsent } from './TrackingConsent';
|
|
7
|
+
import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
8
|
+
export { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, InternalLog, 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;
|
|
@@ -1,27 +1,37 @@
|
|
|
1
1
|
/// <reference types="react-native" />
|
|
2
|
+
import type { DdRumResourceTracingAttributes } from './DdRumXhr';
|
|
2
3
|
export declare const TRACE_ID_HEADER_KEY = "x-datadog-trace-id";
|
|
3
4
|
export declare const PARENT_ID_HEADER_KEY = "x-datadog-parent-id";
|
|
4
5
|
export declare const ORIGIN_HEADER_KEY = "x-datadog-origin";
|
|
5
6
|
export declare const SAMPLING_PRIORITY_HEADER_KEY = "x-datadog-sampling-priority";
|
|
6
|
-
export declare const SAMPLED_HEADER_KEY = "x-datadog-sampled";
|
|
7
7
|
export declare const ORIGIN_RUM = "rum";
|
|
8
|
+
export declare const RESOURCE_SIZE_ERROR_MESSAGE = "Couldn't get resource size, because an error occured: ";
|
|
8
9
|
export declare function calculateResponseSize(xhr: XMLHttpRequest): number;
|
|
9
10
|
/**
|
|
10
|
-
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
|
|
11
|
-
*/
|
|
11
|
+
* Provides RUM auto-instrumentation feature to track resources (fetch, XHR, axios) as RUM events.
|
|
12
|
+
*/
|
|
12
13
|
export declare class DdRumResourceTracking {
|
|
13
14
|
private static isTracking;
|
|
15
|
+
private static tracingSamplingRate;
|
|
16
|
+
private static firstPartyHostsRegex;
|
|
14
17
|
private static originalXhrOpen;
|
|
15
18
|
private static originalXhrSend;
|
|
16
19
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
static startTracking(
|
|
20
|
+
* Starts tracking resources and sends a RUM Resource event every time a network request is detected.
|
|
21
|
+
*/
|
|
22
|
+
static startTracking({ tracingSamplingRate, firstPartyHosts }: {
|
|
23
|
+
tracingSamplingRate: number;
|
|
24
|
+
firstPartyHosts: string[];
|
|
25
|
+
}): void;
|
|
20
26
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
static startTrackingInternal(xhrType:
|
|
27
|
+
* Starts tracking resources and sends a RUM Resource event every time a fetch or XHR call is detected.
|
|
28
|
+
*/
|
|
29
|
+
static startTrackingInternal(xhrType: typeof XMLHttpRequest, { tracingSamplingRate, firstPartyHosts }: {
|
|
30
|
+
tracingSamplingRate: number;
|
|
31
|
+
firstPartyHosts: string[];
|
|
32
|
+
}): void;
|
|
24
33
|
static stopTracking(): void;
|
|
34
|
+
static getTracingAttributes(url: string): DdRumResourceTracingAttributes;
|
|
25
35
|
static proxyXhr(xhrType: any): void;
|
|
26
36
|
private static proxyOpen;
|
|
27
37
|
private static proxySend;
|
|
@@ -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
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.0-
|
|
1
|
+
export declare const version = "1.0.0-rc8";
|
|
@@ -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-rc8",
|
|
4
4
|
"description": "A client-side React Native module to interact with Datadog",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"prepare": "bob build"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@datadog/mobile-react-native": "^1.0.0-
|
|
39
|
+
"@datadog/mobile-react-native": "^1.0.0-rc8",
|
|
40
40
|
"react-native-gesture-handler": "1.10.3",
|
|
41
41
|
"react-native-navigation": "7.13.0"
|
|
42
42
|
},
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
]
|
|
71
71
|
]
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "67456f90ac95007f8f99beb065ccbf6ec9a6f478"
|
|
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
|
+
}
|