@datadog/mobile-react-native 1.5.2 → 1.6.0

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 (103) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/gradle.properties +1 -1
  3. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +4 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +6 -1
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdLogs.kt +162 -6
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdRum.kt +9 -0
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +4 -0
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +5 -1
  9. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +4 -0
  10. package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +242 -2
  11. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +10 -0
  12. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +6 -2
  13. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +2 -0
  14. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +2 -2
  15. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +3 -1
  16. package/ios/Sources/Attributes.swift +7 -0
  17. package/ios/Sources/DdLogs.m +31 -0
  18. package/ios/Sources/DdLogs.swift +84 -4
  19. package/ios/Sources/DdRum.m +3 -0
  20. package/ios/Sources/DdRum.swift +7 -0
  21. package/ios/Sources/DdSdk.swift +2 -0
  22. package/ios/Sources/DdSdkConfiguration.swift +7 -1
  23. package/ios/Sources/RNDdSdkConfiguration.swift +5 -1
  24. package/lib/commonjs/DdSdkReactNative.js +5 -1
  25. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  26. package/lib/commonjs/InternalLog.js +6 -2
  27. package/lib/commonjs/InternalLog.js.map +1 -1
  28. package/lib/commonjs/errorUtils.js +20 -1
  29. package/lib/commonjs/errorUtils.js.map +1 -1
  30. package/lib/commonjs/logs/DdLogs.js +102 -11
  31. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  32. package/lib/commonjs/logs/eventMapper.js.map +1 -1
  33. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  34. package/lib/commonjs/rum/DdRum.js +6 -0
  35. package/lib/commonjs/rum/DdRum.js.map +1 -1
  36. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +60 -46
  37. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  38. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +2 -2
  39. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  40. package/lib/commonjs/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js +9 -1
  41. package/lib/commonjs/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js.map +1 -1
  42. package/lib/commonjs/rum/types.js.map +1 -1
  43. package/lib/commonjs/types.js.map +1 -1
  44. package/lib/commonjs/version.js +1 -1
  45. package/lib/commonjs/version.js.map +1 -1
  46. package/lib/module/DdSdkReactNative.js +5 -1
  47. package/lib/module/DdSdkReactNative.js.map +1 -1
  48. package/lib/module/InternalLog.js +2 -1
  49. package/lib/module/InternalLog.js.map +1 -1
  50. package/lib/module/errorUtils.js +15 -0
  51. package/lib/module/errorUtils.js.map +1 -1
  52. package/lib/module/logs/DdLogs.js +103 -12
  53. package/lib/module/logs/DdLogs.js.map +1 -1
  54. package/lib/module/logs/eventMapper.js.map +1 -1
  55. package/lib/module/nativeModulesTypes.js.map +1 -1
  56. package/lib/module/rum/DdRum.js +5 -0
  57. package/lib/module/rum/DdRum.js.map +1 -1
  58. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +61 -46
  59. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  60. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +2 -2
  61. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  62. package/lib/module/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js +9 -1
  63. package/lib/module/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js.map +1 -1
  64. package/lib/module/rum/types.js.map +1 -1
  65. package/lib/module/types.js.map +1 -1
  66. package/lib/module/version.js +1 -1
  67. package/lib/module/version.js.map +1 -1
  68. package/lib/typescript/InternalLog.d.ts +1 -0
  69. package/lib/typescript/errorUtils.d.ts +2 -0
  70. package/lib/typescript/logs/DdLogs.d.ts +13 -5
  71. package/lib/typescript/logs/eventMapper.d.ts +5 -5
  72. package/lib/typescript/logs/types.d.ts +34 -8
  73. package/lib/typescript/nativeModulesTypes.d.ts +44 -4
  74. package/lib/typescript/rum/DdRum.d.ts +1 -0
  75. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +3 -2
  76. package/lib/typescript/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts +1 -1
  77. package/lib/typescript/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.d.ts +5 -2
  78. package/lib/typescript/rum/types.d.ts +4 -0
  79. package/lib/typescript/types.d.ts +4 -0
  80. package/lib/typescript/version.d.ts +1 -1
  81. package/package.json +2 -2
  82. package/src/DdSdkReactNative.tsx +6 -1
  83. package/src/InternalLog.tsx +3 -1
  84. package/src/__tests__/errorUtils.test.ts +49 -0
  85. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +14 -14
  86. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +452 -109
  87. package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +18 -0
  88. package/src/errorUtils.ts +15 -0
  89. package/src/logs/DdLogs.ts +166 -16
  90. package/src/logs/__tests__/DdLogs.test.ts +169 -0
  91. package/src/logs/__tests__/eventMapper.test.ts +34 -0
  92. package/src/logs/eventMapper.ts +15 -4
  93. package/src/logs/types.ts +36 -8
  94. package/src/nativeModulesTypes.ts +73 -4
  95. package/src/rum/DdRum.ts +5 -0
  96. package/src/rum/__tests__/DdRum.test.ts +12 -27
  97. package/src/rum/instrumentation/DdRumErrorTracking.tsx +41 -10
  98. package/src/rum/instrumentation/interactionTracking/DdEventsInterceptor.tsx +7 -4
  99. package/src/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.ts +11 -3
  100. package/src/rum/types.ts +5 -0
  101. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -0
  102. package/src/types.tsx +2 -0
  103. package/src/version.ts +1 -1
