@datadog/mobile-react-native 2.13.2 → 2.14.1

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 (58) hide show
  1. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  2. package/datadog-sourcemaps.gradle +2 -1
  3. package/ios/Sources/SdkVersion.swift +1 -1
  4. package/lib/commonjs/logs/DdLogs.js +17 -13
  5. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  6. package/lib/commonjs/metro/plugin/metroSerializer.js.map +1 -1
  7. package/lib/commonjs/rum/DdAttributes.js +7 -1
  8. package/lib/commonjs/rum/DdAttributes.js.map +1 -1
  9. package/lib/commonjs/rum/DdRum.js +18 -11
  10. package/lib/commonjs/rum/DdRum.js.map +1 -1
  11. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +1 -1
  12. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  13. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +1 -2
  14. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  15. package/lib/commonjs/utils/argsUtils.js +6 -0
  16. package/lib/commonjs/utils/argsUtils.js.map +1 -1
  17. package/lib/commonjs/utils/errorUtils.js +1 -13
  18. package/lib/commonjs/utils/errorUtils.js.map +1 -1
  19. package/lib/commonjs/version.js +1 -1
  20. package/lib/module/logs/DdLogs.js +17 -13
  21. package/lib/module/logs/DdLogs.js.map +1 -1
  22. package/lib/module/metro/plugin/metroSerializer.js.map +1 -1
  23. package/lib/module/rum/DdAttributes.js +7 -1
  24. package/lib/module/rum/DdAttributes.js.map +1 -1
  25. package/lib/module/rum/DdRum.js +18 -11
  26. package/lib/module/rum/DdRum.js.map +1 -1
  27. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +2 -2
  28. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  29. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +1 -2
  30. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  31. package/lib/module/utils/argsUtils.js +7 -0
  32. package/lib/module/utils/argsUtils.js.map +1 -1
  33. package/lib/module/utils/errorUtils.js +0 -11
  34. package/lib/module/utils/errorUtils.js.map +1 -1
  35. package/lib/module/version.js +1 -1
  36. package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
  37. package/lib/typescript/rum/DdAttributes.d.ts +6 -0
  38. package/lib/typescript/rum/DdAttributes.d.ts.map +1 -1
  39. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  40. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts.map +1 -1
  41. package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
  42. package/lib/typescript/utils/argsUtils.d.ts +6 -0
  43. package/lib/typescript/utils/argsUtils.d.ts.map +1 -1
  44. package/lib/typescript/utils/errorUtils.d.ts +0 -1
  45. package/lib/typescript/utils/errorUtils.d.ts.map +1 -1
  46. package/lib/typescript/version.d.ts +1 -1
  47. package/package.json +2 -2
  48. package/src/logs/DdLogs.ts +23 -13
  49. package/src/logs/__tests__/DdLogs.test.ts +64 -8
  50. package/src/metro/plugin/metroSerializer.ts +3 -3
  51. package/src/rum/DdAttributes.ts +8 -1
  52. package/src/rum/DdRum.ts +26 -11
  53. package/src/rum/__tests__/DdRum.test.ts +16 -2
  54. package/src/rum/instrumentation/DdRumErrorTracking.tsx +2 -8
  55. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +1 -3
  56. package/src/utils/argsUtils.ts +6 -0
  57. package/src/utils/errorUtils.ts +0 -13
  58. package/src/version.ts +1 -1
