@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.
Files changed (137) hide show
  1. package/DatadogSDKReactNative.podspec +1 -1
  2. package/README.md +47 -16
  3. package/android/build.gradle +2 -3
  4. package/android/gradle.properties +4 -4
  5. package/android/src/main/java/com/datadog/reactnative/DdRum.kt +25 -24
  6. package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +6 -6
  7. package/ios/Sources/DdRum.m +10 -9
  8. package/ios/Sources/DdRum.swift +24 -24
  9. package/ios/Sources/DdTrace.m +2 -2
  10. package/ios/Sources/DdTrace.swift +6 -6
  11. package/lib/commonjs/DdSdkReactNative.js +42 -22
  12. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  13. package/lib/commonjs/DdSdkReactNativeConfiguration.js +17 -2
  14. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  15. package/lib/commonjs/InternalLog.js +51 -0
  16. package/lib/commonjs/InternalLog.js.map +1 -0
  17. package/lib/commonjs/ProxyConfiguration.js.map +1 -1
  18. package/lib/commonjs/SdkVerbosity.js +26 -0
  19. package/lib/commonjs/SdkVerbosity.js.map +1 -0
  20. package/lib/commonjs/TimeProvider.js +72 -0
  21. package/lib/commonjs/TimeProvider.js.map +1 -0
  22. package/lib/commonjs/Timer.js +10 -23
  23. package/lib/commonjs/Timer.js.map +1 -1
  24. package/lib/commonjs/TrackingConsent.js.map +1 -1
  25. package/lib/commonjs/foundation.js +62 -40
  26. package/lib/commonjs/foundation.js.map +1 -1
  27. package/lib/commonjs/index.js +26 -18
  28. package/lib/commonjs/index.js.map +1 -1
  29. package/lib/commonjs/internal.js +14 -0
  30. package/lib/commonjs/internal.js.map +1 -0
  31. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +14 -5
  32. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  33. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +51 -20
  34. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  35. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +141 -30
  36. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  37. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +46 -7
  38. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  39. package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  40. package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js +34 -0
  41. package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
  42. package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +1 -1
  43. package/lib/commonjs/types.js.map +1 -1
  44. package/lib/commonjs/version.js +10 -0
  45. package/lib/commonjs/version.js.map +1 -0
  46. package/lib/module/DdSdkReactNative.js +34 -22
  47. package/lib/module/DdSdkReactNative.js.map +1 -1
  48. package/lib/module/DdSdkReactNativeConfiguration.js +18 -3
  49. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  50. package/lib/module/InternalLog.js +46 -0
  51. package/lib/module/InternalLog.js.map +1 -0
  52. package/lib/module/ProxyConfiguration.js.map +1 -1
  53. package/lib/module/SdkVerbosity.js +18 -0
  54. package/lib/module/SdkVerbosity.js.map +1 -0
  55. package/lib/module/TimeProvider.js +63 -0
  56. package/lib/module/TimeProvider.js.map +1 -0
  57. package/lib/module/Timer.js +14 -23
  58. package/lib/module/Timer.js.map +1 -1
  59. package/lib/module/TrackingConsent.js.map +1 -1
  60. package/lib/module/foundation.js +42 -40
  61. package/lib/module/foundation.js.map +1 -1
  62. package/lib/module/index.js +3 -2
  63. package/lib/module/index.js.map +1 -1
  64. package/lib/module/internal.js +2 -0
  65. package/lib/module/internal.js.map +1 -0
  66. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +11 -5
  67. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  68. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +46 -20
  69. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  70. package/lib/module/rum/instrumentation/DdRumResourceTracking.js +133 -29
  71. package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
  72. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +41 -6
  73. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  74. package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
  75. package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js +25 -0
  76. package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
  77. package/lib/module/rum/instrumentation/TraceIdentifier.js.map +1 -1
  78. package/lib/module/types.js.map +1 -1
  79. package/lib/module/version.js +3 -0
  80. package/lib/module/version.js.map +1 -0
  81. package/lib/typescript/DdSdkReactNative.d.ts +7 -6
  82. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +15 -4
  83. package/lib/typescript/InternalLog.d.ts +6 -0
  84. package/lib/typescript/SdkVerbosity.d.ts +9 -0
  85. package/lib/typescript/TimeProvider.d.ts +20 -0
  86. package/lib/typescript/Timer.d.ts +3 -2
  87. package/lib/typescript/index.d.ts +3 -2
  88. package/lib/typescript/internal.d.ts +1 -0
  89. package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
  90. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +3 -2
  91. package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +13 -8
  92. package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
  93. package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +13 -3
  94. package/lib/typescript/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
  95. package/lib/typescript/types.d.ts +12 -11
  96. package/lib/typescript/version.d.ts +1 -0
  97. package/package.json +7 -4
  98. package/src/DdSdkReactNative.tsx +112 -58
  99. package/src/DdSdkReactNativeConfiguration.tsx +22 -14
  100. package/src/InternalLog.tsx +45 -0
  101. package/src/ProxyConfiguration.tsx +5 -5
  102. package/src/{NativeSdkVerbosity.tsx → SdkVerbosity.tsx} +6 -6
  103. package/src/TimeProvider.tsx +64 -0
  104. package/src/Timer.ts +20 -35
  105. package/src/TrackingConsent.tsx +3 -3
  106. package/src/__mocks__/InternalLog.tsx +9 -0
  107. package/src/__tests__/DdRumWrapper.test.tsx +98 -0
  108. package/src/__tests__/DdSdkReactNative.test.tsx +699 -500
  109. package/src/__tests__/InternalLog.test.tsx +379 -0
  110. package/src/__tests__/TimeProvider.test.tsx +75 -0
  111. package/src/__tests__/Timer.test.ts +148 -57
  112. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +151 -92
  113. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +243 -76
  114. package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +723 -403
  115. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +239 -85
  116. package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +31 -0
  117. package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +13 -15
  118. package/src/__tests__/rum/instrumentation/__utils__/XMLHttpRequestMock.ts +97 -0
  119. package/src/foundation.tsx +55 -42
  120. package/src/index.tsx +13 -3
  121. package/src/internal.tsx +1 -0
  122. package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
  123. package/src/rum/instrumentation/DdRumErrorTracking.tsx +75 -42
  124. package/src/rum/instrumentation/DdRumResourceTracking.tsx +312 -166
  125. package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +72 -25
  126. package/src/rum/instrumentation/DdRumXhr.tsx +21 -11
  127. package/src/rum/instrumentation/EventsInterceptor.tsx +3 -3
  128. package/src/rum/instrumentation/NoOpEventsInterceptor.tsx +2 -2
  129. package/src/rum/instrumentation/ShallowObjectEqualityChecker.ts +24 -0
  130. package/src/rum/instrumentation/TraceIdentifier.tsx +19 -19
  131. package/src/types.tsx +199 -157
  132. package/src/version.ts +2 -0
  133. package/lib/commonjs/NativeSdkVerbosity.js +0 -26
  134. package/lib/commonjs/NativeSdkVerbosity.js.map +0 -1
  135. package/lib/module/NativeSdkVerbosity.js +0 -18
  136. package/lib/module/NativeSdkVerbosity.js.map +0 -1
  137. package/lib/typescript/NativeSdkVerbosity.d.ts +0 -9
