@datadog/mobile-react-native 1.6.0 → 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 (63) hide show
  1. package/DatadogSDKReactNative.podspec +2 -2
  2. package/android/build.gradle +2 -1
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdRum.kt +16 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +28 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +6 -0
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +6 -0
  7. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +17 -0
  8. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +120 -28
  9. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +17 -1
  10. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +15 -0
  11. package/ios/Sources/DdRum.m +5 -0
  12. package/ios/Sources/DdRum.swift +10 -0
  13. package/ios/Sources/DdSdk.swift +38 -0
  14. package/ios/Sources/DdSdkConfiguration.swift +12 -0
  15. package/ios/Sources/RNDdSdkConfiguration.swift +6 -0
  16. package/lib/commonjs/DdSdkReactNative.js +1 -1
  17. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  18. package/lib/commonjs/DdSdkReactNativeConfiguration.js +45 -2
  19. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  20. package/lib/commonjs/index.js +12 -0
  21. package/lib/commonjs/index.js.map +1 -1
  22. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  23. package/lib/commonjs/rum/DdRum.js +8 -0
  24. package/lib/commonjs/rum/DdRum.js.map +1 -1
  25. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +4 -2
  26. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  27. package/lib/commonjs/types.js +4 -1
  28. package/lib/commonjs/types.js.map +1 -1
  29. package/lib/commonjs/version.js +1 -1
  30. package/lib/commonjs/version.js.map +1 -1
  31. package/lib/module/DdSdkReactNative.js +1 -1
  32. package/lib/module/DdSdkReactNative.js.map +1 -1
  33. package/lib/module/DdSdkReactNativeConfiguration.js +42 -1
  34. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  35. package/lib/module/index.js +2 -2
  36. package/lib/module/index.js.map +1 -1
  37. package/lib/module/nativeModulesTypes.js.map +1 -1
  38. package/lib/module/rum/DdRum.js +7 -0
  39. package/lib/module/rum/DdRum.js.map +1 -1
  40. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +4 -2
  41. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  42. package/lib/module/types.js +4 -1
  43. package/lib/module/types.js.map +1 -1
  44. package/lib/module/version.js +1 -1
  45. package/lib/module/version.js.map +1 -1
  46. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +47 -0
  47. package/lib/typescript/index.d.ts +2 -2
  48. package/lib/typescript/nativeModulesTypes.d.ts +7 -0
  49. package/lib/typescript/rum/DdRum.d.ts +1 -0
  50. package/lib/typescript/types.d.ts +4 -1
  51. package/lib/typescript/version.d.ts +1 -1
  52. package/package.json +2 -2
  53. package/src/DdSdkReactNative.tsx +3 -0
  54. package/src/DdSdkReactNativeConfiguration.tsx +56 -1
  55. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +20 -3
  56. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +47 -25
  57. package/src/index.tsx +6 -2
  58. package/src/nativeModulesTypes.ts +8 -0
  59. package/src/rum/DdRum.ts +12 -0
  60. package/src/rum/instrumentation/DdRumErrorTracking.tsx +5 -2
  61. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +3 -0
  62. package/src/types.tsx +3 -0
  63. package/src/version.ts +1 -1
@@ -17,8 +17,8 @@ Pod::Spec.new do |s|
17
17
  s.source_files = "ios/Sources/*.{h,m,mm,swift}"
18
18
 
19
19
  s.dependency "React-Core"
20
- s.dependency 'DatadogSDK', '~> 1.19.0'
21
- s.dependency 'DatadogSDKCrashReporting', '~> 1.19.0'
20
+ s.dependency 'DatadogSDK', '~> 1.20.0'
21
+ s.dependency 'DatadogSDKCrashReporting', '~> 1.20.0'
22
22
 
23
23
  s.test_spec 'Tests' do |test_spec|
24
24
  test_spec.source_files = 'ios/Tests/*.swift'
