@datadog/mobile-react-native 3.8.0 → 3.10.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 (143) hide show
  1. package/android/src/main/kotlin/com/datadog/reactnative/DdFlagsImplementation.kt +6 -3
  2. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +16 -8
  3. package/android/src/main/kotlin/com/datadog/reactnative/FrameRateProvider.kt +11 -6
  4. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  5. package/android/src/test/kotlin/com/datadog/reactnative/DdFlagsImplementationTest.kt +19 -0
  6. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +131 -0
  7. package/datadog-configuration.schema.json +11 -0
  8. package/ios/Sources/DdRumImplementation.swift +2 -2
  9. package/ios/Sources/DdSdkConfiguration.swift +13 -0
  10. package/ios/Sources/DdSdkImplementation.swift +4 -3
  11. package/ios/Sources/DdSdkNativeInitialization.swift +26 -8
  12. package/ios/Sources/JSRefreshRateListener.swift +6 -2
  13. package/ios/Sources/RNDdSdkConfiguration.swift +9 -0
  14. package/ios/Sources/SdkVersion.swift +1 -1
  15. package/lib/commonjs/DdSdkReactNative.js +16 -16
  16. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  17. package/lib/commonjs/config/FileBasedConfiguration.js +3 -1
  18. package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
  19. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +3 -0
  20. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  21. package/lib/commonjs/config/features/RumConfiguration.js +8 -0
  22. package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
  23. package/lib/commonjs/flags/FlagsClient.js +81 -8
  24. package/lib/commonjs/flags/FlagsClient.js.map +1 -1
  25. package/lib/commonjs/flags/configuration/precomputed.js +2 -3
  26. package/lib/commonjs/flags/configuration/precomputed.js.map +1 -1
  27. package/lib/commonjs/flags/internal.js.map +1 -1
  28. package/lib/commonjs/rum/DdRum.js +2 -2
  29. package/lib/commonjs/rum/DdRum.js.map +1 -1
  30. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +3 -3
  31. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  32. package/lib/commonjs/sdk/AttributesEncoding/defaultEncoders.js +1 -1
  33. package/lib/commonjs/sdk/AttributesEncoding/defaultEncoders.js.map +1 -1
  34. package/lib/commonjs/sdk/AttributesEncoding/helpers.js +3 -3
  35. package/lib/commonjs/sdk/AttributesEncoding/helpers.js.map +1 -1
  36. package/lib/commonjs/sdk/AttributesEncoding/utils.js +8 -0
  37. package/lib/commonjs/sdk/AttributesEncoding/utils.js.map +1 -1
  38. package/lib/commonjs/sdk/DatadogProvider/Buffer/BoundedBuffer.js +2 -2
  39. package/lib/commonjs/sdk/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -1
  40. package/lib/commonjs/sdk/DdSdkInternal.js +22 -22
  41. package/lib/commonjs/sdk/DdSdkInternal.js.map +1 -1
  42. package/lib/commonjs/sdk/EventMappers/EventMapper.js +2 -2
  43. package/lib/commonjs/sdk/EventMappers/EventMapper.js.map +1 -1
  44. package/lib/commonjs/utils/time-provider/TimeProvider.js +4 -1
  45. package/lib/commonjs/utils/time-provider/TimeProvider.js.map +1 -1
  46. package/lib/commonjs/version.js +1 -1
  47. package/lib/commonjs/version.js.map +1 -1
  48. package/lib/module/DdSdkReactNative.js +16 -16
  49. package/lib/module/DdSdkReactNative.js.map +1 -1
  50. package/lib/module/config/FileBasedConfiguration.js +3 -1
  51. package/lib/module/config/FileBasedConfiguration.js.map +1 -1
  52. package/lib/module/config/async/AutoInstrumentationConfiguration.js +3 -0
  53. package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  54. package/lib/module/config/features/RumConfiguration.js +8 -0
  55. package/lib/module/config/features/RumConfiguration.js.map +1 -1
  56. package/lib/module/flags/FlagsClient.js +81 -8
  57. package/lib/module/flags/FlagsClient.js.map +1 -1
  58. package/lib/module/flags/configuration/precomputed.js +2 -3
  59. package/lib/module/flags/configuration/precomputed.js.map +1 -1
  60. package/lib/module/flags/internal.js.map +1 -1
  61. package/lib/module/rum/DdRum.js +2 -2
  62. package/lib/module/rum/DdRum.js.map +1 -1
  63. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +3 -3
  64. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  65. package/lib/module/sdk/AttributesEncoding/defaultEncoders.js +2 -2
  66. package/lib/module/sdk/AttributesEncoding/defaultEncoders.js.map +1 -1
  67. package/lib/module/sdk/AttributesEncoding/helpers.js +4 -4
  68. package/lib/module/sdk/AttributesEncoding/helpers.js.map +1 -1
  69. package/lib/module/sdk/AttributesEncoding/utils.js +7 -0
  70. package/lib/module/sdk/AttributesEncoding/utils.js.map +1 -1
  71. package/lib/module/sdk/DatadogProvider/Buffer/BoundedBuffer.js +2 -2
  72. package/lib/module/sdk/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -1
  73. package/lib/module/sdk/DdSdkInternal.js +21 -22
  74. package/lib/module/sdk/DdSdkInternal.js.map +1 -1
  75. package/lib/module/sdk/EventMappers/EventMapper.js +2 -2
  76. package/lib/module/sdk/EventMappers/EventMapper.js.map +1 -1
  77. package/lib/module/utils/time-provider/TimeProvider.js +4 -1
  78. package/lib/module/utils/time-provider/TimeProvider.js.map +1 -1
  79. package/lib/module/version.js +1 -1
  80. package/lib/module/version.js.map +1 -1
  81. package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
  82. package/lib/typescript/config/FileBasedConfiguration.type.d.ts +2 -0
  83. package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
  84. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +4 -0
  85. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
  86. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts +2 -0
  87. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts.map +1 -1
  88. package/lib/typescript/config/features/RumConfiguration.d.ts +4 -0
  89. package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
  90. package/lib/typescript/config/features/RumConfiguration.type.d.ts +21 -0
  91. package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
  92. package/lib/typescript/config/features/RumConfigurationNative.d.ts +2 -0
  93. package/lib/typescript/config/features/RumConfigurationNative.d.ts.map +1 -1
  94. package/lib/typescript/flags/FlagsClient.d.ts +38 -1
  95. package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
  96. package/lib/typescript/flags/internal.d.ts +1 -0
  97. package/lib/typescript/flags/internal.d.ts.map +1 -1
  98. package/lib/typescript/flags/types.d.ts +1 -1
  99. package/lib/typescript/flags/types.d.ts.map +1 -1
  100. package/lib/typescript/sdk/AttributesEncoding/defaultEncoders.d.ts.map +1 -1
  101. package/lib/typescript/sdk/AttributesEncoding/utils.d.ts +1 -0
  102. package/lib/typescript/sdk/AttributesEncoding/utils.d.ts.map +1 -1
  103. package/lib/typescript/sdk/DdSdkInternal.d.ts +1 -8
  104. package/lib/typescript/sdk/DdSdkInternal.d.ts.map +1 -1
  105. package/lib/typescript/utils/time-provider/TimeProvider.d.ts.map +1 -1
  106. package/lib/typescript/version.d.ts +1 -1
  107. package/lib/typescript/version.d.ts.map +1 -1
  108. package/package.json +2 -2
  109. package/src/DdSdkReactNative.tsx +16 -16
  110. package/src/__tests__/DdSdkReactNative.test.tsx +272 -19
  111. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +12 -0
  112. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +3 -3
  113. package/src/config/FileBasedConfiguration.ts +6 -1
  114. package/src/config/FileBasedConfiguration.type.ts +2 -0
  115. package/src/config/__tests__/FileBasedConfiguration.test.ts +79 -0
  116. package/src/config/__tests__/__fixtures__/configuration-all-fields.json +2 -0
  117. package/src/config/async/AutoInstrumentationConfiguration.ts +9 -0
  118. package/src/config/async/PartialInitializationConfiguration.ts +2 -0
  119. package/src/config/features/RumConfiguration.ts +10 -0
  120. package/src/config/features/RumConfiguration.type.ts +23 -0
  121. package/src/config/features/RumConfigurationNative.ts +2 -0
  122. package/src/flags/FlagsClient.ts +128 -19
  123. package/src/flags/__tests__/FlagsClient.test.ts +167 -0
  124. package/src/flags/configuration/precomputed.ts +2 -3
  125. package/src/flags/internal.ts +2 -0
  126. package/src/flags/types.ts +2 -0
  127. package/src/rum/DdRum.ts +2 -2
  128. package/src/rum/__tests__/DdRum.test.ts +4 -4
  129. package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +3 -3
  130. package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +104 -1
  131. package/src/sdk/AttributesEncoding/__tests__/attributesEncoding.test.ts +25 -0
  132. package/src/sdk/AttributesEncoding/defaultEncoders.ts +6 -2
  133. package/src/sdk/AttributesEncoding/helpers.ts +6 -6
  134. package/src/sdk/AttributesEncoding/utils.ts +8 -0
  135. package/src/sdk/DatadogProvider/Buffer/BoundedBuffer.ts +2 -2
  136. package/src/sdk/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +5 -5
  137. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +165 -0
  138. package/src/sdk/DdSdkInternal.ts +23 -30
  139. package/src/sdk/EventMappers/EventMapper.ts +2 -2
  140. package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +2 -2
  141. package/src/utils/__tests__/TimeProvider.test.tsx +49 -0
  142. package/src/utils/time-provider/TimeProvider.tsx +10 -1
  143. package/src/version.ts +1 -1
