@datadog/mobile-react-native 2.3.5 → 2.4.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 (95) hide show
  1. package/DatadogSDKReactNative.podspec +6 -6
  2. package/android/build.gradle +4 -4
  3. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  4. package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +2 -0
  5. package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +15 -0
  6. package/android/src/test/resources/input/complete-configuration.json +5 -1
  7. package/datadog-configuration.schema.json +54 -9
  8. package/datadog-sourcemaps.gradle +64 -1
  9. package/ios/Sources/DatadogSDKWrapper.swift +3 -3
  10. package/ios/Sources/SdkVersion.swift +1 -1
  11. package/lib/commonjs/DdSdkReactNative.js +2 -1
  12. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  13. package/lib/commonjs/DdSdkReactNativeConfiguration.js +7 -4
  14. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  15. package/lib/commonjs/logs/DdLogs.js +10 -8
  16. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  17. package/lib/commonjs/rum/DdRum.js +50 -48
  18. package/lib/commonjs/rum/DdRum.js.map +1 -1
  19. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +14 -9
  20. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  21. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +2 -6
  22. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  23. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js +182 -0
  24. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js.map +1 -0
  25. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +10 -57
  26. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
  27. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +18 -10
  28. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
  29. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +4 -2
  30. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  31. package/lib/commonjs/trace/DdTrace.js +4 -2
  32. package/lib/commonjs/trace/DdTrace.js.map +1 -1
  33. package/lib/commonjs/utils/argsUtils.js +43 -0
  34. package/lib/commonjs/utils/argsUtils.js.map +1 -0
  35. package/lib/commonjs/version.js +1 -1
  36. package/lib/commonjs/version.js.map +1 -1
  37. package/lib/module/DdSdkReactNative.js +2 -1
  38. package/lib/module/DdSdkReactNative.js.map +1 -1
  39. package/lib/module/DdSdkReactNativeConfiguration.js +7 -4
  40. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  41. package/lib/module/logs/DdLogs.js +9 -8
  42. package/lib/module/logs/DdLogs.js.map +1 -1
  43. package/lib/module/rum/DdRum.js +48 -47
  44. package/lib/module/rum/DdRum.js.map +1 -1
  45. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +14 -9
  46. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  47. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +2 -6
  48. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  49. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js +169 -0
  50. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.js.map +1 -0
  51. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js +3 -54
  52. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.js.map +1 -1
  53. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js +13 -8
  54. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.js.map +1 -1
  55. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js +3 -2
  56. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.js.map +1 -1
  57. package/lib/module/trace/DdTrace.js +3 -2
  58. package/lib/module/trace/DdTrace.js.map +1 -1
  59. package/lib/module/utils/argsUtils.js +30 -0
  60. package/lib/module/utils/argsUtils.js.map +1 -0
  61. package/lib/module/version.js +1 -1
  62. package/lib/module/version.js.map +1 -1
  63. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +5 -1
  64. package/lib/typescript/rum/DdRum.d.ts +2 -2
  65. package/lib/typescript/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts +12 -3
  66. package/lib/typescript/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts +2 -3
  67. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.d.ts +111 -0
  68. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.d.ts +1 -24
  69. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.d.ts +2 -0
  70. package/lib/typescript/utils/argsUtils.d.ts +1 -0
  71. package/lib/typescript/version.d.ts +1 -1
  72. package/package.json +2 -2
  73. package/src/DdSdkReactNative.tsx +4 -1
  74. package/src/DdSdkReactNativeConfiguration.tsx +10 -4
  75. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +7 -2
  76. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +32 -0
  77. package/src/logs/DdLogs.ts +9 -8
  78. package/src/logs/__tests__/DdLogs.test.ts +543 -0
  79. package/src/rum/DdRum.ts +112 -94
  80. package/src/rum/__tests__/DdRum.test.ts +552 -0
  81. package/src/rum/instrumentation/interactionTracking/DdEventsInterceptor.tsx +23 -7
  82. package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +3 -4
  83. package/src/rum/instrumentation/resourceTracking/distributedTracing/TracingIdentifier.tsx +227 -0
  84. package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/__utils__/TracingIdentifierUtils.ts +64 -0
  85. package/src/rum/instrumentation/resourceTracking/distributedTracing/__tests__/distributedTracing.test.ts +314 -42
  86. package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracing.tsx +4 -59
  87. package/src/rum/instrumentation/resourceTracking/distributedTracing/distributedTracingHeaders.ts +33 -19
  88. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/ResourceReporter.ts +7 -2
  89. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +134 -11
  90. package/src/sdk/FileBasedConfiguration/__tests__/FileBasedConfiguration.test.ts +3 -0
  91. package/src/trace/DdTrace.ts +12 -2
  92. package/src/trace/__tests__/DdTrace.test.ts +146 -0
  93. package/src/utils/__tests__/argsUtils.test.ts +66 -0
  94. package/src/utils/argsUtils.ts +35 -0
  95. package/src/version.ts +1 -1