@@ -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 = Date.now()): Promise<string> {
34
- // TODO swap context and stacktrace in the native call, requires native bridges update
35
- // @ts-ignore
36
- return this.nativeTrace.startSpan(operation, timestampMs, context);
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 = Date.now()): Promise<void> {
51
- // TODO swap context and stacktrace in the native call, requires native bridges update
52
- // @ts-ignore
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
- stopView(key: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> {
56
- // TODO swap context and stacktrace in the native call, requires native bridges update
57
- // @ts-ignore
58
- return this.nativeRum.stopView(key, timestampMs, context);
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
- startAction(type: string, name: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> {
61
- // TODO swap context and stacktrace in the native call, requires native bridges update
62
- // @ts-ignore
63
- return this.nativeRum.startAction(type, name, timestampMs, context);
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
- stopAction(context: object = {}, timestampMs: number = Date.now()): Promise<void> {
66
- // TODO swap context and stacktrace in the native call, requires native bridges update
67
- // @ts-ignore
68
- return this.nativeRum.stopAction(timestampMs, context);
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
- addAction(type: string, name: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> {
71
- // TODO swap context and stacktrace in the native call, requires native bridges update
72
- // @ts-ignore
73
- return this.nativeRum.addAction(type, name, timestampMs, context);
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
- startResource(key: string, method: string, url: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> {
76
- // TODO swap context and stacktrace in the native call, requires native bridges update
77
- // @ts-ignore
78
- return this.nativeRum.startResource(key, method, url, timestampMs, context);
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
- stopResource(key: string, statusCode: number, kind: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> {
81
- // TODO swap context and stacktrace in the native call, requires native bridges update
82
- // @ts-ignore
83
- return this.nativeRum.stopResource(key, statusCode, kind, timestampMs, context);
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
- addError(message: string, source: string, stacktrace: string, context: object = {}, timestampMs: number = Date.now()): Promise<void> {
86
- // TODO swap context and stacktrace in the native call, requires native bridges update
87
- // @ts-ignore
88
- return this.nativeRum.addError(message, source, stacktrace, timestampMs, context);
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 { DdLogs, DdTrace, DdRum, DdSdkReactNativeConfiguration, DdSdkReactNative, ProxyConfiguration, ProxyType, TrackingConsent };
14
+ export {
15
+ DdLogs,
16
+ DdTrace,
17
+ DdRum,
18
+ DdSdkReactNativeConfiguration,
19
+ DdSdkReactNative,
20
+ ProxyConfiguration,
21
+ ProxyType,
22
+ TrackingConsent,
23
+ SdkVerbosity
24
+ };
@@ -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 type EventsInterceptor from './EventsInterceptor'
8
- import { DdRum } from '../../foundation'
7
+ import { InternalLog } from '../../InternalLog';
8
+ import { SdkVerbosity } from '../../SdkVerbosity';
9
+ import { DdRum } from '../../foundation';
9
10
 
10
- export const UNKNOWN_TARGET_NAME = "unknown_target"
11
- const DEBOUNCE_EVENT_THRESHOLD_IN_MS = 10
12
- const HANDLE_EVENT_APP_EXECUTION_TIME_IN_MS = 1
13
- const DD_ACTION_NAME_PROP = "dd-action-name"
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(Date.now() - this.debouncingStartedTimestamp)
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 = currentTime + HANDLE_EVENT_APP_EXECUTION_TIME_IN_MS
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(targetNode.elementType)
49
- return elementTypeName ? elementTypeName : UNKNOWN_TARGET_NAME
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 === "string") {
55
- elementTypeName = elementType
56
- } else if (elementType && typeof elementType.name === "string") {
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 = "TAP",
96
+ TAP = 'TAP',
81
97
  /** User scrolled a view. */
82
- SCROLL = "SCROLL",
98
+ SCROLL = 'SCROLL',
83
99
  /** User swiped on a view. */
84
- SWIPE = "SWIPE",
100
+ SWIPE = 'SWIPE',
85
101
  /** User clicked on a widget (not used on Mobile). */
86
- CLICK = "CLICK",
102
+ CLICK = 'CLICK',
87
103
  /** A custom action. */
88
- CUSTOM = "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 EMPTY_STACK_TRACE = ""
12
- const TYPE_SOURCE = "SOURCE"
13
- const TYPE_CONSOLE = "CONSOLE"
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
- console.log("DdRumErrorTracking already started");
37
- return
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
- DdRum.addError(
56
- String(error),
57
- TYPE_SOURCE,
58
- DdRumErrorTracking.getErrorStackTrace(error),
59
- { "_dd.error.is_crash": isFatal, "_dd.error.raw": error }
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 != undefined && paramStack != EMPTY_STACK_TRACE) {
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.map((param) => {
87
- if (typeof param === 'string') { return param }
88
- else if (param instanceof Error) { return String(param) }
89
- else { return JSON.stringify(param) }
90
- }).join(' ');
91
-
92
-
93
- DdRum.addError(
94
- message,
95
- TYPE_CONSOLE,
96
- stack
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
- if (error == undefined) {
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 ('componentStack' in error) {
110
- stack = String(error.componentStack);
111
- } else if (('sourceURL' in error) && ('line' in error) && ('column' in error)) {
112
- stack = `at ${error.sourceURL}:${error.line}:${error.column}`;
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
- return stack
147
+
148
+ return stack;
115
149
  }
116
150
  }
117
-