@datadog/mobile-react-native 1.0.0-rc3 → 1.0.0-rc6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DatadogSDKReactNative.podspec +1 -1
- package/README.md +47 -16
- package/android/build.gradle +2 -3
- package/android/gradle.properties +4 -4
- package/android/src/main/java/com/datadog/reactnative/DdRum.kt +25 -24
- package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +6 -6
- package/ios/Sources/DdRum.m +10 -9
- package/ios/Sources/DdRum.swift +24 -24
- package/ios/Sources/DdTrace.m +2 -2
- package/ios/Sources/DdTrace.swift +6 -6
- package/lib/commonjs/DdSdkReactNative.js +42 -22
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +17 -2
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/InternalLog.js +51 -0
- package/lib/commonjs/InternalLog.js.map +1 -0
- package/lib/commonjs/ProxyConfiguration.js.map +1 -1
- package/lib/commonjs/SdkVerbosity.js +26 -0
- package/lib/commonjs/SdkVerbosity.js.map +1 -0
- package/lib/commonjs/TimeProvider.js +72 -0
- package/lib/commonjs/TimeProvider.js.map +1 -0
- package/lib/commonjs/Timer.js +10 -23
- package/lib/commonjs/Timer.js.map +1 -1
- package/lib/commonjs/TrackingConsent.js.map +1 -1
- package/lib/commonjs/foundation.js +62 -40
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +26 -18
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal.js +14 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +14 -5
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +51 -20
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +141 -30
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +46 -7
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js +34 -0
- package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +10 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/DdSdkReactNative.js +34 -22
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +18 -3
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/InternalLog.js +46 -0
- package/lib/module/InternalLog.js.map +1 -0
- package/lib/module/ProxyConfiguration.js.map +1 -1
- package/lib/module/SdkVerbosity.js +18 -0
- package/lib/module/SdkVerbosity.js.map +1 -0
- package/lib/module/TimeProvider.js +63 -0
- package/lib/module/TimeProvider.js.map +1 -0
- package/lib/module/Timer.js +14 -23
- package/lib/module/Timer.js.map +1 -1
- package/lib/module/TrackingConsent.js.map +1 -1
- package/lib/module/foundation.js +42 -40
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +2 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js +11 -5
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +46 -20
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js +133 -29
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +41 -6
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js +25 -0
- package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
- package/lib/module/rum/instrumentation/TraceIdentifier.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +3 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/DdSdkReactNative.d.ts +7 -6
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +15 -4
- package/lib/typescript/InternalLog.d.ts +6 -0
- package/lib/typescript/SdkVerbosity.d.ts +9 -0
- package/lib/typescript/TimeProvider.d.ts +20 -0
- package/lib/typescript/Timer.d.ts +3 -2
- package/lib/typescript/index.d.ts +3 -2
- package/lib/typescript/internal.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +3 -2
- package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +13 -8
- package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
- package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +13 -3
- package/lib/typescript/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
- package/lib/typescript/types.d.ts +12 -11
- package/lib/typescript/version.d.ts +1 -0
- package/package.json +7 -4
- package/src/DdSdkReactNative.tsx +112 -58
- package/src/DdSdkReactNativeConfiguration.tsx +22 -14
- package/src/InternalLog.tsx +45 -0
- package/src/ProxyConfiguration.tsx +5 -5
- package/src/{NativeSdkVerbosity.tsx → SdkVerbosity.tsx} +6 -6
- package/src/TimeProvider.tsx +64 -0
- package/src/Timer.ts +20 -35
- package/src/TrackingConsent.tsx +3 -3
- package/src/__mocks__/InternalLog.tsx +9 -0
- package/src/__tests__/DdRumWrapper.test.tsx +98 -0
- package/src/__tests__/DdSdkReactNative.test.tsx +699 -500
- package/src/__tests__/InternalLog.test.tsx +379 -0
- package/src/__tests__/TimeProvider.test.tsx +75 -0
- package/src/__tests__/Timer.test.ts +148 -57
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +151 -92
- package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +243 -76
- package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +723 -403
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +239 -85
- package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +31 -0
- package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +13 -15
- package/src/__tests__/rum/instrumentation/__utils__/XMLHttpRequestMock.ts +97 -0
- package/src/foundation.tsx +55 -42
- package/src/index.tsx +13 -3
- package/src/internal.tsx +1 -0
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +75 -42
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +312 -166
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +72 -25
- package/src/rum/instrumentation/DdRumXhr.tsx +21 -11
- package/src/rum/instrumentation/EventsInterceptor.tsx +3 -3
- package/src/rum/instrumentation/NoOpEventsInterceptor.tsx +2 -2
- package/src/rum/instrumentation/ShallowObjectEqualityChecker.ts +24 -0
- package/src/rum/instrumentation/TraceIdentifier.tsx +19 -19
- package/src/types.tsx +199 -157
- package/src/version.ts +2 -0
- package/lib/commonjs/NativeSdkVerbosity.js +0 -26
- package/lib/commonjs/NativeSdkVerbosity.js.map +0 -1
- package/lib/module/NativeSdkVerbosity.js +0 -18
- package/lib/module/NativeSdkVerbosity.js.map +0 -1
- package/lib/typescript/NativeSdkVerbosity.d.ts +0 -9
package/src/foundation.tsx
CHANGED
|
@@ -6,21 +6,33 @@
|
|
|
6
6
|
|
|
7
7
|
import { NativeModules } from 'react-native';
|
|
8
8
|
import { DdSdkConfiguration, DdSdkType, DdLogsType, DdTraceType, DdRumType } from './types';
|
|
9
|
+
import {InternalLog} from "./InternalLog"
|
|
10
|
+
import {SdkVerbosity} from "./SdkVerbosity";
|
|
11
|
+
import {TimeProvider} from "./TimeProvider";
|
|
12
|
+
|
|
13
|
+
const timeProvider = new TimeProvider();
|
|
9
14
|
|
|
10
15
|
class DdLogsWrapper implements DdLogsType {
|
|
11
16
|
|
|
12
17
|
private nativeLogs: DdLogsType = NativeModules.DdLogs;
|
|
13
18
|
|
|
14
19
|
debug(message: string, context: object = {}): Promise<void> {
|
|
20
|
+
InternalLog.log("Tracking debug log “" + message + "”", SdkVerbosity.DEBUG);
|
|
15
21
|
return this.nativeLogs.debug(message, context);
|
|
16
22
|
}
|
|
23
|
+
|
|
17
24
|
info(message: string, context: object = {}): Promise<void> {
|
|
25
|
+
InternalLog.log("Tracking info log “" + message + "”", SdkVerbosity.DEBUG);
|
|
18
26
|
return this.nativeLogs.info(message, context);
|
|
19
27
|
}
|
|
28
|
+
|
|
20
29
|
warn(message: string, context: object = {}): Promise<void> {
|
|
30
|
+
InternalLog.log("Tracking warn log “" + message + "”", SdkVerbosity.DEBUG);
|
|
21
31
|
return this.nativeLogs.warn(message, context);
|
|
22
32
|
}
|
|
33
|
+
|
|
23
34
|
error(message: string, context: object = {}): Promise<void> {
|
|
35
|
+
InternalLog.log("Tracking error log “" + message + "”", SdkVerbosity.DEBUG);
|
|
24
36
|
return this.nativeLogs.error(message, context);
|
|
25
37
|
}
|
|
26
38
|
|
|
@@ -30,67 +42,68 @@ class DdTraceWrapper implements DdTraceType {
|
|
|
30
42
|
|
|
31
43
|
private nativeTrace: DdTraceType = NativeModules.DdTrace;
|
|
32
44
|
|
|
33
|
-
startSpan(operation: string, context: object = {}, timestampMs: number =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
finishSpan(spanId: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> {
|
|
39
|
-
// TODO swap context and stacktrace in the native call, requires native bridges update
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
return this.nativeTrace.finishSpan(spanId, timestampMs, context);
|
|
45
|
+
startSpan(operation: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<string> {
|
|
46
|
+
let spanId = this.nativeTrace.startSpan(operation, context, timestampMs);
|
|
47
|
+
InternalLog.log("Starting span “" + operation + "” #" + spanId, SdkVerbosity.DEBUG);
|
|
48
|
+
return spanId
|
|
42
49
|
}
|
|
43
50
|
|
|
51
|
+
finishSpan(spanId: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
52
|
+
InternalLog.log("Finishing span #" + spanId, SdkVerbosity.DEBUG);
|
|
53
|
+
return this.nativeTrace.finishSpan(spanId, context, timestampMs);
|
|
54
|
+
}
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
class DdRumWrapper implements DdRumType {
|
|
47
58
|
|
|
48
59
|
private nativeRum: DdRumType = NativeModules.DdRum;
|
|
49
60
|
|
|
50
|
-
startView(key: string, name: string, context: object = {}, timestampMs: number =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return this.nativeRum.startView(key, name, timestampMs, context);
|
|
61
|
+
startView(key: string, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
62
|
+
InternalLog.log("Starting RUM View “" + name + "” #" + key, SdkVerbosity.DEBUG);
|
|
63
|
+
return this.nativeRum.startView(key, name, context, timestampMs);
|
|
54
64
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return this.nativeRum.stopView(key,
|
|
65
|
+
|
|
66
|
+
stopView(key: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
67
|
+
InternalLog.log("Stopping RUM View #" + key, SdkVerbosity.DEBUG);
|
|
68
|
+
return this.nativeRum.stopView(key, context, timestampMs);
|
|
59
69
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return this.nativeRum.startAction(type, name,
|
|
70
|
+
|
|
71
|
+
startAction(type: string, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
72
|
+
InternalLog.log("Starting RUM Action “" + name + "” (" + type + ")", SdkVerbosity.DEBUG);
|
|
73
|
+
return this.nativeRum.startAction(type, name, context, timestampMs);
|
|
64
74
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return this.nativeRum.stopAction(
|
|
75
|
+
|
|
76
|
+
stopAction(context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
77
|
+
InternalLog.log("Stopping current RUM Action", SdkVerbosity.DEBUG);
|
|
78
|
+
return this.nativeRum.stopAction(context, timestampMs);
|
|
69
79
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return this.nativeRum.addAction(type, name,
|
|
80
|
+
|
|
81
|
+
addAction(type: string, name: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
82
|
+
InternalLog.log("Adding RUM Action “" + name + "” (" + type + ")", SdkVerbosity.DEBUG);
|
|
83
|
+
return this.nativeRum.addAction(type, name, context, timestampMs);
|
|
74
84
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return this.nativeRum.startResource(key, method, url,
|
|
85
|
+
|
|
86
|
+
startResource(key: string, method: string, url: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
87
|
+
InternalLog.log("Starting RUM Resource #" + key + " " + method + ": " + url, SdkVerbosity.DEBUG);
|
|
88
|
+
return this.nativeRum.startResource(key, method, url, context, timestampMs);
|
|
79
89
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return this.nativeRum.stopResource(key, statusCode, kind,
|
|
90
|
+
|
|
91
|
+
stopResource(key: string, statusCode: number, kind: string, size: number = -1, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
92
|
+
InternalLog.log("Stopping RUM Resource #" + key + " status:" + statusCode, SdkVerbosity.DEBUG);
|
|
93
|
+
return this.nativeRum.stopResource(key, statusCode, kind, size, context, timestampMs);
|
|
84
94
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
|
|
96
|
+
addError(message: string, source: string, stacktrace: string, context: object = {}, timestampMs: number = timeProvider.now()): Promise<void> {
|
|
97
|
+
InternalLog.log("Adding RUM Error “" + message + "”", SdkVerbosity.DEBUG);
|
|
98
|
+
let updatedContext: any = context;
|
|
99
|
+
updatedContext["_dd.error.source_type"] = "react-native";
|
|
100
|
+
return this.nativeRum.addError(message, source, stacktrace, updatedContext, timestampMs);
|
|
89
101
|
}
|
|
102
|
+
|
|
90
103
|
addTiming(name: string): Promise<void> {
|
|
104
|
+
InternalLog.log("Adding timing “" + name + "” to RUM View", SdkVerbosity.DEBUG);
|
|
91
105
|
return this.nativeRum.addTiming(name);
|
|
92
106
|
}
|
|
93
|
-
|
|
94
107
|
}
|
|
95
108
|
|
|
96
109
|
const DdSdk: DdSdkType = NativeModules.DdSdk;
|
package/src/index.tsx
CHANGED
|
@@ -4,11 +4,21 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
8
|
-
|
|
9
7
|
import { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';
|
|
10
8
|
import { DdSdkReactNative } from './DdSdkReactNative';
|
|
11
9
|
import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
|
|
10
|
+
import { SdkVerbosity } from './SdkVerbosity';
|
|
12
11
|
import { TrackingConsent } from './TrackingConsent';
|
|
12
|
+
import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
13
13
|
|
|
14
|
-
export {
|
|
14
|
+
export {
|
|
15
|
+
DdLogs,
|
|
16
|
+
DdTrace,
|
|
17
|
+
DdRum,
|
|
18
|
+
DdSdkReactNativeConfiguration,
|
|
19
|
+
DdSdkReactNative,
|
|
20
|
+
ProxyConfiguration,
|
|
21
|
+
ProxyType,
|
|
22
|
+
TrackingConsent,
|
|
23
|
+
SdkVerbosity
|
|
24
|
+
};
|
package/src/internal.tsx
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InternalLog } from './InternalLog';
|
|
@@ -4,71 +4,87 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
7
|
+
import { InternalLog } from '../../InternalLog';
|
|
8
|
+
import { SdkVerbosity } from '../../SdkVerbosity';
|
|
9
|
+
import { DdRum } from '../../foundation';
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
11
|
+
import type EventsInterceptor from './EventsInterceptor';
|
|
12
|
+
|
|
13
|
+
export const UNKNOWN_TARGET_NAME = 'unknown_target';
|
|
14
|
+
const DEBOUNCE_EVENT_THRESHOLD_IN_MS = 10;
|
|
15
|
+
const HANDLE_EVENT_APP_EXECUTION_TIME_IN_MS = 1;
|
|
16
|
+
const DD_ACTION_NAME_PROP = 'dd-action-name';
|
|
14
17
|
|
|
15
18
|
export class DdEventsInterceptor implements EventsInterceptor {
|
|
19
|
+
static ACTION_EVENT_DROPPED_WARN_MESSAGE =
|
|
20
|
+
'An action event was dropped because either the `onPress` method arguments' +
|
|
21
|
+
' were undefined or they were missing the target information.';
|
|
16
22
|
|
|
17
|
-
private debouncingStartedTimestamp = Number.MIN_VALUE
|
|
23
|
+
private debouncingStartedTimestamp = Number.MIN_VALUE;
|
|
18
24
|
|
|
19
25
|
interceptOnPress(...args: any[]): void {
|
|
20
26
|
if (args.length > 0 && args[0] && args[0]._targetInst) {
|
|
21
|
-
const currentTime = Date.now()
|
|
22
|
-
const timestampDifference = Math.abs(
|
|
27
|
+
const currentTime = Date.now();
|
|
28
|
+
const timestampDifference = Math.abs(
|
|
29
|
+
Date.now() - this.debouncingStartedTimestamp
|
|
30
|
+
);
|
|
23
31
|
if (timestampDifference > DEBOUNCE_EVENT_THRESHOLD_IN_MS) {
|
|
24
|
-
const targetNode = args[0]._targetInst
|
|
25
|
-
this.handleTargetEvent(targetNode)
|
|
32
|
+
const targetNode = args[0]._targetInst;
|
|
33
|
+
this.handleTargetEvent(targetNode);
|
|
26
34
|
// we add an approximated 1 millisecond for the execution time of the `handleTargetEvent` function
|
|
27
|
-
this.debouncingStartedTimestamp =
|
|
35
|
+
this.debouncingStartedTimestamp =
|
|
36
|
+
currentTime + HANDLE_EVENT_APP_EXECUTION_TIME_IN_MS;
|
|
28
37
|
}
|
|
38
|
+
} else {
|
|
39
|
+
InternalLog.log(
|
|
40
|
+
DdEventsInterceptor.ACTION_EVENT_DROPPED_WARN_MESSAGE,
|
|
41
|
+
SdkVerbosity.WARN
|
|
42
|
+
);
|
|
29
43
|
}
|
|
30
44
|
}
|
|
31
45
|
|
|
32
46
|
private handleTargetEvent(targetNode: any | null) {
|
|
33
47
|
if (targetNode) {
|
|
34
48
|
const resolvedTargetName = this.resolveTargetName(targetNode);
|
|
35
|
-
DdRum.addAction(RumActionType.TAP.valueOf(), resolvedTargetName)
|
|
49
|
+
DdRum.addAction(RumActionType.TAP.valueOf(), resolvedTargetName);
|
|
36
50
|
}
|
|
37
51
|
}
|
|
38
52
|
|
|
39
53
|
private resolveTargetName(targetNode: any): string {
|
|
40
|
-
const closestActionLabel = this.findClosestActionLabel(targetNode)
|
|
54
|
+
const closestActionLabel = this.findClosestActionLabel(targetNode);
|
|
41
55
|
if (closestActionLabel != null) {
|
|
42
|
-
return closestActionLabel
|
|
56
|
+
return closestActionLabel;
|
|
43
57
|
}
|
|
44
|
-
const accessibilityLabel = targetNode.memoizedProps?.accessibilityLabel
|
|
58
|
+
const accessibilityLabel = targetNode.memoizedProps?.accessibilityLabel;
|
|
45
59
|
if (accessibilityLabel != null) {
|
|
46
|
-
return accessibilityLabel
|
|
60
|
+
return accessibilityLabel;
|
|
47
61
|
}
|
|
48
|
-
const elementTypeName = this.resolveElementTypeName(
|
|
49
|
-
|
|
62
|
+
const elementTypeName = this.resolveElementTypeName(
|
|
63
|
+
targetNode.elementType
|
|
64
|
+
);
|
|
65
|
+
return elementTypeName || UNKNOWN_TARGET_NAME;
|
|
50
66
|
}
|
|
51
67
|
|
|
52
68
|
private resolveElementTypeName(elementType: any): string | null {
|
|
53
|
-
let elementTypeName = null
|
|
54
|
-
if (typeof elementType ===
|
|
55
|
-
elementTypeName = elementType
|
|
56
|
-
} else if (elementType && typeof elementType.name ===
|
|
57
|
-
elementTypeName = elementType.name
|
|
69
|
+
let elementTypeName = null;
|
|
70
|
+
if (typeof elementType === 'string') {
|
|
71
|
+
elementTypeName = elementType;
|
|
72
|
+
} else if (elementType && typeof elementType.name === 'string') {
|
|
73
|
+
elementTypeName = elementType.name;
|
|
58
74
|
}
|
|
59
|
-
return elementTypeName
|
|
75
|
+
return elementTypeName;
|
|
60
76
|
}
|
|
61
77
|
|
|
62
78
|
private findClosestActionLabel(targetNode: any): string | null {
|
|
63
|
-
let currentNode = targetNode
|
|
79
|
+
let currentNode = targetNode;
|
|
64
80
|
while (currentNode) {
|
|
65
|
-
const props = currentNode.memoizedProps
|
|
81
|
+
const props = currentNode.memoizedProps;
|
|
66
82
|
if (props && props[DD_ACTION_NAME_PROP]) {
|
|
67
|
-
return props[DD_ACTION_NAME_PROP]
|
|
83
|
+
return props[DD_ACTION_NAME_PROP];
|
|
68
84
|
}
|
|
69
|
-
currentNode = currentNode.return
|
|
85
|
+
currentNode = currentNode.return;
|
|
70
86
|
}
|
|
71
|
-
return null
|
|
87
|
+
return null;
|
|
72
88
|
}
|
|
73
89
|
}
|
|
74
90
|
|
|
@@ -77,13 +93,13 @@ export class DdEventsInterceptor implements EventsInterceptor {
|
|
|
77
93
|
*/
|
|
78
94
|
export enum RumActionType {
|
|
79
95
|
/** User tapped on a widget. */
|
|
80
|
-
TAP =
|
|
96
|
+
TAP = 'TAP',
|
|
81
97
|
/** User scrolled a view. */
|
|
82
|
-
SCROLL =
|
|
98
|
+
SCROLL = 'SCROLL',
|
|
83
99
|
/** User swiped on a view. */
|
|
84
|
-
SWIPE =
|
|
100
|
+
SWIPE = 'SWIPE',
|
|
85
101
|
/** User clicked on a widget (not used on Mobile). */
|
|
86
|
-
CLICK =
|
|
102
|
+
CLICK = 'CLICK',
|
|
87
103
|
/** A custom action. */
|
|
88
|
-
CUSTOM =
|
|
104
|
+
CUSTOM = 'CUSTOM'
|
|
89
105
|
}
|
|
@@ -5,26 +5,28 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { ErrorHandlerCallback } from 'react-native';
|
|
8
|
-
import { DdRum } from '../../foundation';
|
|
9
8
|
|
|
9
|
+
import { InternalLog } from '../../InternalLog';
|
|
10
|
+
import { SdkVerbosity } from '../../SdkVerbosity';
|
|
11
|
+
import { DdRum } from '../../foundation';
|
|
10
12
|
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
13
|
+
const EMPTY_MESSAGE = 'Unknown Error';
|
|
14
|
+
const EMPTY_STACK_TRACE = '';
|
|
15
|
+
const TYPE_SOURCE = 'SOURCE';
|
|
16
|
+
const TYPE_CONSOLE = 'CONSOLE';
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
|
-
* Provides RUM auto-instrumentation feature to track errors as RUM events.
|
|
17
|
-
*/
|
|
19
|
+
* Provides RUM auto-instrumentation feature to track errors as RUM events.
|
|
20
|
+
*/
|
|
18
21
|
export class DdRumErrorTracking {
|
|
19
|
-
|
|
20
22
|
private static isTracking = false;
|
|
21
23
|
|
|
22
24
|
private static isInDefaultErrorHandler = false;
|
|
23
25
|
|
|
24
|
-
// eslint-disable-next-line
|
|
26
|
+
// eslint-disable-next-line
|
|
25
27
|
private static defaultErrorHandler: ErrorHandlerCallback = (_error: any, _isFatal?: boolean) => { }
|
|
26
28
|
|
|
27
|
-
// eslint-disable-next-line
|
|
29
|
+
// eslint-disable-next-line
|
|
28
30
|
private static defaultConsoleError = (..._params: unknown[]) => { }
|
|
29
31
|
|
|
30
32
|
/**
|
|
@@ -33,31 +35,41 @@ export class DdRumErrorTracking {
|
|
|
33
35
|
static startTracking(): void {
|
|
34
36
|
// extra safety to avoid wrapping the Error handler twice
|
|
35
37
|
if (DdRumErrorTracking.isTracking) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
InternalLog.log(
|
|
39
|
+
'Datadog SDK is already tracking errors',
|
|
40
|
+
SdkVerbosity.WARN
|
|
41
|
+
);
|
|
42
|
+
return;
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
if (ErrorUtils) {
|
|
41
46
|
DdRumErrorTracking.defaultErrorHandler = ErrorUtils.getGlobalHandler();
|
|
42
47
|
DdRumErrorTracking.defaultConsoleError = console.error;
|
|
43
48
|
|
|
44
|
-
|
|
45
49
|
ErrorUtils.setGlobalHandler(DdRumErrorTracking.onGlobalError);
|
|
46
50
|
console.error = DdRumErrorTracking.onConsoleError;
|
|
47
51
|
|
|
48
52
|
DdRumErrorTracking.isTracking = true;
|
|
53
|
+
InternalLog.log(
|
|
54
|
+
'Datadog SDK is tracking errors',
|
|
55
|
+
SdkVerbosity.INFO
|
|
56
|
+
);
|
|
57
|
+
} else {
|
|
58
|
+
InternalLog.log(
|
|
59
|
+
'Datadog SDK cannot track errors, ErrorUtils is not defined',
|
|
60
|
+
SdkVerbosity.ERROR
|
|
61
|
+
);
|
|
49
62
|
}
|
|
50
|
-
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
54
66
|
static onGlobalError(error: any, isFatal?: boolean): void {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
).then(() => {
|
|
67
|
+
const message = DdRumErrorTracking.getErrorMessage(error);
|
|
68
|
+
const stacktrace = DdRumErrorTracking.getErrorStackTrace(error);
|
|
69
|
+
DdRum.addError(message, TYPE_SOURCE, stacktrace, {
|
|
70
|
+
'_dd.error.is_crash': isFatal,
|
|
71
|
+
'_dd.error.raw': error
|
|
72
|
+
}).then(() => {
|
|
61
73
|
DdRumErrorTracking.isInDefaultErrorHandler = true;
|
|
62
74
|
try {
|
|
63
75
|
DdRumErrorTracking.defaultErrorHandler(error, isFatal);
|
|
@@ -68,7 +80,6 @@ export class DdRumErrorTracking {
|
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
static onConsoleError(...params: unknown[]): void {
|
|
71
|
-
|
|
72
83
|
if (DdRumErrorTracking.isInDefaultErrorHandler) {
|
|
73
84
|
return;
|
|
74
85
|
}
|
|
@@ -76,42 +87,64 @@ export class DdRumErrorTracking {
|
|
|
76
87
|
let stack: string = EMPTY_STACK_TRACE;
|
|
77
88
|
for (let i = 0; i < params.length; i += 1) {
|
|
78
89
|
const param = params[i];
|
|
79
|
-
const paramStack = DdRumErrorTracking.getErrorStackTrace(param)
|
|
80
|
-
if (paramStack
|
|
90
|
+
const paramStack = DdRumErrorTracking.getErrorStackTrace(param);
|
|
91
|
+
if (paramStack !== EMPTY_STACK_TRACE) {
|
|
81
92
|
stack = paramStack;
|
|
82
93
|
break;
|
|
83
94
|
}
|
|
84
95
|
}
|
|
85
96
|
|
|
86
|
-
const message = params
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
).then(() => {
|
|
97
|
+
const message = params
|
|
98
|
+
.map(param => {
|
|
99
|
+
if (typeof param === 'string') {
|
|
100
|
+
return param;
|
|
101
|
+
} else {
|
|
102
|
+
return DdRumErrorTracking.getErrorMessage(param);
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
.join(' ');
|
|
106
|
+
|
|
107
|
+
DdRum.addError(message, TYPE_CONSOLE, stack).then(() => {
|
|
98
108
|
DdRumErrorTracking.defaultConsoleError.apply(console, params);
|
|
99
109
|
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private static getErrorMessage(error: any | undefined): string {
|
|
113
|
+
let message = EMPTY_MESSAGE;
|
|
114
|
+
if (error === undefined || error === null) {
|
|
115
|
+
message = EMPTY_MESSAGE;
|
|
116
|
+
} else if (typeof error === 'object' && 'message' in error) {
|
|
117
|
+
message = String(error.message);
|
|
118
|
+
} else {
|
|
119
|
+
message = String(error);
|
|
120
|
+
}
|
|
100
121
|
|
|
122
|
+
return message;
|
|
101
123
|
}
|
|
102
124
|
|
|
103
125
|
private static getErrorStackTrace(error: any | undefined): string {
|
|
104
|
-
let stack = EMPTY_STACK_TRACE
|
|
105
|
-
|
|
126
|
+
let stack = EMPTY_STACK_TRACE;
|
|
127
|
+
|
|
128
|
+
if (error === undefined || error === null) {
|
|
106
129
|
stack = EMPTY_STACK_TRACE;
|
|
107
130
|
} else if (typeof error === 'string') {
|
|
108
131
|
stack = EMPTY_STACK_TRACE;
|
|
109
|
-
} else if ('
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
132
|
+
} else if (typeof error === 'object') {
|
|
133
|
+
if ('componentStack' in error) {
|
|
134
|
+
stack = String(error.componentStack);
|
|
135
|
+
} else if ('stacktrace' in error) {
|
|
136
|
+
stack = String(error.stacktrace);
|
|
137
|
+
} else if ('stack' in error) {
|
|
138
|
+
stack = String(error.stack);
|
|
139
|
+
} else if (
|
|
140
|
+
'sourceURL' in error &&
|
|
141
|
+
'line' in error &&
|
|
142
|
+
'column' in error
|
|
143
|
+
) {
|
|
144
|
+
stack = `at ${error.sourceURL}:${error.line}:${error.column}`;
|
|
145
|
+
}
|
|
113
146
|
}
|
|
114
|
-
|
|
147
|
+
|
|
148
|
+
return stack;
|
|
115
149
|
}
|
|
116
150
|
}
|
|
117
|
-
|