@@ -702,7 +702,15 @@ describe('DdLogs', () => {
702
702
 
703
703
  expect(InternalLog.log).toHaveBeenNthCalledWith(
704
704
  1,
705
- expect.anything(),
705
+ expect.stringContaining('Tracking debug log'),
706
+ SdkVerbosity.DEBUG
707
+ );
708
+
709
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
710
+ 2,
711
+ expect.stringContaining(
712
+ 'The given context is an array, it will be nested'
713
+ ),
706
714
  SdkVerbosity.WARN
707
715
  );
708
716
 
@@ -732,7 +740,13 @@ describe('DdLogs', () => {
732
740
 
733
741
  expect(InternalLog.log).toHaveBeenNthCalledWith(
734
742
  1,
735
- expect.anything(),
743
+ expect.stringContaining('Tracking debug log'),
744
+ SdkVerbosity.DEBUG
745
+ );
746
+
747
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
748
+ 2,
749
+ expect.stringContaining('Context will be empty.'),
736
750
  SdkVerbosity.ERROR
737
751
  );
738
752
 
@@ -792,7 +806,15 @@ describe('DdLogs', () => {
792
806
 
793
807
  expect(InternalLog.log).toHaveBeenNthCalledWith(
794
808
  1,
795
- expect.anything(),
809
+ expect.stringContaining('Tracking warn log'),
810
+ SdkVerbosity.DEBUG
811
+ );
812
+
813
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
814
+ 2,
815
+ expect.stringContaining(
816
+ 'The given context is an array, it will be nested'
817
+ ),
796
818
  SdkVerbosity.WARN
797
819
  );
798
820
 
@@ -820,7 +842,13 @@ describe('DdLogs', () => {
820
842
 
821
843
  expect(InternalLog.log).toHaveBeenNthCalledWith(
822
844
  1,
823
- expect.anything(),
845
+ expect.stringContaining('Tracking warn log'),
846
+ SdkVerbosity.DEBUG
847
+ );
848
+
849
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
850
+ 2,
851
+ expect.stringContaining('Context will be empty.'),
824
852
  SdkVerbosity.ERROR
825
853
  );
826
854
 
@@ -880,7 +908,15 @@ describe('DdLogs', () => {
880
908
 
881
909
  expect(InternalLog.log).toHaveBeenNthCalledWith(
882
910
  1,
883
- expect.anything(),
911
+ expect.stringContaining('Tracking info log'),
912
+ SdkVerbosity.DEBUG
913
+ );
914
+
915
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
916
+ 2,
917
+ expect.stringContaining(
918
+ 'The given context is an array, it will be nested'
919
+ ),
884
920
  SdkVerbosity.WARN
885
921
  );
886
922
 
@@ -908,7 +944,13 @@ describe('DdLogs', () => {
908
944
 
909
945
  expect(InternalLog.log).toHaveBeenNthCalledWith(
910
946
  1,
911
- expect.anything(),
947
+ expect.stringContaining('Tracking info log'),
948
+ SdkVerbosity.DEBUG
949
+ );
950
+
951
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
952
+ 2,
953
+ expect.stringContaining('Context will be empty.'),
912
954
  SdkVerbosity.ERROR
913
955
  );
914
956
 
@@ -968,7 +1010,15 @@ describe('DdLogs', () => {
968
1010
 
969
1011
  expect(InternalLog.log).toHaveBeenNthCalledWith(
970
1012
  1,
971
- expect.anything(),
1013
+ expect.stringContaining('Tracking error log'),
1014
+ SdkVerbosity.DEBUG
1015
+ );
1016
+
1017
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
1018
+ 2,
1019
+ expect.stringContaining(
1020
+ 'The given context is an array, it will be nested'
1021
+ ),
972
1022
  SdkVerbosity.WARN
973
1023
  );
974
1024
 
@@ -998,7 +1048,13 @@ describe('DdLogs', () => {
998
1048
 
999
1049
  expect(InternalLog.log).toHaveBeenNthCalledWith(
1000
1050
  1,
1001
- expect.anything(),
1051
+ expect.stringContaining('Tracking error log'),
1052
+ SdkVerbosity.DEBUG
1053
+ );
1054
+
1055
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
1056
+ 2,
1057
+ expect.stringContaining('Context will be empty.'),
1002
1058
  SdkVerbosity.ERROR
1003
1059
  );
1004
1060
 
@@ -46,7 +46,7 @@ export const createDatadogMetroSerializer = (
46
46
  const serializer = customSerializer || createDefaultMetroSerializer();
47
47
  return async (entryPoint, preModules, graph, options) => {
48
48
  // Skip for hot reload mode
49
- if (graph.transformOptions.hot) {
49
+ if ((graph.transformOptions as any).hot) {
50
50
  return serializer(entryPoint, preModules, graph, options);
51
51
  }
52
52
 
@@ -109,7 +109,7 @@ export const createDefaultMetroSerializer = (): MetroSerializer => {
109
109
  // Modify the bundle through the datadogBundleCallback, if we are not in hot-reload mode
110
110
  if (
111
111
  (options as any).datadogBundleCallback &&
112
- !graph.transformOptions.hot
112
+ !(graph.transformOptions as any).hot
113
113
  ) {
114
114
  bundle = (options as any).datadogBundleCallback(bundle);
115
115
  }
@@ -119,7 +119,7 @@ export const createDefaultMetroSerializer = (): MetroSerializer => {
119
119
  const { code } = bundleToString(bundle);
120
120
 
121
121
  // If we are in hot-reload mode, we skip sourcemaps generation, and only return the code.
122
- if (graph.transformOptions.hot) {
122
+ if ((graph.transformOptions as any).hot) {
123
123
  return code;
124
124
  }
125
125
 
@@ -16,5 +16,12 @@ export const DdAttributes = {
16
16
  * Custom fingerprint to an error.
17
17
  * Expects {@link String} value.
18
18
  */
19
- errorFingerprint: '_dd.error.fingerprint'
19
+ errorFingerprint: '_dd.error.fingerprint',
20
+
21
+ /**
22
+ * Debug ID attached to a log or a RUM event.
23
+ * The Debug ID establishes a unique connection between a bundle and its corresponding sourcemap.
24
+ * Expects {@link String} value.
25
+ */
26
+ debugId: '_dd.debug_id'
20
27
  };
package/src/rum/DdRum.ts CHANGED
@@ -7,12 +7,12 @@ import type { GestureResponderEvent } from 'react-native';
7
7
 
8
8
  import { InternalLog } from '../InternalLog';
9
9
  import { SdkVerbosity } from '../SdkVerbosity';
10
+ import { debugId } from '../metro/debugIdResolver';
10
11
  import type { DdNativeRumType } from '../nativeModulesTypes';
11
12
  import { bufferVoidNativeCall } from '../sdk/DatadogProvider/Buffer/bufferNativeCall';
12
13
  import { DdSdk } from '../sdk/DdSdk';
13
14
  import { GlobalState } from '../sdk/GlobalState/GlobalState';
14
15
  import { validateContext } from '../utils/argsUtils';
15
- import { getErrorContext } from '../utils/errorUtils';
16
16
  import { DefaultTimeProvider } from '../utils/time-provider/DefaultTimeProvider';
17
17
  import type { TimeProvider } from '../utils/time-provider/TimeProvider';
18
18
 
@@ -141,13 +141,16 @@ class DdRumWrapper implements DdRumType {
141
141
  const mappedEvent = this.actionEventMapper.applyEventMapper({
142
142
  type,
143
143
  name,
144
- context: validateContext(context),
144
+ context,
145
145
  timestampMs,
146
146
  actionContext
147
147
  });
148
148
  if (!mappedEvent) {
149
149
  return generateEmptyPromise();
150
150
  }
151
+
152
+ const validatedContext = validateContext(mappedEvent.context);
153
+
151
154
  InternalLog.log(
152
155
  `Adding RUM Action “${name}” (${type})`,
153
156
  SdkVerbosity.DEBUG
@@ -156,7 +159,7 @@ class DdRumWrapper implements DdRumType {
156
159
  this.nativeRum.addAction(
157
160
  mappedEvent.type,
158
161
  mappedEvent.name,
159
- mappedEvent.context,
162
+ validatedContext,
160
163
  mappedEvent.timestampMs
161
164
  )
162
165
  );
@@ -199,7 +202,7 @@ class DdRumWrapper implements DdRumType {
199
202
  statusCode,
200
203
  kind,
201
204
  size,
202
- context: validateContext(context),
205
+ context,
203
206
  timestampMs,
204
207
  resourceContext
205
208
  });
@@ -223,6 +226,8 @@ class DdRumWrapper implements DdRumType {
223
226
  );
224
227
  }
225
228
 
229
+ const validatedContext = validateContext(mappedEvent.context);
230
+
226
231
  InternalLog.log(
227
232
  `Stopping RUM Resource #${key} status:${statusCode}`,
228
233
  SdkVerbosity.DEBUG
@@ -233,7 +238,7 @@ class DdRumWrapper implements DdRumType {
233
238
  mappedEvent.statusCode,
234
239
  mappedEvent.kind,
235
240
  mappedEvent.size,
236
- mappedEvent.context,
241
+ validatedContext,
237
242
  mappedEvent.timestampMs
238
243
  )
239
244
  );
@@ -251,7 +256,7 @@ class DdRumWrapper implements DdRumType {
251
256
  message,
252
257
  source,
253
258
  stacktrace,
254
- context: getErrorContext(validateContext(context)),
259
+ context,
255
260
  timestampMs,
256
261
  fingerprint: fingerprint ?? ''
257
262
  });
@@ -260,8 +265,16 @@ class DdRumWrapper implements DdRumType {
260
265
  return generateEmptyPromise();
261
266
  }
262
267
  InternalLog.log(`Adding RUM Error “${message}”`, SdkVerbosity.DEBUG);
263
- const updatedContext: any = mappedEvent.context;
268
+
269
+ const updatedContext: any = validateContext(mappedEvent.context);
270
+
264
271
  updatedContext[DdAttributes.errorSourceType] = 'react-native';
272
+
273
+ const _debugId = debugId;
274
+ if (_debugId) {
275
+ updatedContext[DdAttributes.debugId] = _debugId;
276
+ }
277
+
265
278
  return bufferVoidNativeCall(() =>
266
279
  this.nativeRum.addError(
267
280
  mappedEvent.message,
@@ -393,7 +406,7 @@ class DdRumWrapper implements DdRumType {
393
406
  const mappedEvent = this.actionEventMapper.applyEventMapper({
394
407
  type,
395
408
  name,
396
- context: validateContext(context),
409
+ context,
397
410
  timestampMs
398
411
  });
399
412
  if (!mappedEvent) {
@@ -409,11 +422,13 @@ class DdRumWrapper implements DdRumType {
409
422
  );
410
423
  }
411
424
 
425
+ const validatedContext = validateContext(mappedEvent.context);
426
+
412
427
  return bufferVoidNativeCall(() =>
413
428
  this.nativeRum.stopAction(
414
429
  mappedEvent.type,
415
430
  mappedEvent.name,
416
- mappedEvent.context,
431
+ validatedContext,
417
432
  mappedEvent.timestampMs
418
433
  )
419
434
  );
@@ -440,7 +455,7 @@ class DdRumWrapper implements DdRumType {
440
455
  return [
441
456
  args[0],
442
457
  args[1],
443
- validateContext(args[2]),
458
+ args[2] || {},
444
459
  args[3] || this.timeProvider.now()
445
460
  ];
446
461
  }
@@ -453,7 +468,7 @@ class DdRumWrapper implements DdRumType {
453
468
  return [
454
469
  type,
455
470
  name,
456
- validateContext(args[0]),
471
+ args[0] || {},
457
472
  args[1] || this.timeProvider.now()
458
473
  ];
459
474
  }
@@ -1181,7 +1181,13 @@ describe('DdRum', () => {
1181
1181
 
1182
1182
  expect(InternalLog.log).toHaveBeenNthCalledWith(
1183
1183
  1,
1184
- expect.anything(),
1184
+ expect.stringContaining('Adding RUM Error'),
1185
+ SdkVerbosity.DEBUG
1186
+ );
1187
+
1188
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
1189
+ 2,
1190
+ expect.stringContaining('Context will be empty'),
1185
1191
  SdkVerbosity.ERROR
1186
1192
  );
1187
1193
 
@@ -1208,7 +1214,15 @@ describe('DdRum', () => {
1208
1214
 
1209
1215
  expect(InternalLog.log).toHaveBeenNthCalledWith(
1210
1216
  1,
1211
- expect.anything(),
1217
+ expect.stringContaining('Adding RUM Error'),
1218
+ SdkVerbosity.DEBUG
1219
+ );
1220
+
1221
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
1222
+ 2,
1223
+ expect.stringContaining(
1224
+ 'The given context is an array, it will be nested'
1225
+ ),
1212
1226
  SdkVerbosity.WARN
1213
1227
  );
1214
1228
 
@@ -14,8 +14,7 @@ import {
14
14
  getErrorStackTrace,
15
15
  EMPTY_STACK_TRACE,
16
16
  getErrorName,
17
- DEFAULT_ERROR_NAME,
18
- getErrorContext
17
+ DEFAULT_ERROR_NAME
19
18
  } from '../../utils/errorUtils';
20
19
  import { executeWithDelay } from '../../utils/jsUtils';
21
20
  import { DdRum } from '../DdRum';
@@ -146,12 +145,7 @@ export class DdRumErrorTracking {
146
145
  context: object = {}
147
146
  ): Promise<[void, void]> => {
148
147
  return Promise.all([
149
- DdRum.addError(
150
- message,
151
- source,
152
- stacktrace,
153
- getErrorContext(context)
154
- ),
148
+ DdRum.addError(message, source, stacktrace, context),
155
149
  DdLogs.error(
156
150
  message,
157
151
  errorName,
@@ -139,8 +139,6 @@ export class DdBabelInteractionTracking {
139
139
  targetObject: TargetObject
140
140
  ): (...args: any[]) => any {
141
141
  return (...args: any[]) => {
142
- const result = func(...args);
143
-
144
142
  if (!this.telemetrySent) {
145
143
  DdSdk?.sendTelemetryLog(
146
144
  BABEL_PLUGIN_TELEMETRY,
@@ -174,7 +172,7 @@ export class DdBabelInteractionTracking {
174
172
  });
175
173
  }
176
174
 
177
- return result;
175
+ return func(...args);
178
176
  };
179
177
  }
180
178
  }
@@ -8,6 +8,12 @@
8
8
  import { InternalLog } from '../InternalLog';
9
9
  import { SdkVerbosity } from '../SdkVerbosity';
10
10
 
11
+ /**
12
+ * Validates the given context before passing it to the native SDKs.
13
+ * @param context the original context
14
+ * @returns the original context if it's a plain object, an object wrapping the context if it's an array,
15
+ * or an empty object if the context is of any other type.
16
+ */
11
17
  export const validateContext = (context: any) => {
12
18
  if (!context) {
13
19
  return {};
@@ -4,8 +4,6 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import { debugId } from '../metro/debugIdResolver';
8
-
9
7
  export const EMPTY_MESSAGE = 'Unknown Error';
10
8
  export const EMPTY_STACK_TRACE = '';
11
9
  export const DEFAULT_ERROR_NAME = 'Error';
@@ -73,14 +71,3 @@ export const getErrorName = (error: unknown): string => {
73
71
  }
74
72
  return DEFAULT_ERROR_NAME;
75
73
  };
76
-
77
- export const getErrorContext = (originalContext: any): Record<string, any> => {
78
- const _debugId = debugId;
79
- if (!_debugId) {
80
- return originalContext;
81
- }
82
- return {
83
- ...originalContext,
84
- '_dd.debug_id': _debugId
85
- };
86
- };
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '2.13.2';
2
+ export const version = '2.14.1';