@@ -74,32 +74,96 @@ export type DdNativeSdkType = {
74
74
  */
75
75
  export type DdNativeLogsType = {
76
76
  /**
77
- * Send a log with level debug.
77
+ * Send a log with DEBUG level.
78
78
  * @param message: The message to send.
79
79
  * @param context: The additional context to send.
80
80
  */
81
81
  debug(message: string, context?: object): Promise<void>;
82
82
 
83
83
  /**
84
- * Send a log with level info.
84
+ * Send a log with INFO level.
85
85
  * @param message: The message to send.
86
86
  * @param context: The additional context to send.
87
87
  */
88
88
  info(message: string, context?: object): Promise<void>;
89
89
 
90
90
  /**
91
- * Send a log with level warn.
91
+ * Send a log with WARN level.
92
92
  * @param message: The message to send.
93
93
  * @param context: The additional context to send.
94
94
  */
95
95
  warn(message: string, context?: object): Promise<void>;
96
96
 
97
97
  /**
98
- * Send a log with level error.
98
+ * Send a log with ERROR level.
99
99
  * @param message: The message to send.
100
100
  * @param context: The additional context to send.
101
101
  */
102
102
  error(message: string, context?: object): Promise<void>;
103
+
104
+ /**
105
+ * Send a log containing an error with DEBUG level.
106
+ * @param message: The message to send.
107
+ * @param errorKind: The error kind to send.
108
+ * @param errorMessage: The error message to send.
109
+ * @param stacktrace: The stack trace to send.
110
+ * @param context: The additional context to send.
111
+ */
112
+ debugWithError(
113
+ message: string,
114
+ errorKind?: string,
115
+ errorMessage?: string,
116
+ stacktrace?: string,
117
+ context?: object
118
+ ): Promise<void>;
119
+
120
+ /**
121
+ * Send a log containing an error with INDO level.
122
+ * @param message: The message to send.
123
+ * @param errorKind: The error kind to send.
124
+ * @param errorMessage: The error message to send.
125
+ * @param stacktrace: The stack trace to send.
126
+ * @param context: The additional context to send.
127
+ */
128
+ infoWithError(
129
+ message: string,
130
+ errorKind?: string,
131
+ errorMessage?: string,
132
+ stacktrace?: string,
133
+ context?: object
134
+ ): Promise<void>;
135
+
136
+ /**
137
+ * Send a log containing an error with WARN level.
138
+ * @param message: The message to send.
139
+ * @param errorKind: The error kind to send.
140
+ * @param errorMessage: The error message to send.
141
+ * @param stacktrace: The stack trace to send.
142
+ * @param context: The additional context to send.
143
+ */
144
+ warnWithError(
145
+ message: string,
146
+ errorKind?: string,
147
+ errorMessage?: string,
148
+ stacktrace?: string,
149
+ context?: object
150
+ ): Promise<void>;
151
+
152
+ /**
153
+ * Send a log containing an error with ERROR level.
154
+ * @param message: The message to send.
155
+ * @param errorKind: The error kind to send.
156
+ * @param errorMessage: The error message to send.
157
+ * @param stacktrace: The stack trace to send.
158
+ * @param context: The additional context to send.
159
+ */
160
+ errorWithError(
161
+ message: string,
162
+ errorKind?: string,
163
+ errorMessage?: string,
164
+ stacktrace?: string,
165
+ context?: object
166
+ ): Promise<void>;
103
167
  };
104
168
 
105
169
  /**
@@ -258,6 +322,11 @@ export type DdNativeRumType = {
258
322
  * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.
259
323
  */
260
324
  addTiming(name: string): Promise<void>;
325
+
326
+ /**
327
+ * Stops the current RUM Session.
328
+ */
329
+ stopSession(): Promise<void>;
261
330
  };