@@ -146,10 +146,11 @@ dependencies {
146
146
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
147
147
  compileOnly "com.squareup.okhttp3:okhttp:3.12.13"
148
148
 
149
- implementation "com.datadoghq:dd-sdk-android:1.19.0"
149
+ implementation "com.datadoghq:dd-sdk-android:1.19.2"
150
150
  testImplementation "org.junit.platform:junit-platform-launcher:1.6.2"
151
151
  testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
152
152
  testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2"
153
+ testImplementation "org.junit.jupiter:junit-jupiter-params:5.6.2"
153
154
  testImplementation "org.mockito:mockito-junit-jupiter:3.4.6"
154
155
  testImplementation "org.assertj:assertj-core:3.18.1"
155
156
  testImplementation "com.github.xgouchet.Elmyr:core:1.3.1"
@@ -21,6 +21,7 @@ import java.util.Locale
21
21
  /**
22
22
  * The entry point to use Datadog's RUM feature.
23
23
  */
24
+ @Suppress("TooManyFunctions")
24
25
  class DdRum(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
25
26
 
26
27
  override fun getName(): String = "DdRum"
@@ -264,6 +265,21 @@ class DdRum(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(
264
265
  promise.resolve(null)
265
266
  }
266
267
 
268
+ /**
269
+ * Adds result of evaluating a feature flag to the view.
270
+ * Feature flag evaluations are local to the active view and are cleared when the view is stopped.
271
+ * @param name The name of the feature flag
272
+ * @param value The value the feature flag evaluated to, encapsulated in a Map
273
+ */
274
+ @ReactMethod
275
+ fun addFeatureFlagEvaluation(name: String, value: ReadableMap, promise: Promise) {
276
+ val value = value.toHashMap()["value"]
277
+ if (value != null) {
278
+ GlobalRum.get().addFeatureFlagEvaluation(name, value)
279
+ }
280
+ promise.resolve(null)
281
+ }
282
+
267
283
  // region Internal
268
284
 
269
285
  private fun String.asRumActionType(): RumActionType {
@@ -12,8 +12,10 @@ import android.util.Log
12
12
  import android.view.Choreographer
13
13
  import com.datadog.android.DatadogSite
14
14
  import com.datadog.android._InternalProxy
15
+ import com.datadog.android.core.configuration.BatchSize
15
16
  import com.datadog.android.core.configuration.Configuration
16
17
  import com.datadog.android.core.configuration.Credentials
18
+ import com.datadog.android.core.configuration.UploadFrequency
17
19
  import com.datadog.android.core.configuration.VitalsUpdateFrequency
18
20
  import com.datadog.android.event.EventMapper
19
21
  import com.datadog.android.privacy.TrackingConsent
@@ -209,11 +211,18 @@ class DdSdk(
209
211
  }
210
212
 
211
213
  configBuilder.trackFrustrations(configuration.trackFrustrations ?: true)
214
+ configBuilder.trackBackgroundRumEvents(configuration.trackBackgroundEvents ?: false)
212
215
 
213
216
  configBuilder.useSite(buildSite(configuration.site))
214
217
  configBuilder.setVitalsUpdateFrequency(
215
218
  buildVitalUpdateFrequency(configuration.vitalsUpdateFrequency)
216
219
  )
220
+ configBuilder.setUploadFrequency(
221
+ buildUploadFrequency(configuration.uploadFrequency)
222
+ )
223
+ configBuilder.setBatchSize(
224
+ buildBatchSize(configuration.batchSize)
225
+ )
217
226
 
218
227
  val telemetrySampleRate = (configuration.telemetrySampleRate as? Number)?.toFloat()
219
228
  telemetrySampleRate?.let { configBuilder.sampleTelemetry(it) }
@@ -437,6 +446,25 @@ class DdSdk(
437
446
  }
438
447
  }
439
448
 
449
+ private fun buildUploadFrequency(uploadFrequency: String?): UploadFrequency {
450
+ val uploadFrequency = uploadFrequency?.lowercase(Locale.US)
451
+ return when (uploadFrequency) {
452
+ "rare" -> UploadFrequency.RARE
453
+ "average" -> UploadFrequency.AVERAGE
454
+ "frequent" -> UploadFrequency.FREQUENT
455
+ else -> UploadFrequency.AVERAGE
456
+ }
457
+ }
458
+
459
+ private fun buildBatchSize(batchSize: String?): BatchSize {
460
+ return when (batchSize?.lowercase(Locale.US)) {
461
+ "small" -> BatchSize.SMALL
462
+ "medium" -> BatchSize.MEDIUM
463
+ "large" -> BatchSize.LARGE
464
+ else -> BatchSize.MEDIUM
465
+ }
466
+ }
467
+
440
468
  private fun handlePostFrameCallbackError(e: IllegalStateException) {
441
469
  datadog.telemetryError(e.message ?: MONITOR_JS_ERROR_MESSAGE, e)
442
470
  }
@@ -20,6 +20,9 @@ package com.datadog.reactnative
20
20
  * @param telemetrySampleRate The sample rate (between 0 and 100) of telemetry events.
21
21
  * @param vitalsUpdateFrequency The frequency to which vitals update are sent (can be 'NEVER', 'RARE', 'AVERAGE' (default), 'FREQUENT').
22
22
  * @param trackFrustrations Whether to track frustration signals or not.
23
+ * @param uploadFrequency The frequency to which batches of data are sent (can be 'RARE', 'AVERAGE' (default), 'FREQUENT')
24
+ * @param batchSize The preferred size for uploaded batches of data (can be 'SMALL', 'MEDIUM' (default), 'LARGE')
25
+ * @param trackBackgroundEvents Enables/Disables tracking RUM event when no RUM View is active. Might increase number of sessions and billing.
23
26
  * @param additionalConfig Additional configuration parameters.
24
27
  * @param configurationForTelemetry Additional configuration data for Datadog telemetry.
25
28
  */
@@ -36,6 +39,9 @@ data class DdSdkConfiguration(
36
39
  val telemetrySampleRate: Double? = null,
37
40
  val vitalsUpdateFrequency: String? = null,
38
41
  val trackFrustrations: Boolean? = null,
42
+ val uploadFrequency: String? = null,
43
+ val batchSize: String? = null,
44
+ val trackBackgroundEvents: Boolean? = null,
39
45
  val additionalConfig: Map<String, Any?>? = null,
40
46
  val configurationForTelemetry: ConfigurationForTelemetry? = null
41
47
  )
@@ -25,6 +25,9 @@ internal fun ReadableMap.asDdSdkConfiguration(): DdSdkConfiguration {
25
25
  telemetrySampleRate = getDouble("telemetrySampleRate"),
26
26
  vitalsUpdateFrequency = getString("vitalsUpdateFrequency"),
27
27
  trackFrustrations = getBoolean("trackFrustrations"),
28
+ uploadFrequency = getString("uploadFrequency"),
29
+ batchSize = getString("batchSize"),
30
+ trackBackgroundEvents = getBoolean("trackBackgroundEvents"),
28
31
  additionalConfig = getMap("additionalConfig")?.toHashMap(),
29
32
  configurationForTelemetry = getMap(
30
33
  "configurationForTelemetry"
@@ -70,6 +73,9 @@ internal fun DdSdkConfiguration.toReadableMap(): ReadableMap {
70
73
  telemetrySampleRate?.let { map.putDouble("telemetrySampleRate", it) }
71
74
  vitalsUpdateFrequency?.let { map.putString("vitalsUpdateFrequency", it) }
72
75
  trackFrustrations?.let { map.putBoolean("trackFrustrations", it) }
76
+ uploadFrequency?.let { map.putString("uploadFrequency", it) }
77
+ batchSize?.let { map.putString("batchSize", it) }
78
+ trackBackgroundEvents?.let { map.putBoolean("trackBackgroundEvents", it) }
73
79
  additionalConfig?.let { map.putMap("additionalConfig", it.toWritableMap()) }
74
80
  return map
75
81
  }
@@ -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
@@ -420,4 +421,20 @@ internal class DdRumTest {
420
421
  // Then
421
422
  verify(mockRumMonitor).stopSession()
422
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
+ }
423
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
@@ -2440,5 +2514,23 @@ internal class DdSdkTest {
2440
2514
  companion object {
2441
2515
  const val ONE_HUNDRED_MILLISSECOND_NS: Long = 100 * 1000L * 1000L
2442
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
+ }
2443
2535
  }
2444
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())
@@ -42,6 +42,21 @@ 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(),
@@ -74,4 +74,9 @@ RCT_EXTERN_METHOD(addTiming:(NSString)name
74
74
  RCT_EXTERN_METHOD(stopSession:(RCTPromiseResolveBlock)resolve
75
75
  withRejecter:(RCTPromiseRejectBlock)reject)
76
76
 
77
+ RCT_EXTERN_METHOD(addFeatureFlagEvaluation:(NSString)name
78
+ withValue:(NSDictionary)value
79
+ withResolver:(RCTPromiseResolveBlock)resolve
80
+ withRejecter:(RCTPromiseRejectBlock)reject)
81
+
77
82
  @end
@@ -29,6 +29,7 @@ internal protocol NativeRUM {
29
29
  download: (start: Date, end: Date)?,
30
30
  responseSize: Int64?,
31
31
  attributes: [AttributeKey: AttributeValue])
32
+ func addFeatureFlagEvaluation(name: String, value: Encodable)
32
33
  }
33
34
 
34
35
  private extension RUMUserActionType {
@@ -194,6 +195,15 @@ class RNDdRum: NSObject {
194
195
  resolve(nil)
195
196
  }
196
197
 
198
+ @objc(addFeatureFlagEvaluation:withValue:withResolver:withRejecter:)
199
+ func addFeatureFlagEvaluation(name: String, value: NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
200
+ let valueAsEncodable = castAttributesToSwift(value)
201
+ if let value = valueAsEncodable["value"] {
202
+ nativeRUM.addFeatureFlagEvaluation(name: name, value: value)
203
+ }
204
+ resolve(nil)
205
+ }
206
+
197
207
  // MARK: - Private methods
198
208
 
199
209
  private func attributes(from context: NSDictionary, with timestampMs: Int64) -> [String: Encodable] {
@@ -185,6 +185,10 @@ class RNDdSdk: NSObject {
185
185
 
186
186
  _ = ddConfigBuilder.set(mobileVitalsFrequency: buildVitalsUpdateFrequency(frequency: configuration.vitalsUpdateFrequency))
187
187
 
188
+ _ = ddConfigBuilder.set(uploadFrequency: buildUploadFrequency(frequency: configuration.uploadFrequency))
189
+
190
+ _ = ddConfigBuilder.set(batchSize: buildBatchSize(batchSize: configuration.batchSize))
191
+
188
192
  if var telemetrySampleRate = (configuration.telemetrySampleRate as? NSNumber)?.floatValue {
189
193
  _ = ddConfigBuilder.set(sampleTelemetry: telemetrySampleRate)
190
194
  }
@@ -193,6 +197,10 @@ class RNDdSdk: NSObject {
193
197
  _ = ddConfigBuilder.trackFrustrations(trackFrustrations)
194
198
  }
195
199
 
200
+ if var trackBackgroundEvents = (configuration.trackBackgroundEvents) {
201
+ _ = ddConfigBuilder.trackBackgroundEvents(trackBackgroundEvents)
202
+ }
203
+
196
204
  if let threshold = configuration.nativeLongTaskThresholdMs as? TimeInterval {
197
205
  if (threshold != 0) {
198
206
  // `nativeLongTaskThresholdMs` attribute is in milliseconds
@@ -325,6 +333,36 @@ class RNDdSdk: NSObject {
325
333
  return vitalsFrequency
326
334
  }
327
335
 
336
+ func buildUploadFrequency(frequency: NSString?) -> Datadog.Configuration.UploadFrequency {
337
+ let uploadFrequency: Datadog.Configuration.UploadFrequency
338
+ switch frequency?.lowercased {
339
+ case "rare":
340
+ uploadFrequency = .rare
341
+ case "average":
342
+ uploadFrequency = .average
343
+ case "frequent":
344
+ uploadFrequency = .frequent
345
+ default:
346
+ uploadFrequency = .average
347
+ }
348
+ return uploadFrequency
349
+ }
350
+
351
+ func buildBatchSize(batchSize: NSString?) -> Datadog.Configuration.BatchSize {
352
+ let size: Datadog.Configuration.BatchSize
353
+ switch batchSize?.lowercased {
354
+ case "small":
355
+ size = .small
356
+ case "medium":
357
+ size = .medium
358
+ case "large":
359
+ size = .large
360
+ default:
361
+ size = .medium
362
+ }
363
+ return size
364
+ }
365
+
328
366
  func setVerbosityLevel(additionalConfig: NSDictionary?) {
329
367
  let verbosityLevel = (additionalConfig?[InternalConfigurationAttributes.sdkVerbosity]) as? NSString
330
368
  switch verbosityLevel?.lowercased {
@@ -20,7 +20,10 @@ import Foundation
20
20
  - trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
21
21
  - telemetrySampleRate: The sample rate (between 0 and 100) of telemetry events.
22
22
  - vitalsUpdateFrequency: The frequency at which to measure vitals performance metrics.
23
+ - uploadFrequency: The frequency at which batches of data are sent.
24
+ - batchSize: The preferred size of batched data uploaded to Datadog.
23
25
  - trackFrustrations: Whether to track frustration signals or not.
26
+ - trackBackgroundEvents: Enables/Disables tracking RUM event when no RUM View is active. Might increase number of sessions and billing.
24
27
  - additionalConfig: Additional configuration parameters.
25
28
  - configurationForTelemetry: Additional configuration paramters only used for telemetry purposes.
26
29
  */
@@ -38,6 +41,9 @@ public class DdSdkConfiguration: NSObject {
38
41
  public var telemetrySampleRate: Double? = nil
39
42
  public var vitalsUpdateFrequency: NSString? = nil
40
43
  public var trackFrustrations: Bool? = nil
44
+ public var uploadFrequency: NSString? = nil
45
+ public var batchSize: NSString? = nil
46
+ public var trackBackgroundEvents: Bool? = nil
41
47
  public var additionalConfig: NSDictionary? = nil
42
48
  public var configurationForTelemetry: ConfigurationForTelemetry? = nil
43
49
 
@@ -54,6 +60,9 @@ public class DdSdkConfiguration: NSObject {
54
60
  telemetrySampleRate: Double?,
55
61
  vitalsUpdateFrequency: NSString?,
56
62
  trackFrustrations: Bool?,
63
+ uploadFrequency: NSString?,
64
+ batchSize: NSString?,
65
+ trackBackgroundEvents: Bool?,
57
66
  additionalConfig: NSDictionary?,
58
67
  configurationForTelemetry: ConfigurationForTelemetry?
59
68
  ) {
@@ -69,6 +78,9 @@ public class DdSdkConfiguration: NSObject {
69
78
  self.telemetrySampleRate = telemetrySampleRate
70
79
  self.vitalsUpdateFrequency = vitalsUpdateFrequency
71
80
  self.trackFrustrations = trackFrustrations
81
+ self.uploadFrequency = uploadFrequency
82
+ self.batchSize = batchSize
83
+ self.trackBackgroundEvents = trackBackgroundEvents
72
84
  self.additionalConfig = additionalConfig
73
85
  self.configurationForTelemetry = configurationForTelemetry
74
86
  }
@@ -22,6 +22,9 @@ extension NSDictionary {
22
22
  let telemetrySampleRate = object(forKey: "telemetrySampleRate") as? Double
23
23
  let vitalsUpdateFrequency = object(forKey: "vitalsUpdateFrequency") as? NSString
24
24
  let trackFrustrations = object(forKey: "trackFrustrations") as? Bool
25
+ let uploadFrequency = object(forKey: "uploadFrequency") as? NSString
26
+ let batchSize = object(forKey: "batchSize") as? NSString
27
+ let trackBackgroundEvents = object(forKey: "trackBackgroundEvents") as? Bool
25
28
  let additionalConfig = object(forKey: "additionalConfig") as? NSDictionary
26
29
  let configurationForTelemetry = object(forKey: "configurationForTelemetry") as? NSDictionary
27
30
  return DdSdkConfiguration(
@@ -37,6 +40,9 @@ extension NSDictionary {
37
40
  telemetrySampleRate: telemetrySampleRate,
38
41
  vitalsUpdateFrequency: vitalsUpdateFrequency,
39
42
  trackFrustrations: trackFrustrations,
43
+ uploadFrequency: uploadFrequency,
44
+ batchSize: batchSize,
45
+ trackBackgroundEvents: trackBackgroundEvents,
40
46
  additionalConfig: additionalConfig,
41
47
  configurationForTelemetry: configurationForTelemetry?.asConfigurationForTelemetry()
42
48
  )