@datadog/mobile-react-native 1.1.5 → 1.2.0-beta2

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 (160) hide show
  1. package/DatadogSDKReactNative.podspec +2 -2
  2. package/README.md +18 -14
  3. package/android/build.gradle +28 -3
  4. package/android/detekt.yml +572 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +12 -0
  6. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +15 -0
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +143 -8
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +25 -1
  9. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +31 -1
  10. package/android/src/main/kotlin/com/datadog/reactnative/VitalFrameCallback.kt +41 -0
  11. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +7 -2
  12. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +429 -27
  13. package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +5 -1
  14. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +40 -1
  15. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +21 -1
  16. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +1 -1
  17. package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +1 -0
  18. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +22 -2
  19. package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +2 -3
  20. package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +94 -0
  21. package/datadog-sourcemaps.gradle +85 -28
  22. package/ios/Sources/Attributes.swift +0 -4
  23. package/ios/Sources/DdSdk.m +10 -0
  24. package/ios/Sources/DdSdk.swift +113 -10
  25. package/ios/Sources/DdSdkConfiguration.swift +38 -1
  26. package/ios/Sources/JSRefreshRateListener.swift +86 -0
  27. package/ios/Sources/QueueHolder.swift +7 -0
  28. package/ios/Sources/RNDdSdkConfiguration.swift +25 -1
  29. package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js +173 -0
  30. package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
  31. package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js +32 -0
  32. package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
  33. package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js +29 -0
  34. package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
  35. package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js +28 -0
  36. package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
  37. package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js +32 -0
  38. package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
  39. package/lib/commonjs/DatadogProvider/DatadogProvider.js +101 -0
  40. package/lib/commonjs/DatadogProvider/DatadogProvider.js.map +1 -0
  41. package/lib/commonjs/DdSdkReactNative.js +140 -59
  42. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  43. package/lib/commonjs/DdSdkReactNativeConfiguration.js +166 -9
  44. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  45. package/lib/commonjs/errorUtils.js +69 -0
  46. package/lib/commonjs/errorUtils.js.map +1 -0
  47. package/lib/commonjs/foundation.js +19 -12
  48. package/lib/commonjs/foundation.js.map +1 -1
  49. package/lib/commonjs/index.js +20 -0
  50. package/lib/commonjs/index.js.map +1 -1
  51. package/lib/commonjs/longTasksUtils.js +40 -0
  52. package/lib/commonjs/longTasksUtils.js.map +1 -0
  53. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  54. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +8 -45
  55. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  56. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +16 -1
  57. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  58. package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +1 -1
  59. package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -1
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
  61. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  62. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
  63. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  64. package/lib/commonjs/types.js +6 -1
  65. package/lib/commonjs/types.js.map +1 -1
  66. package/lib/commonjs/version.js +1 -1
  67. package/lib/commonjs/version.js.map +1 -1
  68. package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js +163 -0
  69. package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
  70. package/lib/module/DatadogProvider/Buffer/BufferSingleton.js +26 -0
  71. package/lib/module/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
  72. package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js +20 -0
  73. package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
  74. package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js +23 -0
  75. package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
  76. package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js +16 -0
  77. package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
  78. package/lib/module/DatadogProvider/DatadogProvider.js +82 -0
  79. package/lib/module/DatadogProvider/DatadogProvider.js.map +1 -0
  80. package/lib/module/DdSdkReactNative.js +132 -57
  81. package/lib/module/DdSdkReactNative.js.map +1 -1
  82. package/lib/module/DdSdkReactNativeConfiguration.js +154 -8
  83. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  84. package/lib/module/errorUtils.js +54 -0
  85. package/lib/module/errorUtils.js.map +1 -0
  86. package/lib/module/foundation.js +18 -12
  87. package/lib/module/foundation.js.map +1 -1
  88. package/lib/module/index.js +3 -2
  89. package/lib/module/index.js.map +1 -1
  90. package/lib/module/longTasksUtils.js +31 -0
  91. package/lib/module/longTasksUtils.js.map +1 -0
  92. package/lib/module/nativeModulesTypes.js.map +1 -1
  93. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +5 -42
  94. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  95. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +14 -1
  96. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
  97. package/lib/module/rum/instrumentation/getJsxRuntime.js +1 -1
  98. package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -1
  99. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
  100. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  101. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
  102. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  103. package/lib/module/types.js +6 -1
  104. package/lib/module/types.js.map +1 -1
  105. package/lib/module/version.js +1 -1
  106. package/lib/module/version.js.map +1 -1
  107. package/lib/typescript/DatadogProvider/Buffer/BoundedBuffer.d.ts +15 -0
  108. package/lib/typescript/DatadogProvider/Buffer/BufferSingleton.d.ts +7 -0
  109. package/lib/typescript/DatadogProvider/Buffer/DatadogBuffer.d.ts +20 -0
  110. package/lib/typescript/DatadogProvider/Buffer/PassThroughBuffer.d.ts +7 -0
  111. package/lib/typescript/DatadogProvider/Buffer/bufferNativeCall.d.ts +3 -0
  112. package/lib/typescript/DatadogProvider/DatadogProvider.d.ts +26 -0
  113. package/lib/typescript/DdSdkReactNative.d.ts +18 -3
  114. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +114 -0
  115. package/lib/typescript/errorUtils.d.ts +12 -0
  116. package/lib/typescript/index.d.ts +3 -2
  117. package/lib/typescript/longTasksUtils.d.ts +6 -0
  118. package/lib/typescript/nativeModulesTypes.d.ts +12 -0
  119. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +0 -2
  120. package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -0
  121. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +1 -0
  122. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +1 -1
  123. package/lib/typescript/types.d.ts +16 -1
  124. package/lib/typescript/version.d.ts +1 -1
  125. package/package.json +3 -2
  126. package/src/DatadogProvider/Buffer/BoundedBuffer.ts +209 -0
  127. package/src/DatadogProvider/Buffer/BufferSingleton.ts +26 -0
  128. package/src/DatadogProvider/Buffer/DatadogBuffer.ts +34 -0
  129. package/src/DatadogProvider/Buffer/PassThroughBuffer.ts +16 -0
  130. package/src/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +202 -0
  131. package/src/DatadogProvider/Buffer/__tests__/BufferSingleton.test.ts +50 -0
  132. package/src/DatadogProvider/Buffer/bufferNativeCall.ts +24 -0
  133. package/src/DatadogProvider/DatadogProvider.tsx +122 -0
  134. package/src/DatadogProvider/__tests__/__utils__/renderWithProvider.tsx +111 -0
  135. package/src/DatadogProvider/__tests__/initialization.test.tsx +182 -0
  136. package/src/DatadogProvider/__tests__/initializationModes.test.tsx +174 -0
  137. package/src/DdSdkReactNative.tsx +206 -109
  138. package/src/DdSdkReactNativeConfiguration.tsx +225 -8
  139. package/src/__tests__/DdRumWrapper.test.tsx +3 -27
  140. package/src/__tests__/DdSdkReactNative.test.tsx +57 -13
  141. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +181 -0
  142. package/src/__tests__/foundation.test.ts +11 -2
  143. package/src/__tests__/longTasksUtils.ts +23 -0
  144. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +18 -4
  145. package/src/errorUtils.ts +58 -0
  146. package/src/foundation.tsx +15 -12
  147. package/src/index.tsx +9 -1
  148. package/src/longTasksUtils.ts +30 -0
  149. package/src/nativeModulesTypes.ts +14 -0
  150. package/src/rum/instrumentation/DdRumErrorTracking.tsx +9 -46
  151. package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +11 -1
  152. package/src/rum/instrumentation/getJsxRuntime.ts +1 -1
  153. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +2 -0
  154. package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +3 -1
  155. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +1 -1
  156. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +2 -1
  157. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -0
  158. package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +12 -47
  159. package/src/types.tsx +11 -1
  160. package/src/version.ts +1 -1
