@datadog/mobile-react-native 1.2.0-beta1 → 1.2.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.
- package/DatadogSDKReactNative.podspec +2 -2
- package/android/build.gradle +28 -3
- package/android/detekt.yml +572 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +4 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +7 -2
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +118 -8
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +23 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +29 -1
- package/android/src/main/kotlin/com/datadog/reactnative/VitalFrameCallback.kt +41 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +7 -2
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +377 -27
- package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +5 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +33 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +21 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +1 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +1 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +21 -2
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +2 -3
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +94 -0
- package/datadog-sourcemaps.gradle +85 -28
- package/ios/Sources/Attributes.swift +0 -4
- package/ios/Sources/DdSdk.swift +99 -13
- package/ios/Sources/DdSdkConfiguration.swift +34 -1
- package/ios/Sources/JSRefreshRateListener.swift +86 -0
- package/ios/Sources/QueueHolder.swift +7 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +23 -1
- package/lib/commonjs/DdSdkReactNative.js +24 -25
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +66 -2
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/errorUtils.js +12 -3
- package/lib/commonjs/errorUtils.js.map +1 -1
- package/lib/commonjs/longTasksUtils.js +40 -0
- package/lib/commonjs/longTasksUtils.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +11 -8
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
- package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
- package/lib/commonjs/types.js +5 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +23 -24
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +64 -1
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/errorUtils.js +12 -3
- package/lib/module/errorUtils.js.map +1 -1
- package/lib/module/longTasksUtils.js +31 -0
- package/lib/module/longTasksUtils.js.map +1 -0
- package/lib/module/rum/instrumentation/getJsxRuntime.js +11 -8
- package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +2 -1
- package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -1
- package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
- package/lib/module/types.js +5 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts +0 -7
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +51 -0
- package/lib/typescript/errorUtils.d.ts +8 -0
- package/lib/typescript/longTasksUtils.d.ts +6 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +1 -1
- package/lib/typescript/types.d.ts +15 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +6 -3
- package/scripts/replace-react-require.js +78 -0
- package/src/DatadogProvider/__tests__/initialization.test.tsx +9 -1
- package/src/DdSdkReactNative.tsx +31 -34
- package/src/DdSdkReactNativeConfiguration.tsx +66 -1
- package/src/__tests__/DdSdkReactNative.test.tsx +56 -13
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +15 -2
- package/src/__tests__/longTasksUtils.ts +23 -0
- package/src/errorUtils.ts +11 -3
- package/src/longTasksUtils.ts +30 -0
- package/src/rum/instrumentation/getJsxRuntime.ts +11 -11
- package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +3 -1
- package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +2 -1
- package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +9 -47
- package/src/types.tsx +10 -1
- package/src/version.ts +1 -1
|
@@ -9,12 +9,19 @@ package com.datadog.reactnative
|
|
|
9
9
|
import android.content.Context
|
|
10
10
|
import android.content.pm.PackageManager
|
|
11
11
|
import android.util.Log
|
|
12
|
+
import android.view.Choreographer
|
|
12
13
|
import com.datadog.android.DatadogSite
|
|
14
|
+
import com.datadog.android._InternalProxy
|
|
13
15
|
import com.datadog.android.core.configuration.Configuration
|
|
14
16
|
import com.datadog.android.core.configuration.Credentials
|
|
17
|
+
import com.datadog.android.core.configuration.VitalsUpdateFrequency
|
|
18
|
+
import com.datadog.android.event.EventMapper
|
|
15
19
|
import com.datadog.android.privacy.TrackingConsent
|
|
20
|
+
import com.datadog.android.rum.GlobalRum
|
|
16
21
|
import com.datadog.android.rum.RumMonitor
|
|
22
|
+
import com.datadog.android.rum.RumPerformanceMetric
|
|
17
23
|
import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy
|
|
24
|
+
import com.datadog.android.telemetry.model.TelemetryConfigurationEvent
|
|
18
25
|
import com.facebook.react.bridge.Promise
|
|
19
26
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
20
27
|
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
@@ -23,6 +30,8 @@ import com.facebook.react.bridge.ReadableMap
|
|
|
23
30
|
import java.net.InetSocketAddress
|
|
24
31
|
import java.net.Proxy
|
|
25
32
|
import java.util.Locale
|
|
33
|
+
import java.util.concurrent.TimeUnit
|
|
34
|
+
import java.util.concurrent.atomic.AtomicBoolean
|
|
26
35
|
|
|
27
36
|
/**
|
|
28
37
|
* The entry point to initialize Datadog's features.
|
|
@@ -33,6 +42,8 @@ class DdSdk(
|
|
|
33
42
|
) : ReactContextBaseJavaModule(reactContext) {
|
|
34
43
|
|
|
35
44
|
internal val appContext: Context = reactContext.applicationContext
|
|
45
|
+
internal val reactContext: ReactApplicationContext = reactContext
|
|
46
|
+
internal val initialized = AtomicBoolean(false)
|
|
36
47
|
|
|
37
48
|
override fun getName(): String = "DdSdk"
|
|
38
49
|
|
|
@@ -54,6 +65,8 @@ class DdSdk(
|
|
|
54
65
|
datadog.initialize(appContext, credentials, nativeConfiguration, trackingConsent)
|
|
55
66
|
|
|
56
67
|
datadog.registerRumMonitor(RumMonitor.Builder().build())
|
|
68
|
+
monitorJsRefreshRate(ddSdkConfiguration)
|
|
69
|
+
initialized.set(true)
|
|
57
70
|
|
|
58
71
|
promise.resolve(null)
|
|
59
72
|
}
|
|
@@ -140,6 +153,7 @@ class DdSdk(
|
|
|
140
153
|
val packageInfo = try {
|
|
141
154
|
appContext.packageManager.getPackageInfo(packageName, 0)
|
|
142
155
|
} catch (e: PackageManager.NameNotFoundException) {
|
|
156
|
+
datadog.telemetryError(e.message ?: PACKAGE_INFO_NOT_FOUND_ERROR_MESSAGE, e)
|
|
143
157
|
return DEFAULT_APP_VERSION
|
|
144
158
|
}
|
|
145
159
|
|
|
@@ -153,7 +167,7 @@ class DdSdk(
|
|
|
153
167
|
|
|
154
168
|
@Suppress("ComplexMethod", "UnsafeCallOnNullableType")
|
|
155
169
|
private fun buildConfiguration(configuration: DdSdkConfiguration): Configuration {
|
|
156
|
-
val additionalConfig = configuration.additionalConfig?.toMutableMap()
|
|
170
|
+
val additionalConfig = configuration.additionalConfig?.toMutableMap()
|
|
157
171
|
|
|
158
172
|
val versionSuffix = configuration.additionalConfig?.get(DD_VERSION_SUFFIX) as? String
|
|
159
173
|
if (versionSuffix != null && additionalConfig != null) {
|
|
@@ -177,10 +191,18 @@ class DdSdk(
|
|
|
177
191
|
}
|
|
178
192
|
|
|
179
193
|
configBuilder.useSite(buildSite(configuration.site))
|
|
194
|
+
configBuilder.setVitalsUpdateFrequency(
|
|
195
|
+
buildVitalUpdateFrequency(configuration.vitalsUpdateFrequency)
|
|
196
|
+
)
|
|
180
197
|
|
|
181
198
|
val telemetrySampleRate = (configuration.telemetrySampleRate as? Number)?.toFloat()
|
|
182
199
|
telemetrySampleRate?.let { configBuilder.sampleTelemetry(it) }
|
|
183
200
|
|
|
201
|
+
val longTask = (configuration.nativeLongTaskThresholdMs as? Number)?.toLong()
|
|
202
|
+
if (longTask != null) {
|
|
203
|
+
configBuilder.trackLongTasks(longTask)
|
|
204
|
+
}
|
|
205
|
+
|
|
184
206
|
val viewTracking = configuration.additionalConfig?.get(DD_NATIVE_VIEW_TRACKING) as? Boolean
|
|
185
207
|
if (viewTracking == true) {
|
|
186
208
|
// Use sensible default
|
|
@@ -189,12 +211,6 @@ class DdSdk(
|
|
|
189
211
|
configBuilder.useViewTrackingStrategy(NoOpViewTrackingStrategy)
|
|
190
212
|
}
|
|
191
213
|
|
|
192
|
-
val longTask =
|
|
193
|
-
(configuration.additionalConfig?.get(DD_LONG_TASK_THRESHOLD) as? Number)?.toLong()
|
|
194
|
-
if (longTask != null) {
|
|
195
|
-
configBuilder.trackLongTasks(longTask)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
214
|
val firstPartyHosts =
|
|
199
215
|
(configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? List<String>)
|
|
200
216
|
if (firstPartyHosts != null) {
|
|
@@ -205,6 +221,36 @@ class DdSdk(
|
|
|
205
221
|
configBuilder.setProxy(proxy, authenticator)
|
|
206
222
|
}
|
|
207
223
|
|
|
224
|
+
_InternalProxy.setTelemetryConfigurationEventMapper(
|
|
225
|
+
configBuilder,
|
|
226
|
+
object : EventMapper<TelemetryConfigurationEvent> {
|
|
227
|
+
override fun map(event: TelemetryConfigurationEvent): TelemetryConfigurationEvent? {
|
|
228
|
+
event.telemetry.configuration.trackNativeErrors =
|
|
229
|
+
configuration.nativeCrashReportEnabled
|
|
230
|
+
// trackCrossPlatformLongTasks will be deprecated for trackLongTask
|
|
231
|
+
event.telemetry.configuration.trackCrossPlatformLongTasks =
|
|
232
|
+
configuration.longTaskThresholdMs != 0.0
|
|
233
|
+
event.telemetry.configuration.trackLongTask =
|
|
234
|
+
configuration.longTaskThresholdMs != 0.0
|
|
235
|
+
event.telemetry.configuration.trackNativeLongTasks =
|
|
236
|
+
configuration.nativeLongTaskThresholdMs != 0.0
|
|
237
|
+
|
|
238
|
+
event.telemetry.configuration.initializationType =
|
|
239
|
+
configuration.configurationForTelemetry?.initializationType
|
|
240
|
+
event.telemetry.configuration.trackInteractions =
|
|
241
|
+
configuration.configurationForTelemetry?.trackInteractions
|
|
242
|
+
event.telemetry.configuration.trackErrors =
|
|
243
|
+
configuration.configurationForTelemetry?.trackErrors
|
|
244
|
+
event.telemetry.configuration.trackResources =
|
|
245
|
+
configuration.configurationForTelemetry?.trackNetworkRequests
|
|
246
|
+
event.telemetry.configuration.trackNetworkRequests =
|
|
247
|
+
configuration.configurationForTelemetry?.trackNetworkRequests
|
|
248
|
+
|
|
249
|
+
return event
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
)
|
|
253
|
+
|
|
208
254
|
return configBuilder.build()
|
|
209
255
|
}
|
|
210
256
|
|
|
@@ -285,6 +331,69 @@ class DdSdk(
|
|
|
285
331
|
}
|
|
286
332
|
}
|
|
287
333
|
|
|
334
|
+
private fun buildVitalUpdateFrequency(vitalsUpdateFrequency: String?): VitalsUpdateFrequency {
|
|
335
|
+
val vitalUpdateFrequencyLower = vitalsUpdateFrequency?.lowercase(Locale.US)
|
|
336
|
+
return when (vitalUpdateFrequencyLower) {
|
|
337
|
+
"never" -> VitalsUpdateFrequency.NEVER
|
|
338
|
+
"rare" -> VitalsUpdateFrequency.RARE
|
|
339
|
+
"average" -> VitalsUpdateFrequency.AVERAGE
|
|
340
|
+
"frequent" -> VitalsUpdateFrequency.FREQUENT
|
|
341
|
+
else -> VitalsUpdateFrequency.AVERAGE
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
private fun handlePostFrameCallbackError(e: IllegalStateException) {
|
|
346
|
+
datadog.telemetryError(e.message ?: MONITOR_JS_ERROR_MESSAGE, e)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
private fun monitorJsRefreshRate(ddSdkConfiguration: DdSdkConfiguration) {
|
|
350
|
+
val frameTimeCallback = buildFrameTimeCallback(ddSdkConfiguration)
|
|
351
|
+
if (frameTimeCallback != null) {
|
|
352
|
+
reactContext.runOnJSQueueThread {
|
|
353
|
+
val vitalFrameCallback =
|
|
354
|
+
VitalFrameCallback(
|
|
355
|
+
frameTimeCallback,
|
|
356
|
+
::handlePostFrameCallbackError
|
|
357
|
+
) {
|
|
358
|
+
initialized.get()
|
|
359
|
+
}
|
|
360
|
+
try {
|
|
361
|
+
Choreographer.getInstance().postFrameCallback(vitalFrameCallback)
|
|
362
|
+
} catch (e: IllegalStateException) {
|
|
363
|
+
// This should never happen as the React Native thread always has a Looper
|
|
364
|
+
handlePostFrameCallbackError(e)
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
private fun buildFrameTimeCallback(ddSdkConfiguration: DdSdkConfiguration):
|
|
371
|
+
((Double) -> Unit)? {
|
|
372
|
+
val jsRefreshRateMonitoringEnabled = buildVitalUpdateFrequency(
|
|
373
|
+
ddSdkConfiguration.vitalsUpdateFrequency
|
|
374
|
+
) != VitalsUpdateFrequency.NEVER
|
|
375
|
+
val jsLongTasksMonitoringEnabled = ddSdkConfiguration.longTaskThresholdMs != 0.0
|
|
376
|
+
|
|
377
|
+
if (!jsLongTasksMonitoringEnabled && !jsRefreshRateMonitoringEnabled) {
|
|
378
|
+
return null
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return {
|
|
382
|
+
if (jsRefreshRateMonitoringEnabled && it > 0.0) {
|
|
383
|
+
GlobalRum.get()._getInternal()?.updatePerformanceMetric(
|
|
384
|
+
RumPerformanceMetric.JS_FRAME_TIME,
|
|
385
|
+
it
|
|
386
|
+
)
|
|
387
|
+
}
|
|
388
|
+
if (jsLongTasksMonitoringEnabled && it > TimeUnit.MILLISECONDS.toNanos(
|
|
389
|
+
ddSdkConfiguration.longTaskThresholdMs?.toLong() ?: 0L
|
|
390
|
+
)
|
|
391
|
+
) {
|
|
392
|
+
GlobalRum.get()._getInternal()?.addLongTask(it.toLong(), "javascript")
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
288
397
|
// endregion
|
|
289
398
|
|
|
290
399
|
companion object {
|
|
@@ -292,7 +401,6 @@ class DdSdk(
|
|
|
292
401
|
internal const val DD_NATIVE_VIEW_TRACKING = "_dd.native_view_tracking"
|
|
293
402
|
internal const val DD_SDK_VERBOSITY = "_dd.sdk_verbosity"
|
|
294
403
|
internal const val DD_SERVICE_NAME = "_dd.service_name"
|
|
295
|
-
internal const val DD_LONG_TASK_THRESHOLD = "_dd.long_task.threshold"
|
|
296
404
|
internal const val DD_FIRST_PARTY_HOSTS = "_dd.first_party_hosts"
|
|
297
405
|
internal const val DD_VERSION = "_dd.version"
|
|
298
406
|
internal const val DD_VERSION_SUFFIX = "_dd.version_suffix"
|
|
@@ -301,5 +409,7 @@ class DdSdk(
|
|
|
301
409
|
internal const val DD_PROXY_TYPE = "_dd.proxy.type"
|
|
302
410
|
internal const val DD_PROXY_USERNAME = "_dd.proxy.username"
|
|
303
411
|
internal const val DD_PROXY_PASSWORD = "_dd.proxy.password"
|
|
412
|
+
internal const val MONITOR_JS_ERROR_MESSAGE = "Error monitoring JS refresh rate"
|
|
413
|
+
internal const val PACKAGE_INFO_NOT_FOUND_ERROR_MESSAGE = "Error getting package info"
|
|
304
414
|
}
|
|
305
415
|
}
|
|
@@ -12,20 +12,42 @@ package com.datadog.reactnative
|
|
|
12
12
|
* @param env The application’s environment, for example: prod, pre-prod, staging, etc.
|
|
13
13
|
* @param applicationId The RUM application ID.
|
|
14
14
|
* @param nativeCrashReportEnabled Whether the SDK should track native (pure iOS or pure Android) crashes (default is false).
|
|
15
|
+
* @param nativeLongTaskThresholdMs The threshold for native long tasks reporting in milliseconds.
|
|
16
|
+
* @param longTaskThresholdMs The threshold for javascript long tasks reporting in milliseconds.
|
|
15
17
|
* @param sampleRate The sample rate (between 0 and 100) of RUM sessions kept.
|
|
16
18
|
* @param site The Datadog site of your organization (can be 'US', 'EU' or 'GOV', default is 'US').
|
|
17
19
|
* @param trackingConsent Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
|
|
18
20
|
* @param telemetrySampleRate The sample rate (between 0 and 100) of telemetry events.
|
|
21
|
+
* @param vitalsUpdateFrequency The frequency to which vitals update are sent (can be 'NEVER', 'RARE', 'AVERAGE' (default), 'FREQUENT').
|
|
19
22
|
* @param additionalConfig Additional configuration parameters.
|
|
23
|
+
* @param configurationForTelemetry Additional configuration data for Datadog telemetry.
|
|
20
24
|
*/
|
|
21
25
|
data class DdSdkConfiguration(
|
|
22
26
|
val clientToken: String,
|
|
23
27
|
val env: String,
|
|
24
28
|
val applicationId: String? = null,
|
|
25
29
|
val nativeCrashReportEnabled: Boolean? = null,
|
|
30
|
+
val nativeLongTaskThresholdMs: Double? = null,
|
|
31
|
+
val longTaskThresholdMs: Double? = null,
|
|
26
32
|
val sampleRate: Double? = null,
|
|
27
33
|
val site: String? = null,
|
|
28
34
|
val trackingConsent: String? = null,
|
|
29
35
|
val telemetrySampleRate: Double? = null,
|
|
30
|
-
val
|
|
36
|
+
val vitalsUpdateFrequency: String? = null,
|
|
37
|
+
val additionalConfig: Map<String, Any?>? = null,
|
|
38
|
+
val configurationForTelemetry: ConfigurationForTelemetry? = null
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Additional configuration data for Datadog telemetry.
|
|
43
|
+
* @param initializationType Type of initialization used.
|
|
44
|
+
* @param trackErrors Whether JS errors are tracked.
|
|
45
|
+
* @param trackInteractions Whether interactions are tracked.
|
|
46
|
+
* @param trackNetworkRequests Whether network requests are tracked.
|
|
47
|
+
*/
|
|
48
|
+
data class ConfigurationForTelemetry(
|
|
49
|
+
val initializationType: String? = null,
|
|
50
|
+
val trackErrors: Boolean? = null,
|
|
51
|
+
val trackInteractions: Boolean? = null,
|
|
52
|
+
val trackNetworkRequests: Boolean? = null
|
|
31
53
|
)
|
|
@@ -15,24 +15,52 @@ internal fun ReadableMap.asDdSdkConfiguration(): DdSdkConfiguration {
|
|
|
15
15
|
env = getString("env").orEmpty(),
|
|
16
16
|
applicationId = getString("applicationId"),
|
|
17
17
|
nativeCrashReportEnabled = getBoolean("nativeCrashReportEnabled"),
|
|
18
|
+
nativeLongTaskThresholdMs = getDouble("nativeLongTaskThresholdMs"),
|
|
19
|
+
longTaskThresholdMs = getDouble("longTaskThresholdMs"),
|
|
18
20
|
sampleRate = getDouble("sampleRate"),
|
|
19
21
|
site = getString("site"),
|
|
20
22
|
trackingConsent = getString("trackingConsent"),
|
|
21
23
|
telemetrySampleRate = getDouble("telemetrySampleRate"),
|
|
22
|
-
|
|
24
|
+
vitalsUpdateFrequency = getString("vitalsUpdateFrequency"),
|
|
25
|
+
additionalConfig = getMap("additionalConfig")?.toHashMap(),
|
|
26
|
+
configurationForTelemetry = getMap(
|
|
27
|
+
"configurationForTelemetry"
|
|
28
|
+
)?.asConfigurationForTelemetry()
|
|
23
29
|
)
|
|
24
30
|
}
|
|
25
31
|
|
|
32
|
+
internal fun ReadableMap.asConfigurationForTelemetry(): ConfigurationForTelemetry {
|
|
33
|
+
return ConfigurationForTelemetry(
|
|
34
|
+
initializationType = getString("initializationType"),
|
|
35
|
+
trackErrors = getBoolean("trackErrors"),
|
|
36
|
+
trackInteractions = getBoolean("trackInteractions"),
|
|
37
|
+
trackNetworkRequests = getBoolean("trackNetworkRequests"),
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Suppress("ComplexMethod")
|
|
26
42
|
internal fun DdSdkConfiguration.toReadableMap(): ReadableMap {
|
|
27
43
|
val map = WritableNativeMap()
|
|
28
44
|
map.putString("clientToken", clientToken)
|
|
29
45
|
map.putString("env", env)
|
|
30
46
|
applicationId?.let { map.putString("applicationId", it) }
|
|
31
47
|
nativeCrashReportEnabled?.let { map.putBoolean("nativeCrashReportEnabled", it) }
|
|
48
|
+
nativeLongTaskThresholdMs?.let { map.putDouble("nativeLongTaskThresholdMs", it) }
|
|
49
|
+
longTaskThresholdMs?.let { map.putDouble("longTaskThresholdMs", it) }
|
|
32
50
|
sampleRate?.let { map.putDouble("sampleRate", it) }
|
|
33
51
|
site?.let { map.putString("site", it) }
|
|
34
52
|
trackingConsent?.let { map.putString("trackingConsent", it) }
|
|
35
53
|
telemetrySampleRate?.let { map.putDouble("telemetrySampleRate", it) }
|
|
54
|
+
vitalsUpdateFrequency?.let { map.putString("vitalsUpdateFrequency", it) }
|
|
36
55
|
additionalConfig?.let { map.putMap("additionalConfig", it.toWritableMap()) }
|
|
37
56
|
return map
|
|
38
57
|
}
|
|
58
|
+
|
|
59
|
+
internal fun ConfigurationForTelemetry.toReadableMap(): ReadableMap {
|
|
60
|
+
val map = WritableNativeMap()
|
|
61
|
+
initializationType?.let { map.putString("initializationType", it) }
|
|
62
|
+
trackErrors?.let { map.putBoolean("trackErrors", it) }
|
|
63
|
+
trackInteractions?.let { map.putBoolean("trackInteractions", it) }
|
|
64
|
+
trackNetworkRequests?.let { map.putBoolean("trackNetworkRequests", it) }
|
|
65
|
+
return map
|
|
66
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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.reactnative
|
|
8
|
+
|
|
9
|
+
import android.view.Choreographer
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Reads the javascript framerate based on the [Choreographer.FrameCallback].
|
|
13
|
+
*/
|
|
14
|
+
internal class VitalFrameCallback(
|
|
15
|
+
private val frameTimeCallback: (Double) -> Unit,
|
|
16
|
+
private val errorHandler: (IllegalStateException) -> Unit,
|
|
17
|
+
private val keepRunning: () -> Boolean
|
|
18
|
+
) : Choreographer.FrameCallback {
|
|
19
|
+
|
|
20
|
+
internal var lastFrameTimestampNs: Long = 0L
|
|
21
|
+
|
|
22
|
+
// region Choreographer.FrameCallback
|
|
23
|
+
|
|
24
|
+
override fun doFrame(frameTimeNanos: Long) {
|
|
25
|
+
if (lastFrameTimestampNs != 0L) {
|
|
26
|
+
val durationNs = (frameTimeNanos - lastFrameTimestampNs).toDouble()
|
|
27
|
+
frameTimeCallback(durationNs)
|
|
28
|
+
}
|
|
29
|
+
lastFrameTimestampNs = frameTimeNanos
|
|
30
|
+
|
|
31
|
+
if (keepRunning()) {
|
|
32
|
+
try {
|
|
33
|
+
Choreographer.getInstance().postFrameCallback(this)
|
|
34
|
+
} catch (e: IllegalStateException) {
|
|
35
|
+
errorHandler(e)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// endregion
|
|
41
|
+
}
|
|
@@ -24,7 +24,6 @@ import fr.xgouchet.elmyr.Forge
|
|
|
24
24
|
import fr.xgouchet.elmyr.annotation.DoubleForgery
|
|
25
25
|
import fr.xgouchet.elmyr.annotation.Forgery
|
|
26
26
|
import fr.xgouchet.elmyr.annotation.IntForgery
|
|
27
|
-
import fr.xgouchet.elmyr.annotation.LongForgery
|
|
28
27
|
import fr.xgouchet.elmyr.annotation.StringForgery
|
|
29
28
|
import fr.xgouchet.elmyr.annotation.StringForgeryType
|
|
30
29
|
import fr.xgouchet.elmyr.junit5.ForgeConfiguration
|
|
@@ -281,7 +280,13 @@ internal class DdRumTest {
|
|
|
281
280
|
)
|
|
282
281
|
|
|
283
282
|
// Then
|
|
284
|
-
verify(mockRumMonitor).stopResource(
|
|
283
|
+
verify(mockRumMonitor).stopResource(
|
|
284
|
+
key,
|
|
285
|
+
statusCode,
|
|
286
|
+
resourceSize.toLong(),
|
|
287
|
+
kind,
|
|
288
|
+
updatedContext
|
|
289
|
+
)
|
|
285
290
|
}
|
|
286
291
|
|
|
287
292
|
@Test
|