@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
|
@@ -51,4 +51,16 @@ internal class DatadogSDKWrapper : DatadogWrapper {
|
|
|
51
51
|
override fun setTrackingConsent(trackingConsent: TrackingConsent) {
|
|
52
52
|
Datadog.setTrackingConsent(trackingConsent)
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
override fun telemetryDebug(message: String) {
|
|
56
|
+
Datadog._internal._telemetry.debug(message)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
override fun telemetryError(message: String, stack: String?, kind: String?) {
|
|
60
|
+
Datadog._internal._telemetry.error(message, stack, kind)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
override fun telemetryError(message: String, throwable: Throwable?) {
|
|
64
|
+
Datadog._internal._telemetry.error(message, throwable)
|
|
65
|
+
}
|
|
54
66
|
}
|
|
@@ -83,4 +83,19 @@ interface DatadogWrapper {
|
|
|
83
83
|
* Sets tracking consent.
|
|
84
84
|
*/
|
|
85
85
|
fun setTrackingConsent(trackingConsent: TrackingConsent)
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Sends telemetry debug event.
|
|
89
|
+
*/
|
|
90
|
+
fun telemetryDebug(message: String)
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Sends telemetry error.
|
|
94
|
+
*/
|
|
95
|
+
fun telemetryError(message: String, stack: String?, kind: String?)
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Sends telemetry error.
|
|
99
|
+
*/
|
|
100
|
+
fun telemetryError(message: String, throwable: Throwable?)
|
|
86
101
|
}
|
|
@@ -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
|
}
|
|
@@ -95,6 +108,28 @@ class DdSdk(
|
|
|
95
108
|
promise.resolve(null)
|
|
96
109
|
}
|
|
97
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Sends a telemetry debug event.
|
|
113
|
+
* @param message Debug message.
|
|
114
|
+
*/
|
|
115
|
+
@ReactMethod
|
|
116
|
+
fun telemetryDebug(message: String, promise: Promise) {
|
|
117
|
+
datadog.telemetryDebug(message)
|
|
118
|
+
promise.resolve(null)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Sends a telemetry error event.
|
|
123
|
+
* @param message Error message.
|
|
124
|
+
* @param stack Error stack.
|
|
125
|
+
* @param kind Error kind.
|
|
126
|
+
*/
|
|
127
|
+
@ReactMethod
|
|
128
|
+
fun telemetryError(message: String, stack: String, kind: String, promise: Promise) {
|
|
129
|
+
datadog.telemetryError(message, stack, kind)
|
|
130
|
+
promise.resolve(null)
|
|
131
|
+
}
|
|
132
|
+
|
|
98
133
|
// endregion
|
|
99
134
|
|
|
100
135
|
// region Internal
|
|
@@ -118,6 +153,7 @@ class DdSdk(
|
|
|
118
153
|
val packageInfo = try {
|
|
119
154
|
appContext.packageManager.getPackageInfo(packageName, 0)
|
|
120
155
|
} catch (e: PackageManager.NameNotFoundException) {
|
|
156
|
+
datadog.telemetryError(e.message ?: PACKAGE_INFO_NOT_FOUND_ERROR_MESSAGE, e)
|
|
121
157
|
return DEFAULT_APP_VERSION
|
|
122
158
|
}
|
|
123
159
|
|
|
@@ -131,7 +167,7 @@ class DdSdk(
|
|
|
131
167
|
|
|
132
168
|
@Suppress("ComplexMethod", "UnsafeCallOnNullableType")
|
|
133
169
|
private fun buildConfiguration(configuration: DdSdkConfiguration): Configuration {
|
|
134
|
-
val additionalConfig = configuration.additionalConfig?.toMutableMap()
|
|
170
|
+
val additionalConfig = configuration.additionalConfig?.toMutableMap()
|
|
135
171
|
|
|
136
172
|
val versionSuffix = configuration.additionalConfig?.get(DD_VERSION_SUFFIX) as? String
|
|
137
173
|
if (versionSuffix != null && additionalConfig != null) {
|
|
@@ -155,6 +191,17 @@ class DdSdk(
|
|
|
155
191
|
}
|
|
156
192
|
|
|
157
193
|
configBuilder.useSite(buildSite(configuration.site))
|
|
194
|
+
configBuilder.setVitalsUpdateFrequency(
|
|
195
|
+
buildVitalUpdateFrequency(configuration.vitalsUpdateFrequency)
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
val telemetrySampleRate = (configuration.telemetrySampleRate as? Number)?.toFloat()
|
|
199
|
+
telemetrySampleRate?.let { configBuilder.sampleTelemetry(it) }
|
|
200
|
+
|
|
201
|
+
val longTask = (configuration.nativeLongTaskThresholdMs as? Number)?.toLong()
|
|
202
|
+
if (longTask != null) {
|
|
203
|
+
configBuilder.trackLongTasks(longTask)
|
|
204
|
+
}
|
|
158
205
|
|
|
159
206
|
val viewTracking = configuration.additionalConfig?.get(DD_NATIVE_VIEW_TRACKING) as? Boolean
|
|
160
207
|
if (viewTracking == true) {
|
|
@@ -164,12 +211,6 @@ class DdSdk(
|
|
|
164
211
|
configBuilder.useViewTrackingStrategy(NoOpViewTrackingStrategy)
|
|
165
212
|
}
|
|
166
213
|
|
|
167
|
-
val longTask =
|
|
168
|
-
(configuration.additionalConfig?.get(DD_LONG_TASK_THRESHOLD) as? Number)?.toLong()
|
|
169
|
-
if (longTask != null) {
|
|
170
|
-
configBuilder.trackLongTasks(longTask)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
214
|
val firstPartyHosts =
|
|
174
215
|
(configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? List<String>)
|
|
175
216
|
if (firstPartyHosts != null) {
|
|
@@ -180,6 +221,36 @@ class DdSdk(
|
|
|
180
221
|
configBuilder.setProxy(proxy, authenticator)
|
|
181
222
|
}
|
|
182
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
|
+
|
|
183
254
|
return configBuilder.build()
|
|
184
255
|
}
|
|
185
256
|
|
|
@@ -260,6 +331,69 @@ class DdSdk(
|
|
|
260
331
|
}
|
|
261
332
|
}
|
|
262
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
|
+
|
|
263
397
|
// endregion
|
|
264
398
|
|
|
265
399
|
companion object {
|
|
@@ -267,7 +401,6 @@ class DdSdk(
|
|
|
267
401
|
internal const val DD_NATIVE_VIEW_TRACKING = "_dd.native_view_tracking"
|
|
268
402
|
internal const val DD_SDK_VERBOSITY = "_dd.sdk_verbosity"
|
|
269
403
|
internal const val DD_SERVICE_NAME = "_dd.service_name"
|
|
270
|
-
internal const val DD_LONG_TASK_THRESHOLD = "_dd.long_task.threshold"
|
|
271
404
|
internal const val DD_FIRST_PARTY_HOSTS = "_dd.first_party_hosts"
|
|
272
405
|
internal const val DD_VERSION = "_dd.version"
|
|
273
406
|
internal const val DD_VERSION_SUFFIX = "_dd.version_suffix"
|
|
@@ -276,5 +409,7 @@ class DdSdk(
|
|
|
276
409
|
internal const val DD_PROXY_TYPE = "_dd.proxy.type"
|
|
277
410
|
internal const val DD_PROXY_USERNAME = "_dd.proxy.username"
|
|
278
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"
|
|
279
414
|
}
|
|
280
415
|
}
|
|
@@ -12,18 +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'.
|
|
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').
|
|
18
22
|
* @param additionalConfig Additional configuration parameters.
|
|
23
|
+
* @param configurationForTelemetry Additional configuration data for Datadog telemetry.
|
|
19
24
|
*/
|
|
20
25
|
data class DdSdkConfiguration(
|
|
21
26
|
val clientToken: String,
|
|
22
27
|
val env: String,
|
|
23
28
|
val applicationId: String? = null,
|
|
24
29
|
val nativeCrashReportEnabled: Boolean? = null,
|
|
30
|
+
val nativeLongTaskThresholdMs: Double? = null,
|
|
31
|
+
val longTaskThresholdMs: Double? = null,
|
|
25
32
|
val sampleRate: Double? = null,
|
|
26
33
|
val site: String? = null,
|
|
27
34
|
val trackingConsent: String? = null,
|
|
28
|
-
val
|
|
35
|
+
val telemetrySampleRate: Double? = null,
|
|
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
|
|
29
53
|
)
|
|
@@ -15,22 +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"),
|
|
24
|
+
vitalsUpdateFrequency = getString("vitalsUpdateFrequency"),
|
|
25
|
+
additionalConfig = getMap("additionalConfig")?.toHashMap(),
|
|
26
|
+
configurationForTelemetry = getMap(
|
|
27
|
+
"configurationForTelemetry"
|
|
28
|
+
)?.asConfigurationForTelemetry()
|
|
22
29
|
)
|
|
23
30
|
}
|
|
24
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")
|
|
25
42
|
internal fun DdSdkConfiguration.toReadableMap(): ReadableMap {
|
|
26
43
|
val map = WritableNativeMap()
|
|
27
44
|
map.putString("clientToken", clientToken)
|
|
28
45
|
map.putString("env", env)
|
|
29
46
|
applicationId?.let { map.putString("applicationId", it) }
|
|
30
47
|
nativeCrashReportEnabled?.let { map.putBoolean("nativeCrashReportEnabled", it) }
|
|
48
|
+
nativeLongTaskThresholdMs?.let { map.putDouble("nativeLongTaskThresholdMs", it) }
|
|
49
|
+
longTaskThresholdMs?.let { map.putDouble("longTaskThresholdMs", it) }
|
|
31
50
|
sampleRate?.let { map.putDouble("sampleRate", it) }
|
|
32
51
|
site?.let { map.putString("site", it) }
|
|
33
52
|
trackingConsent?.let { map.putString("trackingConsent", it) }
|
|
53
|
+
telemetrySampleRate?.let { map.putDouble("telemetrySampleRate", it) }
|
|
54
|
+
vitalsUpdateFrequency?.let { map.putString("vitalsUpdateFrequency", it) }
|
|
34
55
|
additionalConfig?.let { map.putMap("additionalConfig", it.toWritableMap()) }
|
|
35
56
|
return map
|
|
36
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
|