@@ -3,7 +3,7 @@
3
3
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
-
6
+
7
7
  package com.datadog.tools.unit
8
8
 
9
9
  import org.assertj.core.api.AbstractAssert
@@ -12,6 +12,26 @@ import org.assertj.core.api.Assertions.assertThat
12
12
  class GenericAssert(actual: Any) :
13
13
  AbstractAssert<GenericAssert, Any>(actual, GenericAssert::class.java) {
14
14
 
15
+ fun doesNotHaveField(name: String): GenericAssert {
16
+ val field: Any? = actual.getFieldValue(name)
17
+ assertThat(field)
18
+ .overridingErrorMessage(
19
+ "Expecting object to not have $name, but found it having value $field"
20
+ )
21
+ .isNull()
22
+ return this
23
+ }
24
+
25
+ fun <T> getActualValue(name: String): T {
26
+ val field: Any? = actual.getFieldValue(name)
27
+ assertThat(field)
28
+ .overridingErrorMessage(
29
+ "Expecting object to have a non null field named $name, but field was null"
30
+ )
31
+ .isNotNull()
32
+ return field!! as T
33
+ }
34
+
15
35
  fun hasField(name: String, nestedAssert: (GenericAssert) -> Unit = {}): GenericAssert {
16
36
  val field: Any? = actual.getFieldValue(name)
17
37
  assertThat(field)
@@ -3,7 +3,7 @@
3
3
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
-
6
+
7
7
  package com.datadog.tools.unit
8
8
 
9
9
  import com.facebook.react.bridge.JavaOnlyMap
@@ -21,6 +21,7 @@ open class BaseConfigurator :
21
21
  forge.addFactory(ThrowableForgeryFactory())
22
22
  forge.addFactory(DdSdkConfigurationForgeryFactory())
23
23
  forge.addFactory(PackageInfoForgeryFactory())
24
+ forge.addFactory(TelemetryConfigurationEventForgeryFactory())
24
25
  forge.useJvmFactories()
25
26
  }
26
27
  }