262
331
 
263
332
  type ActionType = 'TAP' | 'SCROLL' | 'SWIPE' | 'BACK' | 'CUSTOM';
package/src/rum/DdRum.ts CHANGED
@@ -326,6 +326,11 @@ class DdRumWrapper implements DdRumType {
326
326
  return bufferVoidNativeCall(() => this.nativeRum.addTiming(name));
327
327
  }
328
328
 
329
+ stopSession(): Promise<void> {
330
+ InternalLog.log('Stopping RUM Session', SdkVerbosity.DEBUG);
331
+ return bufferVoidNativeCall(() => this.nativeRum.stopSession());
332
+ }
333
+
329
334
  registerErrorEventMapper(errorEventMapper: ErrorEventMapper) {
330
335
  this.errorEventMapper = generateErrorEventMapper(errorEventMapper);
331
336
  }
@@ -24,12 +24,12 @@ jest.mock('../../TimeProvider', () => {
24
24
  });
25
25
 
26
26
  describe('DdRum', () => {
27
- describe('DdRum.stopAction', () => {
28
- beforeEach(() => {
29
- jest.clearAllMocks();
30
- BufferSingleton.onInitialization();
31
- });
27
+ beforeEach(() => {
28
+ jest.clearAllMocks();
29
+ BufferSingleton.onInitialization();
30
+ });
32
31
 
32
+ describe('DdRum.stopAction', () => {
33
33
  test('calls the native SDK when called with new API', async () => {
34
34
  await DdRum.stopAction('scroll', 'page', { user: 'me' }, 123);
35
35
  expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
@@ -151,11 +151,6 @@ describe('DdRum', () => {
151
151
  });
152
152
 
153
153
  describe('DdRum.addError', () => {
154
- beforeEach(() => {
155
- jest.clearAllMocks();
156
- DdRum.unregisterErrorEventMapper();
157
- });
158
-
159
154
  it('registers event mapper and maps error', async () => {
160
155
  const errorEventMapper: ErrorEventMapper = error => {
161
156
  error.message = 'New message';
@@ -196,12 +191,6 @@ describe('DdRum', () => {
196
191
  });
197
192
 
198
193
  describe('DdRum.stopResource', () => {
199
- beforeEach(() => {
200
- jest.clearAllMocks();
201
- DdRum.unregisterResourceEventMapper();
202
- BufferSingleton.onInitialization();
203
- });
204
-
205
194
  it('registers event mapper and maps resource', async () => {
206
195
  const resourceEventMapper: ResourceEventMapper = resource => {
207
196
  resource.context = { retryAttempts: 3 };
@@ -270,11 +259,6 @@ describe('DdRum', () => {
270
259
  });
271
260
 
272
261
  describe('DdRum.addAction', () => {
273
- beforeEach(() => {
274
- jest.clearAllMocks();
275
- DdRum.unregisterActionEventMapper();
276
- });
277
-
278
262
  it('registers event mapper and maps action', async () => {
279
263
  const actionEventMapper: ActionEventMapper = action => {
280
264
  action.context = { frustration: true };
@@ -318,12 +302,6 @@ describe('DdRum', () => {
318
302
  });
319
303
 
320
304
  describe('DdRum.stopAction', () => {
321
- beforeEach(() => {
322
- jest.clearAllMocks();
323
- DdRum.unregisterActionEventMapper();
324
- BufferSingleton.onInitialization();
325
- });
326
-
327
305
  it('registers event mapper and maps action', async () => {
328
306
  const actionEventMapper: ActionEventMapper = action => {
329
307
  action.context = { frustration: true };
@@ -384,6 +362,13 @@ describe('DdRum', () => {
384
362
  });
385
363
  });
386
364
 
365
+ describe('DdRum.stopSession', () => {
366
+ it('calls the native API', async () => {
367
+ await DdRum.stopSession();
368
+ expect(NativeModules.DdRum.stopSession).toHaveBeenCalledWith();
369
+ });
370
+ });
371
+
387
372
  describe('PropagatorTypes', () => {
388
373
  it('matches with the native name of propagators', () => {
389
374
  /**
@@ -11,8 +11,11 @@ import { SdkVerbosity } from '../../SdkVerbosity';
11
11
  import {
12
12
  getErrorMessage,
13
13
  getErrorStackTrace,
14
- EMPTY_STACK_TRACE
14
+ EMPTY_STACK_TRACE,
15
+ getErrorName,
16
+ DEFAULT_ERROR_NAME
15
17
  } from '../../errorUtils';
18
+ import { DdLogs } from '../../logs/DdLogs';
16
19
  import { DdRum } from '../DdRum';
17
20
  import { ErrorSource } from '../types';
18
21
 
@@ -63,11 +66,11 @@ export class DdRumErrorTracking {
63
66
  }
64
67
  }
65
68
 
66
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
67
- static onGlobalError(error: any, isFatal?: boolean): void {
69
+ static onGlobalError = (error: any, isFatal?: boolean): void => {
68
70
  const message = getErrorMessage(error);
69
71
  const stacktrace = getErrorStackTrace(error);
70
- DdRum.addError(message, ErrorSource.SOURCE, stacktrace, {
72
+ const errorName = getErrorName(error);
73
+ this.reportError(message, ErrorSource.SOURCE, stacktrace, errorName, {
71
74
  '_dd.error.is_crash': isFatal,
72
75
  '_dd.error.raw': error
73
76
  }).then(() => {
@@ -78,19 +81,32 @@ export class DdRumErrorTracking {
78
81
  DdRumErrorTracking.isInDefaultErrorHandler = false;
79
82
  }
80
83
  });
81
- }
84
+ };
82
85
 
83
- static onConsoleError(...params: unknown[]): void {
86
+ static onConsoleError = (...params: unknown[]): void => {
84
87
  if (DdRumErrorTracking.isInDefaultErrorHandler) {
85
88
  return;
86
89
  }
87
90
 
88
91
  let stack: string = EMPTY_STACK_TRACE;
92
+ let errorName: string = DEFAULT_ERROR_NAME;
89
93
  for (let i = 0; i < params.length; i += 1) {
90
94
  const param = params[i];
95
+
91
96
  const paramStack = getErrorStackTrace(param);
92
97
  if (paramStack !== EMPTY_STACK_TRACE) {
93
98
  stack = paramStack;
99
+ }
100
+
101
+ const paramErrorName = getErrorName(param);
102
+ if (paramErrorName !== DEFAULT_ERROR_NAME) {
103
+ errorName = paramErrorName;
104
+ }
105
+
106
+ if (
107
+ errorName !== DEFAULT_ERROR_NAME &&
108
+ stack !== EMPTY_STACK_TRACE
109
+ ) {
94
110
  break;
95
111
  }
96
112
  }
@@ -105,8 +121,23 @@ export class DdRumErrorTracking {
105
121
  })
106
122
  .join(' ');
107
123
 
108
- DdRum.addError(message, ErrorSource.CONSOLE, stack).then(() => {
109
- DdRumErrorTracking.defaultConsoleError.apply(console, params);
110
- });
111
- }
124
+ this.reportError(message, ErrorSource.CONSOLE, stack, errorName).then(
125
+ () => {
126
+ DdRumErrorTracking.defaultConsoleError.apply(console, params);
127
+ }
128
+ );
129
+ };
130
+
131
+ private static reportError = (
132
+ message: string,
133
+ source: ErrorSource,
134
+ stacktrace: string,
135
+ errorName: string,
136
+ context?: object
137
+ ): Promise<[void, void]> => {
138
+ return Promise.all([
139
+ DdRum.addError(message, source, stacktrace, context),
140
+ DdLogs.error(message, errorName, message, stacktrace, context)
141
+ ]);
142
+ };
112
143
  }
@@ -19,9 +19,12 @@ const HANDLE_EVENT_APP_EXECUTION_TIME_IN_MS = 1;
19
19
  const DD_ACTION_NAME_PROP = 'dd-action-name';
20
20
 
21
21
  export class DdEventsInterceptor implements EventsInterceptor {
22
- static ACTION_EVENT_DROPPED_WARN_MESSAGE =
22
+ static ACTION_EVENT_DROPPED_DEBUG_MESSAGE =
23
23
  'An action event was dropped because either the `onPress` method arguments' +
24
- ' were undefined or they were missing the target information.';
24
+ ' were undefined or they were missing the target information.' +
25
+ ' This log can happen if you use an abstraction component with an `onPress` prop' +
26
+ ' that does not receive the native event is first argument.' +
27
+ ' In this case, you can ignore this log.';
25
28
 
26
29
  private debouncingStartedTimestamp = Number.MIN_VALUE;
27
30
 
@@ -40,8 +43,8 @@ export class DdEventsInterceptor implements EventsInterceptor {
40
43
  }
41
44
  } else {
42
45
  InternalLog.log(
43
- DdEventsInterceptor.ACTION_EVENT_DROPPED_WARN_MESSAGE,
44
- SdkVerbosity.WARN
46
+ DdEventsInterceptor.ACTION_EVENT_DROPPED_DEBUG_MESSAGE,
47
+ SdkVerbosity.DEBUG
45
48
  );
46
49
  }
47
50
  }
@@ -5,12 +5,20 @@
5
5
  */
6
6
 
7
7
  /**
8
- * Does a shallow comparison between 2 objects
8
+ * Does a shallow comparison between 2 objects.
9
+ *
10
+ * In some rare cases, one of the objects can be `undefined` or `null`.
11
+ * This is documented in https://github.com/DataDog/dd-sdk-reactnative/issues/419.
9
12
  */
10
13
  export const areObjectShallowEqual = (
11
- objectA: Record<string, unknown>,
12
- objectB: Record<string, unknown>
14
+ objectA: Record<string, unknown> | undefined | null,
15
+ objectB: Record<string, unknown> | undefined | null
13
16
  ): boolean => {
17
+ // Handle edge case when one object is `undefined` or `null`
18
+ if (!objectA || !objectB) {
19
+ return objectA === objectB;
20
+ }
21
+
14
22
  const keys = Object.keys(objectA);
15
23
  if (keys.length !== Object.keys(objectB).length) {
16
24
  return false;
package/src/rum/types.ts CHANGED
@@ -142,6 +142,11 @@ export type DdRumType = {
142
142
  * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.
143
143
  */
144
144
  addTiming(name: string): Promise<void>;
145
+
146
+ /**
147
+ * Stops the current RUM Session.
148
+ */
149
+ stopSession(): Promise<void>;
145
150
  };
146
151
 
147
152
  /**
@@ -70,6 +70,8 @@ describe('DatadogProvider', () => {
70
70
  "clientToken": "fakeToken",
71
71
  "configurationForTelemetry": {
72
72
  "initializationType": "SYNC",
73
+ "reactNativeVersion": "0.71.2",
74
+ "reactVersion": "18.2.0",
73
75
  "trackErrors": true,
74
76
  "trackInteractions": true,
75
77
  "trackNetworkRequests": false,
package/src/types.tsx CHANGED
@@ -27,6 +27,8 @@ export class DdSdkConfiguration {
27
27
  trackErrors: boolean;
28
28
  trackInteractions: boolean;
29
29
  trackNetworkRequests: boolean;
30
+ reactVersion: string;
31
+ reactNativeVersion: string;
30
32
  }
31
33
  ) {}
32
34
  }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '1.5.2';
2
+ export const version = '1.6.0';