@datadog/mobile-react-native 1.0.0-rc4 → 1.0.0-rc7
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 +1 -1
- package/android/gradle.properties +4 -4
- package/lib/commonjs/DdSdkReactNative.js +38 -23
- 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 +56 -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 +51 -11
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +34 -18
- package/lib/commonjs/index.js.map +1 -1
- 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 +34 -23
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +62 -36
- 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 +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +31 -23
- 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 +52 -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 +31 -11
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +4 -2
- package/lib/module/index.js.map +1 -1
- 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 +30 -23
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js +57 -34
- 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 +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts +6 -6
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +15 -4
- package/lib/typescript/InternalLog.d.ts +11 -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 +4 -2
- package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
- package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +10 -9
- 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/version.d.ts +1 -1
- package/package.json +6 -3
- package/src/DdSdkReactNative.tsx +112 -62
- package/src/DdSdkReactNativeConfiguration.tsx +22 -14
- package/src/InternalLog.tsx +50 -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 +40 -33
- package/src/__tests__/DdSdkReactNative.test.tsx +697 -513
- 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 +179 -106
- package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +714 -644
- 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 +80 -61
- package/src/index.tsx +15 -3
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +61 -49
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +307 -233
- 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 -158
- package/src/version.ts +1 -1
- 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,85 +6,104 @@
|
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
debug(message: string, context: object = {}): Promise<void> {
|
|
20
|
+
InternalLog.log("Tracking debug log “" + message + "”", SdkVerbosity.DEBUG);
|
|
21
|
+
return this.nativeLogs.debug(message, context);
|
|
22
|
+
}
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
info(message: string, context: object = {}): Promise<void> {
|
|
25
|
+
InternalLog.log("Tracking info log “" + message + "”", SdkVerbosity.DEBUG);
|
|
26
|
+
return this.nativeLogs.info(message, context);
|
|
27
|
+
}
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
warn(message: string, context: object = {}): Promise<void> {
|
|
30
|
+
InternalLog.log("Tracking warn log “" + message + "”", SdkVerbosity.DEBUG);
|
|
31
|
+
return this.nativeLogs.warn(message, context);
|
|
32
|
+
}
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
error(message: string, context: object = {}): Promise<void> {
|
|
35
|
+
InternalLog.log("Tracking error log “" + message + "”", SdkVerbosity.DEBUG);
|
|
36
|
+
return this.nativeLogs.error(message, context);
|
|
37
|
+
}
|
|
29
38
|
|
|
30
39
|
}
|
|
31
40
|
|
|
32
41
|
class DdTraceWrapper implements DdTraceType {
|
|
33
42
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
startSpan(operation: string, context: object = {}, timestampMs: number = Date.now()): Promise<string> {
|
|
37
|
-
return this.nativeTrace.startSpan(operation, context, timestampMs);
|
|
38
|
-
}
|
|
43
|
+
private nativeTrace: DdTraceType = NativeModules.DdTrace;
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
59
|
+
private nativeRum: DdRumType = NativeModules.DdRum;
|
|
60
|
+
|
|
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);
|
|
64
|
+
}
|
|
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);
|
|
69
|
+
}
|
|
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);
|
|
74
|
+
}
|
|
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);
|
|
79
|
+
}
|
|
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);
|
|
84
|
+
}
|
|
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);
|
|
89
|
+
}
|
|
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);
|
|
94
|
+
}
|
|
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);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
addTiming(name: string): Promise<void> {
|
|
104
|
+
InternalLog.log("Adding timing “" + name + "” to RUM View", SdkVerbosity.DEBUG);
|
|
105
|
+
return this.nativeRum.addTiming(name);
|
|
106
|
+
}
|
|
88
107
|
}
|
|
89
108
|
|
|
90
109
|
const DdSdk: DdSdkType = NativeModules.DdSdk;
|
package/src/index.tsx
CHANGED
|
@@ -4,11 +4,23 @@
|
|
|
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';
|
|
9
|
+
import { InternalLog } from './InternalLog';
|
|
11
10
|
import { ProxyConfiguration, ProxyType } from './ProxyConfiguration';
|
|
11
|
+
import { SdkVerbosity } from './SdkVerbosity';
|
|
12
12
|
import { TrackingConsent } from './TrackingConsent';
|
|
13
|
+
import { DdLogs, DdTrace, DdRum } from './foundation';
|
|
13
14
|
|
|
14
|
-
export {
|
|
15
|
+
export {
|
|
16
|
+
DdLogs,
|
|
17
|
+
DdTrace,
|
|
18
|
+
DdRum,
|
|
19
|
+
DdSdkReactNativeConfiguration,
|
|
20
|
+
DdSdkReactNative,
|
|
21
|
+
InternalLog,
|
|
22
|
+
ProxyConfiguration,
|
|
23
|
+
ProxyType,
|
|
24
|
+
TrackingConsent,
|
|
25
|
+
SdkVerbosity
|
|
26
|
+
};
|
|
@@ -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,27 +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 EMPTY_MESSAGE =
|
|
12
|
-
const EMPTY_STACK_TRACE =
|
|
13
|
-
const TYPE_SOURCE =
|
|
14
|
-
const TYPE_CONSOLE =
|
|
13
|
+
const EMPTY_MESSAGE = 'Unknown Error';
|
|
14
|
+
const EMPTY_STACK_TRACE = '';
|
|
15
|
+
const TYPE_SOURCE = 'SOURCE';
|
|
16
|
+
const TYPE_CONSOLE = 'CONSOLE';
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
|
-
* Provides RUM auto-instrumentation feature to track errors as RUM events.
|
|
18
|
-
*/
|
|
19
|
+
* Provides RUM auto-instrumentation feature to track errors as RUM events.
|
|
20
|
+
*/
|
|
19
21
|
export class DdRumErrorTracking {
|
|
20
|
-
|
|
21
22
|
private static isTracking = false;
|
|
22
23
|
|
|
23
24
|
private static isInDefaultErrorHandler = false;
|
|
24
25
|
|
|
25
|
-
// eslint-disable-next-line
|
|
26
|
+
// eslint-disable-next-line
|
|
26
27
|
private static defaultErrorHandler: ErrorHandlerCallback = (_error: any, _isFatal?: boolean) => { }
|
|
27
28
|
|
|
28
|
-
// eslint-disable-next-line
|
|
29
|
+
// eslint-disable-next-line
|
|
29
30
|
private static defaultConsoleError = (..._params: unknown[]) => { }
|
|
30
31
|
|
|
31
32
|
/**
|
|
@@ -34,33 +35,41 @@ export class DdRumErrorTracking {
|
|
|
34
35
|
static startTracking(): void {
|
|
35
36
|
// extra safety to avoid wrapping the Error handler twice
|
|
36
37
|
if (DdRumErrorTracking.isTracking) {
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
InternalLog.log(
|
|
39
|
+
'Datadog SDK is already tracking errors',
|
|
40
|
+
SdkVerbosity.WARN
|
|
41
|
+
);
|
|
42
|
+
return;
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
if (ErrorUtils) {
|
|
42
46
|
DdRumErrorTracking.defaultErrorHandler = ErrorUtils.getGlobalHandler();
|
|
43
47
|
DdRumErrorTracking.defaultConsoleError = console.error;
|
|
44
48
|
|
|
45
|
-
|
|
46
49
|
ErrorUtils.setGlobalHandler(DdRumErrorTracking.onGlobalError);
|
|
47
50
|
console.error = DdRumErrorTracking.onConsoleError;
|
|
48
51
|
|
|
49
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
|
+
);
|
|
50
62
|
}
|
|
51
|
-
|
|
52
63
|
}
|
|
53
64
|
|
|
54
65
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
55
66
|
static onGlobalError(error: any, isFatal?: boolean): void {
|
|
56
67
|
const message = DdRumErrorTracking.getErrorMessage(error);
|
|
57
68
|
const stacktrace = DdRumErrorTracking.getErrorStackTrace(error);
|
|
58
|
-
DdRum.addError(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
{ "_dd.error.is_crash": isFatal, "_dd.error.raw": error }
|
|
63
|
-
).then(() => {
|
|
69
|
+
DdRum.addError(message, TYPE_SOURCE, stacktrace, {
|
|
70
|
+
'_dd.error.is_crash': isFatal,
|
|
71
|
+
'_dd.error.raw': error
|
|
72
|
+
}).then(() => {
|
|
64
73
|
DdRumErrorTracking.isInDefaultErrorHandler = true;
|
|
65
74
|
try {
|
|
66
75
|
DdRumErrorTracking.defaultErrorHandler(error, isFatal);
|
|
@@ -71,7 +80,6 @@ export class DdRumErrorTracking {
|
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
static onConsoleError(...params: unknown[]): void {
|
|
74
|
-
|
|
75
83
|
if (DdRumErrorTracking.isInDefaultErrorHandler) {
|
|
76
84
|
return;
|
|
77
85
|
}
|
|
@@ -80,59 +88,63 @@ export class DdRumErrorTracking {
|
|
|
80
88
|
for (let i = 0; i < params.length; i += 1) {
|
|
81
89
|
const param = params[i];
|
|
82
90
|
const paramStack = DdRumErrorTracking.getErrorStackTrace(param);
|
|
83
|
-
if (paramStack
|
|
91
|
+
if (paramStack !== EMPTY_STACK_TRACE) {
|
|
84
92
|
stack = paramStack;
|
|
85
93
|
break;
|
|
86
94
|
}
|
|
87
95
|
}
|
|
88
96
|
|
|
89
|
-
const message = params
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
).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(() => {
|
|
100
108
|
DdRumErrorTracking.defaultConsoleError.apply(console, params);
|
|
101
109
|
});
|
|
102
|
-
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
private static getErrorMessage(error: any | undefined): string {
|
|
106
113
|
let message = EMPTY_MESSAGE;
|
|
107
|
-
if (error
|
|
114
|
+
if (error === undefined || error === null) {
|
|
108
115
|
message = EMPTY_MESSAGE;
|
|
109
|
-
} else if (
|
|
116
|
+
} else if (typeof error === 'object' && 'message' in error) {
|
|
110
117
|
message = String(error.message);
|
|
111
118
|
} else {
|
|
112
119
|
message = String(error);
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
return message
|
|
122
|
+
return message;
|
|
116
123
|
}
|
|
117
124
|
|
|
118
125
|
private static getErrorStackTrace(error: any | undefined): string {
|
|
119
|
-
let stack = EMPTY_STACK_TRACE
|
|
126
|
+
let stack = EMPTY_STACK_TRACE;
|
|
120
127
|
|
|
121
|
-
if (error
|
|
128
|
+
if (error === undefined || error === null) {
|
|
122
129
|
stack = EMPTY_STACK_TRACE;
|
|
123
130
|
} else if (typeof error === 'string') {
|
|
124
131
|
stack = EMPTY_STACK_TRACE;
|
|
125
|
-
} else if ('
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
stack
|
|
131
|
-
|
|
132
|
-
|
|
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
|
+
}
|
|
133
146
|
}
|
|
134
147
|
|
|
135
|
-
return stack
|
|
148
|
+
return stack;
|
|
136
149
|
}
|
|
137
150
|
}
|
|
138
|
-
|