@datadog/mobile-react-native 1.2.0-beta1 → 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/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
|
@@ -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
|
|
@@ -1052,17 +1114,11 @@ internal class DdSdkTest {
|
|
|
1052
1114
|
@Forgery configuration: DdSdkConfiguration,
|
|
1053
1115
|
forge: Forge
|
|
1054
1116
|
) {
|
|
1055
|
-
|
|
1056
|
-
val threshold = forge.anElementFrom(
|
|
1057
|
-
forge.aLong(min = 0, max = 65536),
|
|
1058
|
-
forge.aDouble(min = 0.0, max = 65536.0)
|
|
1059
|
-
)
|
|
1117
|
+
val threshold = forge.aDouble(min = 100.0, max = 65536.0)
|
|
1060
1118
|
|
|
1061
1119
|
// Given
|
|
1062
1120
|
val bridgeConfiguration = configuration.copy(
|
|
1063
|
-
|
|
1064
|
-
DdSdk.DD_LONG_TASK_THRESHOLD to threshold
|
|
1065
|
-
)
|
|
1121
|
+
nativeLongTaskThresholdMs = threshold
|
|
1066
1122
|
)
|
|
1067
1123
|
val credentialCaptor = argumentCaptor<Credentials>()
|
|
1068
1124
|
val configCaptor = argumentCaptor<Configuration>()
|
|
@@ -1090,6 +1146,34 @@ internal class DdSdkTest {
|
|
|
1090
1146
|
}
|
|
1091
1147
|
}
|
|
1092
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
|
+
|
|
1093
1177
|
@Test
|
|
1094
1178
|
fun `𝕄 set first party hosts 𝕎 initialize() {first party hosts}`(
|
|
1095
1179
|
@Forgery configuration: DdSdkConfiguration,
|
|
@@ -1121,20 +1205,264 @@ internal class DdSdkTest {
|
|
|
1121
1205
|
}
|
|
1122
1206
|
}
|
|
1123
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
|
+
|
|
1124
1403
|
// endregion
|
|
1125
1404
|
|
|
1126
1405
|
// region version suffix
|
|
1127
1406
|
|
|
1128
1407
|
@Test
|
|
1129
1408
|
fun `𝕄 set version 𝕎 initialize() {versionSuffix}`(
|
|
1130
|
-
|
|
1131
|
-
|
|
1409
|
+
@Forgery configuration: DdSdkConfiguration,
|
|
1410
|
+
@StringForgery versionSuffix: String
|
|
1132
1411
|
) {
|
|
1133
1412
|
// Given
|
|
1134
1413
|
val bridgeConfiguration = configuration.copy(
|
|
1135
|
-
|
|
1136
|
-
|
|
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
|
|
1137
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
|
+
)
|
|
1138
1466
|
)
|
|
1139
1467
|
val configCaptor = argumentCaptor<Configuration>()
|
|
1140
1468
|
|
|
@@ -1143,19 +1471,36 @@ internal class DdSdkTest {
|
|
|
1143
1471
|
|
|
1144
1472
|
// Then
|
|
1145
1473
|
verify(mockDatadog).initialize(
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1474
|
+
same(mockContext),
|
|
1475
|
+
any(),
|
|
1476
|
+
configCaptor.capture(),
|
|
1477
|
+
eq(configuration.trackingConsent.asTrackingConsent())
|
|
1150
1478
|
)
|
|
1151
1479
|
assertThat(configCaptor.firstValue)
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
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
|
|
1158
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
|
+
}
|
|
1159
1504
|
}
|
|
1160
1505
|
|
|
1161
1506
|
// endregion
|
|
@@ -1596,4 +1941,9 @@ internal class DdSdkTest {
|
|
|
1596
1941
|
}
|
|
1597
1942
|
|
|
1598
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
|
+
}
|
|
1599
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 {
|
|
@@ -35,6 +48,25 @@ fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
|
|
|
35
48
|
}
|
|
36
49
|
site?.let { map.put("site", it) }
|
|
37
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
|
+
}
|
|
38
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) }
|
|
39
71
|
return map.toReadableMap()
|
|
40
72
|
}
|
|
@@ -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)
|
|
@@ -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
|
}
|