@@ -8,6 +8,8 @@
8
8
  import { NativeModules } from 'react-native';
9
9
 
10
10
  import { DdSdkReactNative } from '../../DdSdkReactNative';
11
+ import { InternalLog } from '../../InternalLog';
12
+ import { SdkVerbosity } from '../../SdkVerbosity';
11
13
  import { BufferSingleton } from '../../sdk/DatadogProvider/Buffer/BufferSingleton';
12
14
  import { DdSdk } from '../../sdk/DdSdk';
13
15
  import { DdRum } from '../DdRum';
@@ -24,12 +26,562 @@ jest.mock('../../utils/time-provider/DefaultTimeProvider', () => {
24
26
  };
25
27
  });
26
28
 
29
+ jest.mock('../../InternalLog', () => {
30
+ return {
31
+ InternalLog: {
32
+ log: jest.fn()
33
+ },
34
+ DATADOG_MESSAGE_PREFIX: 'DATADOG:'
35
+ };
36
+ });
37
+
27
38
  describe('DdRum', () => {
28
39
  beforeEach(() => {
29
40
  jest.clearAllMocks();
30
41
  BufferSingleton.onInitialization();
31
42
  });
32
43
 
44
+ describe('Context validation', () => {
45
+ describe('DdRum.startView', () => {
46
+ test('uses given context when context is valid', async () => {
47
+ const context = {
48
+ testA: 123,
49
+ testB: 'ok'
50
+ };
51
+ await DdRum.startView('key', 'name', context);
52
+
53
+ expect(NativeModules.DdRum.startView).toHaveBeenCalledWith(
54
+ expect.anything(),
55
+ expect.anything(),
56
+ context,
57
+ expect.anything()
58
+ );
59
+ });
60
+
61
+ test('uses empty context with error when context is invalid or null', async () => {
62
+ const context: any = 123;
63
+ await DdRum.startView('key', 'name', context);
64
+
65
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
66
+ 2,
67
+ expect.anything(),
68
+ SdkVerbosity.ERROR
69
+ );
70
+
71
+ expect(NativeModules.DdRum.startView).toHaveBeenCalledWith(
72
+ expect.anything(),
73
+ expect.anything(),
74
+ {},
75
+ expect.anything()
76
+ );
77
+ });
78
+
79
+ test('nests given context in new object when context is array', async () => {
80
+ const context: any = [123, '456'];
81
+ await DdRum.startView('key', 'name', context);
82
+
83
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
84
+ 2,
85
+ expect.anything(),
86
+ SdkVerbosity.WARN
87
+ );
88
+
89
+ expect(NativeModules.DdRum.startView).toHaveBeenCalledWith(
90
+ expect.anything(),
91
+ expect.anything(),
92
+ { context },
93
+ expect.anything()
94
+ );
95
+ });
96
+ });
97
+
98
+ describe('DdRum.stopView', () => {
99
+ test('uses given context when context is valid', async () => {
100
+ const context = {
101
+ testA: 123,
102
+ testB: 'ok'
103
+ };
104
+ await DdRum.startView('key', 'name');
105
+ await DdRum.stopView('key', context);
106
+
107
+ expect(NativeModules.DdRum.stopView).toHaveBeenCalledWith(
108
+ 'key',
109
+ context,
110
+ expect.anything()
111
+ );
112
+ });
113
+
114
+ test('uses empty context with error when context is invalid or null', async () => {
115
+ const context: any = 123;
116
+
117
+ await DdRum.startView('key', 'name');
118
+ await DdRum.stopView('key', context);
119
+
120
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
121
+ 3,
122
+ expect.anything(),
123
+ SdkVerbosity.ERROR
124
+ );
125
+
126
+ expect(NativeModules.DdRum.stopView).toHaveBeenCalledWith(
127
+ 'key',
128
+ {},
129
+ expect.anything()
130
+ );
131
+ });
132
+
133
+ test('nests given context in new object when context is array', async () => {
134
+ const context: any = [123, '456'];
135
+
136
+ await DdRum.startView('key', 'name');
137
+ await DdRum.stopView('key', context);
138
+
139
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
140
+ 3,
141
+ expect.anything(),
142
+ SdkVerbosity.WARN
143
+ );
144
+
145
+ expect(NativeModules.DdRum.stopView).toHaveBeenCalledWith(
146
+ 'key',
147
+ { context },
148
+ expect.anything()
149
+ );
150
+ });
151
+ });
152
+
153
+ describe('DdRum.startAction', () => {
154
+ test('uses given context when context is valid', async () => {
155
+ const context = {
156
+ testA: 123,
157
+ testB: 'ok'
158
+ };
159
+ await DdRum.startAction(RumActionType.SCROLL, 'name', context);
160
+
161
+ expect(NativeModules.DdRum.startAction).toHaveBeenCalledWith(
162
+ expect.anything(),
163
+ expect.anything(),
164
+ context,
165
+ expect.anything()
166
+ );
167
+ });
168
+
169
+ test('uses empty context with error when context is invalid or null', async () => {
170
+ const context: any = 123;
171
+ await DdRum.startAction(RumActionType.SCROLL, 'name', context);
172
+
173
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
174
+ 2,
175
+ expect.anything(),
176
+ SdkVerbosity.ERROR
177
+ );
178
+
179
+ expect(NativeModules.DdRum.startAction).toHaveBeenCalledWith(
180
+ expect.anything(),
181
+ expect.anything(),
182
+ {},
183
+ expect.anything()
184
+ );
185
+ });
186
+
187
+ test('nests given context in new object when context is array', async () => {
188
+ const context: any = [123, '456'];
189
+ await DdRum.startAction(RumActionType.SCROLL, 'name', context);
190
+
191
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
192
+ 2,
193
+ expect.anything(),
194
+ SdkVerbosity.WARN
195
+ );
196
+
197
+ expect(NativeModules.DdRum.startAction).toHaveBeenCalledWith(
198
+ expect.anything(),
199
+ expect.anything(),
200
+ { context },
201
+ expect.anything()
202
+ );
203
+ });
204
+ });
205
+
206
+ describe('DdRum.stopAction', () => {
207
+ describe('New API', () => {
208
+ test('uses given context when context is valid', async () => {
209
+ const context = {
210
+ testA: 123,
211
+ testB: 'ok'
212
+ };
213
+ await DdRum.startAction(RumActionType.SCROLL, 'name');
214
+ await DdRum.stopAction(
215
+ RumActionType.SCROLL,
216
+ 'name',
217
+ context
218
+ );
219
+
220
+ expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
221
+ RumActionType.SCROLL,
222
+ 'name',
223
+ context,
224
+ expect.anything()
225
+ );
226
+ });
227
+
228
+ test('uses empty context with error when context is invalid or null', async () => {
229
+ const context: any = 123;
230
+
231
+ await DdRum.startAction(RumActionType.SCROLL, 'name');
232
+ await DdRum.stopAction(
233
+ RumActionType.SCROLL,
234
+ 'name',
235
+ context
236
+ );
237
+
238
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
239
+ 3,
240
+ expect.anything(),
241
+ SdkVerbosity.ERROR
242
+ );
243
+
244
+ expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
245
+ RumActionType.SCROLL,
246
+ 'name',
247
+ {},
248
+ expect.anything()
249
+ );
250
+ });
251
+
252
+ test('nests given context in new object when context is array', async () => {
253
+ const context: any = [123, '456'];
254
+
255
+ await DdRum.startAction(RumActionType.SCROLL, 'name');
256
+ await DdRum.stopAction(
257
+ RumActionType.SCROLL,
258
+ 'name',
259
+ context
260
+ );
261
+
262
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
263
+ 3,
264
+ expect.anything(),
265
+ SdkVerbosity.WARN
266
+ );
267
+
268
+ expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
269
+ RumActionType.SCROLL,
270
+ 'name',
271
+ { context },
272
+ expect.anything()
273
+ );
274
+ });
275
+ });
276
+
277
+ describe('Old API', () => {
278
+ test('uses given context when context is valid', async () => {
279
+ const context = {
280
+ testA: 123,
281
+ testB: 'ok'
282
+ };
283
+ await DdRum.startAction(RumActionType.SCROLL, 'name');
284
+ await DdRum.stopAction(context);
285
+
286
+ expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
287
+ RumActionType.SCROLL,
288
+ 'name',
289
+ context,
290
+ expect.anything()
291
+ );
292
+ });
293
+
294
+ test('uses empty context with error when context is invalid or null', async () => {
295
+ await DdRum.startAction(RumActionType.SCROLL, 'name');
296
+ await DdRum.stopAction(undefined);
297
+
298
+ expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
299
+ RumActionType.SCROLL,
300
+ 'name',
301
+ {},
302
+ expect.anything()
303
+ );
304
+ });
305
+
306
+ test('nests given context in new object when context is array', async () => {
307
+ const context: any = [123, '456'];
308
+
309
+ await DdRum.startAction(RumActionType.SCROLL, 'name');
310
+ await DdRum.stopAction(context);
311
+
312
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
313
+ 3,
314
+ expect.anything(),
315
+ SdkVerbosity.WARN
316
+ );
317
+
318
+ expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
319
+ RumActionType.SCROLL,
320
+ 'name',
321
+ { context },
322
+ expect.anything()
323
+ );
324
+ });
325
+ });
326
+ });
327
+
328
+ describe('DdRum.startResource', () => {
329
+ test('uses given context when context is valid', async () => {
330
+ const context = {
331
+ testA: 123,
332
+ testB: 'ok'
333
+ };
334
+ await DdRum.startResource('key', 'method', 'url', context);
335
+
336
+ expect(NativeModules.DdRum.startResource).toHaveBeenCalledWith(
337
+ 'key',
338
+ 'method',
339
+ 'url',
340
+ context,
341
+ expect.anything()
342
+ );
343
+ });
344
+
345
+ test('uses empty context with error when context is invalid or null', async () => {
346
+ const context: any = 123;
347
+
348
+ await DdRum.startResource('key', 'method', 'url', context);
349
+
350
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
351
+ 2,
352
+ expect.anything(),
353
+ SdkVerbosity.ERROR
354
+ );
355
+
356
+ expect(NativeModules.DdRum.startResource).toHaveBeenCalledWith(
357
+ 'key',
358
+ 'method',
359
+ 'url',
360
+ {},
361
+ expect.anything()
362
+ );
363
+ });
364
+
365
+ test('nests given context in new object when context is array', async () => {
366
+ const context: any = [123, '456'];
367
+
368
+ await DdRum.startResource('key', 'method', 'url', context);
369
+
370
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
371
+ 2,
372
+ expect.anything(),
373
+ SdkVerbosity.WARN
374
+ );
375
+
376
+ expect(NativeModules.DdRum.startResource).toHaveBeenCalledWith(
377
+ 'key',
378
+ 'method',
379
+ 'url',
380
+ { context },
381
+ expect.anything()
382
+ );
383
+ });
384
+ });
385
+
386
+ describe('DdRum.stopResource', () => {
387
+ test('uses given context when context is valid', async () => {
388
+ const context = {
389
+ testA: 123,
390
+ testB: 'ok'
391
+ };
392
+
393
+ await DdRum.startResource('key', 'method', 'url', {});
394
+ await DdRum.stopResource('key', 200, 'other', -1, context);
395
+
396
+ expect(NativeModules.DdRum.stopResource).toHaveBeenCalledWith(
397
+ 'key',
398
+ 200,
399
+ 'other',
400
+ -1,
401
+ context,
402
+ expect.anything()
403
+ );
404
+ });
405
+
406
+ test('uses empty context with error when context is invalid or null', async () => {
407
+ const context: any = 123;
408
+
409
+ await DdRum.startResource('key', 'method', 'url', {});
410
+ await DdRum.stopResource('key', 200, 'other', -1, context);
411
+
412
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
413
+ 2,
414
+ expect.anything(),
415
+ SdkVerbosity.ERROR
416
+ );
417
+
418
+ expect(NativeModules.DdRum.stopResource).toHaveBeenCalledWith(
419
+ 'key',
420
+ 200,
421
+ 'other',
422
+ -1,
423
+ {},
424
+ expect.anything()
425
+ );
426
+ });
427
+
428
+ test('nests given context in new object when context is array', async () => {
429
+ const context: any = [123, '456'];
430
+
431
+ await DdRum.startResource('key', 'method', 'url', {});
432
+ await DdRum.stopResource('key', 200, 'other', -1, context);
433
+
434
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
435
+ 2,
436
+ expect.anything(),
437
+ SdkVerbosity.WARN
438
+ );
439
+
440
+ expect(NativeModules.DdRum.stopResource).toHaveBeenCalledWith(
441
+ 'key',
442
+ 200,
443
+ 'other',
444
+ -1,
445
+ { context },
446
+ expect.anything()
447
+ );
448
+ });
449
+ });
450
+
451
+ describe('DdRum.addAction', () => {
452
+ test('uses given context when context is valid', async () => {
453
+ const context = {
454
+ testA: 123,
455
+ testB: 'ok'
456
+ };
457
+ await DdRum.addAction(RumActionType.SCROLL, 'name', context);
458
+
459
+ expect(NativeModules.DdRum.addAction).toHaveBeenCalledWith(
460
+ expect.anything(),
461
+ expect.anything(),
462
+ context,
463
+ expect.anything()
464
+ );
465
+ });
466
+
467
+ test('uses empty context with error when context is invalid or null', async () => {
468
+ const context: any = 123;
469
+ await DdRum.addAction(RumActionType.SCROLL, 'name', context);
470
+
471
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
472
+ 1,
473
+ expect.anything(),
474
+ SdkVerbosity.ERROR
475
+ );
476
+
477
+ expect(NativeModules.DdRum.addAction).toHaveBeenCalledWith(
478
+ expect.anything(),
479
+ expect.anything(),
480
+ {},
481
+ expect.anything()
482
+ );
483
+ });
484
+
485
+ test('nests given context in new object when context is array', async () => {
486
+ const context: any = [123, '456'];
487
+ await DdRum.addAction(RumActionType.SCROLL, 'name', context);
488
+
489
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
490
+ 1,
491
+ expect.anything(),
492
+ SdkVerbosity.WARN
493
+ );
494
+
495
+ expect(NativeModules.DdRum.addAction).toHaveBeenCalledWith(
496
+ expect.anything(),
497
+ expect.anything(),
498
+ { context },
499
+ expect.anything()
500
+ );
501
+ });
502
+ });
503
+
504
+ describe('DdRum.addError', () => {
505
+ test('uses given context when context is valid', async () => {
506
+ const context = {
507
+ testA: 123,
508
+ testB: 'ok'
509
+ };
510
+
511
+ await DdRum.addError(
512
+ 'error',
513
+ ErrorSource.CUSTOM,
514
+ 'stacktrace',
515
+ context
516
+ );
517
+
518
+ expect(NativeModules.DdRum.addError).toHaveBeenCalledWith(
519
+ 'error',
520
+ ErrorSource.CUSTOM,
521
+ 'stacktrace',
522
+ {
523
+ ...context,
524
+ '_dd.error.source_type': 'react-native'
525
+ },
526
+ expect.anything()
527
+ );
528
+ });
529
+
530
+ test('uses empty context with error when context is invalid or null', async () => {
531
+ const context: any = 123;
532
+ await DdRum.addError(
533
+ 'error',
534
+ ErrorSource.CUSTOM,
535
+ 'stacktrace',
536
+ context
537
+ );
538
+
539
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
540
+ 1,
541
+ expect.anything(),
542
+ SdkVerbosity.ERROR
543
+ );
544
+
545
+ expect(NativeModules.DdRum.addError).toHaveBeenCalledWith(
546
+ 'error',
547
+ ErrorSource.CUSTOM,
548
+ 'stacktrace',
549
+ {
550
+ '_dd.error.source_type': 'react-native'
551
+ },
552
+ expect.anything()
553
+ );
554
+ });
555
+
556
+ test('nests given context in new object when context is array', async () => {
557
+ const context: any = [123, '456'];
558
+ await DdRum.addError(
559
+ 'error',
560
+ ErrorSource.CUSTOM,
561
+ 'stacktrace',
562
+ context
563
+ );
564
+
565
+ expect(InternalLog.log).toHaveBeenNthCalledWith(
566
+ 1,
567
+ expect.anything(),
568
+ SdkVerbosity.WARN
569
+ );
570
+
571
+ expect(NativeModules.DdRum.addError).toHaveBeenCalledWith(
572
+ 'error',
573
+ ErrorSource.CUSTOM,
574
+ 'stacktrace',
575
+ {
576
+ context,
577
+ '_dd.error.source_type': 'react-native'
578
+ },
579
+ expect.anything()
580
+ );
581
+ });
582
+ });
583
+ });
584
+
33
585
  describe('DdRum.stopAction', () => {
34
586
  test('calls the native SDK when called with new API', async () => {
35
587
  await DdRum.stopAction(
@@ -18,6 +18,17 @@ const DEBOUNCE_EVENT_THRESHOLD_IN_MS = 10;
18
18
  const HANDLE_EVENT_APP_EXECUTION_TIME_IN_MS = 1;
19
19
  const DD_ACTION_NAME_PROP = 'dd-action-name';
20
20
 
21
+ export type DdEventsInterceptorOptions = {
22
+ /**
23
+ * Specifies a custom prop to name RUM actions on elements having an `onPress` prop
24
+ * */
25
+ actionNameAttribute?: string;
26
+ /**
27
+ * Determines whether the accessibility label can be used to resolve the action name.
28
+ * */
29
+ useAccessibilityLabel?: boolean;
30
+ };
31
+
21
32
  export class DdEventsInterceptor implements EventsInterceptor {
22
33
  static ACTION_EVENT_DROPPED_DEBUG_MESSAGE =
23
34
  'An action event was dropped because either the `onPress` method arguments' +
@@ -29,11 +40,11 @@ export class DdEventsInterceptor implements EventsInterceptor {
29
40
  private debouncingStartedTimestamp = Number.MIN_VALUE;
30
41
 
31
42
  private actionNameAttribute?: string;
43
+ private useAccessibilityLabel: boolean;
32
44
 
33
- constructor({
34
- actionNameAttribute
35
- }: { actionNameAttribute?: string } = {}) {
36
- this.actionNameAttribute = actionNameAttribute;
45
+ constructor(options: DdEventsInterceptorOptions = {}) {
46
+ this.actionNameAttribute = options.actionNameAttribute;
47
+ this.useAccessibilityLabel = options.useAccessibilityLabel ?? true;
37
48
  }
38
49
 
39
50
  interceptOnPress(...args: any[]): void {
@@ -75,10 +86,15 @@ export class DdEventsInterceptor implements EventsInterceptor {
75
86
  if (closestActionLabel != null) {
76
87
  return closestActionLabel;
77
88
  }
78
- const accessibilityLabel = targetNode.memoizedProps?.accessibilityLabel;
79
- if (accessibilityLabel != null) {
80
- return accessibilityLabel;
89
+
90
+ if (this.useAccessibilityLabel) {
91
+ const accessibilityLabel =
92
+ targetNode.memoizedProps?.accessibilityLabel;
93
+ if (accessibilityLabel != null) {
94
+ return accessibilityLabel;
95
+ }
81
96
  }
97
+
82
98
  const elementTypeName = this.resolveElementTypeName(
83
99
  targetNode.elementType
84
100
  );
@@ -12,6 +12,7 @@ import { DdSdk } from '../../../sdk/DdSdk';
12
12
  import { getErrorMessage } from '../../../utils/errorUtils';
13
13
 
14
14
  import { DdEventsInterceptor } from './DdEventsInterceptor';
15
+ import type { DdEventsInterceptorOptions } from './DdEventsInterceptor';
15
16
  import type EventsInterceptor from './EventsInterceptor';
16
17
  import NoOpEventsInterceptor from './NoOpEventsInterceptor';
17
18
  import { areObjectShallowEqual } from './ShallowObjectEqualityChecker';
@@ -58,9 +59,7 @@ export class DdRumUserInteractionTracking {
58
59
  * Please note that we are only considering as valid - for - tracking only the user interactions that have
59
60
  * a visible output (either an UI state change or a Resource request)
60
61
  */
61
- static startTracking({
62
- actionNameAttribute
63
- }: { actionNameAttribute?: string } = {}): void {
62
+ static startTracking(options: DdEventsInterceptorOptions): void {
64
63
  // extra safety to avoid wrapping more than 1 time this function
65
64
  if (DdRumUserInteractionTracking.isTracking) {
66
65
  InternalLog.log(
@@ -70,7 +69,7 @@ export class DdRumUserInteractionTracking {
70
69
  return;
71
70
  }
72
71
  DdRumUserInteractionTracking.eventsInterceptor = new DdEventsInterceptor(
73
- { actionNameAttribute }
72
+ options
74
73
  );
75
74
 
76
75
  const original = React.createElement;