@datadog/mobile-react-native 1.5.2 → 1.7.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 (119) hide show
  1. package/DatadogSDKReactNative.podspec +2 -2
  2. package/android/build.gradle +2 -1
  3. package/android/gradle.properties +1 -1
  4. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +4 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +6 -1
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdLogs.kt +162 -6
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdRum.kt +25 -0
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +32 -0
  9. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +11 -1
  10. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +10 -0
  11. package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +242 -2
  12. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +27 -0
  13. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +126 -30
  14. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +19 -1
  15. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +2 -2
  16. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +18 -1
  17. package/ios/Sources/Attributes.swift +7 -0
  18. package/ios/Sources/DdLogs.m +31 -0
  19. package/ios/Sources/DdLogs.swift +84 -4
  20. package/ios/Sources/DdRum.m +8 -0
  21. package/ios/Sources/DdRum.swift +17 -0
  22. package/ios/Sources/DdSdk.swift +40 -0
  23. package/ios/Sources/DdSdkConfiguration.swift +19 -1
  24. package/ios/Sources/RNDdSdkConfiguration.swift +11 -1
  25. package/lib/commonjs/DdSdkReactNative.js +6 -2
  26. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  27. package/lib/commonjs/DdSdkReactNativeConfiguration.js +45 -2
  28. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  29. package/lib/commonjs/InternalLog.js +6 -2
  30. package/lib/commonjs/InternalLog.js.map +1 -1
  31. package/lib/commonjs/errorUtils.js +20 -1
  32. package/lib/commonjs/errorUtils.js.map +1 -1
  33. package/lib/commonjs/index.js +12 -0
  34. package/lib/commonjs/index.js.map +1 -1
  35. package/lib/commonjs/logs/DdLogs.js +102 -11
  36. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  37. package/lib/commonjs/logs/eventMapper.js.map +1 -1
  38. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  39. package/lib/commonjs/rum/DdRum.js +14 -0
  40. package/lib/commonjs/rum/DdRum.js.map +1 -1
  41. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +62 -46
  42. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  43. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +2 -2
  44. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  45. package/lib/commonjs/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js +9 -1
  46. package/lib/commonjs/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js.map +1 -1
  47. package/lib/commonjs/rum/types.js.map +1 -1
  48. package/lib/commonjs/types.js +4 -1
  49. package/lib/commonjs/types.js.map +1 -1
  50. package/lib/commonjs/version.js +1 -1
  51. package/lib/commonjs/version.js.map +1 -1
  52. package/lib/module/DdSdkReactNative.js +6 -2
  53. package/lib/module/DdSdkReactNative.js.map +1 -1
  54. package/lib/module/DdSdkReactNativeConfiguration.js +42 -1
  55. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  56. package/lib/module/InternalLog.js +2 -1
  57. package/lib/module/InternalLog.js.map +1 -1
  58. package/lib/module/errorUtils.js +15 -0
  59. package/lib/module/errorUtils.js.map +1 -1
  60. package/lib/module/index.js +2 -2
  61. package/lib/module/index.js.map +1 -1
  62. package/lib/module/logs/DdLogs.js +103 -12
  63. package/lib/module/logs/DdLogs.js.map +1 -1
  64. package/lib/module/logs/eventMapper.js.map +1 -1
  65. package/lib/module/nativeModulesTypes.js.map +1 -1
  66. package/lib/module/rum/DdRum.js +12 -0
  67. package/lib/module/rum/DdRum.js.map +1 -1
  68. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +63 -46
  69. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  70. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +2 -2
  71. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  72. package/lib/module/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js +9 -1
  73. package/lib/module/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js.map +1 -1
  74. package/lib/module/rum/types.js.map +1 -1
  75. package/lib/module/types.js +4 -1
  76. package/lib/module/types.js.map +1 -1
  77. package/lib/module/version.js +1 -1
  78. package/lib/module/version.js.map +1 -1
  79. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +47 -0
  80. package/lib/typescript/InternalLog.d.ts +1 -0
  81. package/lib/typescript/errorUtils.d.ts +2 -0
  82. package/lib/typescript/index.d.ts +2 -2
  83. package/lib/typescript/logs/DdLogs.d.ts +13 -5
  84. package/lib/typescript/logs/eventMapper.d.ts +5 -5
  85. package/lib/typescript/logs/types.d.ts +34 -8
  86. package/lib/typescript/nativeModulesTypes.d.ts +51 -4
  87. package/lib/typescript/rum/DdRum.d.ts +2 -0
  88. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +3 -2
  89. package/lib/typescript/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts +1 -1
  90. package/lib/typescript/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.d.ts +5 -2
  91. package/lib/typescript/rum/types.d.ts +4 -0
  92. package/lib/typescript/types.d.ts +8 -1
  93. package/lib/typescript/version.d.ts +1 -1
  94. package/package.json +2 -2
  95. package/src/DdSdkReactNative.tsx +9 -1
  96. package/src/DdSdkReactNativeConfiguration.tsx +56 -1
  97. package/src/InternalLog.tsx +3 -1
  98. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +20 -3
  99. package/src/__tests__/errorUtils.test.ts +49 -0
  100. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +14 -14
  101. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +474 -109
  102. package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +18 -0
  103. package/src/errorUtils.ts +15 -0
  104. package/src/index.tsx +6 -2
  105. package/src/logs/DdLogs.ts +166 -16
  106. package/src/logs/__tests__/DdLogs.test.ts +169 -0
  107. package/src/logs/__tests__/eventMapper.test.ts +34 -0
  108. package/src/logs/eventMapper.ts +15 -4
  109. package/src/logs/types.ts +36 -8
  110. package/src/nativeModulesTypes.ts +81 -4
  111. package/src/rum/DdRum.ts +17 -0
  112. package/src/rum/__tests__/DdRum.test.ts +12 -27
  113. package/src/rum/instrumentation/DdRumErrorTracking.tsx +44 -10
  114. package/src/rum/instrumentation/interactionTracking/DdEventsInterceptor.tsx +7 -4
  115. package/src/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.ts +11 -3
  116. package/src/rum/types.ts +5 -0
  117. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +5 -0
  118. package/src/types.tsx +5 -0
  119. package/src/version.ts +1 -1