@@ -3,9 +3,10 @@
3
3
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
-
6
+
7
7
  package com.datadog.tools.unit.forge
8
8
 
9
+ import com.datadog.reactnative.ConfigurationForTelemetry
9
10
  import com.datadog.reactnative.DdSdkConfiguration
10
11
  import fr.xgouchet.elmyr.Forge
11
12
  import fr.xgouchet.elmyr.ForgeryFactory
@@ -18,7 +19,18 @@ class DdSdkConfigurationForgeryFactory : ForgeryFactory<DdSdkConfiguration> {
18
19
  env = forge.anAlphabeticalString(),
19
20
  applicationId = forge.aNullable { getForgery<UUID>().toString() },
20
21
  nativeCrashReportEnabled = forge.aNullable { aBool() },
22
+ nativeLongTaskThresholdMs = forge.aNullable { aDouble(100.0, 5000.0) },
23
+ longTaskThresholdMs = forge.aDouble(0.0, 100.0),
21
24
  sampleRate = forge.aNullable { aDouble(0.0, 100.0) },
25
+ telemetrySampleRate = forge.aNullable { aDouble(0.0, 100.0) },
26
+ vitalsUpdateFrequency = forge.aNullable {
27
+ anElementFrom(
28
+ "RARE",
29
+ "NEVER",
30
+ "FREQUENT",
31
+ "AVERAGE"
32
+ )
33
+ },
22
34
  site = forge.aNullable { anElementFrom("US", "EU", "GOV") },
23
35
  additionalConfig = forge.aMap {
24
36
  forge.anAsciiString() to forge.anElementFrom(
@@ -27,7 +39,15 @@ class DdSdkConfigurationForgeryFactory : ForgeryFactory<DdSdkConfiguration> {
27
39
  null
28
40
  )
29
41
  },
30
- trackingConsent = forge.aNullable { anElementFrom("pending", "granted", "not_granted") }
42
+ trackingConsent = forge.aNullable {
43
+ anElementFrom("pending", "granted", "not_granted")
44
+ },
45
+ configurationForTelemetry = ConfigurationForTelemetry(
46
+ initializationType = forge.anAlphabeticalString(),
47
+ trackErrors = forge.aBool(),
48
+ trackInteractions = forge.aBool(),
49
+ trackNetworkRequests = forge.aBool()
50
+ )
31
51
  )
32
52
  }
33
53
  }
@@ -3,17 +3,16 @@
3
3
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
-
6
+
7
7
  package com.datadog.tools.unit.forge
8
8
 
9
9
  import android.content.pm.PackageInfo
10
10
  import fr.xgouchet.elmyr.Forge
11
11
  import fr.xgouchet.elmyr.ForgeryFactory
12
- import java.util.UUID
13
12
 
