@datadog/mobile-react-navigation 1.0.0-rc5 → 1.0.0-rc9
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/DdRumReactNavigationTracking.js +77 -51
- package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/react-navigation.js +2 -0
- package/lib/commonjs/rum/instrumentation/react-navigation.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js +74 -52
- package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/react-navigation.js +2 -0
- package/lib/module/rum/instrumentation/react-navigation.js.map +1 -0
- 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/DdRumUserInteractionTracking.d.ts +3 -3
- package/lib/typescript/core/src/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +15 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +18 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +6 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +8 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +19 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.d.ts +8 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.d.ts +6 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.d.ts +17 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/URLHostParser.d.ts +6 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +25 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +3 -0
- package/lib/typescript/core/src/version.d.ts +1 -1
- package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts +9 -3
- package/lib/typescript/react-navigation/src/rum/instrumentation/react-navigation.d.ts +116 -0
- package/package.json +11 -6
- package/src/__tests__/rum/instrumentation/DdRumReactNavigationTracking.test.tsx +481 -385
- package/src/__tests__/rum/instrumentation/__utils__/AppStateMock.ts +75 -0
- package/src/__tests__/rum/instrumentation/__utils__/AppStateMockLegacy.ts +61 -0
- package/src/__tests__/rum/instrumentation/__utils__/Navigators/NavigatorsV5.tsx +105 -0
- package/src/__tests__/rum/instrumentation/__utils__/Navigators/NavigatorsV6.tsx +105 -0
- package/src/index.tsx +4 -1
- package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +145 -64
- package/src/rum/instrumentation/react-navigation.ts +158 -0
- package/lib/typescript/core/src/rum/instrumentation/DdRumResourceTracking.d.ts +0 -30
- package/lib/typescript/core/src/rum/instrumentation/DdRumXhr.d.ts +0 -13
- package/lib/typescript/core/src/rum/instrumentation/TraceIdentifier.d.ts +0 -1
|
@@ -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 DdRumReactNavigationTracking,\n ViewNamePredicate\n} from './rum/instrumentation/DdRumReactNavigationTracking';\n\nexport { DdRumReactNavigationTracking, ViewNamePredicate };\n"]}
|
|
@@ -19,27 +19,26 @@ class DdRumReactNavigationTracking {
|
|
|
19
19
|
* Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.
|
|
20
20
|
* @param navigationRef the reference to the real NavigationContainer.
|
|
21
21
|
*/
|
|
22
|
-
static startTrackingViews(navigationRef) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
22
|
+
static startTrackingViews(navigationRef, viewNamePredicate = function (_route, trackedName) {
|
|
23
|
+
return trackedName;
|
|
24
|
+
}) {
|
|
27
25
|
if (navigationRef == null) {
|
|
28
|
-
|
|
26
|
+
_mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE, _mobileReactNative.SdkVerbosity.ERROR);
|
|
27
|
+
|
|
29
28
|
return;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {
|
|
33
|
-
|
|
32
|
+
_mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE, _mobileReactNative.SdkVerbosity.ERROR);
|
|
34
33
|
} else if (DdRumReactNavigationTracking.registeredContainer == null) {
|
|
35
34
|
DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;
|
|
36
35
|
const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();
|
|
37
36
|
DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());
|
|
38
|
-
navigationRef.addListener(
|
|
37
|
+
navigationRef.addListener('state', listener);
|
|
39
38
|
DdRumReactNavigationTracking.registeredContainer = navigationRef;
|
|
39
|
+
DdRumReactNavigationTracking.backHandler = _reactNative.BackHandler.addEventListener('hardwareBackPress', DdRumReactNavigationTracking.onBackPress);
|
|
40
|
+
this.appStateSubscription = _reactNative.AppState.addEventListener('change', DdRumReactNavigationTracking.appStateListener);
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();
|
|
43
42
|
}
|
|
44
43
|
/**
|
|
45
44
|
* Stops tracking the NavigationContainer.
|
|
@@ -49,22 +48,34 @@ class DdRumReactNavigationTracking {
|
|
|
49
48
|
|
|
50
49
|
static stopTrackingViews(navigationRef) {
|
|
51
50
|
if (navigationRef != null) {
|
|
52
|
-
|
|
51
|
+
var _DdRumReactNavigation;
|
|
52
|
+
|
|
53
|
+
navigationRef.removeListener('state', DdRumReactNavigationTracking.navigationStateChangeListener);
|
|
54
|
+
(_DdRumReactNavigation = DdRumReactNavigationTracking.backHandler) === null || _DdRumReactNavigation === void 0 ? void 0 : _DdRumReactNavigation.remove();
|
|
55
|
+
DdRumReactNavigationTracking.backHandler = null;
|
|
53
56
|
DdRumReactNavigationTracking.registeredContainer = null;
|
|
54
57
|
|
|
55
58
|
DdRumReactNavigationTracking.viewNamePredicate = function (_route, trackedName) {
|
|
56
59
|
return trackedName;
|
|
57
60
|
};
|
|
61
|
+
} // For versions of React Native below 0.65, addEventListener does not return a subscription.
|
|
62
|
+
// We have to call AppState.removeEventListener instead.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if (this.appStateSubscription) {
|
|
66
|
+
this.appStateSubscription.remove();
|
|
67
|
+
} else {
|
|
68
|
+
_reactNative.AppState.removeEventListener('change', DdRumReactNavigationTracking.appStateListener);
|
|
58
69
|
}
|
|
59
70
|
}
|
|
60
71
|
|
|
61
|
-
static handleRouteNavigation(route) {
|
|
72
|
+
static handleRouteNavigation(route, appStateStatus = undefined) {
|
|
62
73
|
var _predicate;
|
|
63
74
|
|
|
64
|
-
|
|
75
|
+
if (route === undefined || route === null) {
|
|
76
|
+
_mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, _mobileReactNative.SdkVerbosity.WARN); // RUMM-1400 in some cases the route seem to be undefined
|
|
77
|
+
|
|
65
78
|
|
|
66
|
-
if (route == undefined || route == null) {
|
|
67
|
-
// RUMM-1400 in some cases the route seem to be undefined
|
|
68
79
|
return;
|
|
69
80
|
}
|
|
70
81
|
|
|
@@ -75,8 +86,8 @@ class DdRumReactNavigationTracking {
|
|
|
75
86
|
if (key != null && screenName != null) {
|
|
76
87
|
if (appStateStatus === 'background') {
|
|
77
88
|
_mobileReactNative.DdRum.stopView(key);
|
|
78
|
-
} else if (appStateStatus === 'active' || appStateStatus
|
|
79
|
-
// case when app goes into foreground,
|
|
89
|
+
} else if (appStateStatus === 'active' || appStateStatus === undefined) {
|
|
90
|
+
// case when app goes into foreground,
|
|
80
91
|
// in that case navigation listener won't be called
|
|
81
92
|
_mobileReactNative.DdRum.startView(key, screenName);
|
|
82
93
|
}
|
|
@@ -85,25 +96,15 @@ class DdRumReactNavigationTracking {
|
|
|
85
96
|
|
|
86
97
|
static resolveNavigationStateChangeListener() {
|
|
87
98
|
if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {
|
|
88
|
-
DdRumReactNavigationTracking.navigationStateChangeListener =
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
let route = (_event$data = event.data) === null || _event$data === void 0 ? void 0 : (_event$data$state = _event$data.state) === null || _event$data$state === void 0 ? void 0 : _event$data$state.routes[(_event$data2 = event.data) === null || _event$data2 === void 0 ? void 0 : (_event$data2$state = _event$data2.state) === null || _event$data2$state === void 0 ? void 0 : _event$data2$state.index];
|
|
92
|
-
|
|
93
|
-
if (route == undefined) {
|
|
94
|
-
// RUMM-1400 in some cases the route seem to be undefined
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
99
|
+
DdRumReactNavigationTracking.navigationStateChangeListener = () => {
|
|
100
|
+
var _DdRumReactNavigation2;
|
|
97
101
|
|
|
98
|
-
|
|
99
|
-
const nestedRoute = route.state.routes[route.state.index];
|
|
102
|
+
const route = (_DdRumReactNavigation2 = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation2 === void 0 ? void 0 : _DdRumReactNavigation2.getCurrentRoute();
|
|
100
103
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
104
|
+
if (route === undefined) {
|
|
105
|
+
_mobileReactNative.InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, _mobileReactNative.SdkVerbosity.WARN);
|
|
105
106
|
|
|
106
|
-
|
|
107
|
+
return;
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
DdRumReactNavigationTracking.handleRouteNavigation(route);
|
|
@@ -113,34 +114,59 @@ class DdRumReactNavigationTracking {
|
|
|
113
114
|
return DdRumReactNavigationTracking.navigationStateChangeListener;
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
|
|
117
|
-
if (DdRumReactNavigationTracking.appStateListener == null) {
|
|
118
|
-
DdRumReactNavigationTracking.appStateListener = appStateStatus => {
|
|
119
|
-
var _DdRumReactNavigation;
|
|
117
|
+
}
|
|
120
118
|
|
|
121
|
-
|
|
119
|
+
exports.DdRumReactNavigationTracking = DdRumReactNavigationTracking;
|
|
122
120
|
|
|
123
|
-
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
121
|
+
_defineProperty(DdRumReactNavigationTracking, "registeredContainer", void 0);
|
|
126
122
|
|
|
127
|
-
|
|
128
|
-
}; // AppState is singleton, so we should add a listener only once in the app lifetime
|
|
123
|
+
_defineProperty(DdRumReactNavigationTracking, "navigationStateChangeListener", void 0);
|
|
129
124
|
|
|
125
|
+
_defineProperty(DdRumReactNavigationTracking, "viewNamePredicate", void 0);
|
|
130
126
|
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
_defineProperty(DdRumReactNavigationTracking, "backHandler", void 0);
|
|
128
|
+
|
|
129
|
+
_defineProperty(DdRumReactNavigationTracking, "appStateSubscription", void 0);
|
|
130
|
+
|
|
131
|
+
_defineProperty(DdRumReactNavigationTracking, "ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE", 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.');
|
|
132
|
+
|
|
133
|
+
_defineProperty(DdRumReactNavigationTracking, "NULL_NAVIGATION_REF_ERROR_MESSAGE", 'Cannot track views with a null navigationRef.');
|
|
134
|
+
|
|
135
|
+
_defineProperty(DdRumReactNavigationTracking, "NAVIGATION_REF_IN_USE_ERROR_MESSAGE", 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.');
|
|
136
|
+
|
|
137
|
+
_defineProperty(DdRumReactNavigationTracking, "isAppExitingOnBackPress", () => {
|
|
138
|
+
if (DdRumReactNavigationTracking.registeredContainer === null) {
|
|
139
|
+
return false;
|
|
133
140
|
}
|
|
134
141
|
|
|
135
|
-
|
|
142
|
+
if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
136
145
|
|
|
137
|
-
|
|
146
|
+
return true;
|
|
147
|
+
});
|
|
138
148
|
|
|
139
|
-
_defineProperty(DdRumReactNavigationTracking, "
|
|
149
|
+
_defineProperty(DdRumReactNavigationTracking, "onBackPress", () => {
|
|
150
|
+
if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {
|
|
151
|
+
DdRumReactNavigationTracking.stopTrackingViews(DdRumReactNavigationTracking.registeredContainer);
|
|
152
|
+
} // We always return false so we make sure the react-navigation callback is called.
|
|
153
|
+
// See https://reactnative.dev/docs/backhandler
|
|
140
154
|
|
|
141
|
-
_defineProperty(DdRumReactNavigationTracking, "navigationStateChangeListener", void 0);
|
|
142
155
|
|
|
143
|
-
|
|
156
|
+
return false;
|
|
157
|
+
});
|
|
144
158
|
|
|
145
|
-
_defineProperty(DdRumReactNavigationTracking, "
|
|
159
|
+
_defineProperty(DdRumReactNavigationTracking, "appStateListener", appStateStatus => {
|
|
160
|
+
var _DdRumReactNavigation3;
|
|
161
|
+
|
|
162
|
+
const currentRoute = (_DdRumReactNavigation3 = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation3 === void 0 ? void 0 : _DdRumReactNavigation3.getCurrentRoute();
|
|
163
|
+
|
|
164
|
+
if (currentRoute === undefined || currentRoute === null) {
|
|
165
|
+
_mobileReactNative.InternalLog.log(`We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`, _mobileReactNative.SdkVerbosity.ERROR);
|
|
166
|
+
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
|
|
171
|
+
});
|
|
146
172
|
//# sourceMappingURL=DdRumReactNavigationTracking.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","console","log","registeredContainer","error","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","registerAppStateListenerIfNeeded","stopTrackingViews","removeListener","navigationStateChangeListener","route","appStateStatus","undefined","key","predicate","screenName","name","DdRum","stopView","startView","event","data","state","routes","index","nestedRoute","appStateListener","currentRoute","AppState","addEventListener"],"mappings":";;;;;;;AAOA;;AACA;;;;AAcA;AACA;AACA;AACO,MAAMA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AACDF,UAAAA,KAAK,GAAGe,WAAR;AACH;;AAEDlC,QAAAA,4BAA4B,CAACY,qBAA7B,CAAmDO,KAAnD;AACH,OAlBD;AAmBH;;AACD,WAAOnB,4BAA4B,CAACkB,6BAApC;AACH;;AAE8C,SAAhCH,gCAAgC,GAAG;AAC9C,QAAIf,4BAA4B,CAACmC,gBAA7B,IAAiD,IAArD,EAA2D;AACvDnC,MAAAA,4BAA4B,CAACmC,gBAA7B,GAAiDf,cAAD,IAAoC;AAAA;;AAEhF,cAAMgB,YAAY,4BAAGpC,4BAA4B,CAACQ,mBAAhC,0DAAG,sBAAkDK,eAAlD,EAArB;;AACA,YAAIuB,YAAY,IAAIf,SAApB,EAA+B;AAC3B;AACH;;AAEDrB,QAAAA,4BAA4B,CAACY,qBAA7B,CAAmDwB,YAAnD,EAAiEhB,cAAjE;AACH,OARD,CADuD,CAWvD;;;AACAiB,4BAASC,gBAAT,CAA0B,QAA1B,EAAoCtC,4BAA4B,CAACmC,gBAAjE;AACH;AACJ;;AAlHqC;;;;gBAA7BnC,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B","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 type { EventArg, NavigationContainerRef, Route } from \"@react-navigation/native\";\nimport { DdRum } from '@datadog/mobile-react-native';\nimport { AppState, AppStateStatus } from 'react-native';\n\ndeclare type NavigationListener = (event: EventArg<string, boolean, any>) => void | null\n\n// AppStateStatus can have values: \n// 'active' - The app is running in the foreground\n// 'background' - The app is running in the background. The user is either in another app or on the home screen\n// 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.\n// 'unknown' [iOS] - Initial value until the current app state is determined\n// 'extension' [iOS] - The app is running as an app extension\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null\n\nexport type ViewNamePredicate = (route: Route<string, any | undefined>, trackedName: string) => string\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n\n private static registeredContainer: NavigationContainerRef | null;\n \n private static navigationStateChangeListener: NavigationListener;\n\n private static appStateListener: AppStateListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }\n ): void {\n\n if (navigationRef == null) {\n console.log (\"Cannot track views with a null navigationRef\");\n return;\n }\n\n if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {\n console.error('Cannot track new navigation container while another one is still tracked');\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());\n navigationRef.addListener(\"state\", listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n }\n\n\n DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(navigationRef: NavigationContainerRef | null): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\"state\", DdRumReactNavigationTracking.navigationStateChangeListener);\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }\n }\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined, \n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route == undefined || route == null) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (appStateStatus === 'active' || appStateStatus == undefined) {\n // case when app goes into foreground, \n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {\n DdRumReactNavigationTracking.navigationStateChangeListener = (event: EventArg<string, boolean, any>) => {\n let route = event.data?.state?.routes[event.data?.state?.index];\n\n if (route == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n\n while (route.state != undefined) {\n const nestedRoute = route.state.routes[route.state.index];\n if (nestedRoute == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n break;\n }\n route = nestedRoute\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static registerAppStateListenerIfNeeded() {\n if (DdRumReactNavigationTracking.appStateListener == null) {\n DdRumReactNavigationTracking.appStateListener = (appStateStatus: AppStateStatus) => {\n\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute == undefined) {\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);\n };\n\n // AppState is singleton, so we should add a listener only once in the app lifetime\n AppState.addEventListener(\"change\", DdRumReactNavigationTracking.appStateListener);\n }\n }\n\n}\n\n"]}
|
|
1
|
+
{"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","InternalLog","log","NULL_NAVIGATION_REF_ERROR_MESSAGE","SdkVerbosity","ERROR","registeredContainer","NAVIGATION_REF_IN_USE_ERROR_MESSAGE","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","backHandler","BackHandler","addEventListener","onBackPress","appStateSubscription","AppState","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","predicate","screenName","name","DdRum","stopView","startView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;;;;;;AAMA;;AAEA;;;;AAqBA;AACA;AACA;AACO,MAAMA,4BAAN,CAAmC;AAuCtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACrBC,aADqB,EAErBC,iBAAoC,GAAG,UACnCC,MADmC,EAEnCC,WAFmC,EAGrC;AACE,WAAOA,WAAP;AACH,GAPoB,EAQjB;AACJ,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBI,qCAAYC,GAAZ,CACIP,4BAA4B,CAACQ,iCADjC,EAEIC,gCAAaC,KAFjB;;AAIA;AACH;;AAED,QACIV,4BAA4B,CAACW,mBAA7B,IAAoD,IAApD,IACA,KAAKA,mBAAL,KAA6BT,aAFjC,EAGE;AACEI,qCAAYC,GAAZ,CACIP,4BAA4B,CAACY,mCADjC,EAEIH,gCAAaC,KAFjB;AAIH,KARD,MAQO,IAAIV,4BAA4B,CAACW,mBAA7B,IAAoD,IAAxD,EAA8D;AACjEX,MAAAA,4BAA4B,CAACG,iBAA7B,GAAiDA,iBAAjD;AACA,YAAMU,QAAQ,GAAGb,4BAA4B,CAACc,oCAA7B,EAAjB;AACAd,MAAAA,4BAA4B,CAACe,qBAA7B,CACIb,aAAa,CAACc,eAAd,EADJ;AAGAd,MAAAA,aAAa,CAACe,WAAd,CAA0B,OAA1B,EAAmCJ,QAAnC;AACAb,MAAAA,4BAA4B,CAACW,mBAA7B,GAAmDT,aAAnD;AACAF,MAAAA,4BAA4B,CAACkB,WAA7B,GAA2CC,yBAAYC,gBAAZ,CACvC,mBADuC,EAEvCpB,4BAA4B,CAACqB,WAFU,CAA3C;AAIA,WAAKC,oBAAL,GAA4BC,sBAASH,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AA4B,CAACW,mBADjC;AAGH,GALsB,CAMvB;AACA;;;AACA,SAAO,KAAP;AACH,C;;gBArCQX,4B,sBA+KL+B,cADgD,IAE/C;AAAA;;AACD,QAAMa,YAAY,6BAAG5C,4BAA4B,CAACW,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAI4B,YAAY,KAAKZ,SAAjB,IAA8BY,YAAY,KAAK,IAAnD,EAAyD;AACrDtC,mCAAYC,GAAZ,CACK,4EAA2EwB,cAAe,gDAD/F,EAEItB,gCAAaC,KAFjB;;AAIA;AACH;;AAEDV,EAAAA,4BAA4B,CAACe,qBAA7B,CACI6B,YADJ,EAEIb,cAFJ;AAIH,C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRum, SdkVerbosity, InternalLog } from '@datadog/mobile-react-native';\nimport type { AppStateStatus, NativeEventSubscription } from 'react-native';\nimport { AppState, BackHandler } from 'react-native';\n\nimport type {\n NavigationContainerRef,\n Route,\n NavigationListener\n} from './react-navigation';\n\n// AppStateStatus can have values:\n// 'active' - The app is running in the foreground\n// 'background' - The app is running in the background. The user is either in another app or on the home screen\n// 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.\n// 'unknown' [iOS] - Initial value until the current app state is determined\n// 'extension' [iOS] - The app is running as an app extension\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null;\n\nexport type ViewNamePredicate = (\n route: Route<string, any | undefined>,\n trackedName: string\n) => string;\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n private static registeredContainer: NavigationContainerRef | null;\n\n private static navigationStateChangeListener: NavigationListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n private static backHandler: NativeEventSubscription | null;\n\n private static appStateSubscription?: NativeEventSubscription;\n\n static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =\n 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';\n static NULL_NAVIGATION_REF_ERROR_MESSAGE =\n 'Cannot track views with a null navigationRef.';\n static NAVIGATION_REF_IN_USE_ERROR_MESSAGE =\n 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.';\n\n static isAppExitingOnBackPress = (): boolean => {\n if (DdRumReactNavigationTracking.registeredContainer === null) {\n return false;\n }\n if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {\n return false;\n }\n return true;\n };\n\n static onBackPress = () => {\n if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {\n DdRumReactNavigationTracking.stopTrackingViews(\n DdRumReactNavigationTracking.registeredContainer\n );\n }\n // We always return false so we make sure the react-navigation callback is called.\n // See https://reactnative.dev/docs/backhandler\n return false;\n };\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n if (navigationRef == null) {\n InternalLog.log(\n DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n if (\n DdRumReactNavigationTracking.registeredContainer != null &&\n this.registeredContainer !== navigationRef\n ) {\n InternalLog.log(\n DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(\n navigationRef.getCurrentRoute()\n );\n navigationRef.addListener('state', listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener(\n 'hardwareBackPress',\n DdRumReactNavigationTracking.onBackPress\n );\n this.appStateSubscription = AppState.addEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(\n navigationRef: NavigationContainerRef | null\n ): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\n 'state',\n DdRumReactNavigationTracking.navigationStateChangeListener\n );\n DdRumReactNavigationTracking.backHandler?.remove();\n DdRumReactNavigationTracking.backHandler = null;\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n };\n }\n\n // For versions of React Native below 0.65, addEventListener does not return a subscription.\n // We have to call AppState.removeEventListener instead.\n if (this.appStateSubscription) {\n this.appStateSubscription.remove();\n } else {\n AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined,\n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route === undefined || route === null) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n // RUMM-1400 in some cases the route seem to be undefined\n return;\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (\n appStateStatus === 'active' ||\n appStateStatus === undefined\n ) {\n // case when app goes into foreground,\n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (\n DdRumReactNavigationTracking.navigationStateChangeListener == null\n ) {\n DdRumReactNavigationTracking.navigationStateChangeListener = () => {\n const route = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n\n if (route === undefined) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static appStateListener: AppStateListener = (\n appStateStatus: AppStateStatus\n ) => {\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute === undefined || currentRoute === null) {\n InternalLog.log(\n `We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(\n currentRoute,\n appStateStatus\n );\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["DdRumReactNavigationTracking","ViewNamePredicate"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["DdRumReactNavigationTracking","ViewNamePredicate"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,SACIA,4BADJ,EAEIC,iBAFJ,QAGO,oDAHP;AAKA,SAASD,4BAAT,EAAuCC,iBAAvC","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 DdRumReactNavigationTracking,\n ViewNamePredicate\n} from './rum/instrumentation/DdRumReactNavigationTracking';\n\nexport { DdRumReactNavigationTracking, ViewNamePredicate };\n"]}
|
|
@@ -5,8 +5,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
5
5
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
6
6
|
* Copyright 2016-Present Datadog, Inc.
|
|
7
7
|
*/
|
|
8
|
-
import { DdRum } from '@datadog/mobile-react-native';
|
|
9
|
-
import { AppState } from 'react-native';
|
|
8
|
+
import { DdRum, SdkVerbosity, InternalLog } from '@datadog/mobile-react-native';
|
|
9
|
+
import { AppState, BackHandler } from 'react-native';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.
|
|
@@ -16,27 +16,25 @@ export class DdRumReactNavigationTracking {
|
|
|
16
16
|
* Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.
|
|
17
17
|
* @param navigationRef the reference to the real NavigationContainer.
|
|
18
18
|
*/
|
|
19
|
-
static startTrackingViews(navigationRef) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
|
|
19
|
+
static startTrackingViews(navigationRef, viewNamePredicate = function (_route, trackedName) {
|
|
20
|
+
return trackedName;
|
|
21
|
+
}) {
|
|
24
22
|
if (navigationRef == null) {
|
|
25
|
-
|
|
23
|
+
InternalLog.log(DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE, SdkVerbosity.ERROR);
|
|
26
24
|
return;
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {
|
|
30
|
-
|
|
28
|
+
InternalLog.log(DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE, SdkVerbosity.ERROR);
|
|
31
29
|
} else if (DdRumReactNavigationTracking.registeredContainer == null) {
|
|
32
30
|
DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;
|
|
33
31
|
const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();
|
|
34
32
|
DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());
|
|
35
|
-
navigationRef.addListener(
|
|
33
|
+
navigationRef.addListener('state', listener);
|
|
36
34
|
DdRumReactNavigationTracking.registeredContainer = navigationRef;
|
|
35
|
+
DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener('hardwareBackPress', DdRumReactNavigationTracking.onBackPress);
|
|
36
|
+
this.appStateSubscription = AppState.addEventListener('change', DdRumReactNavigationTracking.appStateListener);
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();
|
|
40
38
|
}
|
|
41
39
|
/**
|
|
42
40
|
* Stops tracking the NavigationContainer.
|
|
@@ -46,22 +44,33 @@ export class DdRumReactNavigationTracking {
|
|
|
46
44
|
|
|
47
45
|
static stopTrackingViews(navigationRef) {
|
|
48
46
|
if (navigationRef != null) {
|
|
49
|
-
|
|
47
|
+
var _DdRumReactNavigation;
|
|
48
|
+
|
|
49
|
+
navigationRef.removeListener('state', DdRumReactNavigationTracking.navigationStateChangeListener);
|
|
50
|
+
(_DdRumReactNavigation = DdRumReactNavigationTracking.backHandler) === null || _DdRumReactNavigation === void 0 ? void 0 : _DdRumReactNavigation.remove();
|
|
51
|
+
DdRumReactNavigationTracking.backHandler = null;
|
|
50
52
|
DdRumReactNavigationTracking.registeredContainer = null;
|
|
51
53
|
|
|
52
54
|
DdRumReactNavigationTracking.viewNamePredicate = function (_route, trackedName) {
|
|
53
55
|
return trackedName;
|
|
54
56
|
};
|
|
57
|
+
} // For versions of React Native below 0.65, addEventListener does not return a subscription.
|
|
58
|
+
// We have to call AppState.removeEventListener instead.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if (this.appStateSubscription) {
|
|
62
|
+
this.appStateSubscription.remove();
|
|
63
|
+
} else {
|
|
64
|
+
AppState.removeEventListener('change', DdRumReactNavigationTracking.appStateListener);
|
|
55
65
|
}
|
|
56
66
|
}
|
|
57
67
|
|
|
58
|
-
static handleRouteNavigation(route) {
|
|
68
|
+
static handleRouteNavigation(route, appStateStatus = undefined) {
|
|
59
69
|
var _predicate;
|
|
60
70
|
|
|
61
|
-
|
|
71
|
+
if (route === undefined || route === null) {
|
|
72
|
+
InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, SdkVerbosity.WARN); // RUMM-1400 in some cases the route seem to be undefined
|
|
62
73
|
|
|
63
|
-
if (route == undefined || route == null) {
|
|
64
|
-
// RUMM-1400 in some cases the route seem to be undefined
|
|
65
74
|
return;
|
|
66
75
|
}
|
|
67
76
|
|
|
@@ -72,8 +81,8 @@ export class DdRumReactNavigationTracking {
|
|
|
72
81
|
if (key != null && screenName != null) {
|
|
73
82
|
if (appStateStatus === 'background') {
|
|
74
83
|
DdRum.stopView(key);
|
|
75
|
-
} else if (appStateStatus === 'active' || appStateStatus
|
|
76
|
-
// case when app goes into foreground,
|
|
84
|
+
} else if (appStateStatus === 'active' || appStateStatus === undefined) {
|
|
85
|
+
// case when app goes into foreground,
|
|
77
86
|
// in that case navigation listener won't be called
|
|
78
87
|
DdRum.startView(key, screenName);
|
|
79
88
|
}
|
|
@@ -82,27 +91,16 @@ export class DdRumReactNavigationTracking {
|
|
|
82
91
|
|
|
83
92
|
static resolveNavigationStateChangeListener() {
|
|
84
93
|
if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {
|
|
85
|
-
DdRumReactNavigationTracking.navigationStateChangeListener =
|
|
86
|
-
var
|
|
94
|
+
DdRumReactNavigationTracking.navigationStateChangeListener = () => {
|
|
95
|
+
var _DdRumReactNavigation2;
|
|
87
96
|
|
|
88
|
-
|
|
97
|
+
const route = (_DdRumReactNavigation2 = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation2 === void 0 ? void 0 : _DdRumReactNavigation2.getCurrentRoute();
|
|
89
98
|
|
|
90
|
-
if (route
|
|
91
|
-
|
|
99
|
+
if (route === undefined) {
|
|
100
|
+
InternalLog.log(DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE, SdkVerbosity.WARN);
|
|
92
101
|
return;
|
|
93
102
|
}
|
|
94
103
|
|
|
95
|
-
while (route.state != undefined) {
|
|
96
|
-
const nestedRoute = route.state.routes[route.state.index];
|
|
97
|
-
|
|
98
|
-
if (nestedRoute == undefined) {
|
|
99
|
-
// RUMM-1400 in some cases the route seem to be undefined
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
route = nestedRoute;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
104
|
DdRumReactNavigationTracking.handleRouteNavigation(route);
|
|
107
105
|
};
|
|
108
106
|
}
|
|
@@ -110,32 +108,56 @@ export class DdRumReactNavigationTracking {
|
|
|
110
108
|
return DdRumReactNavigationTracking.navigationStateChangeListener;
|
|
111
109
|
}
|
|
112
110
|
|
|
113
|
-
|
|
114
|
-
if (DdRumReactNavigationTracking.appStateListener == null) {
|
|
115
|
-
DdRumReactNavigationTracking.appStateListener = appStateStatus => {
|
|
116
|
-
var _DdRumReactNavigation;
|
|
111
|
+
}
|
|
117
112
|
|
|
118
|
-
|
|
113
|
+
_defineProperty(DdRumReactNavigationTracking, "registeredContainer", void 0);
|
|
119
114
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
_defineProperty(DdRumReactNavigationTracking, "navigationStateChangeListener", void 0);
|
|
116
|
+
|
|
117
|
+
_defineProperty(DdRumReactNavigationTracking, "viewNamePredicate", void 0);
|
|
123
118
|
|
|
124
|
-
|
|
125
|
-
}; // AppState is singleton, so we should add a listener only once in the app lifetime
|
|
119
|
+
_defineProperty(DdRumReactNavigationTracking, "backHandler", void 0);
|
|
126
120
|
|
|
121
|
+
_defineProperty(DdRumReactNavigationTracking, "appStateSubscription", void 0);
|
|
127
122
|
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
_defineProperty(DdRumReactNavigationTracking, "ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE", 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.');
|
|
124
|
+
|
|
125
|
+
_defineProperty(DdRumReactNavigationTracking, "NULL_NAVIGATION_REF_ERROR_MESSAGE", 'Cannot track views with a null navigationRef.');
|
|
126
|
+
|
|
127
|
+
_defineProperty(DdRumReactNavigationTracking, "NAVIGATION_REF_IN_USE_ERROR_MESSAGE", 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.');
|
|
128
|
+
|
|
129
|
+
_defineProperty(DdRumReactNavigationTracking, "isAppExitingOnBackPress", () => {
|
|
130
|
+
if (DdRumReactNavigationTracking.registeredContainer === null) {
|
|
131
|
+
return false;
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
133
137
|
|
|
134
|
-
|
|
138
|
+
return true;
|
|
139
|
+
});
|
|
135
140
|
|
|
136
|
-
_defineProperty(DdRumReactNavigationTracking, "
|
|
141
|
+
_defineProperty(DdRumReactNavigationTracking, "onBackPress", () => {
|
|
142
|
+
if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {
|
|
143
|
+
DdRumReactNavigationTracking.stopTrackingViews(DdRumReactNavigationTracking.registeredContainer);
|
|
144
|
+
} // We always return false so we make sure the react-navigation callback is called.
|
|
145
|
+
// See https://reactnative.dev/docs/backhandler
|
|
137
146
|
|
|
138
|
-
_defineProperty(DdRumReactNavigationTracking, "appStateListener", void 0);
|
|
139
147
|
|
|
140
|
-
|
|
148
|
+
return false;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
_defineProperty(DdRumReactNavigationTracking, "appStateListener", appStateStatus => {
|
|
152
|
+
var _DdRumReactNavigation3;
|
|
153
|
+
|
|
154
|
+
const currentRoute = (_DdRumReactNavigation3 = DdRumReactNavigationTracking.registeredContainer) === null || _DdRumReactNavigation3 === void 0 ? void 0 : _DdRumReactNavigation3.getCurrentRoute();
|
|
155
|
+
|
|
156
|
+
if (currentRoute === undefined || currentRoute === null) {
|
|
157
|
+
InternalLog.log(`We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`, SdkVerbosity.ERROR);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);
|
|
162
|
+
});
|
|
141
163
|
//# sourceMappingURL=DdRumReactNavigationTracking.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRum","AppState","DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","console","log","registeredContainer","error","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","registerAppStateListenerIfNeeded","stopTrackingViews","removeListener","navigationStateChangeListener","route","appStateStatus","undefined","key","predicate","screenName","name","stopView","startView","event","data","state","routes","index","nestedRoute","appStateListener","currentRoute","addEventListener"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAGA,SAASA,KAAT,QAAsB,8BAAtB;AACA,SAASC,QAAT,QAAyC,cAAzC;;AAcA;AACA;AACA;AACA,OAAO,MAAMC,4BAAN,CAAmC;AAUtC;AACJ;AACA;AACA;AAC6B,SAAlBC,kBAAkB,CACjBC,aADiB,EAGb;AAAA,QADJC,iBACI,uEADmC,UAAUC,MAAV,EAAkDC,WAAlD,EAAuE;AAAE,aAAOA,WAAP;AAAqB,KACjI;;AAER,QAAIH,aAAa,IAAI,IAArB,EAA2B;AACvBI,MAAAA,OAAO,CAACC,GAAR,CAAa,8CAAb;AACA;AACH;;AAED,QAAIP,4BAA4B,CAACQ,mBAA7B,IAAoD,IAApD,IAA4D,KAAKA,mBAAL,KAA6BN,aAA7F,EAA4G;AACxGI,MAAAA,OAAO,CAACG,KAA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BAAhC,0DAAG,sBAAkDK,eAAlD,EAArB;;AACA,YAAIsB,YAAY,IAAId,SAApB,EAA+B;AAC3B;AACH;;AAEDrB,QAAAA,4BAA4B,CAACY,qBAA7B,CAAmDuB,YAAnD,EAAiEf,cAAjE;AACH,OARD,CADuD,CAWvD;;;AACArB,MAAAA,QAAQ,CAACqC,gBAAT,CAA0B,QAA1B,EAAoCpC,4BAA4B,CAACkC,gBAAjE;AACH;AACJ;;AAlHqC;;gBAA7BlC,4B;;gBAAAA,4B;;gBAAAA,4B;;gBAAAA,4B","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 type { EventArg, NavigationContainerRef, Route } from \"@react-navigation/native\";\nimport { DdRum } from '@datadog/mobile-react-native';\nimport { AppState, AppStateStatus } from 'react-native';\n\ndeclare type NavigationListener = (event: EventArg<string, boolean, any>) => void | null\n\n// AppStateStatus can have values: \n// 'active' - The app is running in the foreground\n// 'background' - The app is running in the background. The user is either in another app or on the home screen\n// 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.\n// 'unknown' [iOS] - Initial value until the current app state is determined\n// 'extension' [iOS] - The app is running as an app extension\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null\n\nexport type ViewNamePredicate = (route: Route<string, any | undefined>, trackedName: string) => string\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n\n private static registeredContainer: NavigationContainerRef | null;\n \n private static navigationStateChangeListener: NavigationListener;\n\n private static appStateListener: AppStateListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }\n ): void {\n\n if (navigationRef == null) {\n console.log (\"Cannot track views with a null navigationRef\");\n return;\n }\n\n if (DdRumReactNavigationTracking.registeredContainer != null && this.registeredContainer !== navigationRef) {\n console.error('Cannot track new navigation container while another one is still tracked');\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(navigationRef.getCurrentRoute());\n navigationRef.addListener(\"state\", listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n }\n\n\n DdRumReactNavigationTracking.registerAppStateListenerIfNeeded();\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(navigationRef: NavigationContainerRef | null): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\"state\", DdRumReactNavigationTracking.navigationStateChangeListener);\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (_route: Route<string, any | undefined>, trackedName: string) { return trackedName; }\n }\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined, \n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route == undefined || route == null) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (appStateStatus === 'active' || appStateStatus == undefined) {\n // case when app goes into foreground, \n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (DdRumReactNavigationTracking.navigationStateChangeListener == null) {\n DdRumReactNavigationTracking.navigationStateChangeListener = (event: EventArg<string, boolean, any>) => {\n let route = event.data?.state?.routes[event.data?.state?.index];\n\n if (route == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n return\n }\n\n while (route.state != undefined) {\n const nestedRoute = route.state.routes[route.state.index];\n if (nestedRoute == undefined) {\n // RUMM-1400 in some cases the route seem to be undefined\n break;\n }\n route = nestedRoute\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static registerAppStateListenerIfNeeded() {\n if (DdRumReactNavigationTracking.appStateListener == null) {\n DdRumReactNavigationTracking.appStateListener = (appStateStatus: AppStateStatus) => {\n\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute == undefined) {\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(currentRoute, appStateStatus);\n };\n\n // AppState is singleton, so we should add a listener only once in the app lifetime\n AppState.addEventListener(\"change\", DdRumReactNavigationTracking.appStateListener);\n }\n }\n\n}\n\n"]}
|
|
1
|
+
{"version":3,"sources":["DdRumReactNavigationTracking.tsx"],"names":["DdRum","SdkVerbosity","InternalLog","AppState","BackHandler","DdRumReactNavigationTracking","startTrackingViews","navigationRef","viewNamePredicate","_route","trackedName","log","NULL_NAVIGATION_REF_ERROR_MESSAGE","ERROR","registeredContainer","NAVIGATION_REF_IN_USE_ERROR_MESSAGE","listener","resolveNavigationStateChangeListener","handleRouteNavigation","getCurrentRoute","addListener","backHandler","addEventListener","onBackPress","appStateSubscription","appStateListener","stopTrackingViews","removeListener","navigationStateChangeListener","remove","removeEventListener","route","appStateStatus","undefined","ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE","WARN","key","predicate","screenName","name","stopView","startView","canGoBack","isAppExitingOnBackPress","currentRoute"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAEA,SAASA,KAAT,EAAgBC,YAAhB,EAA8BC,WAA9B,QAAiD,8BAAjD;AAEA,SAASC,QAAT,EAAmBC,WAAnB,QAAsC,cAAtC;;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MY,YAAY,6BAAGvC,4BAA4B,CAACS,mBAAhC,2DAAG,uBAAkDK,eAAlD,EAArB;;AACA,MAAIyB,YAAY,KAAKX,SAAjB,IAA8BW,YAAY,KAAK,IAAnD,EAAyD;AACrD1C,IAAAA,WAAW,CAACS,GAAZ,CACK,4EAA2EqB,cAAe,gDAD/F,EAEI/B,YAAY,CAACY,KAFjB;AAIA;AACH;;AAEDR,EAAAA,4BAA4B,CAACa,qBAA7B,CACI0B,YADJ,EAEIZ,cAFJ;AAIH,C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { DdRum, SdkVerbosity, InternalLog } from '@datadog/mobile-react-native';\nimport type { AppStateStatus, NativeEventSubscription } from 'react-native';\nimport { AppState, BackHandler } from 'react-native';\n\nimport type {\n NavigationContainerRef,\n Route,\n NavigationListener\n} from './react-navigation';\n\n// AppStateStatus can have values:\n// 'active' - The app is running in the foreground\n// 'background' - The app is running in the background. The user is either in another app or on the home screen\n// 'inactive' [iOS] - This is a transition state that currently never happens for typical React Native apps.\n// 'unknown' [iOS] - Initial value until the current app state is determined\n// 'extension' [iOS] - The app is running as an app extension\ndeclare type AppStateListener = (appStateStatus: AppStateStatus) => void | null;\n\nexport type ViewNamePredicate = (\n route: Route<string, any | undefined>,\n trackedName: string\n) => string;\n\n/**\n * Provides RUM integration for the [ReactNavigation](https://reactnavigation.org/) API.\n */\nexport class DdRumReactNavigationTracking {\n private static registeredContainer: NavigationContainerRef | null;\n\n private static navigationStateChangeListener: NavigationListener;\n\n private static viewNamePredicate: ViewNamePredicate;\n\n private static backHandler: NativeEventSubscription | null;\n\n private static appStateSubscription?: NativeEventSubscription;\n\n static ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE =\n 'A navigation change was detected but the RUM ViewEvent was dropped as the route was undefined.';\n static NULL_NAVIGATION_REF_ERROR_MESSAGE =\n 'Cannot track views with a null navigationRef.';\n static NAVIGATION_REF_IN_USE_ERROR_MESSAGE =\n 'Cannot track new navigation container while another one is still tracked. Please call `DdRumReactNavigationTracking.stopTrackingViews` on the previous container reference.';\n\n static isAppExitingOnBackPress = (): boolean => {\n if (DdRumReactNavigationTracking.registeredContainer === null) {\n return false;\n }\n if (DdRumReactNavigationTracking.registeredContainer.canGoBack()) {\n return false;\n }\n return true;\n };\n\n static onBackPress = () => {\n if (DdRumReactNavigationTracking.isAppExitingOnBackPress()) {\n DdRumReactNavigationTracking.stopTrackingViews(\n DdRumReactNavigationTracking.registeredContainer\n );\n }\n // We always return false so we make sure the react-navigation callback is called.\n // See https://reactnative.dev/docs/backhandler\n return false;\n };\n\n /**\n * Starts tracking the NavigationContainer and sends a RUM View event every time the navigation route changed.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static startTrackingViews(\n navigationRef: NavigationContainerRef | null,\n viewNamePredicate: ViewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n }\n ): void {\n if (navigationRef == null) {\n InternalLog.log(\n DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n if (\n DdRumReactNavigationTracking.registeredContainer != null &&\n this.registeredContainer !== navigationRef\n ) {\n InternalLog.log(\n DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,\n SdkVerbosity.ERROR\n );\n } else if (DdRumReactNavigationTracking.registeredContainer == null) {\n DdRumReactNavigationTracking.viewNamePredicate = viewNamePredicate;\n const listener = DdRumReactNavigationTracking.resolveNavigationStateChangeListener();\n DdRumReactNavigationTracking.handleRouteNavigation(\n navigationRef.getCurrentRoute()\n );\n navigationRef.addListener('state', listener);\n DdRumReactNavigationTracking.registeredContainer = navigationRef;\n DdRumReactNavigationTracking.backHandler = BackHandler.addEventListener(\n 'hardwareBackPress',\n DdRumReactNavigationTracking.onBackPress\n );\n this.appStateSubscription = AppState.addEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n /**\n * Stops tracking the NavigationContainer.\n * @param navigationRef the reference to the real NavigationContainer.\n */\n static stopTrackingViews(\n navigationRef: NavigationContainerRef | null\n ): void {\n if (navigationRef != null) {\n navigationRef.removeListener(\n 'state',\n DdRumReactNavigationTracking.navigationStateChangeListener\n );\n DdRumReactNavigationTracking.backHandler?.remove();\n DdRumReactNavigationTracking.backHandler = null;\n DdRumReactNavigationTracking.registeredContainer = null;\n DdRumReactNavigationTracking.viewNamePredicate = function (\n _route: Route<string, any | undefined>,\n trackedName: string\n ) {\n return trackedName;\n };\n }\n\n // For versions of React Native below 0.65, addEventListener does not return a subscription.\n // We have to call AppState.removeEventListener instead.\n if (this.appStateSubscription) {\n this.appStateSubscription.remove();\n } else {\n AppState.removeEventListener(\n 'change',\n DdRumReactNavigationTracking.appStateListener\n );\n }\n }\n\n private static handleRouteNavigation(\n route: Route<string, any | undefined> | undefined,\n appStateStatus: AppStateStatus | undefined = undefined\n ) {\n if (route === undefined || route === null) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n // RUMM-1400 in some cases the route seem to be undefined\n return;\n }\n const key = route.key;\n\n const predicate = DdRumReactNavigationTracking.viewNamePredicate;\n const screenName = predicate(route, route.name) ?? route.name;\n\n if (key != null && screenName != null) {\n if (appStateStatus === 'background') {\n DdRum.stopView(key);\n } else if (\n appStateStatus === 'active' ||\n appStateStatus === undefined\n ) {\n // case when app goes into foreground,\n // in that case navigation listener won't be called\n DdRum.startView(key, screenName);\n }\n }\n }\n\n private static resolveNavigationStateChangeListener(): NavigationListener {\n if (\n DdRumReactNavigationTracking.navigationStateChangeListener == null\n ) {\n DdRumReactNavigationTracking.navigationStateChangeListener = () => {\n const route = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n\n if (route === undefined) {\n InternalLog.log(\n DdRumReactNavigationTracking.ROUTE_UNDEFINED_NAVIGATION_WARNING_MESSAGE,\n SdkVerbosity.WARN\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(route);\n };\n }\n return DdRumReactNavigationTracking.navigationStateChangeListener;\n }\n\n private static appStateListener: AppStateListener = (\n appStateStatus: AppStateStatus\n ) => {\n const currentRoute = DdRumReactNavigationTracking.registeredContainer?.getCurrentRoute();\n if (currentRoute === undefined || currentRoute === null) {\n InternalLog.log(\n `We could not determine the route when changing the application state to: ${appStateStatus}. No RUM View event will be sent in this case.`,\n SdkVerbosity.ERROR\n );\n return;\n }\n\n DdRumReactNavigationTracking.handleRouteNavigation(\n currentRoute,\n appStateStatus\n );\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -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;
|