@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.
- package/DatadogSDKReactNative.podspec +2 -2
- package/README.md +18 -14
- package/android/build.gradle +28 -3
- package/android/detekt.yml +572 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +12 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +15 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +143 -8
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +25 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +31 -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 +429 -27
- package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +5 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +40 -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 +22 -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.m +10 -0
- package/ios/Sources/DdSdk.swift +113 -10
- package/ios/Sources/DdSdkConfiguration.swift +38 -1
- package/ios/Sources/JSRefreshRateListener.swift +86 -0
- package/ios/Sources/QueueHolder.swift +7 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +25 -1
- package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js +173 -0
- package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js +32 -0
- package/lib/commonjs/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js +29 -0
- package/lib/commonjs/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js +28 -0
- package/lib/commonjs/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
- package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js +32 -0
- package/lib/commonjs/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
- package/lib/commonjs/DatadogProvider/DatadogProvider.js +101 -0
- package/lib/commonjs/DatadogProvider/DatadogProvider.js.map +1 -0
- package/lib/commonjs/DdSdkReactNative.js +140 -59
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +166 -9
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/errorUtils.js +69 -0
- package/lib/commonjs/errorUtils.js.map +1 -0
- package/lib/commonjs/foundation.js +19 -12
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +20 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/longTasksUtils.js +40 -0
- package/lib/commonjs/longTasksUtils.js.map +1 -0
- package/lib/commonjs/nativeModulesTypes.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +8 -45
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +16 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js +1 -1
- 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 +6 -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/DatadogProvider/Buffer/BoundedBuffer.js +163 -0
- package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/BufferSingleton.js +26 -0
- package/lib/module/DatadogProvider/Buffer/BufferSingleton.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js +20 -0
- package/lib/module/DatadogProvider/Buffer/DatadogBuffer.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js +23 -0
- package/lib/module/DatadogProvider/Buffer/PassThroughBuffer.js.map +1 -0
- package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js +16 -0
- package/lib/module/DatadogProvider/Buffer/bufferNativeCall.js.map +1 -0
- package/lib/module/DatadogProvider/DatadogProvider.js +82 -0
- package/lib/module/DatadogProvider/DatadogProvider.js.map +1 -0
- package/lib/module/DdSdkReactNative.js +132 -57
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +154 -8
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/errorUtils.js +54 -0
- package/lib/module/errorUtils.js.map +1 -0
- package/lib/module/foundation.js +18 -12
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/longTasksUtils.js +31 -0
- package/lib/module/longTasksUtils.js.map +1 -0
- package/lib/module/nativeModulesTypes.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +5 -42
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +14 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/getJsxRuntime.js +1 -1
- 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 +6 -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/DatadogProvider/Buffer/BoundedBuffer.d.ts +15 -0
- package/lib/typescript/DatadogProvider/Buffer/BufferSingleton.d.ts +7 -0
- package/lib/typescript/DatadogProvider/Buffer/DatadogBuffer.d.ts +20 -0
- package/lib/typescript/DatadogProvider/Buffer/PassThroughBuffer.d.ts +7 -0
- package/lib/typescript/DatadogProvider/Buffer/bufferNativeCall.d.ts +3 -0
- package/lib/typescript/DatadogProvider/DatadogProvider.d.ts +26 -0
- package/lib/typescript/DdSdkReactNative.d.ts +18 -3
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +114 -0
- package/lib/typescript/errorUtils.d.ts +12 -0
- package/lib/typescript/index.d.ts +3 -2
- package/lib/typescript/longTasksUtils.d.ts +6 -0
- package/lib/typescript/nativeModulesTypes.d.ts +12 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +0 -2
- package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -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 +16 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +3 -2
- package/src/DatadogProvider/Buffer/BoundedBuffer.ts +209 -0
- package/src/DatadogProvider/Buffer/BufferSingleton.ts +26 -0
- package/src/DatadogProvider/Buffer/DatadogBuffer.ts +34 -0
- package/src/DatadogProvider/Buffer/PassThroughBuffer.ts +16 -0
- package/src/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +202 -0
- package/src/DatadogProvider/Buffer/__tests__/BufferSingleton.test.ts +50 -0
- package/src/DatadogProvider/Buffer/bufferNativeCall.ts +24 -0
- package/src/DatadogProvider/DatadogProvider.tsx +122 -0
- package/src/DatadogProvider/__tests__/__utils__/renderWithProvider.tsx +111 -0
- package/src/DatadogProvider/__tests__/initialization.test.tsx +182 -0
- package/src/DatadogProvider/__tests__/initializationModes.test.tsx +174 -0
- package/src/DdSdkReactNative.tsx +206 -109
- package/src/DdSdkReactNativeConfiguration.tsx +225 -8
- package/src/__tests__/DdRumWrapper.test.tsx +3 -27
- package/src/__tests__/DdSdkReactNative.test.tsx +57 -13
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +181 -0
- package/src/__tests__/foundation.test.ts +11 -2
- package/src/__tests__/longTasksUtils.ts +23 -0
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +18 -4
- package/src/errorUtils.ts +58 -0
- package/src/foundation.tsx +15 -12
- package/src/index.tsx +9 -1
- package/src/longTasksUtils.ts +30 -0
- package/src/nativeModulesTypes.ts +14 -0
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +9 -46
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +11 -1
- package/src/rum/instrumentation/getJsxRuntime.ts +1 -1
- package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +2 -0
- 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/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -0
- package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +12 -47
- package/src/types.tsx +11 -1
- package/src/version.ts +1 -1
|
@@ -1,35 +1,57 @@
|
|
|
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
|
+
|
|
1
7
|
package com.datadog.reactnative
|
|
2
8
|
|
|
3
|
-
import android.util.Log
|
|
4
9
|
import android.content.pm.PackageInfo
|
|
10
|
+
import android.util.Log
|
|
11
|
+
import android.view.Choreographer
|
|
5
12
|
import com.datadog.android.DatadogEndpoint
|
|
6
13
|
import com.datadog.android.core.configuration.BatchSize
|
|
7
14
|
import com.datadog.android.core.configuration.Configuration
|
|
8
15
|
import com.datadog.android.core.configuration.Credentials
|
|
9
16
|
import com.datadog.android.core.configuration.UploadFrequency
|
|
17
|
+
import com.datadog.android.core.configuration.VitalsUpdateFrequency
|
|
18
|
+
import com.datadog.android.event.EventMapper
|
|
10
19
|
import com.datadog.android.plugin.DatadogPlugin
|
|
11
20
|
import com.datadog.android.privacy.TrackingConsent
|
|
21
|
+
import com.datadog.android.rum.GlobalRum
|
|
22
|
+
import com.datadog.android.rum.RumMonitor
|
|
23
|
+
import com.datadog.android.rum.RumPerformanceMetric
|
|
24
|
+
import com.datadog.android.rum._RumInternalProxy
|
|
12
25
|
import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy
|
|
26
|
+
import com.datadog.android.telemetry.model.TelemetryConfigurationEvent
|
|
13
27
|
import com.datadog.tools.unit.GenericAssert.Companion.assertThat
|
|
14
28
|
import com.datadog.tools.unit.forge.BaseConfigurator
|
|
29
|
+
import com.datadog.tools.unit.getStaticValue
|
|
30
|
+
import com.datadog.tools.unit.setStaticValue
|
|
15
31
|
import com.datadog.tools.unit.toReadableJavaOnlyMap
|
|
16
32
|
import com.datadog.tools.unit.toReadableMap
|
|
17
33
|
import com.facebook.react.bridge.Promise
|
|
18
34
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
19
35
|
import com.nhaarman.mockitokotlin2.any
|
|
20
36
|
import com.nhaarman.mockitokotlin2.argumentCaptor
|
|
37
|
+
import com.nhaarman.mockitokotlin2.doNothing
|
|
21
38
|
import com.nhaarman.mockitokotlin2.doReturn
|
|
39
|
+
import com.nhaarman.mockitokotlin2.doThrow
|
|
22
40
|
import com.nhaarman.mockitokotlin2.eq
|
|
23
41
|
import com.nhaarman.mockitokotlin2.inOrder
|
|
24
42
|
import com.nhaarman.mockitokotlin2.isNull
|
|
43
|
+
import com.nhaarman.mockitokotlin2.mock
|
|
25
44
|
import com.nhaarman.mockitokotlin2.never
|
|
26
45
|
import com.nhaarman.mockitokotlin2.same
|
|
27
46
|
import com.nhaarman.mockitokotlin2.verify
|
|
47
|
+
import com.nhaarman.mockitokotlin2.verifyZeroInteractions
|
|
28
48
|
import com.nhaarman.mockitokotlin2.whenever
|
|
29
49
|
import fr.xgouchet.elmyr.Forge
|
|
30
50
|
import fr.xgouchet.elmyr.annotation.AdvancedForgery
|
|
51
|
+
import fr.xgouchet.elmyr.annotation.BoolForgery
|
|
31
52
|
import fr.xgouchet.elmyr.annotation.Forgery
|
|
32
53
|
import fr.xgouchet.elmyr.annotation.IntForgery
|
|
54
|
+
import fr.xgouchet.elmyr.annotation.LongForgery
|
|
33
55
|
import fr.xgouchet.elmyr.annotation.MapForgery
|
|
34
56
|
import fr.xgouchet.elmyr.annotation.StringForgery
|
|
35
57
|
import fr.xgouchet.elmyr.annotation.StringForgeryType
|
|
@@ -38,6 +60,7 @@ import fr.xgouchet.elmyr.junit5.ForgeExtension
|
|
|
38
60
|
import java.net.InetSocketAddress
|
|
39
61
|
import java.net.Proxy
|
|
40
62
|
import java.util.Locale
|
|
63
|
+
import java.util.concurrent.atomic.AtomicBoolean
|
|
41
64
|
import org.assertj.core.api.Assertions.assertThat
|
|
42
65
|
import org.junit.jupiter.api.AfterEach
|
|
43
66
|
import org.junit.jupiter.api.Assumptions.assumeTrue
|
|
@@ -45,12 +68,23 @@ import org.junit.jupiter.api.BeforeEach
|
|
|
45
68
|
import org.junit.jupiter.api.Test
|
|
46
69
|
import org.junit.jupiter.api.extension.ExtendWith
|
|
47
70
|
import org.junit.jupiter.api.extension.Extensions
|
|
48
|
-
import org.mockito.Mock
|
|
49
71
|
import org.mockito.Answers
|
|
72
|
+
import org.mockito.Mock
|
|
50
73
|
import org.mockito.junit.jupiter.MockitoExtension
|
|
51
74
|
import org.mockito.junit.jupiter.MockitoSettings
|
|
52
75
|
import org.mockito.quality.Strictness
|
|
53
76
|
|
|
77
|
+
fun mockChoreographerInstance(mock: Choreographer = mock()) {
|
|
78
|
+
Choreographer::class.java.setStaticValue(
|
|
79
|
+
"sThreadInstance",
|
|
80
|
+
object : ThreadLocal<Choreographer>() {
|
|
81
|
+
override fun initialValue(): Choreographer {
|
|
82
|
+
return mock
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
54
88
|
@Extensions(
|
|
55
89
|
ExtendWith(MockitoExtension::class),
|
|
56
90
|
ExtendWith(ForgeExtension::class)
|
|
@@ -61,9 +95,18 @@ internal class DdSdkTest {
|
|
|
61
95
|
|
|
62
96
|
lateinit var testedBridgeSdk: DdSdk
|
|
63
97
|
|
|
98
|
+
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
99
|
+
lateinit var mockReactContext: ReactApplicationContext
|
|
100
|
+
|
|
64
101
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
65
102
|
lateinit var mockContext: ReactApplicationContext
|
|
66
103
|
|
|
104
|
+
@Mock
|
|
105
|
+
lateinit var mockRumMonitor: RumMonitor
|
|
106
|
+
|
|
107
|
+
@Mock
|
|
108
|
+
lateinit var mockRumInternalProxy: _RumInternalProxy
|
|
109
|
+
|
|
67
110
|
@Mock
|
|
68
111
|
lateinit var mockDatadog: DatadogWrapper
|
|
69
112
|
|
|
@@ -76,17 +119,36 @@ internal class DdSdkTest {
|
|
|
76
119
|
@Forgery
|
|
77
120
|
lateinit var mockPackageInfo: PackageInfo
|
|
78
121
|
|
|
122
|
+
@Mock
|
|
123
|
+
lateinit var mockChoreographer: Choreographer
|
|
124
|
+
|
|
79
125
|
@BeforeEach
|
|
80
126
|
fun `set up`() {
|
|
81
|
-
|
|
127
|
+
GlobalRum.registerIfAbsent(mockRumMonitor)
|
|
128
|
+
whenever(mockRumMonitor._getInternal()) doReturn mockRumInternalProxy
|
|
129
|
+
|
|
130
|
+
doNothing().whenever(mockChoreographer).postFrameCallback(any())
|
|
131
|
+
mockChoreographerInstance(mockChoreographer)
|
|
132
|
+
whenever(mockReactContext.applicationContext) doReturn mockContext
|
|
82
133
|
whenever(mockContext.packageName) doReturn "packageName"
|
|
83
|
-
whenever(
|
|
84
|
-
|
|
134
|
+
whenever(
|
|
135
|
+
mockContext.packageManager.getPackageInfo(
|
|
136
|
+
"packageName",
|
|
137
|
+
0
|
|
138
|
+
)
|
|
139
|
+
) doReturn mockPackageInfo
|
|
140
|
+
whenever(mockReactContext.runOnJSQueueThread(any())).thenAnswer { answer ->
|
|
141
|
+
answer.getArgument<Runnable>(0).run()
|
|
142
|
+
true
|
|
143
|
+
}
|
|
144
|
+
testedBridgeSdk = DdSdk(mockReactContext, mockDatadog)
|
|
85
145
|
}
|
|
86
146
|
|
|
87
147
|
@AfterEach
|
|
88
148
|
fun `tear down`() {
|
|
89
149
|
GlobalState.globalAttributes.clear()
|
|
150
|
+
GlobalRum.javaClass.setStaticValue("monitor", mock<RumMonitor>())
|
|
151
|
+
GlobalRum.javaClass.getStaticValue<GlobalRum, AtomicBoolean>("isRegistered").set(false)
|
|
90
152
|
}
|
|
91
153
|
|
|
92
154
|
// region initialize / nativeCrashReportEnabled
|
|
@@ -291,6 +353,58 @@ internal class DdSdkTest {
|
|
|
291
353
|
|
|
292
354
|
// endregion
|
|
293
355
|
|
|
356
|
+
// region initialize / telemetry sample rate
|
|
357
|
+
|
|
358
|
+
@Test
|
|
359
|
+
fun `𝕄 initialize native with telemetry sample rate SDK 𝕎 initialize() {}`() {
|
|
360
|
+
// Given
|
|
361
|
+
val credentialCaptor = argumentCaptor<Credentials>()
|
|
362
|
+
val configCaptor = argumentCaptor<Configuration>()
|
|
363
|
+
val expectedTelemetrySampleRate = fakeConfiguration.telemetrySampleRate?.toFloat() ?: 20f
|
|
364
|
+
|
|
365
|
+
// When
|
|
366
|
+
testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
367
|
+
|
|
368
|
+
// Then
|
|
369
|
+
inOrder(mockDatadog) {
|
|
370
|
+
verify(mockDatadog).initialize(
|
|
371
|
+
same(mockContext),
|
|
372
|
+
credentialCaptor.capture(),
|
|
373
|
+
configCaptor.capture(),
|
|
374
|
+
any()
|
|
375
|
+
)
|
|
376
|
+
verify(mockDatadog).registerRumMonitor(any())
|
|
377
|
+
}
|
|
378
|
+
assertThat(configCaptor.firstValue)
|
|
379
|
+
.hasField("coreConfig") {
|
|
380
|
+
it.hasFieldEqualTo("needsClearTextHttp", false)
|
|
381
|
+
it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
|
|
382
|
+
it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
|
|
383
|
+
it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
|
|
384
|
+
}
|
|
385
|
+
.hasField("logsConfig") {
|
|
386
|
+
it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
|
|
387
|
+
}
|
|
388
|
+
.hasField("tracesConfig") {
|
|
389
|
+
it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
|
|
390
|
+
}
|
|
391
|
+
.hasField("rumConfig") {
|
|
392
|
+
it.hasFieldEqualTo("plugins", emptyList<DatadogPlugin>())
|
|
393
|
+
it.hasFieldEqualTo("telemetrySamplingRate", expectedTelemetrySampleRate)
|
|
394
|
+
}
|
|
395
|
+
.hasFieldEqualTo(
|
|
396
|
+
"additionalConfig",
|
|
397
|
+
fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty()
|
|
398
|
+
)
|
|
399
|
+
val credentials = credentialCaptor.firstValue
|
|
400
|
+
assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken)
|
|
401
|
+
assertThat(credentials.envName).isEqualTo(fakeConfiguration.env)
|
|
402
|
+
assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId)
|
|
403
|
+
assertThat(credentials.variant).isEqualTo("")
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// endregion
|
|
407
|
+
|
|
294
408
|
// region initialize / additionalConfig
|
|
295
409
|
|
|
296
410
|
@Test
|
|
@@ -1000,17 +1114,11 @@ internal class DdSdkTest {
|
|
|
1000
1114
|
@Forgery configuration: DdSdkConfiguration,
|
|
1001
1115
|
forge: Forge
|
|
1002
1116
|
) {
|
|
1003
|
-
|
|
1004
|
-
val threshold = forge.anElementFrom(
|
|
1005
|
-
forge.aLong(min = 0, max = 65536),
|
|
1006
|
-
forge.aDouble(min = 0.0, max = 65536.0)
|
|
1007
|
-
)
|
|
1117
|
+
val threshold = forge.aDouble(min = 100.0, max = 65536.0)
|
|
1008
1118
|
|
|
1009
1119
|
// Given
|
|
1010
1120
|
val bridgeConfiguration = configuration.copy(
|
|
1011
|
-
|
|
1012
|
-
DdSdk.DD_LONG_TASK_THRESHOLD to threshold
|
|
1013
|
-
)
|
|
1121
|
+
nativeLongTaskThresholdMs = threshold
|
|
1014
1122
|
)
|
|
1015
1123
|
val credentialCaptor = argumentCaptor<Credentials>()
|
|
1016
1124
|
val configCaptor = argumentCaptor<Configuration>()
|
|
@@ -1038,6 +1146,34 @@ internal class DdSdkTest {
|
|
|
1038
1146
|
}
|
|
1039
1147
|
}
|
|
1040
1148
|
|
|
1149
|
+
@Test
|
|
1150
|
+
fun `𝕄 not set long task threshold 𝕎 initialize() {long task threshold is 0}`(
|
|
1151
|
+
@Forgery configuration: DdSdkConfiguration,
|
|
1152
|
+
forge: Forge
|
|
1153
|
+
) {
|
|
1154
|
+
// Given
|
|
1155
|
+
val bridgeConfiguration = configuration.copy(
|
|
1156
|
+
nativeLongTaskThresholdMs = 0.0
|
|
1157
|
+
)
|
|
1158
|
+
val credentialCaptor = argumentCaptor<Credentials>()
|
|
1159
|
+
val configCaptor = argumentCaptor<Configuration>()
|
|
1160
|
+
|
|
1161
|
+
// When
|
|
1162
|
+
testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
1163
|
+
|
|
1164
|
+
// Then
|
|
1165
|
+
verify(mockDatadog).initialize(
|
|
1166
|
+
same(mockContext),
|
|
1167
|
+
credentialCaptor.capture(),
|
|
1168
|
+
configCaptor.capture(),
|
|
1169
|
+
eq(configuration.trackingConsent.asTrackingConsent())
|
|
1170
|
+
)
|
|
1171
|
+
assertThat(configCaptor.firstValue)
|
|
1172
|
+
.hasField("rumConfig") { rumConfig ->
|
|
1173
|
+
rumConfig.doesNotHaveField("longTaskTrackingStrategy")
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1041
1177
|
@Test
|
|
1042
1178
|
fun `𝕄 set first party hosts 𝕎 initialize() {first party hosts}`(
|
|
1043
1179
|
@Forgery configuration: DdSdkConfiguration,
|
|
@@ -1069,20 +1205,264 @@ internal class DdSdkTest {
|
|
|
1069
1205
|
}
|
|
1070
1206
|
}
|
|
1071
1207
|
|
|
1208
|
+
@Test
|
|
1209
|
+
fun `𝕄 initialize native SDK 𝕎 initialize() {rare vitals frequency update}`(
|
|
1210
|
+
@Forgery configuration: DdSdkConfiguration
|
|
1211
|
+
) {
|
|
1212
|
+
// Given
|
|
1213
|
+
val bridgeConfiguration = configuration.copy(
|
|
1214
|
+
vitalsUpdateFrequency = "RARE"
|
|
1215
|
+
)
|
|
1216
|
+
val credentialCaptor = argumentCaptor<Credentials>()
|
|
1217
|
+
val configCaptor = argumentCaptor<Configuration>()
|
|
1218
|
+
|
|
1219
|
+
// When
|
|
1220
|
+
testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
1221
|
+
|
|
1222
|
+
// Then
|
|
1223
|
+
inOrder(mockDatadog) {
|
|
1224
|
+
verify(mockDatadog).initialize(
|
|
1225
|
+
same(mockContext),
|
|
1226
|
+
credentialCaptor.capture(),
|
|
1227
|
+
configCaptor.capture(),
|
|
1228
|
+
eq(configuration.trackingConsent.asTrackingConsent())
|
|
1229
|
+
)
|
|
1230
|
+
verify(mockDatadog).registerRumMonitor(any())
|
|
1231
|
+
}
|
|
1232
|
+
assertThat(configCaptor.firstValue)
|
|
1233
|
+
.hasField("rumConfig") {
|
|
1234
|
+
it.hasFieldEqualTo("vitalsMonitorUpdateFrequency", VitalsUpdateFrequency.RARE)
|
|
1235
|
+
}
|
|
1236
|
+
argumentCaptor<Choreographer.FrameCallback> {
|
|
1237
|
+
verify(mockChoreographer).postFrameCallback(capture())
|
|
1238
|
+
assertThat(firstValue).isInstanceOf(VitalFrameCallback::class.java)
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
@Test
|
|
1243
|
+
fun `𝕄 initialize native SDK 𝕎 initialize() {never vitals frequency update}`(
|
|
1244
|
+
@Forgery configuration: DdSdkConfiguration
|
|
1245
|
+
) {
|
|
1246
|
+
// Given
|
|
1247
|
+
doThrow(IllegalStateException()).whenever(mockChoreographer).postFrameCallback(any())
|
|
1248
|
+
val bridgeConfiguration = configuration.copy(
|
|
1249
|
+
vitalsUpdateFrequency = "NEVER",
|
|
1250
|
+
longTaskThresholdMs = 0.0
|
|
1251
|
+
)
|
|
1252
|
+
val credentialCaptor = argumentCaptor<Credentials>()
|
|
1253
|
+
val configCaptor = argumentCaptor<Configuration>()
|
|
1254
|
+
|
|
1255
|
+
// When
|
|
1256
|
+
testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
1257
|
+
|
|
1258
|
+
// Then
|
|
1259
|
+
inOrder(mockDatadog) {
|
|
1260
|
+
verify(mockDatadog).initialize(
|
|
1261
|
+
same(mockContext),
|
|
1262
|
+
credentialCaptor.capture(),
|
|
1263
|
+
configCaptor.capture(),
|
|
1264
|
+
eq(configuration.trackingConsent.asTrackingConsent())
|
|
1265
|
+
)
|
|
1266
|
+
verify(mockDatadog).registerRumMonitor(any())
|
|
1267
|
+
}
|
|
1268
|
+
assertThat(configCaptor.firstValue)
|
|
1269
|
+
.hasField("rumConfig") {
|
|
1270
|
+
it.hasFieldEqualTo("vitalsMonitorUpdateFrequency", VitalsUpdateFrequency.NEVER)
|
|
1271
|
+
}
|
|
1272
|
+
verifyZeroInteractions(mockChoreographer)
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
@Test
|
|
1276
|
+
fun `𝕄 initialize native SDK 𝕎 initialize() {malformed frequency update, long task 0}`(
|
|
1277
|
+
@StringForgery fakeFrequency: String,
|
|
1278
|
+
@LongForgery(min = 0L) timestampNs: Long,
|
|
1279
|
+
@LongForgery(min = ONE_HUNDRED_MILLISSECOND_NS, max = 5 * ONE_SECOND_NS) threshold: Long,
|
|
1280
|
+
@LongForgery(min = 1, max = ONE_SECOND_NS) frameDurationOverThreshold: Long,
|
|
1281
|
+
@Forgery configuration: DdSdkConfiguration
|
|
1282
|
+
) {
|
|
1283
|
+
// Given
|
|
1284
|
+
val bridgeConfiguration = configuration.copy(
|
|
1285
|
+
vitalsUpdateFrequency = fakeFrequency,
|
|
1286
|
+
longTaskThresholdMs = 0.0
|
|
1287
|
+
)
|
|
1288
|
+
val credentialCaptor = argumentCaptor<Credentials>()
|
|
1289
|
+
val configCaptor = argumentCaptor<Configuration>()
|
|
1290
|
+
val frameDurationNs = threshold + frameDurationOverThreshold
|
|
1291
|
+
|
|
1292
|
+
// When
|
|
1293
|
+
testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
1294
|
+
|
|
1295
|
+
// Then
|
|
1296
|
+
inOrder(mockDatadog) {
|
|
1297
|
+
verify(mockDatadog).initialize(
|
|
1298
|
+
same(mockContext),
|
|
1299
|
+
credentialCaptor.capture(),
|
|
1300
|
+
configCaptor.capture(),
|
|
1301
|
+
eq(configuration.trackingConsent.asTrackingConsent())
|
|
1302
|
+
)
|
|
1303
|
+
verify(mockDatadog).registerRumMonitor(any())
|
|
1304
|
+
}
|
|
1305
|
+
assertThat(configCaptor.firstValue)
|
|
1306
|
+
.hasField("rumConfig") {
|
|
1307
|
+
it.hasFieldEqualTo("vitalsMonitorUpdateFrequency", VitalsUpdateFrequency.AVERAGE)
|
|
1308
|
+
}
|
|
1309
|
+
argumentCaptor<Choreographer.FrameCallback> {
|
|
1310
|
+
verify(mockChoreographer).postFrameCallback(capture())
|
|
1311
|
+
assertThat(firstValue).isInstanceOf(VitalFrameCallback::class.java)
|
|
1312
|
+
|
|
1313
|
+
// When
|
|
1314
|
+
firstValue.doFrame(timestampNs)
|
|
1315
|
+
firstValue.doFrame(timestampNs + frameDurationNs)
|
|
1316
|
+
|
|
1317
|
+
// then
|
|
1318
|
+
verify(mockRumMonitor._getInternal()!!).updatePerformanceMetric(
|
|
1319
|
+
RumPerformanceMetric.JS_FRAME_TIME,
|
|
1320
|
+
frameDurationNs.toDouble()
|
|
1321
|
+
)
|
|
1322
|
+
verify(mockRumMonitor._getInternal()!!, never()).addLongTask(
|
|
1323
|
+
frameDurationNs,
|
|
1324
|
+
"javascript"
|
|
1325
|
+
)
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
@Test
|
|
1330
|
+
fun `𝕄 send long tasks 𝕎 frame time is over threshold() {}`(
|
|
1331
|
+
@LongForgery(min = 0L) timestampNs: Long,
|
|
1332
|
+
@LongForgery(min = ONE_HUNDRED_MILLISSECOND_NS, max = 5 * ONE_SECOND_NS) threshold: Long,
|
|
1333
|
+
@LongForgery(min = 1, max = ONE_SECOND_NS) frameDurationOverThreshold: Long,
|
|
1334
|
+
@Forgery configuration: DdSdkConfiguration
|
|
1335
|
+
) {
|
|
1336
|
+
// Given
|
|
1337
|
+
val bridgeConfiguration = configuration.copy(
|
|
1338
|
+
vitalsUpdateFrequency = "AVERAGE",
|
|
1339
|
+
longTaskThresholdMs = (threshold / 1_000_000).toDouble(),
|
|
1340
|
+
)
|
|
1341
|
+
val frameDurationNs = threshold + frameDurationOverThreshold
|
|
1342
|
+
|
|
1343
|
+
// When
|
|
1344
|
+
testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
1345
|
+
|
|
1346
|
+
// Then
|
|
1347
|
+
argumentCaptor<Choreographer.FrameCallback> {
|
|
1348
|
+
verify(mockChoreographer).postFrameCallback(capture())
|
|
1349
|
+
|
|
1350
|
+
// When
|
|
1351
|
+
firstValue.doFrame(timestampNs)
|
|
1352
|
+
firstValue.doFrame(timestampNs + frameDurationNs)
|
|
1353
|
+
|
|
1354
|
+
// then
|
|
1355
|
+
verify(mockRumMonitor._getInternal()!!).updatePerformanceMetric(
|
|
1356
|
+
RumPerformanceMetric.JS_FRAME_TIME,
|
|
1357
|
+
frameDurationNs.toDouble()
|
|
1358
|
+
)
|
|
1359
|
+
verify(mockRumMonitor._getInternal()!!).addLongTask(
|
|
1360
|
+
frameDurationNs,
|
|
1361
|
+
"javascript"
|
|
1362
|
+
)
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
@Test
|
|
1367
|
+
fun `𝕄 send long tasks 𝕎 frame time is over threshold() { never vitals frequency update }`(
|
|
1368
|
+
@LongForgery(min = 0L) timestampNs: Long,
|
|
1369
|
+
@LongForgery(min = ONE_HUNDRED_MILLISSECOND_NS, max = 5 * ONE_SECOND_NS) threshold: Long,
|
|
1370
|
+
@LongForgery(min = 1, max = ONE_SECOND_NS) frameDurationOverThreshold: Long,
|
|
1371
|
+
@Forgery configuration: DdSdkConfiguration
|
|
1372
|
+
) {
|
|
1373
|
+
// Given
|
|
1374
|
+
val bridgeConfiguration = configuration.copy(
|
|
1375
|
+
vitalsUpdateFrequency = "NEVER",
|
|
1376
|
+
longTaskThresholdMs = (threshold / 1_000_000).toDouble(),
|
|
1377
|
+
)
|
|
1378
|
+
val frameDurationNs = threshold + frameDurationOverThreshold
|
|
1379
|
+
|
|
1380
|
+
// When
|
|
1381
|
+
testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
1382
|
+
|
|
1383
|
+
// Then
|
|
1384
|
+
argumentCaptor<Choreographer.FrameCallback> {
|
|
1385
|
+
verify(mockChoreographer).postFrameCallback(capture())
|
|
1386
|
+
|
|
1387
|
+
// When
|
|
1388
|
+
firstValue.doFrame(timestampNs)
|
|
1389
|
+
firstValue.doFrame(timestampNs + frameDurationNs)
|
|
1390
|
+
|
|
1391
|
+
// Then
|
|
1392
|
+
verify(mockRumMonitor._getInternal()!!).addLongTask(
|
|
1393
|
+
frameDurationNs,
|
|
1394
|
+
"javascript"
|
|
1395
|
+
)
|
|
1396
|
+
verify(mockRumMonitor._getInternal()!!, never()).updatePerformanceMetric(
|
|
1397
|
+
RumPerformanceMetric.JS_FRAME_TIME,
|
|
1398
|
+
frameDurationNs.toDouble()
|
|
1399
|
+
)
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1072
1403
|
// endregion
|
|
1073
1404
|
|
|
1074
1405
|
// region version suffix
|
|
1075
1406
|
|
|
1076
1407
|
@Test
|
|
1077
1408
|
fun `𝕄 set version 𝕎 initialize() {versionSuffix}`(
|
|
1078
|
-
|
|
1079
|
-
|
|
1409
|
+
@Forgery configuration: DdSdkConfiguration,
|
|
1410
|
+
@StringForgery versionSuffix: String
|
|
1080
1411
|
) {
|
|
1081
1412
|
// Given
|
|
1082
1413
|
val bridgeConfiguration = configuration.copy(
|
|
1083
|
-
|
|
1084
|
-
|
|
1414
|
+
additionalConfig = mapOf(
|
|
1415
|
+
DdSdk.DD_VERSION_SUFFIX to versionSuffix
|
|
1416
|
+
)
|
|
1417
|
+
)
|
|
1418
|
+
val configCaptor = argumentCaptor<Configuration>()
|
|
1419
|
+
|
|
1420
|
+
// When
|
|
1421
|
+
testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
1422
|
+
|
|
1423
|
+
// Then
|
|
1424
|
+
verify(mockDatadog).initialize(
|
|
1425
|
+
same(mockContext),
|
|
1426
|
+
any(),
|
|
1427
|
+
configCaptor.capture(),
|
|
1428
|
+
eq(configuration.trackingConsent.asTrackingConsent())
|
|
1429
|
+
)
|
|
1430
|
+
assertThat(configCaptor.firstValue)
|
|
1431
|
+
.hasFieldEqualTo(
|
|
1432
|
+
"additionalConfig",
|
|
1433
|
+
mapOf(
|
|
1434
|
+
DdSdk.DD_VERSION_SUFFIX to versionSuffix,
|
|
1435
|
+
DdSdk.DD_VERSION to mockPackageInfo.versionName + versionSuffix
|
|
1085
1436
|
)
|
|
1437
|
+
)
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
// endregion
|
|
1441
|
+
|
|
1442
|
+
// region configuration telemetry mapper
|
|
1443
|
+
|
|
1444
|
+
@Test
|
|
1445
|
+
fun `𝕄 set telemetry configuration mapper 𝕎 initialize() {}`(
|
|
1446
|
+
@Forgery configuration: DdSdkConfiguration,
|
|
1447
|
+
@Forgery telemetryConfigurationEvent: TelemetryConfigurationEvent,
|
|
1448
|
+
@BoolForgery trackNativeViews: Boolean,
|
|
1449
|
+
@BoolForgery trackNativeErrors: Boolean,
|
|
1450
|
+
@StringForgery initializationType: String,
|
|
1451
|
+
@BoolForgery trackInteractions: Boolean,
|
|
1452
|
+
@BoolForgery trackErrors: Boolean,
|
|
1453
|
+
@BoolForgery trackNetworkRequests: Boolean
|
|
1454
|
+
) {
|
|
1455
|
+
// Given
|
|
1456
|
+
val bridgeConfiguration = configuration.copy(
|
|
1457
|
+
nativeCrashReportEnabled = trackNativeErrors,
|
|
1458
|
+
nativeLongTaskThresholdMs = 0.0,
|
|
1459
|
+
longTaskThresholdMs = 0.0,
|
|
1460
|
+
configurationForTelemetry = ConfigurationForTelemetry(
|
|
1461
|
+
initializationType = initializationType,
|
|
1462
|
+
trackErrors = trackErrors,
|
|
1463
|
+
trackInteractions = trackInteractions,
|
|
1464
|
+
trackNetworkRequests = trackNetworkRequests
|
|
1465
|
+
)
|
|
1086
1466
|
)
|
|
1087
1467
|
val configCaptor = argumentCaptor<Configuration>()
|
|
1088
1468
|
|
|
@@ -1091,19 +1471,36 @@ internal class DdSdkTest {
|
|
|
1091
1471
|
|
|
1092
1472
|
// Then
|
|
1093
1473
|
verify(mockDatadog).initialize(
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1474
|
+
same(mockContext),
|
|
1475
|
+
any(),
|
|
1476
|
+
configCaptor.capture(),
|
|
1477
|
+
eq(configuration.trackingConsent.asTrackingConsent())
|
|
1098
1478
|
)
|
|
1099
1479
|
assertThat(configCaptor.firstValue)
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1480
|
+
.hasField("rumConfig") {
|
|
1481
|
+
val configurationMapper = it
|
|
1482
|
+
.getActualValue<EventMapper<TelemetryConfigurationEvent>>("rumEventMapper")
|
|
1483
|
+
val result = configurationMapper.map(telemetryConfigurationEvent)!!
|
|
1484
|
+
assertThat(result.telemetry.configuration.trackNativeErrors!!).isEqualTo(
|
|
1485
|
+
trackNativeErrors
|
|
1106
1486
|
)
|
|
1487
|
+
assertThat(result.telemetry.configuration.trackCrossPlatformLongTasks!!)
|
|
1488
|
+
.isEqualTo(false)
|
|
1489
|
+
assertThat(result.telemetry.configuration.trackLongTask!!)
|
|
1490
|
+
.isEqualTo(false)
|
|
1491
|
+
assertThat(result.telemetry.configuration.trackNativeLongTasks!!)
|
|
1492
|
+
.isEqualTo(false)
|
|
1493
|
+
|
|
1494
|
+
assertThat(result.telemetry.configuration.initializationType!!)
|
|
1495
|
+
.isEqualTo(initializationType)
|
|
1496
|
+
assertThat(result.telemetry.configuration.trackInteractions!!)
|
|
1497
|
+
.isEqualTo(trackInteractions)
|
|
1498
|
+
assertThat(result.telemetry.configuration.trackErrors!!).isEqualTo(trackErrors)
|
|
1499
|
+
assertThat(result.telemetry.configuration.trackResources!!)
|
|
1500
|
+
.isEqualTo(trackNetworkRequests)
|
|
1501
|
+
assertThat(result.telemetry.configuration.trackNetworkRequests!!)
|
|
1502
|
+
.isEqualTo(trackNetworkRequests)
|
|
1503
|
+
}
|
|
1107
1504
|
}
|
|
1108
1505
|
|
|
1109
1506
|
// endregion
|
|
@@ -1544,4 +1941,9 @@ internal class DdSdkTest {
|
|
|
1544
1941
|
}
|
|
1545
1942
|
|
|
1546
1943
|
// endregion
|
|
1944
|
+
|
|
1945
|
+
companion object {
|
|
1946
|
+
const val ONE_HUNDRED_MILLISSECOND_NS: Long = 100 * 1000L * 1000L
|
|
1947
|
+
const val ONE_SECOND_NS: Long = 1000L * 1000L * 1000L
|
|
1948
|
+
}
|
|
1547
1949
|
}
|
|
@@ -98,7 +98,11 @@ internal class DdTraceTest {
|
|
|
98
98
|
@BeforeEach
|
|
99
99
|
fun `set up`() {
|
|
100
100
|
whenever(mockTracer.buildSpan(fakeOperation)) doReturn mockSpanBuilder
|
|
101
|
-
whenever(
|
|
101
|
+
whenever(
|
|
102
|
+
mockSpanBuilder.withStartTimestamp(
|
|
103
|
+
fakeTimestamp.toLong() * 1000
|
|
104
|
+
)
|
|
105
|
+
) doReturn mockSpanBuilder
|
|
102
106
|
whenever(mockSpanBuilder.start()) doReturn mockSpan
|
|
103
107
|
whenever(mockSpan.context()) doReturn mockSpanContext
|
|
104
108
|
whenever(mockSpanContext.toSpanId()) doReturn fakeSpanId
|
|
@@ -3,10 +3,13 @@
|
|
|
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
|
+
import com.datadog.android.core.configuration.VitalsUpdateFrequency
|
|
10
|
+
import com.datadog.reactnative.ConfigurationForTelemetry
|
|
9
11
|
import com.datadog.reactnative.DdSdkConfiguration
|
|
12
|
+
import com.datadog.reactnative.toReadableMap
|
|
10
13
|
import com.facebook.react.bridge.ReadableMap
|
|
11
14
|
|
|
12
15
|
fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
|
|
@@ -19,6 +22,16 @@ fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
|
|
|
19
22
|
} else {
|
|
20
23
|
nativeCrashReportEnabled
|
|
21
24
|
}
|
|
25
|
+
map["nativeLongTaskThresholdMs"] = if (nativeLongTaskThresholdMs == null) {
|
|
26
|
+
0f
|
|
27
|
+
} else {
|
|
28
|
+
nativeLongTaskThresholdMs
|
|
29
|
+
}
|
|
30
|
+
map["longTaskThresholdMs"] = if (longTaskThresholdMs == null) {
|
|
31
|
+
0f
|
|
32
|
+
} else {
|
|
33
|
+
longTaskThresholdMs
|
|
34
|
+
}
|
|
22
35
|
if (sampleRate != null) {
|
|
23
36
|
map["sampleRate"] = sampleRate
|
|
24
37
|
} else {
|
|
@@ -26,8 +39,34 @@ fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
|
|
|
26
39
|
// ReadableMap#getDouble which doesn't allow having null value
|
|
27
40
|
map["sampleRate"] = 100f
|
|
28
41
|
}
|
|
42
|
+
if (telemetrySampleRate != null) {
|
|
43
|
+
map["telemetrySampleRate"] = telemetrySampleRate
|
|
44
|
+
} else {
|
|
45
|
+
// we have to put something, because ReadableMap.asDdSdkConfiguration() will call
|
|
46
|
+
// ReadableMap#getDouble which doesn't allow having null value
|
|
47
|
+
map["telemetrySampleRate"] = 20f
|
|
48
|
+
}
|
|
29
49
|
site?.let { map.put("site", it) }
|
|
30
50
|
trackingConsent?.let { map.put("trackingConsent", it) }
|
|
51
|
+
if (vitalsUpdateFrequency != null) {
|
|
52
|
+
map["vitalsUpdateFrequency"] = vitalsUpdateFrequency
|
|
53
|
+
} else {
|
|
54
|
+
// we have to put something, because ReadableMap.asDdSdkConfiguration() will call
|
|
55
|
+
// ReadableMap#getString which doesn't allow having null value
|
|
56
|
+
map["vitalsUpdateFrequency"] = VitalsUpdateFrequency.AVERAGE.toString()
|
|
57
|
+
}
|
|
31
58
|
additionalConfig?.let { map.put("additionalConfig", it.toReadableMap()) }
|
|
59
|
+
configurationForTelemetry?.let {
|
|
60
|
+
map.put("configurationForTelemetry", it.toReadableJavaOnlyMap())
|
|
61
|
+
}
|
|
62
|
+
return map.toReadableMap()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
internal fun ConfigurationForTelemetry.toReadableJavaOnlyMap(): ReadableMap {
|
|
66
|
+
val map = mutableMapOf<String, Any?>()
|
|
67
|
+
initializationType?.let { map.put("initializationType", it) }
|
|
68
|
+
trackErrors?.let { map.put("trackErrors", it) }
|
|
69
|
+
trackInteractions?.let { map.put("trackInteractions", it) }
|
|
70
|
+
trackNetworkRequests?.let { map.put("trackNetworkRequests", it) }
|
|
32
71
|
return map.toReadableMap()
|
|
33
72
|
}
|