14
13
  class PackageInfoForgeryFactory : ForgeryFactory<PackageInfo> {
15
14
  override fun getForgery(forge: Forge): PackageInfo {
16
- val packageInfo = PackageInfo();
15
+ val packageInfo = PackageInfo()
17
16
  packageInfo.versionName = forge.aStringMatching("[0-9]\\.[0-9]\\.[0-9]")
18
17
  return packageInfo
19
18
  }
@@ -0,0 +1,94 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ package com.datadog.tools.unit.forge
8
+
9
+ import com.datadog.android.telemetry.model.TelemetryConfigurationEvent
10
+ import fr.xgouchet.elmyr.Forge
11
+ import fr.xgouchet.elmyr.ForgeryFactory
12
+ import fr.xgouchet.elmyr.jvm.ext.aTimestamp
13
+ import java.util.UUID
14
+
15
+ internal class TelemetryConfigurationEventForgeryFactory :
16
+ ForgeryFactory<TelemetryConfigurationEvent> {
17
+
18
+ override fun getForgery(forge: Forge): TelemetryConfigurationEvent {
19
+ return TelemetryConfigurationEvent(
20
+ date = forge.aTimestamp(),
21
+ source = forge.aValueFrom(TelemetryConfigurationEvent.Source::class.java),
22
+ service = forge.anAlphabeticalString(),
23
+ version = forge.anAlphabeticalString(),
24
+ application = forge.aNullable {
25
+ TelemetryConfigurationEvent.Application(
26
+ forge.getForgery<UUID>().toString()
27
+ )
28
+ },
29
+ session = forge.aNullable {
30
+ TelemetryConfigurationEvent.Session(
31
+ forge.getForgery<UUID>().toString()
32
+ )
33
+ },
34
+ view = forge.aNullable {
35
+ TelemetryConfigurationEvent.View(
36
+ forge.getForgery<UUID>().toString()
37
+ )
38
+ },
39
+ action = forge.aNullable {
40
+ TelemetryConfigurationEvent.Action(
41
+ forge.getForgery<UUID>().toString()
42
+ )
43
+ },
44
+ dd = TelemetryConfigurationEvent.Dd(),
45
+ telemetry = TelemetryConfigurationEvent.Telemetry(
46
+ configuration = TelemetryConfigurationEvent.Configuration(
47
+ forge.aNullable { aLong() },
48
+ forge.aNullable { aLong() },
49
+ forge.aNullable { aLong() },
50
+ forge.aNullable { aLong() },
51
+ forge.aNullable { aLong() },
52
+ forge.aNullable { aLong() },
53
+ forge.aNullable { aLong() },
54
+ forge.aNullable { aBool() },
55
+ forge.aNullable { aBool() },
56
+ forge.aNullable { aBool() },
57
+ forge.aNullable { aBool() },
58
+ forge.aNullable { aBool() },
59
+ forge.aNullable { aBool() },
60
+ forge.aNullable { aBool() },
61
+ forge.aNullable { aBool() },
62
+ forge.aNullable { aString() },
63
+ forge.aNullable { aBool() },
64
+ forge.aNullable { aString() },
65
+ forge.aNullable { aBool() },
66
+ forge.aNullable { aBool() },
67
+ forge.aNullable { aBool() },
68
+ forge.aNullable { aBool() },
69
+ forge.aNullable { aBool() },
70
+ forge.aNullable { aList { aString() } },
71
+ forge.aNullable { aList { aString() } },
72
+ forge.aNullable { aBool() },
73
+ forge.aNullable {
74
+ aValueFrom(TelemetryConfigurationEvent.ViewTrackingStrategy::class.java)
75
+ },
76
+ forge.aNullable { aBool() },
77
+ forge.aNullable { aLong() },
78
+ forge.aNullable { aBool() },
79
+ forge.aNullable { aBool() },
80
+ forge.aNullable { aBool() },
81
+ forge.aNullable { aBool() },
82
+ forge.aNullable { aBool() },
83
+ forge.aNullable { aBool() },
84
+ forge.aNullable { aBool() },
85
+ forge.aNullable { aBool() },
86
+ forge.aNullable { aString() },
87
+ forge.aNullable { aBool() },
88
+ forge.aNullable { aLong() },
89
+ forge.aNullable { aLong() }
90
+ )
91
+ )
92
+ )
93
+ }
94
+ }
@@ -6,9 +6,6 @@
6
6
 
7
7
  import org.apache.tools.ant.taskdefs.condition.Os
8
8
 
9
- def reactConfig = project.hasProperty("react") ? project.react : [:]
10
- def reactRoot = file(reactConfig.root ?: "../../")
11
-
12
9
  afterEvaluate {
13
10
 
14
11
  def androidExtension = extensions.findByName("android")
@@ -33,7 +30,10 @@ afterEvaluate {
33
30
  def targetName = variant.name.capitalize()
34
31
  def targetPath = variant.dirName
35
32
 
36
- def bundleTask = tasks.findByName("bundle${targetName}JsAndAssets")
33
+ def reactConfig = getReactConfig(buildDir, targetName)
34
+ def reactRoot = file(reactConfig.root)
35
+
36
+ def bundleTask = tasks.findByName(reactConfig.bundleTaskName)
37
37
 
38
38
  if (bundleTask == null) {
39
39
  logger.info("Cannot find JS bundle task for variant=${targetName}.")
@@ -47,10 +47,7 @@ afterEvaluate {
47
47
  def serviceName = getServiceName(variant)
48
48
  logger.info("Service name used for the upload of variant=${targetName} is ${serviceName}.")
49
49
 
50
- def bundleAssetName = reactConfig.bundleAssetName ?: "index.android.bundle"
51
-
52
- def jsBundleDir = file("$buildDir/generated/assets/react/${targetPath}")
53
- def jsBundleFile = file("$jsBundleDir/$bundleAssetName")
50
+ def bundleAssetName = reactConfig.bundleAssetName
54
51
 
55
52
  def jsSourceMapsDir = file("$buildDir/generated/sourcemaps/react/${targetPath}")
56
53
  def jsOutputSourceMapFile = file("$jsSourceMapsDir/${bundleAssetName}.map")
@@ -59,27 +56,30 @@ afterEvaluate {
59
56
  group = "datadog"
60
57
  description = "Uploads sourcemaps to Datadog."
61
58
 
62
- def execCommand = [
63
- "yarn",
64
- "datadog-ci",
65
- "react-native",
66
- "upload",
67
- "--platform",
68
- "android",
69
- "--service",
70
- serviceName,
71
- "--bundle",
72
- jsBundleFile.absolutePath,
73
- "--sourcemap",
74
- jsOutputSourceMapFile.absolutePath,
75
- "--release-version",
76
- releaseVersion,
77
- "--build-version",
78
- buildVersion
79
- ]
59
+ def execCommand = { jsBundleFile ->
60
+ return [
61
+ "yarn",
62
+ "datadog-ci",
63
+ "react-native",
64
+ "upload",
65
+ "--platform",
66
+ "android",
67
+ "--service",
68
+ serviceName,
69
+ "--bundle",
70
+ jsBundleFile.absolutePath,
71
+ "--sourcemap",
72
+ jsOutputSourceMapFile.absolutePath,
73
+ "--release-version",
74
+ releaseVersion,
75
+ "--build-version",
76
+ buildVersion
77
+ ]
78
+ }
80
79
 
81
80
  doFirst {
82
- if (!jsBundleFile.exists()) {
81
+ def jsBundleFile = reactConfig.bundleFileResolver()
82
+ if (jsBundleFile == null) {
83
83
  throw new GradleException("JS bundle file doesn't exist, aborting upload.")
84
84
  }
85
85
 
@@ -87,7 +87,7 @@ afterEvaluate {
87
87
  throw new GradleException("JS sourcemap file doesn't exist, aborting upload.")
88
88
  }
89
89
 
90
- runShellCommand(execCommand, reactRoot)
90
+ runShellCommand(execCommand(jsBundleFile), reactRoot)
91
91
 
92
92
  }
93
93
  }
@@ -98,6 +98,63 @@ afterEvaluate {
98
98
  }
99
99
  }
100
100
 
101
+ /**
102
+ * We use a function here to resolve the correct bundle location after the bundle task
103
+ * is over, as its location can depend on the Android Gradle Plugin version.
104
+ */
105
+ private def getBundleFileResolver(String[] jsBundleDirs, String bundleAssetName) {
106
+ def resolver = { ->
107
+ return jsBundleDirs.collect {
108
+ file("$it/$bundleAssetName")
109
+ }.find {
110
+ it.exists()
111
+ }
112
+ }
113
+
114
+ return resolver
115
+ }
116
+
117
+ /**
118
+ * From RN 0.71, the following things changed in the RN gradle plugin:
119
+ * - bundle task name changed from "bundle${targetName}JsAndAssets" to "createBundle${targetName}JsAndAssets"
120
+ * - bundle dir changed from "$buildDir/generated/assets/react/${targetPath}" to "$buildDir/ASSETS/createBundle${targetPath}JsAndAssets"
121
+ * (and then "$buildDir/generated/assets/createBundle${targetPath}JsAndAssets" with the release of Android Gradle Plugin 7.4, see https://github.com/facebook/react-native/issues/35439)
122
+ * - config was in "project.react" and is now in "project.extensions.react"
123
+ * - accessing parameters values requires calling a getter
124
+ */
125
+ private def getReactConfig(File buildDir, String targetName) {
126
+ def reactConfig = [:]
127
+
128
+ if (project.extensions.findByName("react")) {
129
+ // From RN 0.71
130
+ def bundleAssetName = project.extensions.react.bundleAssetName.get() ?: "index.android.bundle"
131
+ reactConfig['bundleTaskName'] = "createBundle${targetName}JsAndAssets"
132
+ reactConfig['bundleFileResolver'] = getBundleFileResolver([
133
+ "$buildDir/ASSETS/createBundle${targetName}JsAndAssets", // Android Gradle Plugin 7.3
134
+ "$buildDir/generated/assets/createBundle${targetName}JsAndAssets" // Android Gradle Plugin 7.4 and up
135
+ ] as String[], bundleAssetName)
136
+ reactConfig['bundleAssetName'] = bundleAssetName
137
+ reactConfig['root'] = project.extensions.react.root.get() ?: "../../"
138
+ } else if (project.hasProperty("react")) {
139
+ // WARNING: on RN 0.71, `project.react` is an empty map, so this `if` must go after the previous one.
140
+ // Legacy way, before RN 0.71
141
+ def bundleAssetName = project.react.bundleAssetName ?: "index.android.bundle"
142
+ reactConfig['bundleTaskName'] = "bundle${targetName}JsAndAssets"
143
+ reactConfig['bundleFileResolver'] = getBundleFileResolver(["$buildDir/generated/assets/react/${targetName}"] as String[], bundleAssetName)
144
+ reactConfig['bundleAssetName'] = bundleAssetName
145
+ reactConfig['root'] = project.react.root ?: "../../"
146
+ } else {
147
+ // We assume this cannot happen with RN >= 0.71, so we use the legacy default values
148
+ def bundleAssetName = "index.android.bundle"
149
+ reactConfig['bundleTaskName'] = "bundle${targetName}JsAndAssets"
150
+ reactConfig['bundleFileResolver'] = getBundleFileResolver(["$buildDir/generated/assets/react/${targetName}"] as String[], bundleAssetName)
151
+ reactConfig['bundleAssetName'] = bundleAssetName
152
+ reactConfig['root'] = "../../"
153
+ }
154
+
155
+ return reactConfig
156
+ }
157
+
101
158
  private def runShellCommand(
102
159
  List<String> command,
103
160
  File workingDirectory
@@ -81,10 +81,6 @@ internal struct InternalConfigurationAttributes {
81
81
  /// Expects `String?` value
82
82
  static let serviceName = "_dd.service_name"
83
83
 
84
- /// Enable overriding the long task threshold for long task detection.
85
- /// Expects `Double?` value
86
- static let longTaskThreshold = "_dd.long_task.threshold"
87
-
88
84
  /// Specify first party hosts for distributed tracing.
89
85
  /// Even if the requests are intercepted at the javascript level, we have to pass this parameter to make sure the headers are
90
86
  /// correctly set when sending the traces to the intake.
@@ -24,4 +24,14 @@ RCT_EXTERN_METHOD(setTrackingConsent:(NSString)trackingConsent
24
24
  withResolver:(RCTPromiseResolveBlock)resolve
25
25
  withRejecter:(RCTPromiseRejectBlock)reject)
26
26
 
27
+ RCT_EXTERN_METHOD(telemetryDebug:(NSString)message
28
+ withResolver:(RCTPromiseResolveBlock)resolve
29
+ withRejecter:(RCTPromiseRejectBlock)reject)
30
+
31
+ RCT_EXTERN_METHOD(telemetryError:(NSString)message
32
+ withStack:(NSString)stack
33
+ withKind:(NSString)kind
34
+ withResolver:(RCTPromiseResolveBlock)resolve
35
+ withRejecter:(RCTPromiseRejectBlock)reject)
36
+
27
37
  @end
@@ -7,6 +7,7 @@
7
7
  import Foundation
8
8
  import Datadog
9
9
  import DatadogCrashReporting
10
+ import React
10
11
 
11
12
  func getDefaultAppVersion() -> String {
12
13
  let bundleShortVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
@@ -16,45 +17,60 @@ func getDefaultAppVersion() -> String {
16
17
 
17
18
  @objc(DdSdk)
18
19
  class RNDdSdk: NSObject {
20
+ @objc var bridge: RCTBridge!
21
+
19
22
  @objc(requiresMainQueueSetup)
20
23
  static func requiresMainQueueSetup() -> Bool {
21
24
  return false
22
25
  }
23
26
 
27
+ let jsRefreshRateMonitor: RefreshRateMonitor
24
28
  let mainDispatchQueue: DispatchQueueType
25
29
  @objc(methodQueue)
26
30
  let methodQueue: DispatchQueue = sharedQueue
27
31
 
32
+ private let jsLongTaskThresholdInSeconds: TimeInterval = 0.1;
33
+
28
34
  convenience override init() {
29
- self.init(mainDispatchQueue: DispatchQueue.main)
35
+ self.init(mainDispatchQueue: DispatchQueue.main, jsRefreshRateMonitor: JSRefreshRateMonitor.init())
30
36
  }
31
37
 
32
- init(mainDispatchQueue: DispatchQueueType) {
38
+ init(mainDispatchQueue: DispatchQueueType, jsRefreshRateMonitor: RefreshRateMonitor) {
33
39
  self.mainDispatchQueue = mainDispatchQueue
40
+ self.jsRefreshRateMonitor = jsRefreshRateMonitor
34
41
  super.init()
35
42
  }
36
-
37
-
43
+
38
44
  @objc(initialize:withResolver:withRejecter:)
39
45
  func initialize(configuration: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
40
46
  // Datadog SDK init needs to happen on the main thread: https://github.com/DataDog/dd-sdk-reactnative/issues/198
41
47
  self.mainDispatchQueue.async {
48
+ let sdkConfiguration = configuration.asDdSdkConfiguration()
49
+
42
50
  if Datadog.isInitialized {
43
51
  // Initializing the SDK twice results in Global.rum and
44
52
  // Global.sharedTracer to be set to no-op instances
45
53
  consolePrint("Datadog SDK is already initialized, skipping initialization.")
54
+ Datadog._internal.telemetry.debug(id: "datadog_react_native: RN SDK was already initialized in native", message: "RN SDK was already initialized in native")
55
+
56
+ // This block is called when SDK is reinitialized and the javascript has been wiped out.
57
+ // In this case, we need to restart the refresh rate monitor, as the javascript thread
58
+ // appears to change at that moment.
59
+ self.startJSRefreshRateMonitoring(sdkConfiguration: sdkConfiguration)
46
60
  resolve(nil)
47
61
  return
48
62
  }
49
- let sdkConfiguration = configuration.asDdSdkConfiguration()
50
63
  self.setVerbosityLevel(additionalConfig: sdkConfiguration.additionalConfig)
51
64
 
52
65
  let ddConfig = self.buildConfiguration(configuration: sdkConfiguration)
53
66
  let consent = self.buildTrackingConsent(consent: sdkConfiguration.trackingConsent)
54
67
  Datadog.initialize(appContext: Datadog.AppContext(), trackingConsent: consent, configuration: ddConfig)
68
+ self.sendConfigurationAsTelemetry(rnConfiguration: sdkConfiguration)
55
69
 
56
70
  Global.rum = RUMMonitor.initialize()
57
71
 
72
+ self.startJSRefreshRateMonitoring(sdkConfiguration: sdkConfiguration)
73
+
58
74
  resolve(nil)
59
75
  }
60
76
  }
@@ -87,6 +103,40 @@ class RNDdSdk: NSObject {
87
103
  Datadog.set(trackingConsent: buildTrackingConsent(consent: trackingConsent))
88
104
  resolve(nil)
89
105
  }
106
+
107
+ @objc(telemetryDebug:withResolver:withRejecter:)
108
+ func telemetryDebug(message: NSString, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
109
+ Datadog._internal.telemetry.debug(id: "datadog_react_native:\(message)", message: message as String)
110
+ resolve(nil)
111
+ }
112
+
113
+ @objc(telemetryError:withStack:withKind:withResolver:withRejecter:)
114
+ func telemetryDebug(message: NSString, stack: NSString, kind: NSString, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
115
+ Datadog._internal.telemetry.error(id: "datadog_react_native:\(String(describing: kind)):\(message)", message: message as String, kind: kind as? String, stack: stack as? String)
116
+ resolve(nil)
117
+ }
118
+
119
+ func sendConfigurationAsTelemetry(rnConfiguration: DdSdkConfiguration) -> Void {
120
+ Datadog._internal.telemetry.setConfigurationMapper { event in
121
+ var event = event
122
+
123
+ var configuration = event.telemetry.configuration
124
+ configuration.initializationType = rnConfiguration.configurationForTelemetry?.initializationType as? String
125
+ configuration.trackErrors = rnConfiguration.configurationForTelemetry?.trackErrors
126
+ configuration.trackInteractions = rnConfiguration.configurationForTelemetry?.trackInteractions
127
+ configuration.trackResources = rnConfiguration.configurationForTelemetry?.trackNetworkRequests
128
+ configuration.trackNetworkRequests = rnConfiguration.configurationForTelemetry?.trackNetworkRequests
129
+
130
+ // trackCrossPlatformLongTasks will be deprecated for trackLongTask
131
+ configuration.trackCrossPlatformLongTasks = rnConfiguration.longTaskThresholdMs != 0
132
+ configuration.trackLongTask = rnConfiguration.longTaskThresholdMs != 0
133
+ configuration.trackNativeErrors = rnConfiguration.nativeCrashReportEnabled
134
+ configuration.trackNativeLongTasks = rnConfiguration.nativeLongTaskThresholdMs != 0
135
+ event.telemetry.configuration = configuration
136
+
137
+ return event
138
+ }
139
+ }
90
140
 
91
141
  func buildConfiguration(configuration: DdSdkConfiguration, defaultAppVersion: String = getDefaultAppVersion()) -> Datadog.Configuration {
92
142
  let ddConfigBuilder: Datadog.Configuration.Builder
@@ -118,6 +168,19 @@ class RNDdSdk: NSObject {
118
168
  default:
119
169
  _ = ddConfigBuilder.set(endpoint: .us1)
120
170
  }
171
+
172
+ _ = ddConfigBuilder.set(mobileVitalsFrequency: buildVitalsUpdateFrequency(frequency: configuration.vitalsUpdateFrequency))
173
+
174
+ if var telemetrySampleRate = (configuration.telemetrySampleRate as? NSNumber)?.floatValue {
175
+ _ = ddConfigBuilder.set(sampleTelemetry: telemetrySampleRate)
176
+ }
177
+
178
+ if let threshold = configuration.nativeLongTaskThresholdMs as? TimeInterval {
179
+ if (threshold != 0) {
180
+ // `nativeLongTaskThresholdMs` attribute is in milliseconds
181
+ _ = ddConfigBuilder.trackRUMLongTasks(threshold: threshold / 1_000)
182
+ }
183
+ }
121
184
 
122
185
  let additionalConfig = configuration.additionalConfig
123
186
 
@@ -138,11 +201,6 @@ class RNDdSdk: NSObject {
138
201
  _ = ddConfigBuilder.set(serviceName: serviceName)
139
202
  }
140
203
 
141
- if let threshold = additionalConfig?[InternalConfigurationAttributes.longTaskThreshold] as? TimeInterval {
142
- // `_dd.long_task.threshold` attribute is in milliseconds
143
- _ = ddConfigBuilder.trackRUMLongTasks(threshold: threshold / 1_000)
144
- }
145
-
146
204
  if let firstPartyHosts = additionalConfig?[InternalConfigurationAttributes.firstPartyHosts] as? [String] {
147
205
  _ = ddConfigBuilder.trackURLSession(firstPartyHosts: Set(firstPartyHosts))
148
206
  }
@@ -213,6 +271,23 @@ class RNDdSdk: NSObject {
213
271
  return trackingConsent
214
272
  }
215
273
 
274
+ func buildVitalsUpdateFrequency(frequency: NSString?) -> Datadog.Configuration.VitalsFrequency {
275
+ let vitalsFrequency: Datadog.Configuration.VitalsFrequency
276
+ switch frequency?.lowercased {
277
+ case "never":
278
+ vitalsFrequency = .never
279
+ case "rare":
280
+ vitalsFrequency = .rare
281
+ case "average":
282
+ vitalsFrequency = .average
283
+ case "frequent":
284
+ vitalsFrequency = .frequent
285
+ default:
286
+ vitalsFrequency = .average
287
+ }
288
+ return vitalsFrequency
289
+ }
290
+
216
291
  func setVerbosityLevel(additionalConfig: NSDictionary?) {
217
292
  let verbosityLevel = (additionalConfig?[InternalConfigurationAttributes.sdkVerbosity]) as? NSString
218
293
  switch verbosityLevel?.lowercased {
@@ -228,4 +303,32 @@ class RNDdSdk: NSObject {
228
303
  Datadog.verbosityLevel = nil
229
304
  }
230
305
  }
306
+
307
+ func startJSRefreshRateMonitoring(sdkConfiguration: DdSdkConfiguration) {
308
+ if let frameTimeCallback = buildFrameTimeCallback(sdkConfiguration: sdkConfiguration) {
309
+ // Falling back to mainDispatchQueue if bridge is nil is only useful for tests
310
+ self.jsRefreshRateMonitor.startMonitoring(jsQueue: bridge ?? mainDispatchQueue, frameTimeCallback: frameTimeCallback)
311
+ }
312
+ }
313
+
314
+ func buildFrameTimeCallback(sdkConfiguration: DdSdkConfiguration)-> ((Double) -> ())? {
315
+ let jsRefreshRateMonitoringEnabled = buildVitalsUpdateFrequency(frequency: sdkConfiguration.vitalsUpdateFrequency) != .never
316
+ let jsLongTaskMonitoringEnabled = sdkConfiguration.longTaskThresholdMs != 0
317
+
318
+ if (!jsRefreshRateMonitoringEnabled && !jsLongTaskMonitoringEnabled) {
319
+ return nil
320
+ }
321
+
322
+ func frameTimeCallback(frameTime: Double) {
323
+ if (jsRefreshRateMonitoringEnabled && frameTime > 0) {
324
+ Global.rum._internal.updatePerformanceMetric(at: Date(), metric: .jsFrameTimeSeconds, value: frameTime)
325
+ }
326
+ if (jsLongTaskMonitoringEnabled && frameTime > sdkConfiguration.longTaskThresholdMs / 1_000) {
327
+ Global.rum._internal.addLongTask(at: Date(), duration: frameTime, attributes: ["long_task.target": "javascript"])
328
+ }
329
+ }
330
+
331
+ return frameTimeCallback
332
+ }
333
+
231
334
  }