@@ -169,14 +169,17 @@ private fun buildFlagsConfiguration(configuration: Map<String, Any?>): FlagsConf
169
169
  }.build()
170
170
  }
171
171
 
172
- private fun buildEvaluationContext(
172
+ internal fun buildEvaluationContext(
173
173
  targetingKey: String,
174
174
  attributes: ReadableMap,
175
175
  ): EvaluationContext {
176
176
  val parsed = mutableMapOf<String, String>()
177
177
 
178
- for ((key, value) in attributes.entryIterator) {
179
- parsed[key] = value.toString()
178
+ // JS null attributes arrive as null; the native context only holds strings, so omit them.
179
+ for ((key, value) in attributes.toHashMap()) {
180
+ if (value != null) {
181
+ parsed[key] = value.toString()
182
+ }
180
183
  }
181
184
 
182
185
  return EvaluationContext(targetingKey, parsed)
@@ -331,7 +331,14 @@ class DdSdkImplementation(
331
331
  ddSdkConfiguration: DdSdkConfiguration
332
332
  ): FrameRateProvider? {
333
333
  val frameTimeCallback = buildFrameTimeCallback(ddSdkConfiguration) ?: return null
334
- val frameRateProvider = FrameRateProvider(frameTimeCallback, jsThreadExecutor)
334
+ // Before API 30 every Display.refreshRate read is an IPC, so use the max refresh rate there
335
+ val display = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
336
+ (appContext.getSystemService(Context.DISPLAY_SERVICE) as? DisplayManager)
337
+ ?.getDisplay(Display.DEFAULT_DISPLAY)
338
+ } else {
339
+ null
340
+ }
341
+ val frameRateProvider = FrameRateProvider(frameTimeCallback, jsThreadExecutor, display)
335
342
  frameRateProvider.start()
336
343
 
337
344
  return frameRateProvider
@@ -340,7 +347,7 @@ class DdSdkImplementation(
340
347
  @Suppress("CyclomaticComplexMethod")
341
348
  private fun buildFrameTimeCallback(
342
349
  ddSdkConfiguration: DdSdkConfiguration
343
- ): ((Double) -> Unit)? {
350
+ ): ((Double, Double?) -> Unit)? {
344
351
  val jsRefreshRateMonitoringEnabled =
345
352
  ddSdkConfiguration.rumConfiguration != null &&
346
353
  buildVitalUpdateFrequency(ddSdkConfiguration.rumConfiguration.vitalsUpdateFrequency) !=
@@ -351,20 +358,21 @@ class DdSdkImplementation(
351
358
  return null
352
359
  }
353
360
 
354
- return {
355
- if (jsRefreshRateMonitoringEnabled && it > 0.0) {
356
- val normalizedFrameTimeSeconds = normalizeFrameTime(it, appContext)
361
+ return { frameTime, displayFps ->
362
+ if (jsRefreshRateMonitoringEnabled && frameTime > 0.0) {
363
+ val normalizedFrameTimeSeconds =
364
+ normalizeFrameTime(frameTime, appContext, deviceDisplayFps = displayFps)
357
365
  datadog.getRumMonitor()
358
366
  ._getInternal()
359
367
  ?.updatePerformanceMetric(RumPerformanceMetric.JS_FRAME_TIME, normalizedFrameTimeSeconds)
360
368
  }
361
369
  if (jsLongTasksMonitoringEnabled &&
362
- it >
370
+ frameTime >
363
371
  TimeUnit.MILLISECONDS.toNanos(
364
372
  ddSdkConfiguration.rumConfiguration?.longTaskThresholdMs?.toLong() ?: 0L
365
373
  )
366
374
  ) {
367
- datadog.getRumMonitor()._getInternal()?.addLongTask(it.toLong(), "javascript")
375
+ datadog.getRumMonitor()._getInternal()?.addLongTask(frameTime.toLong(), "javascript")
368
376
  }
369
377
  }
370
378
  }
@@ -374,7 +382,7 @@ class DdSdkImplementation(
374
382
  * @param frameTimeSeconds: the frame time to normalize. In seconds.
375
383
  * @param context: The current app context
376
384
  * @param fpsBudget: The maximum fps under which the frame Time will be normalized [0-fpsBudget]. Defaults to 60Hz.
377
- * @param deviceDisplayFps: The maximum fps supported by the device. If not provided it will be set from the value obtained from the app context.
385
+ * @param deviceDisplayFps: The refresh rate the display is currently running at. If not provided it will be set from the maximum value obtained from the app context.
378
386
  */
379
387
  @Suppress("CyclomaticComplexMethod")
380
388
  fun normalizeFrameTime(
@@ -7,14 +7,17 @@
7
7
  package com.datadog.reactnative
8
8
 
9
9
  import android.view.Choreographer
10
+ import android.view.Display
10
11
 
11
12
  internal class FrameRateProvider(
12
- reactFrameRateCallback: ((Double) -> Unit),
13
- jsThreadExecutor: JsThreadExecutor
13
+ reactFrameRateCallback: ((Double, Double?) -> Unit),
14
+ jsThreadExecutor: JsThreadExecutor,
15
+ display: Display?
14
16
  ) {
15
17
  private val frameCallback: FpsFrameCallback = FpsFrameCallback(
16
18
  reactFrameRateCallback,
17
- jsThreadExecutor
19
+ jsThreadExecutor,
20
+ display
18
21
  )
19
22
 
20
23
  fun start() {
@@ -28,8 +31,9 @@ internal class FrameRateProvider(
28
31
  }
29
32
 
30
33
  internal class FpsFrameCallback(
31
- private val reactFrameRateCallback: ((Double) -> Unit),
32
- private val jsThreadExecutor: JsThreadExecutor
34
+ private val reactFrameRateCallback: ((Double, Double?) -> Unit),
35
+ private val jsThreadExecutor: JsThreadExecutor,
36
+ private val display: Display?
33
37
  ) : Choreographer.FrameCallback {
34
38
 
35
39
  private var choreographer: Choreographer? = null
@@ -37,7 +41,8 @@ internal class FpsFrameCallback(
37
41
 
38
42
  override fun doFrame(time: Long) {
39
43
  if (lastFrameTime != -1L) {
40
- reactFrameRateCallback((time - lastFrameTime).toDouble())
44
+ // Refresh rate the display is currently running at
45
+ reactFrameRateCallback((time - lastFrameTime).toDouble(), display?.refreshRate?.toDouble())
41
46
  }
42
47
  lastFrameTime = time
43
48
  choreographer?.postFrameCallback(this)
@@ -7,4 +7,4 @@
7
7
  package com.datadog.reactnative
8
8
 
9
9
  // This is automatically updated by the update-version.sh script
10
- internal const val SDK_VERSION = "3.8.0"
10
+ internal const val SDK_VERSION = "3.10.0"
@@ -12,6 +12,7 @@ import com.datadog.android.flags.Flags
12
12
  import com.datadog.android.flags.FlagsConfiguration
13
13
  import com.datadog.tools.unit.toReadableMap
14
14
  import com.facebook.react.bridge.Promise
15
+ import org.assertj.core.api.Assertions.assertThat
15
16
  import org.junit.jupiter.api.Test
16
17
  import org.junit.jupiter.api.extension.ExtendWith
17
18
  import org.junit.jupiter.api.extension.Extensions
@@ -74,4 +75,22 @@ internal class DdFlagsImplementationTest {
74
75
  datadogMock.close()
75
76
  }
76
77
  }
78
+
79
+ @Test
80
+ fun `M omit null attributes W buildEvaluationContext()`() {
81
+ // Given
82
+ val attributes = mapOf(
83
+ "country" to "US",
84
+ "age" to 42,
85
+ "size" to null
86
+ ).toReadableMap()
87
+
88
+ // When
89
+ val context = buildEvaluationContext("user", attributes)
90
+
91
+ // Then
92
+ assertThat(context.targetingKey).isEqualTo("user")
93
+ assertThat(context.attributes).containsOnlyKeys("country", "age")
94
+ assertThat(context.attributes["country"]).isEqualTo("US")
95
+ }
77
96
  }
@@ -9,6 +9,7 @@ package com.datadog.reactnative
9
9
  import android.content.Context
10
10
  import android.content.pm.PackageInfo
11
11
  import android.hardware.display.DisplayManager
12
+ import android.os.Build
12
13
  import android.os.Looper
13
14
  import android.util.Log
14
15
  import android.view.Choreographer
@@ -3670,6 +3671,136 @@ internal class DdSdkTest {
3670
3671
  verify(mockDisplay, times(1)).supportedModes
3671
3672
  }
3672
3673
 
3674
+ @Test
3675
+ fun `𝕄 normalize JS frame time with the display's current refresh rate 𝕎 doFrame()`(
3676
+ @Forgery configuration: DdSdkConfiguration
3677
+ ) {
3678
+ // Given
3679
+ val rumConfiguration = configuration.rumConfiguration?.copy(
3680
+ vitalsUpdateFrequency = "AVERAGE",
3681
+ longTaskThresholdMs = 0.0
3682
+ )
3683
+ val bridgeConfiguration = configuration.copy(rumConfiguration = rumConfiguration)
3684
+ val mockDisplayManager = mock<DisplayManager>()
3685
+ val mockDisplay = mock<Display>()
3686
+ whenever(mockContext.getSystemService(Context.DISPLAY_SERVICE)) doReturn mockDisplayManager
3687
+ whenever(mockDisplayManager.getDisplay(Display.DEFAULT_DISPLAY)) doReturn mockDisplay
3688
+ val originalSdkInt = Build.VERSION.SDK_INT
3689
+ Build.VERSION::class.java.setStaticValue("SDK_INT", Build.VERSION_CODES.R)
3690
+
3691
+ val rumMock = org.mockito.Mockito.mockStatic(Rum::class.java)
3692
+ val traceMock = org.mockito.Mockito.mockStatic(Trace::class.java)
3693
+ val logsMock = org.mockito.Mockito.mockStatic(Logs::class.java)
3694
+
3695
+ try {
3696
+ rumMock.`when`<Unit> { Rum.enable(any(), any()) }.then { }
3697
+ logsMock.`when`<Unit> { Logs.enable(any(), any()) }.then { }
3698
+ traceMock.`when`<Unit> { Trace.enable(any(), any()) }.then { }
3699
+
3700
+ // When
3701
+ testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
3702
+
3703
+ // Then
3704
+ argumentCaptor<Choreographer.FrameCallback> {
3705
+ verify(mockChoreographer).postFrameCallback(capture())
3706
+ var timestampNs = 0L
3707
+ firstValue.doFrame(timestampNs)
3708
+
3709
+ // 120 fps, display running at 120Hz -> Normalized to 60fps
3710
+ whenever(mockDisplay.refreshRate) doReturn 120f
3711
+ timestampNs += 8_333_333L
3712
+ firstValue.doFrame(timestampNs)
3713
+ verify(mockRumInternalProxy).updatePerformanceMetric(
3714
+ RumPerformanceMetric.JS_FRAME_TIME,
3715
+ 16_666_666.0
3716
+ )
3717
+
3718
+ // 60 fps, display running at 120Hz -> Normalized to 30fps
3719
+ timestampNs += 16_666_667L
3720
+ firstValue.doFrame(timestampNs)
3721
+ verify(mockRumInternalProxy).updatePerformanceMetric(
3722
+ RumPerformanceMetric.JS_FRAME_TIME,
3723
+ 33_333_334.0
3724
+ )
3725
+
3726
+ // 60 fps, display running at 60Hz -> Normalized to 60fps
3727
+ whenever(mockDisplay.refreshRate) doReturn 60f
3728
+ timestampNs += 16_666_667L
3729
+ firstValue.doFrame(timestampNs)
3730
+ verify(mockRumInternalProxy).updatePerformanceMetric(
3731
+ RumPerformanceMetric.JS_FRAME_TIME,
3732
+ 16_666_667.0
3733
+ )
3734
+
3735
+ // 30 fps, display running at 60Hz -> Normalized to 30fps
3736
+ timestampNs += 33_333_333L
3737
+ firstValue.doFrame(timestampNs)
3738
+ verify(mockRumInternalProxy).updatePerformanceMetric(
3739
+ RumPerformanceMetric.JS_FRAME_TIME,
3740
+ 33_333_333.0
3741
+ )
3742
+ }
3743
+ } finally {
3744
+ Build.VERSION::class.java.setStaticValue("SDK_INT", originalSdkInt)
3745
+ rumMock.close()
3746
+ logsMock.close()
3747
+ traceMock.close()
3748
+ }
3749
+ }
3750
+
3751
+ @Test
3752
+ fun `𝕄 normalize JS frame time with the max refresh rate 𝕎 doFrame() {API below 30}`(
3753
+ @Forgery configuration: DdSdkConfiguration
3754
+ ) {
3755
+ // Given
3756
+ val rumConfiguration = configuration.rumConfiguration?.copy(
3757
+ vitalsUpdateFrequency = "AVERAGE",
3758
+ longTaskThresholdMs = 0.0
3759
+ )
3760
+ val bridgeConfiguration = configuration.copy(rumConfiguration = rumConfiguration)
3761
+ val mockDisplayManager = mock<DisplayManager>()
3762
+ val mockDisplay = mock<Display>()
3763
+ val mockDisplayMode = mock<Display.Mode>()
3764
+ whenever(mockContext.getSystemService(Context.DISPLAY_SERVICE)) doReturn mockDisplayManager
3765
+ whenever(mockDisplayManager.getDisplay(Display.DEFAULT_DISPLAY)) doReturn mockDisplay
3766
+ whenever(mockDisplayMode.refreshRate) doReturn 120f
3767
+ whenever(mockDisplay.supportedModes) doReturn arrayOf(mockDisplayMode)
3768
+ val originalSdkInt = Build.VERSION.SDK_INT
3769
+ Build.VERSION::class.java.setStaticValue("SDK_INT", Build.VERSION_CODES.Q)
3770
+
3771
+ val rumMock = org.mockito.Mockito.mockStatic(Rum::class.java)
3772
+ val traceMock = org.mockito.Mockito.mockStatic(Trace::class.java)
3773
+ val logsMock = org.mockito.Mockito.mockStatic(Logs::class.java)
3774
+
3775
+ try {
3776
+ rumMock.`when`<Unit> { Rum.enable(any(), any()) }.then { }
3777
+ logsMock.`when`<Unit> { Logs.enable(any(), any()) }.then { }
3778
+ traceMock.`when`<Unit> { Trace.enable(any(), any()) }.then { }
3779
+
3780
+ // When
3781
+ testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
3782
+
3783
+ // Then
3784
+ argumentCaptor<Choreographer.FrameCallback> {
3785
+ verify(mockChoreographer).postFrameCallback(capture())
3786
+ firstValue.doFrame(0L)
3787
+
3788
+ // 60 fps, 120Hz capable display -> Normalized with the max refresh rate to 30fps
3789
+ firstValue.doFrame(16_666_667L)
3790
+ verify(mockRumInternalProxy).updatePerformanceMetric(
3791
+ RumPerformanceMetric.JS_FRAME_TIME,
3792
+ 33_333_334.0
3793
+ )
3794
+ verify(mockDisplay, never()).refreshRate
3795
+ }
3796
+ } finally {
3797
+ Build.VERSION::class.java.setStaticValue("SDK_INT", originalSdkInt)
3798
+ rumMock.close()
3799
+ logsMock.close()
3800
+ traceMock.close()
3801
+ }
3802
+ }
3803
+
3673
3804
  // endregion
3674
3805
 
3675
3806
  // region Internal
@@ -211,6 +211,17 @@
211
211
  "description": "Enables native interaction tracking.",
212
212
  "type": "boolean"
213
213
  },
214
+ "nativeIosResourceTracking": {
215
+ "description": "Controls automatic native network (URLSession) resource tracking. iOS only: has no effect on Android. If not set (default): legacy behavior, enables iOS network tracking if `firstPartyHosts` is defined. `true`: enables iOS network tracking (with trace headers for `firstPartyHosts`, if defined). `false`: disables iOS network tracking.",
216
+ "type": "boolean"
217
+ },
218
+ "nativeIosResourceTrackingDisallowList": {
219
+ "description": "URL patterns excluded from automatic native iOS network (URLSession) resource tracking. Patterns are matched against the full URL: plain strings match exactly, `*` matches any characters. Patterns without any literal characters (e.g. `\"*\"`) are ignored. Matching requests also get no trace headers injected and no APM span. Only takes effect when native iOS resource tracking is enabled (see `nativeIosResourceTracking`); it never enables tracking by itself. If set while tracking is disabled, the native SDK logs a warning (subject to `verbosity`). iOS only: has no effect on Android. Default: []",
220
+ "type": "array",
221
+ "items": {
222
+ "type": "string"
223
+ }
224
+ },
214
225
  "nativeCrashReportEnabled": {
215
226
  "description": "Enables crash reporting for native platforms (iOS, Android). Default `false`.",
216
227
  "type": "boolean"
@@ -165,13 +165,13 @@ public class DdRumImplementation: NSObject {
165
165
  let pageY = touch["pageY"] as? NSNumber
166
166
  {
167
167
  addAction(
168
- at: Date(timeIntervalSince1970: timestampMs / 1_000),
168
+ at: Date(),
169
169
  type: RUMActionType(from: type),
170
170
  name: name,
171
171
  reactTag: reactTag,
172
172
  location: .init(x: CGFloat(truncating: x), y: CGFloat(truncating: y)),
173
173
  pageLocation: .init(x: CGFloat(truncating: pageX), y: CGFloat(truncating: pageY)),
174
- attributes: castAttributesToSwift(context)
174
+ attributes: attributes(from: context, with: timestampMs)
175
175
  )
176
176
  } else {
177
177
  nativeRUM.addAction(type: RUMActionType(from: type), name: name, attributes: attributes(from: context, with: timestampMs))
@@ -95,6 +95,13 @@ public class DdSdkConfiguration: NSObject {
95
95
  /// - nativeLongTaskThresholdMs: The threshold for reporting native long tasks in milliseconds.
96
96
  /// - nativeViewTracking: Enables tracking of native iOS/Android UI views.
97
97
  /// - nativeInteractionTracking: Enables tracking of native UI interactions.
98
+ /// - nativeIosResourceTracking: Controls automatic URLSession resource tracking (iOS only).
99
+ /// `nil` (default): legacy behavior, tracking enabled iff `firstPartyHosts` is non-nil.
100
+ /// `true`: tracking always enabled (trace headers for `firstPartyHosts`, if non-nil).
101
+ /// `false`: tracking disabled.
102
+ /// - nativeIosResourceTrackingDisallowList: URL patterns excluded from automatic URLSession resource tracking
103
+ /// (iOS only). Passed to `RUM.Configuration.URLSessionTracking.disallowList`; only effective when
104
+ /// URLSession tracking is enabled. Default: `[]`.
98
105
  /// - firstPartyHosts: List of backend hosts considered first-party for network tracing.
99
106
  /// - appHangThreshold: Threshold in seconds for reporting non-fatal app hangs (iOS only).
100
107
  /// - trackWatchdogTerminations: Whether the SDK should track application terminations
@@ -115,6 +122,8 @@ public class RumConfiguration: NSObject {
115
122
  public var nativeLongTaskThresholdMs: Double? = nil
116
123
  public var nativeViewTracking: Bool? = nil
117
124
  public var nativeInteractionTracking: Bool? = nil
125
+ public var nativeIosResourceTracking: Bool? = nil
126
+ public var nativeIosResourceTrackingDisallowList: [String] = []
118
127
  public var firstPartyHosts: [String: Set<TracingHeaderType>]? = nil
119
128
  public var appHangThreshold: Double? = nil
120
129
  public var trackWatchdogTerminations: Bool
@@ -135,6 +144,8 @@ public class RumConfiguration: NSObject {
135
144
  nativeLongTaskThresholdMs: Double? = nil,
136
145
  nativeViewTracking: Bool?,
137
146
  nativeInteractionTracking: Bool?,
147
+ nativeIosResourceTracking: Bool? = nil,
148
+ nativeIosResourceTrackingDisallowList: [String] = [],
138
149
  firstPartyHosts: [String: Set<TracingHeaderType>]?,
139
150
  appHangThreshold: Double?,
140
151
  trackWatchdogTerminations: Bool,
@@ -154,6 +165,8 @@ public class RumConfiguration: NSObject {
154
165
  self.nativeLongTaskThresholdMs = nativeLongTaskThresholdMs
155
166
  self.nativeViewTracking = nativeViewTracking
156
167
  self.nativeInteractionTracking = nativeInteractionTracking
168
+ self.nativeIosResourceTracking = nativeIosResourceTracking
169
+ self.nativeIosResourceTrackingDisallowList = nativeIosResourceTrackingDisallowList
157
170
  self.firstPartyHosts = firstPartyHosts
158
171
  self.appHangThreshold = appHangThreshold
159
172
  self.trackWatchdogTerminations = trackWatchdogTerminations
@@ -309,7 +309,7 @@ public class DdSdkImplementation: NSObject {
309
309
  }
310
310
  }
311
311
 
312
- func buildFrameTimeCallback(sdkConfiguration: DdSdkConfiguration) -> ((Double) -> Void)? {
312
+ func buildFrameTimeCallback(sdkConfiguration: DdSdkConfiguration) -> ((Double, Double) -> Void)? {
313
313
  let jsRefreshRateMonitoringEnabled =
314
314
  sdkConfiguration.rumConfiguration != nil
315
315
  && sdkConfiguration.rumConfiguration?.vitalsUpdateFrequency != nil
@@ -321,7 +321,7 @@ public class DdSdkImplementation: NSObject {
321
321
  return nil
322
322
  }
323
323
 
324
- func frameTimeCallback(frameTime: Double) {
324
+ func frameTimeCallback(frameTime: Double, displayFps: Double) {
325
325
  // These checks happen before dispatching because they are quick and less overhead than the dispatch itself.
326
326
  let shouldRecordFrameTime = jsRefreshRateMonitoringEnabled && frameTime > 0
327
327
  let shouldRecordLongTask =
@@ -338,7 +338,8 @@ public class DdSdkImplementation: NSObject {
338
338
  sharedQueue.async {
339
339
  if shouldRecordFrameTime {
340
340
  let normalizedFrameTimeSeconds =
341
- DdSdkImplementation.normalizeFrameTimeForDeviceRefreshRate(frameTime)
341
+ DdSdkImplementation.normalizeFrameTimeForDeviceRefreshRate(
342
+ frameTime, deviceDisplayFps: displayFps)
342
343
  rumMonitorInternal.updatePerformanceMetric(
343
344
  at: now, metric: .jsFrameTimeSeconds, value: normalizedFrameTimeSeconds,
344
345
  attributes: [:])
@@ -168,22 +168,40 @@ public class DdSdkNativeInitialization: NSObject {
168
168
  uiKitActionsPredicate = DefaultUIKitRUMActionsPredicate()
169
169
  }
170
170
 
171
- var urlSessionTracking: RUM.Configuration.URLSessionTracking? = nil
171
+ // `nativeIosResourceTracking` (iOS only):
172
+ // - nil (default): legacy behavior, tracking enabled iff `firstPartyHosts` is non-nil.
173
+ // - true: tracking always enabled (trace headers only if `firstPartyHosts` is non-nil).
174
+ // - false: tracking disabled.
175
+ // `nativeIosResourceTrackingDisallowList` is applied only when tracking is enabled; it never enables it.
176
+ var firstPartyHostsTracing: RUM.Configuration.URLSessionTracking.FirstPartyHostsTracing? = nil
172
177
  if let firstPartyHosts = rumConfig.firstPartyHosts {
178
+ firstPartyHostsTracing = .traceWithHeaders(
179
+ hostsWithHeaders: firstPartyHosts,
180
+ sampleRate: Float(
181
+ configuration.rumConfiguration?.resourceTraceSampleRate
182
+ ?? DefaultConfiguration.resourceTraceSampleRate)
183
+ )
184
+ }
185
+ let shouldTrackURLSession = rumConfig.nativeIosResourceTracking ?? (rumConfig.firstPartyHosts != nil)
186
+
187
+ var urlSessionTracking: RUM.Configuration.URLSessionTracking? = nil
188
+ if shouldTrackURLSession {
173
189
  urlSessionTracking = RUM.Configuration.URLSessionTracking(
174
- firstPartyHostsTracing: .traceWithHeaders(
175
- hostsWithHeaders: firstPartyHosts,
176
- sampleRate: Float(
177
- configuration.rumConfiguration?.resourceTraceSampleRate
178
- ?? DefaultConfiguration.resourceTraceSampleRate)
179
- ),
190
+ firstPartyHostsTracing: firstPartyHostsTracing,
180
191
  resourceAttributesProvider: { request, _, _, _ in
181
192
  let trackedBy = request.value(forHTTPHeaderField: InternalConfigurationAttributes.trackedByHeaderKey)
182
193
  if trackedBy == InternalConfigurationAttributes.trackedByHeaderValue {
183
194
  return [InternalConfigurationAttributes.dropResource: true]
184
195
  }
185
196
  return nil
186
- }
197
+ },
198
+ disallowList: rumConfig.nativeIosResourceTrackingDisallowList
199
+ )
200
+ } else if !rumConfig.nativeIosResourceTrackingDisallowList.isEmpty {
201
+ DD.logger.warn(
202
+ "nativeIosResourceTrackingDisallowList is set but native iOS resource tracking is disabled "
203
+ + "(nativeIosResourceTracking is false, or unset with no firstPartyHosts). "
204
+ + "The disallow list will be ignored."
187
205
  )
188
206
  }
189
207
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  import Foundation
8
8
 
9
- typealias frame_time_callback = (Double) -> Void
9
+ typealias frame_time_callback = (_ frameTime: Double, _ displayFps: Double) -> Void
10
10
 
11
11
  internal protocol RefreshRateListener {
12
12
  func start()
@@ -54,6 +54,7 @@ private final class JSRefreshRateListener: RefreshRateListener {
54
54
  private var jsQueue: DispatchQueueType
55
55
  private var frameTimeCallback: frame_time_callback
56
56
  private var lastFrameTimestamp: TimeInterval = -1
57
+ private var displayFps: Double = -1
57
58
  private var jsDisplayLink: CADisplayLink?
58
59
 
59
60
  init(jsQueue: DispatchQueueType, frameTimeCallback: @escaping frame_time_callback) {
@@ -80,8 +81,11 @@ private final class JSRefreshRateListener: RefreshRateListener {
80
81
  let frameTimestamp = displayLink.timestamp
81
82
  if lastFrameTimestamp != -1 {
82
83
  let frameDuration = frameTimestamp - lastFrameTimestamp
83
- frameTimeCallback(frameDuration)
84
+ frameTimeCallback(frameDuration, displayFps)
84
85
  }
85
86
  lastFrameTimestamp = frameTimestamp
87
+
88
+ // Refresh rate the display is currently running at
89
+ displayFps = 1.0 / (displayLink.targetTimestamp - frameTimestamp)
86
90
  }
87
91
  }
@@ -60,6 +60,9 @@ extension NSDictionary {
60
60
  let nativeLongTaskThresholdMs = rumDict["nativeLongTaskThresholdMs"] as? Double
61
61
  let nativeViewTracking = rumDict["nativeViewTracking"] as? Bool
62
62
  let nativeInteractionTracking = rumDict["nativeInteractionTracking"] as? Bool
63
+ // No default on purpose: nil means legacy URLSession tracking behavior
64
+ let nativeIosResourceTracking = rumDict["nativeIosResourceTracking"] as? Bool
65
+ let nativeIosResourceTrackingDisallowList = rumDict["nativeIosResourceTrackingDisallowList"] as? [String]
63
66
 
64
67
  let firstPartyHostsArray = rumDict["firstPartyHosts"] as? NSArray
65
68
  let firstPartyHosts = firstPartyHostsArray?.asFirstPartyHosts()
@@ -89,6 +92,8 @@ extension NSDictionary {
89
92
  nativeViewTracking: nativeViewTracking ?? DefaultConfiguration.nativeViewTracking,
90
93
  nativeInteractionTracking: nativeInteractionTracking
91
94
  ?? DefaultConfiguration.nativeInteractionTracking,
95
+ nativeIosResourceTracking: nativeIosResourceTracking,
96
+ nativeIosResourceTrackingDisallowList: nativeIosResourceTrackingDisallowList ?? [],
92
97
  firstPartyHosts: firstPartyHosts,
93
98
  appHangThreshold: appHangThreshold,
94
99
  trackWatchdogTerminations: trackWatchdogTerminations
@@ -378,6 +383,10 @@ extension Dictionary where Key == String, Value == AnyObject {
378
383
  ?? DefaultConfiguration.nativeViewTracking,
379
384
  nativeInteractionTracking: rum["nativeInteractionTracking"] as? Bool
380
385
  ?? DefaultConfiguration.nativeInteractionTracking,
386
+ // No default on purpose: nil means legacy URLSession tracking behavior
387
+ nativeIosResourceTracking: rum["nativeIosResourceTracking"] as? Bool,
388
+ nativeIosResourceTrackingDisallowList:
389
+ (rum["nativeIosResourceTrackingDisallowList"] as? [String]) ?? [],
381
390
  firstPartyHosts: firstPartyHosts,
382
391
  appHangThreshold: rum["appHangThreshold"] as? Double,
383
392
  trackWatchdogTerminations: rum["trackWatchdogTerminations"] as? Bool
@@ -7,4 +7,4 @@
7
7
  import Foundation
8
8
 
9
9
  // This is automatically updated by the update-version.sh script
10
- let SdkVersion = "3.8.0"
10
+ let SdkVersion = "3.10.0"