@@ -6,11 +6,19 @@
6
6
 
7
7
  package com.datadog.reactnative
8
8
 
9
+ import android.util.Log
9
10
  import com.datadog.android.log.Logger
11
+ import com.datadog.tools.unit.GenericAssert.Companion.assertThat
10
12
  import com.facebook.react.bridge.Promise
11
13
  import com.facebook.react.bridge.ReactApplicationContext
12
14
  import com.facebook.react.bridge.ReadableMap
15
+ import com.nhaarman.mockitokotlin2.argumentCaptor
16
+ import com.nhaarman.mockitokotlin2.doReturn
17
+ import com.nhaarman.mockitokotlin2.times
13
18
  import com.nhaarman.mockitokotlin2.verify
19
+ import com.nhaarman.mockitokotlin2.verifyZeroInteractions
20
+ import com.nhaarman.mockitokotlin2.whenever
21
+ import fr.xgouchet.elmyr.Forge
14
22
  import fr.xgouchet.elmyr.annotation.AdvancedForgery
15
23
  import fr.xgouchet.elmyr.annotation.MapForgery
16
24
  import fr.xgouchet.elmyr.annotation.StringForgery
@@ -41,9 +49,18 @@ internal class DdLogsTest {
41
49
  @StringForgery
42
50
  lateinit var fakeMessage: String
43
51
 
52
+ private var fakeErrorKind: String? = null
53
+
54
+ private var fakeErrorMessage: String? = null
55
+
56
+ private var fakeStacktrace: String? = null
57
+
44
58
  @Mock
45
59
  lateinit var mockPromise: Promise
46
60
 
61
+ @Mock
62
+ lateinit var mockDatadog: DatadogWrapper
63
+
47
64
  @Mock
48
65
  lateinit var mockReactContext: ReactApplicationContext
49
66
 
@@ -63,8 +80,12 @@ internal class DdLogsTest {
63
80
  lateinit var fakeGlobalState: Map<String, String>
64
81
 
65
82
  @BeforeEach
66
- fun `set up`() {
67
- testedLogs = DdLogs(mockReactContext, mockLogger)
83
+ fun `set up`(forge: Forge) {
84
+ whenever(mockDatadog.isInitialized()) doReturn true
85
+ testedLogs = DdLogs(mockReactContext, mockLogger, mockDatadog)
86
+ fakeErrorKind = forge.aNullable { forge.aString() }
87
+ fakeErrorMessage = forge.aNullable { forge.aString() }
88
+ fakeStacktrace = forge.aNullable { forge.aString() }
68
89
  }
69
90
 
70
91
  @AfterEach
@@ -167,4 +188,223 @@ internal class DdLogsTest {
167
188
  // Then
168
189
  verify(mockLogger).e(fakeMessage, attributes = expectedAttributes)
169
190
  }
191
+
192
+ @Test
193
+ fun `M forward debug log with error W debugWithError()`() {
194
+ // When
195
+ testedLogs.debugWithError(
196
+ fakeMessage,
197
+ fakeErrorKind,
198
+ fakeErrorMessage,
199
+ fakeStacktrace,
200
+ mockContext,
201
+ mockPromise
202
+ )
203
+
204
+ // Then
205
+ verify(mockLogger).log(
206
+ Log.DEBUG,
207
+ fakeMessage,
208
+ fakeErrorKind,
209
+ fakeErrorMessage,
210
+ fakeStacktrace,
211
+ attributes = mockContext.toHashMap()
212
+ )
213
+ }
214
+
215
+ @Test
216
+ fun `M forward info log with error W infoWithError()`() {
217
+ // When
218
+ testedLogs.infoWithError(
219
+ fakeMessage,
220
+ fakeErrorKind,
221
+ fakeErrorMessage,
222
+ fakeStacktrace,
223
+ mockContext,
224
+ mockPromise
225
+ )
226
+
227
+ // Then
228
+ verify(mockLogger).log(
229
+ Log.INFO,
230
+ fakeMessage,
231
+ fakeErrorKind,
232
+ fakeErrorMessage,
233
+ fakeStacktrace,
234
+ attributes = mockContext.toHashMap()
235
+ )
236
+ }
237
+
238
+ @Test
239
+ fun `M forward warn log with error W warnWithError()`() {
240
+ // When
241
+ testedLogs.warnWithError(
242
+ fakeMessage,
243
+ fakeErrorKind,
244
+ fakeErrorMessage,
245
+ fakeStacktrace,
246
+ mockContext,
247
+ mockPromise
248
+ )
249
+
250
+ // Then
251
+ verify(mockLogger).log(
252
+ Log.WARN,
253
+ fakeMessage,
254
+ fakeErrorKind,
255
+ fakeErrorMessage,
256
+ fakeStacktrace,
257
+ attributes = mockContext.toHashMap()
258
+ )
259
+ }
260
+
261
+ @Test
262
+ fun `M forward error log with error W errorWithError()`() {
263
+ // When
264
+ testedLogs.errorWithError(
265
+ fakeMessage,
266
+ fakeErrorKind,
267
+ fakeErrorMessage,
268
+ fakeStacktrace,
269
+ mockContext,
270
+ mockPromise
271
+ )
272
+
273
+ // Then
274
+ verify(mockLogger).log(
275
+ Log.ERROR,
276
+ fakeMessage,
277
+ fakeErrorKind,
278
+ fakeErrorMessage,
279
+ fakeStacktrace,
280
+ attributes = mockContext.toHashMap()
281
+ )
282
+ }
283
+
284
+ @Test
285
+ fun `M not forward logs W SDK is not initialized`() {
286
+ // When
287
+ whenever(mockDatadog.isInitialized()) doReturn false
288
+ var newTestedLogs = DdLogs(mockReactContext, mockLogger, mockDatadog)
289
+ newTestedLogs.debug(fakeMessage, mockContext, mockPromise)
290
+ newTestedLogs.info(fakeMessage, mockContext, mockPromise)
291
+ newTestedLogs.warn(fakeMessage, mockContext, mockPromise)
292
+ newTestedLogs.error(fakeMessage, mockContext, mockPromise)
293
+ testedLogs.debugWithError(
294
+ fakeMessage,
295
+ fakeErrorKind,
296
+ fakeErrorMessage,
297
+ fakeStacktrace,
298
+ mockContext,
299
+ mockPromise
300
+ )
301
+ testedLogs.infoWithError(
302
+ fakeMessage,
303
+ fakeErrorKind,
304
+ fakeErrorMessage,
305
+ fakeStacktrace,
306
+ mockContext,
307
+ mockPromise
308
+ )
309
+ testedLogs.warnWithError(
310
+ fakeMessage,
311
+ fakeErrorKind,
312
+ fakeErrorMessage,
313
+ fakeStacktrace,
314
+ mockContext,
315
+ mockPromise
316
+ )
317
+ testedLogs.errorWithError(
318
+ fakeMessage,
319
+ fakeErrorKind,
320
+ fakeErrorMessage,
321
+ fakeStacktrace,
322
+ mockContext,
323
+ mockPromise
324
+ )
325
+
326
+ // Then
327
+ verifyZeroInteractions(mockLogger)
328
+ val exceptionCaptor = argumentCaptor<IllegalStateException>()
329
+ verify(mockPromise, times(8)).reject(exceptionCaptor.capture())
330
+ assertThat(exceptionCaptor.firstValue.message)
331
+ .isEqualTo("DD_INTERNAL_LOG_SENT_BEFORE_SDK_INIT")
332
+
333
+ // When SDK is finally initialized
334
+ whenever(mockDatadog.isInitialized()) doReturn true
335
+ newTestedLogs.debug(fakeMessage, mockContext, mockPromise)
336
+ newTestedLogs.info(fakeMessage, mockContext, mockPromise)
337
+ newTestedLogs.warn(fakeMessage, mockContext, mockPromise)
338
+ newTestedLogs.error(fakeMessage, mockContext, mockPromise)
339
+ testedLogs.debugWithError(
340
+ fakeMessage,
341
+ fakeErrorKind,
342
+ fakeErrorMessage,
343
+ fakeStacktrace,
344
+ mockContext,
345
+ mockPromise
346
+ )
347
+ testedLogs.infoWithError(
348
+ fakeMessage,
349
+ fakeErrorKind,
350
+ fakeErrorMessage,
351
+ fakeStacktrace,
352
+ mockContext,
353
+ mockPromise
354
+ )
355
+ testedLogs.warnWithError(
356
+ fakeMessage,
357
+ fakeErrorKind,
358
+ fakeErrorMessage,
359
+ fakeStacktrace,
360
+ mockContext,
361
+ mockPromise
362
+ )
363
+ testedLogs.errorWithError(
364
+ fakeMessage,
365
+ fakeErrorKind,
366
+ fakeErrorMessage,
367
+ fakeStacktrace,
368
+ mockContext,
369
+ mockPromise
370
+ )
371
+
372
+ // Then
373
+ verify(mockLogger).i(fakeMessage, attributes = mockContext.toHashMap())
374
+ verify(mockLogger).d(fakeMessage, attributes = mockContext.toHashMap())
375
+ verify(mockLogger).w(fakeMessage, attributes = mockContext.toHashMap())
376
+ verify(mockLogger).e(fakeMessage, attributes = mockContext.toHashMap())
377
+ verify(mockLogger).log(
378
+ Log.DEBUG,
379
+ fakeMessage,
380
+ fakeErrorKind,
381
+ fakeErrorMessage,
382
+ fakeStacktrace,
383
+ attributes = mockContext.toHashMap()
384
+ )
385
+ verify(mockLogger).log(
386
+ Log.INFO,
387
+ fakeMessage,
388
+ fakeErrorKind,
389
+ fakeErrorMessage,
390
+ fakeStacktrace,
391
+ attributes = mockContext.toHashMap()
392
+ )
393
+ verify(mockLogger).log(
394
+ Log.WARN,
395
+ fakeMessage,
396
+ fakeErrorKind,
397
+ fakeErrorMessage,
398
+ fakeStacktrace,
399
+ attributes = mockContext.toHashMap()
400
+ )
401
+ verify(mockLogger).log(
402
+ Log.ERROR,
403
+ fakeMessage,
404
+ fakeErrorKind,
405
+ fakeErrorMessage,
406
+ fakeStacktrace,
407
+ attributes = mockContext.toHashMap()
408
+ )
409
+ }
170
410
  }
@@ -21,6 +21,7 @@ import com.facebook.react.bridge.ReactApplicationContext
21
21
  import com.nhaarman.mockitokotlin2.mock
22
22
  import com.nhaarman.mockitokotlin2.verify
23
23
  import fr.xgouchet.elmyr.Forge
24
+ import fr.xgouchet.elmyr.annotation.BoolForgery
24
25
  import fr.xgouchet.elmyr.annotation.DoubleForgery
25
26
  import fr.xgouchet.elmyr.annotation.Forgery
26
27
  import fr.xgouchet.elmyr.annotation.IntForgery
@@ -410,4 +411,30 @@ internal class DdRumTest {
410
411
  // Then
411
412
  verify(mockRumMonitor).addTiming(timing)
412
413
  }
414
+
415
+ @Test
416
+ fun `M call stopSession W stopSession()`() {
417
+
418
+ // When
419
+ testedDdRum.stopSession(mockPromise)
420
+
421
+ // Then
422
+ verify(mockRumMonitor).stopSession()
423
+ }
424
+
425
+ @Test
426
+ fun `M call addFeatureFlagEvaluation W addFeatureFlagEvaluation(boolean value)`(
427
+ @StringForgery name: String,
428
+ @BoolForgery value: Boolean
429
+ ) {
430
+ val valueAsReadableMap = mapOf<String, Any?>(
431
+ "value" to value
432
+ )
433
+
434
+ // When
435
+ testedDdRum.addFeatureFlagEvaluation(name, valueAsReadableMap.toReadableMap(), mockPromise)
436
+
437
+ // Then
438
+ verify(mockRumMonitor).addFeatureFlagEvaluation(name, value)
439
+ }
413
440
  }
@@ -66,6 +66,7 @@ import java.net.InetSocketAddress
66
66
  import java.net.Proxy
67
67
  import java.util.Locale
68
68
  import java.util.concurrent.atomic.AtomicBoolean
69
+ import java.util.stream.Stream
69
70
  import org.assertj.core.api.Assertions.assertThat
70
71
  import org.junit.jupiter.api.AfterEach
71
72
  import org.junit.jupiter.api.Assumptions.assumeTrue
@@ -73,6 +74,9 @@ import org.junit.jupiter.api.BeforeEach
73
74
  import org.junit.jupiter.api.Test
74
75
  import org.junit.jupiter.api.extension.ExtendWith
75
76
  import org.junit.jupiter.api.extension.Extensions
77
+ import org.junit.jupiter.params.ParameterizedTest
78
+ import org.junit.jupiter.params.provider.Arguments
79
+ import org.junit.jupiter.params.provider.MethodSource
76
80
  import org.mockito.Answers
77
81
  import org.mockito.Mock
78
82
  import org.mockito.junit.jupiter.MockitoExtension
@@ -182,8 +186,6 @@ internal class DdSdkTest {
182
186
  .hasField("coreConfig") {
183
187
  it.hasFieldEqualTo("needsClearTextHttp", false)
184
188
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
185
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
186
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
187
189
  }
188
190
  .hasField("logsConfig") {
189
191
  it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
@@ -232,8 +234,6 @@ internal class DdSdkTest {
232
234
  .hasField("coreConfig") {
233
235
  it.hasFieldEqualTo("needsClearTextHttp", false)
234
236
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
235
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
236
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
237
237
  }
238
238
  .hasField("logsConfig") {
239
239
  it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
@@ -280,8 +280,6 @@ internal class DdSdkTest {
280
280
  .hasField("coreConfig") {
281
281
  it.hasFieldEqualTo("needsClearTextHttp", false)
282
282
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
283
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
284
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
285
283
  }
286
284
  .hasField("logsConfig") {
287
285
  it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
@@ -332,8 +330,6 @@ internal class DdSdkTest {
332
330
  .hasField("coreConfig") {
333
331
  it.hasFieldEqualTo("needsClearTextHttp", false)
334
332
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
335
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
336
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
337
333
  }
338
334
  .hasField("logsConfig") {
339
335
  it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
@@ -384,8 +380,6 @@ internal class DdSdkTest {
384
380
  .hasField("coreConfig") {
385
381
  it.hasFieldEqualTo("needsClearTextHttp", false)
386
382
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
387
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
388
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
389
383
  }
390
384
  .hasField("logsConfig") {
391
385
  it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
@@ -436,8 +430,6 @@ internal class DdSdkTest {
436
430
  .hasField("coreConfig") {
437
431
  it.hasFieldEqualTo("needsClearTextHttp", false)
438
432
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
439
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
440
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
441
433
  }
442
434
  .hasField("logsConfig") {
443
435
  it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
@@ -479,8 +471,6 @@ internal class DdSdkTest {
479
471
  .hasField("coreConfig") {
480
472
  it.hasFieldEqualTo("needsClearTextHttp", false)
481
473
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
482
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
483
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
484
474
  }
485
475
  .hasField("logsConfig") {
486
476
  it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
@@ -532,8 +522,6 @@ internal class DdSdkTest {
532
522
  .hasField("coreConfig") {
533
523
  it.hasFieldEqualTo("needsClearTextHttp", false)
534
524
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
535
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
536
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
537
525
  }
538
526
  .hasField("logsConfig") {
539
527
  it.hasFieldEqualTo("endpointUrl", DatadogSite.US1.intakeEndpoint)
@@ -589,8 +577,6 @@ internal class DdSdkTest {
589
577
  .hasField("coreConfig") {
590
578
  it.hasFieldEqualTo("needsClearTextHttp", false)
591
579
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
592
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
593
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
594
580
  }
595
581
  .hasField("logsConfig") {
596
582
  it.hasFieldEqualTo("endpointUrl", DatadogSite.US1.intakeEndpoint)
@@ -646,8 +632,6 @@ internal class DdSdkTest {
646
632
  .hasField("coreConfig") {
647
633
  it.hasFieldEqualTo("needsClearTextHttp", false)
648
634
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
649
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
650
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
651
635
  }
652
636
  .hasField("logsConfig") {
653
637
  it.hasFieldEqualTo("endpointUrl", DatadogSite.US3.intakeEndpoint)
@@ -703,8 +687,6 @@ internal class DdSdkTest {
703
687
  .hasField("coreConfig") {
704
688
  it.hasFieldEqualTo("needsClearTextHttp", false)
705
689
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
706
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
707
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
708
690
  }
709
691
  .hasField("logsConfig") {
710
692
  it.hasFieldEqualTo("endpointUrl", DatadogSite.US5.intakeEndpoint)
@@ -760,8 +742,6 @@ internal class DdSdkTest {
760
742
  .hasField("coreConfig") {
761
743
  it.hasFieldEqualTo("needsClearTextHttp", false)
762
744
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
763
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
764
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
765
745
  }
766
746
  .hasField("logsConfig") {
767
747
  it.hasFieldEqualTo("endpointUrl", DatadogSite.US1_FED.intakeEndpoint)
@@ -817,8 +797,6 @@ internal class DdSdkTest {
817
797
  .hasField("coreConfig") {
818
798
  it.hasFieldEqualTo("needsClearTextHttp", false)
819
799
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
820
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
821
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
822
800
  }
823
801
  .hasField("logsConfig") {
824
802
  it.hasFieldEqualTo("endpointUrl", DatadogSite.EU1.intakeEndpoint)
@@ -874,8 +852,6 @@ internal class DdSdkTest {
874
852
  .hasField("coreConfig") {
875
853
  it.hasFieldEqualTo("needsClearTextHttp", false)
876
854
  it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
877
- it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
878
- it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
879
855
  }
880
856
  .hasField("logsConfig") {
881
857
  it.hasFieldEqualTo("endpointUrl", DatadogSite.AP1.intakeEndpoint)
@@ -1582,6 +1558,104 @@ internal class DdSdkTest {
1582
1558
  }
1583
1559
  }
1584
1560
 
1561
+ @ParameterizedTest
1562
+ @MethodSource("provideUploadFrequency")
1563
+ fun `𝕄 initialize native SDK 𝕎 initialize() {upload frequency}`(
1564
+ input: String,
1565
+ expectedUploadFrequency: UploadFrequency,
1566
+ @Forgery configuration: DdSdkConfiguration
1567
+ ) {
1568
+ // Given
1569
+ val bridgeConfiguration = configuration.copy(
1570
+ uploadFrequency = input,
1571
+ )
1572
+ val credentialCaptor = argumentCaptor<Credentials>()
1573
+ val configCaptor = argumentCaptor<Configuration>()
1574
+
1575
+ // When
1576
+ testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
1577
+
1578
+ // Then
1579
+ inOrder(mockDatadog) {
1580
+ verify(mockDatadog).initialize(
1581
+ same(mockContext),
1582
+ credentialCaptor.capture(),
1583
+ configCaptor.capture(),
1584
+ eq(configuration.trackingConsent.asTrackingConsent())
1585
+ )
1586
+ verify(mockDatadog).registerRumMonitor(any())
1587
+ }
1588
+ assertThat(configCaptor.firstValue)
1589
+ .hasField("coreConfig") {
1590
+ it.hasFieldEqualTo("uploadFrequency", expectedUploadFrequency)
1591
+ }
1592
+ }
1593
+
1594
+ @ParameterizedTest
1595
+ @MethodSource("provideBatchSize")
1596
+ fun `𝕄 initialize native SDK 𝕎 initialize() {batch size}`(
1597
+ input: String,
1598
+ expectedBatchSize: BatchSize,
1599
+ @Forgery configuration: DdSdkConfiguration
1600
+ ) {
1601
+ // Given
1602
+ val bridgeConfiguration = configuration.copy(
1603
+ batchSize = input,
1604
+ )
1605
+ val credentialCaptor = argumentCaptor<Credentials>()
1606
+ val configCaptor = argumentCaptor<Configuration>()
1607
+
1608
+ // When
1609
+ testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
1610
+
1611
+ // Then
1612
+ inOrder(mockDatadog) {
1613
+ verify(mockDatadog).initialize(
1614
+ same(mockContext),
1615
+ credentialCaptor.capture(),
1616
+ configCaptor.capture(),
1617
+ eq(configuration.trackingConsent.asTrackingConsent())
1618
+ )
1619
+ verify(mockDatadog).registerRumMonitor(any())
1620
+ }
1621
+ assertThat(configCaptor.firstValue)
1622
+ .hasField("coreConfig") {
1623
+ it.hasFieldEqualTo("batchSize", expectedBatchSize)
1624
+ }
1625
+ }
1626
+
1627
+ @Test
1628
+ fun `𝕄 initialize native SDK 𝕎 initialize() {trackBackgroundEvents}`(
1629
+ @Forgery configuration: DdSdkConfiguration,
1630
+ forge: Forge
1631
+ ) {
1632
+ // Given
1633
+ val trackBackgroundEvents = forge.aNullable { forge.aBool() }
1634
+ val bridgeConfiguration = configuration.copy(
1635
+ trackBackgroundEvents = trackBackgroundEvents,
1636
+ )
1637
+ val credentialCaptor = argumentCaptor<Credentials>()
1638
+ val configCaptor = argumentCaptor<Configuration>()
1639
+
1640
+ // When
1641
+ testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
1642
+
1643
+ // Then
1644
+ inOrder(mockDatadog) {
1645
+ verify(mockDatadog).initialize(
1646
+ same(mockContext),
1647
+ credentialCaptor.capture(),
1648
+ configCaptor.capture(),
1649
+ eq(configuration.trackingConsent.asTrackingConsent())
1650
+ )
1651
+ verify(mockDatadog).registerRumMonitor(any())
1652
+ }
1653
+ assertThat(configCaptor.firstValue)
1654
+ .hasField("rumConfig") {
1655
+ it.hasFieldEqualTo("backgroundEventTracking", trackBackgroundEvents ?: false)
1656
+ }
1657
+ }
1658
+
1585
1659
  @Test
1586
1660
  fun `𝕄 initialize native SDK 𝕎 initialize() {rare vitals frequency update}`(
1587
1661
  @Forgery configuration: DdSdkConfiguration
@@ -1827,7 +1901,9 @@ internal class DdSdkTest {
1827
1901
  @StringForgery initializationType: String,
1828
1902
  @BoolForgery trackInteractions: Boolean,
1829
1903
  @BoolForgery trackErrors: Boolean,
1830
- @BoolForgery trackNetworkRequests: Boolean
1904
+ @BoolForgery trackNetworkRequests: Boolean,
1905
+ @StringForgery reactVersion: String,
1906
+ @StringForgery reactNativeVersion: String
1831
1907
  ) {
1832
1908
  // Given
1833
1909
  val bridgeConfiguration = configuration.copy(
@@ -1838,7 +1914,9 @@ internal class DdSdkTest {
1838
1914
  initializationType = initializationType,
1839
1915
  trackErrors = trackErrors,
1840
1916
  trackInteractions = trackInteractions,
1841
- trackNetworkRequests = trackNetworkRequests
1917
+ trackNetworkRequests = trackNetworkRequests,
1918
+ reactVersion = reactVersion,
1919
+ reactNativeVersion = reactNativeVersion
1842
1920
  )
1843
1921
  )
1844
1922
  val configCaptor = argumentCaptor<Configuration>()
@@ -2436,5 +2514,23 @@ internal class DdSdkTest {
2436
2514
  companion object {
2437
2515
  const val ONE_HUNDRED_MILLISSECOND_NS: Long = 100 * 1000L * 1000L
2438
2516
  const val ONE_SECOND_NS: Long = 1000L * 1000L * 1000L
2517
+
2518
+ @JvmStatic
2519
+ fun provideBatchSize(): Stream<Arguments?>? {
2520
+ return Stream.of(
2521
+ Arguments.of("SMALL", BatchSize.SMALL),
2522
+ Arguments.of("MEDIUM", BatchSize.MEDIUM),
2523
+ Arguments.of("LARGE", BatchSize.LARGE),
2524
+ )
2525
+ }
2526
+
2527
+ @JvmStatic
2528
+ fun provideUploadFrequency(): Stream<Arguments?>? {
2529
+ return Stream.of(
2530
+ Arguments.of("RARE", UploadFrequency.RARE),
2531
+ Arguments.of("AVERAGE", UploadFrequency.AVERAGE),
2532
+ Arguments.of("FREQUENT", UploadFrequency.FREQUENT),
2533
+ )
2534
+ }
2439
2535
  }
2440
2536
  }
@@ -6,10 +6,11 @@
6
6
 
7
7
  package com.datadog.tools.unit
8
8
 
9
+ import com.datadog.android.core.configuration.BatchSize
10
+ import com.datadog.android.core.configuration.UploadFrequency
9
11
  import com.datadog.android.core.configuration.VitalsUpdateFrequency
10
12
  import com.datadog.reactnative.ConfigurationForTelemetry
11
13
  import com.datadog.reactnative.DdSdkConfiguration
12
- import com.datadog.reactnative.toReadableMap
13
14
  import com.facebook.react.bridge.ReadableMap
14
15
 
15
16
  fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
@@ -60,6 +61,21 @@ fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
60
61
  } else {
61
62
  trackFrustrations
62
63
  }
64
+ if (uploadFrequency != null) {
65
+ map["uploadFrequency"] = uploadFrequency
66
+ } else {
67
+ map["uploadFrequency"] = UploadFrequency.AVERAGE.toString()
68
+ }
69
+ if (batchSize != null) {
70
+ map["batchSize"] = batchSize
71
+ } else {
72
+ map["batchSize"] = BatchSize.MEDIUM.toString()
73
+ }
74
+ map["trackBackgroundEvents"] = if (trackBackgroundEvents == null) {
75
+ false
76
+ } else {
77
+ trackBackgroundEvents
78
+ }
63
79
  additionalConfig?.let { map.put("additionalConfig", it.toReadableMap()) }
64
80
  configurationForTelemetry?.let {
65
81
  map.put("configurationForTelemetry", it.toReadableJavaOnlyMap())
@@ -73,5 +89,7 @@ internal fun ConfigurationForTelemetry.toReadableJavaOnlyMap(): ReadableMap {
73
89
  trackErrors?.let { map.put("trackErrors", it) }
74
90
  trackInteractions?.let { map.put("trackInteractions", it) }
75
91
  trackNetworkRequests?.let { map.put("trackNetworkRequests", it) }
92
+ reactVersion?.let { map.put("reactVersion", it) }
93
+ reactNativeVersion?.let { map.put("reactNativeVersion", it) }
76
94
  return map.toReadableMap()
77
95
  }
@@ -9,7 +9,7 @@ package com.datadog.tools.unit
9
9
  import org.assertj.core.api.AbstractAssert
10
10
  import org.assertj.core.api.Assertions.assertThat
11
11
 
12
- class GenericAssert(actual: Any) :
12
+ class GenericAssert(actual: Any?) :
13
13
  AbstractAssert<GenericAssert, Any>(actual, GenericAssert::class.java) {
14
14
 
15
15
  fun doesNotHaveField(name: String): GenericAssert {
@@ -62,7 +62,7 @@ class GenericAssert(actual: Any) :
62
62
  }
63
63
 
64
64
  companion object {
65
- fun assertThat(actual: Any): GenericAssert {
65
+ fun assertThat(actual: Any?): GenericAssert {
66
66
  return GenericAssert(actual)
67
67
  }
68
68
  }
@@ -42,11 +42,28 @@ class DdSdkConfigurationForgeryFactory : ForgeryFactory<DdSdkConfiguration> {
42
42
  trackingConsent = forge.aNullable {
43
43
  anElementFrom("pending", "granted", "not_granted")
44
44
  },
45
+ uploadFrequency = forge.aNullable {
46
+ anElementFrom(
47
+ "RARE",
48
+ "FREQUENT",
49
+ "AVERAGE"
50
+ )
51
+ },
52
+ batchSize = forge.aNullable {
53
+ anElementFrom(
54
+ "SMALL",
55
+ "MEDIUM",
56
+ "LARGE"
57
+ )
58
+ },
59
+ trackBackgroundEvents = forge.aNullable { forge.aBool() },
45
60
  configurationForTelemetry = ConfigurationForTelemetry(
46
61
  initializationType = forge.anAlphabeticalString(),
47
62
  trackErrors = forge.aBool(),
48
63
  trackInteractions = forge.aBool(),
49
- trackNetworkRequests = forge.aBool()
64
+ trackNetworkRequests = forge.aBool(),
65
+ reactVersion = forge.aString(),
66
+ reactNativeVersion = forge.aString(),
50
67
  ),
51
68
  trackFrustrations = forge.aNullable { aBool() },
52
69
  )