@datadog/mobile-react-native 3.3.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DatadogSDKReactNative.podspec +7 -7
- package/android/build.gradle +7 -7
- package/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +4 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +13 -5
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +14 -6
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkSessionStartedListener.kt +93 -22
- package/android/src/main/kotlin/com/datadog/reactnative/FrameRateProvider.kt +16 -8
- package/android/src/main/kotlin/com/datadog/reactnative/JsThreadExecutor.kt +27 -0
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/android/src/newarch/kotlin/com/datadog/reactnative/DdRum.kt +5 -1
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdRum.kt +5 -1
- package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +9 -1
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +68 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkSessionStartedListenerTest.kt +38 -1
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +63 -5
- package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +25 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/TestJsThreadExecutor.kt +16 -0
- package/ios/Sources/DdRum.mm +6 -4
- package/ios/Sources/DdRumImplementation.swift +82 -7
- package/ios/Sources/DdSdkNativeInitialization.swift +24 -17
- package/ios/Sources/DdSdkSessionStartedListener.swift +28 -1
- package/ios/Sources/RNDdSdkConfiguration.swift +2 -0
- package/ios/Sources/RNViewResolution.swift +88 -0
- package/ios/Sources/RUMMonitorInternalProtocol.swift +8 -0
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/DdSdkReactNative.js +25 -21
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/config/DatadogProviderConfiguration.js +3 -1
- package/lib/commonjs/config/DatadogProviderConfiguration.js.map +1 -1
- package/lib/commonjs/metro/debugIdResolver.js +5 -3
- package/lib/commonjs/metro/debugIdResolver.js.map +1 -1
- package/lib/commonjs/metro/plugin/metroSerializer.js +4 -3
- package/lib/commonjs/metro/plugin/metroSerializer.js.map +1 -1
- package/lib/commonjs/rum/DdRum.js +14 -1
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/rum/eventMappers/actionEventMapper.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/commonjs/sdk/AttributesEncoding/defaultEncoders.js +6 -1
- package/lib/commonjs/sdk/AttributesEncoding/defaultEncoders.js.map +1 -1
- package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js +13 -1
- package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -1
- package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/DdSdkReactNative.js +25 -21
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/config/DatadogProviderConfiguration.js +3 -1
- package/lib/module/config/DatadogProviderConfiguration.js.map +1 -1
- package/lib/module/metro/debugIdResolver.js +5 -3
- package/lib/module/metro/debugIdResolver.js.map +1 -1
- package/lib/module/metro/plugin/metroSerializer.js +4 -3
- package/lib/module/metro/plugin/metroSerializer.js.map +1 -1
- package/lib/module/rum/DdRum.js +14 -1
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/rum/eventMappers/actionEventMapper.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
- package/lib/module/sdk/AttributesEncoding/defaultEncoders.js +6 -1
- package/lib/module/sdk/AttributesEncoding/defaultEncoders.js.map +1 -1
- package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js +13 -1
- package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -1
- package/lib/module/specs/NativeDdRum.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts +6 -9
- package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
- package/lib/typescript/config/DatadogProviderConfiguration.d.ts +3 -1
- package/lib/typescript/config/DatadogProviderConfiguration.d.ts.map +1 -1
- package/lib/typescript/metro/debugIdResolver.d.ts.map +1 -1
- package/lib/typescript/metro/plugin/metroSerializer.d.ts +1 -1
- package/lib/typescript/metro/plugin/metroSerializer.d.ts.map +1 -1
- package/lib/typescript/nativeModulesTypes.d.ts +2 -1
- package/lib/typescript/nativeModulesTypes.d.ts.map +1 -1
- package/lib/typescript/rum/DdRum.d.ts.map +1 -1
- package/lib/typescript/rum/eventMappers/actionEventMapper.d.ts +1 -0
- package/lib/typescript/rum/eventMappers/actionEventMapper.d.ts.map +1 -1
- package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
- package/lib/typescript/sdk/AttributesEncoding/defaultEncoders.d.ts.map +1 -1
- package/lib/typescript/sdk/UserInfoSingleton/UserInfoSingleton.d.ts +4 -1
- package/lib/typescript/sdk/UserInfoSingleton/UserInfoSingleton.d.ts.map +1 -1
- package/lib/typescript/sdk/UserInfoSingleton/types.d.ts +1 -1
- package/lib/typescript/sdk/UserInfoSingleton/types.d.ts.map +1 -1
- package/lib/typescript/specs/NativeDdRum.d.ts +2 -1
- package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +8 -7
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/DdSdkReactNative.tsx +35 -31
- package/src/__tests__/DdSdkReactNative.test.tsx +22 -3
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +8 -0
- package/src/config/DatadogProviderConfiguration.ts +3 -1
- package/src/metro/__tests__/metro.test.ts +13 -0
- package/src/metro/debugIdResolver.ts +7 -3
- package/src/metro/plugin/metroSerializer.ts +11 -3
- package/src/nativeModulesTypes.ts +2 -0
- package/src/rum/DdRum.ts +25 -0
- package/src/rum/__tests__/DdRum.test.ts +33 -0
- package/src/rum/eventMappers/actionEventMapper.ts +1 -0
- package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +2 -1
- package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +28 -0
- package/src/sdk/AttributesEncoding/__tests__/defaultEncoders.test.ts +25 -1
- package/src/sdk/AttributesEncoding/defaultEncoders.ts +11 -1
- package/src/sdk/DatadogProvider/__tests__/__utils__/renderWithProvider.tsx +24 -7
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +19 -15
- package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +85 -54
- package/src/sdk/UserInfoSingleton/UserInfoSingleton.ts +15 -2
- package/src/sdk/UserInfoSingleton/types.ts +1 -1
- package/src/specs/NativeDdRum.ts +2 -0
- package/src/types.tsx +6 -7
- package/src/version.ts +1 -1
|
@@ -19,15 +19,15 @@ Pod::Spec.new do |s|
|
|
|
19
19
|
s.dependency "React-Core"
|
|
20
20
|
|
|
21
21
|
# /!\ Remember to keep the versions in sync with DatadogSDKReactNativeSessionReplay.podspec
|
|
22
|
-
s.dependency 'DatadogCore', '3.
|
|
23
|
-
s.dependency 'DatadogLogs', '3.
|
|
24
|
-
s.dependency 'DatadogTrace', '3.
|
|
25
|
-
s.dependency 'DatadogRUM', '3.
|
|
26
|
-
s.dependency 'DatadogCrashReporting', '3.
|
|
27
|
-
s.dependency 'DatadogFlags', '3.
|
|
22
|
+
s.dependency 'DatadogCore', '3.11.0'
|
|
23
|
+
s.dependency 'DatadogLogs', '3.11.0'
|
|
24
|
+
s.dependency 'DatadogTrace', '3.11.0'
|
|
25
|
+
s.dependency 'DatadogRUM', '3.11.0'
|
|
26
|
+
s.dependency 'DatadogCrashReporting', '3.11.0'
|
|
27
|
+
s.dependency 'DatadogFlags', '3.11.0'
|
|
28
28
|
|
|
29
29
|
# DatadogWebViewTracking is not available for tvOS
|
|
30
|
-
s.ios.dependency 'DatadogWebViewTracking', '3.
|
|
30
|
+
s.ios.dependency 'DatadogWebViewTracking', '3.11.0'
|
|
31
31
|
|
|
32
32
|
s.test_spec 'Tests' do |test_spec|
|
|
33
33
|
test_spec.source_files = 'ios/Tests/**/*.{swift,json}'
|
package/android/build.gradle
CHANGED
|
@@ -200,7 +200,7 @@ dependencies {
|
|
|
200
200
|
// This breaks builds if the React Native target is below 0.76.0. as it relies on Gradle 8.5.0.
|
|
201
201
|
// To avoid this, we enforce 1.0.0-beta01 on RN < 0.76.0
|
|
202
202
|
if (reactNativeMinorVersion < 76) {
|
|
203
|
-
implementation("com.datadoghq:dd-sdk-android-rum:3.
|
|
203
|
+
implementation("com.datadoghq:dd-sdk-android-rum:3.10.0") {
|
|
204
204
|
exclude group: "androidx.metrics", module: "metrics-performance"
|
|
205
205
|
}
|
|
206
206
|
implementation "androidx.metrics:metrics-performance:1.0.0-beta01"
|
|
@@ -220,13 +220,13 @@ dependencies {
|
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
} else {
|
|
223
|
-
implementation "com.datadoghq:dd-sdk-android-rum:3.
|
|
223
|
+
implementation "com.datadoghq:dd-sdk-android-rum:3.10.0"
|
|
224
224
|
}
|
|
225
|
-
implementation "com.datadoghq:dd-sdk-android-logs:3.
|
|
226
|
-
implementation "com.datadoghq:dd-sdk-android-trace:3.
|
|
227
|
-
implementation "com.datadoghq:dd-sdk-android-webview:3.
|
|
228
|
-
implementation "com.datadoghq:dd-sdk-android-ndk:3.
|
|
229
|
-
implementation "com.datadoghq:dd-sdk-android-flags:3.
|
|
225
|
+
implementation "com.datadoghq:dd-sdk-android-logs:3.10.0"
|
|
226
|
+
implementation "com.datadoghq:dd-sdk-android-trace:3.10.0"
|
|
227
|
+
implementation "com.datadoghq:dd-sdk-android-webview:3.10.0"
|
|
228
|
+
implementation "com.datadoghq:dd-sdk-android-ndk:3.10.0"
|
|
229
|
+
implementation "com.datadoghq:dd-sdk-android-flags:3.10.0"
|
|
230
230
|
implementation "com.google.code.gson:gson:2.11.0"
|
|
231
231
|
testImplementation "org.junit.platform:junit-platform-launcher:1.6.2"
|
|
232
232
|
testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
|
|
@@ -119,12 +119,16 @@ class DdRumImplementation(private val datadog: DatadogWrapper = DatadogSDKWrappe
|
|
|
119
119
|
* Add a RUM Action.
|
|
120
120
|
* @param type The action type (tap, scroll, swipe, click, custom).
|
|
121
121
|
* @param name The action name.
|
|
122
|
+
* @param touch The native touch data for tap actions, or null for other action types.
|
|
123
|
+
* Currently unused on Android; reserved for heatmap support.
|
|
122
124
|
* @param context The additional context to send.
|
|
123
125
|
* @param timestampMs The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
124
126
|
*/
|
|
127
|
+
@Suppress("LongParameterList", "UnusedParameter")
|
|
125
128
|
fun addAction(
|
|
126
129
|
type: String,
|
|
127
130
|
name: String,
|
|
131
|
+
touch: ReadableMap?,
|
|
128
132
|
context: ReadableMap,
|
|
129
133
|
timestampMs: Double,
|
|
130
134
|
promise: Promise
|
|
@@ -30,7 +30,8 @@ class DdSdkImplementation(
|
|
|
30
30
|
private val reactContext: ReactApplicationContext,
|
|
31
31
|
private val datadog: DatadogWrapper = DatadogSDKWrapper(),
|
|
32
32
|
private val ddTelemetry: DdTelemetry = DdTelemetry(),
|
|
33
|
-
private val uiThreadExecutor: UiThreadExecutor = ReactUiThreadExecutor()
|
|
33
|
+
private val uiThreadExecutor: UiThreadExecutor = ReactUiThreadExecutor(),
|
|
34
|
+
private val jsThreadExecutor: JsThreadExecutor = ReactJsThreadExecutor(reactContext)
|
|
34
35
|
) {
|
|
35
36
|
internal val appContext: Context = reactContext.applicationContext
|
|
36
37
|
internal val initialized = AtomicBoolean(false)
|
|
@@ -45,6 +46,15 @@ class DdSdkImplementation(
|
|
|
45
46
|
fun initialize(configuration: ReadableMap, promise: Promise) {
|
|
46
47
|
val ddSdkConfiguration = configuration.asDdSdkConfiguration()
|
|
47
48
|
|
|
49
|
+
// On new arch DdSdk is a lazy TurboModule — it's instantiated on the first JS-side
|
|
50
|
+
// method call (typically this initialize()), which usually lands AFTER the activity's
|
|
51
|
+
// first onHostResume. That means registerLifecycleEvents's listener missed the first
|
|
52
|
+
// resume, reactContext is still null on the session listener, and the replay inside
|
|
53
|
+
// nativeInitialization.initialize → onRnSdkInitialized has no emitter target. Setting
|
|
54
|
+
// the reactContext here — we are provably being dispatched through an active one —
|
|
55
|
+
// closes that race so the cached session ID is delivered on the first JS init.
|
|
56
|
+
DdSdkSessionStartedListener.getInstance().setReactContext(reactContext)
|
|
57
|
+
|
|
48
58
|
val nativeInitialization = DdSdkNativeInitialization(appContext, datadog, ddTelemetry)
|
|
49
59
|
nativeInitialization.initialize(ddSdkConfiguration)
|
|
50
60
|
|
|
@@ -318,10 +328,8 @@ class DdSdkImplementation(
|
|
|
318
328
|
ddSdkConfiguration: DdSdkConfiguration
|
|
319
329
|
): FrameRateProvider? {
|
|
320
330
|
val frameTimeCallback = buildFrameTimeCallback(ddSdkConfiguration) ?: return null
|
|
321
|
-
val frameRateProvider = FrameRateProvider(frameTimeCallback,
|
|
322
|
-
|
|
323
|
-
frameRateProvider.start()
|
|
324
|
-
}
|
|
331
|
+
val frameRateProvider = FrameRateProvider(frameTimeCallback, jsThreadExecutor)
|
|
332
|
+
frameRateProvider.start()
|
|
325
333
|
|
|
326
334
|
return frameRateProvider
|
|
327
335
|
}
|
|
@@ -47,7 +47,7 @@ class DdSdkNativeInitialization internal constructor(
|
|
|
47
47
|
private val jsonFileReader: JSONFileReader = JSONFileReader()
|
|
48
48
|
) {
|
|
49
49
|
@Suppress("CyclomaticComplexMethod")
|
|
50
|
-
internal fun initialize(ddSdkConfiguration: DdSdkConfiguration) {
|
|
50
|
+
internal fun initialize(ddSdkConfiguration: DdSdkConfiguration, isCalledFromJs: Boolean = true) {
|
|
51
51
|
val sdkConfiguration = buildSdkConfiguration(ddSdkConfiguration)
|
|
52
52
|
val trackingConsent = buildTrackingConsent(ddSdkConfiguration.trackingConsent)
|
|
53
53
|
var rumConfiguration: RumConfiguration? = null
|
|
@@ -71,10 +71,14 @@ class DdSdkNativeInitialization internal constructor(
|
|
|
71
71
|
|
|
72
72
|
configureRumAndTracesForLogs(ddSdkConfiguration)
|
|
73
73
|
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
if (isCalledFromJs) {
|
|
75
|
+
DdSdkSessionStartedListener.getInstance().onRnSdkInitialized()
|
|
76
|
+
// Handles the case in which the SDK was already initialized with initFromNative.
|
|
77
|
+
if (datadog.isInitialized()) {
|
|
78
|
+
datadog.getRumMonitor().getCurrentSessionId {
|
|
79
|
+
it?.let { sessionId ->
|
|
80
|
+
DdSdkSessionStartedListener.getInstance().onSessionStarted(sessionId, false)
|
|
81
|
+
}
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
}
|
|
@@ -345,6 +349,7 @@ class DdSdkNativeInitialization internal constructor(
|
|
|
345
349
|
"us3" -> DatadogSite.US3
|
|
346
350
|
"us5" -> DatadogSite.US5
|
|
347
351
|
"us1_fed", "gov" -> DatadogSite.US1_FED
|
|
352
|
+
"us2_fed" -> DatadogSite.US2_FED
|
|
348
353
|
"ap1" -> DatadogSite.AP1
|
|
349
354
|
"ap2" -> DatadogSite.AP2
|
|
350
355
|
else -> DatadogSite.US1
|
|
@@ -413,7 +418,10 @@ class DdSdkNativeInitialization internal constructor(
|
|
|
413
418
|
fun initFromNative(appContext: Context) {
|
|
414
419
|
val nativeInitialization = DdSdkNativeInitialization(appContext.applicationContext)
|
|
415
420
|
try {
|
|
416
|
-
nativeInitialization.initialize(
|
|
421
|
+
nativeInitialization.initialize(
|
|
422
|
+
ddSdkConfiguration = nativeInitialization.getConfigurationFromJSONFile(),
|
|
423
|
+
isCalledFromJs = false
|
|
424
|
+
)
|
|
417
425
|
} catch (@Suppress("TooGenericExceptionCaught") error: Exception) {
|
|
418
426
|
Log.w(
|
|
419
427
|
DdSdkNativeInitialization::class.java.canonicalName,
|
|
@@ -14,13 +14,27 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
|
14
14
|
import org.jetbrains.annotations.TestOnly
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
internal class DdSdkSessionStartedListener private constructor(): RumSessionListener {
|
|
17
|
+
internal class DdSdkSessionStartedListener private constructor() : RumSessionListener {
|
|
18
18
|
companion object {
|
|
19
|
+
// JS-side callable module registered via BatchedBridge.registerCallableModule.
|
|
19
20
|
private const val BRIDGE_MODULE_NAME = "DatadogInternalReactBridge"
|
|
20
21
|
private const val BRIDGE_MODULE_METHOD = "__datadogOnMessageReceived"
|
|
21
22
|
|
|
22
23
|
private var instance: DdSdkSessionStartedListener? = null
|
|
23
24
|
|
|
25
|
+
// Process-level state — tracks whether JS initialize() has ever run since the
|
|
26
|
+
// app process started. Kept outside the instance on purpose: the listener
|
|
27
|
+
// singleton is recreated on every onHostPause/onHostDestroy via invalidate(),
|
|
28
|
+
// but the JS bridge module registration survives activity lifecycle events, so
|
|
29
|
+
// this flag must survive them too.
|
|
30
|
+
private var isRnSdkInitialized: Boolean = false
|
|
31
|
+
|
|
32
|
+
// Routes UI-thread dispatch through an injectable abstraction so JVM unit tests
|
|
33
|
+
// can use TestUiThreadExecutor (synchronous, no main looper required) instead of
|
|
34
|
+
// the real UiThreadUtil.
|
|
35
|
+
private var uiThreadExecutor: UiThreadExecutor = ReactUiThreadExecutor()
|
|
36
|
+
|
|
37
|
+
// Returns the shared listener instance, creating it on first call.
|
|
24
38
|
fun getInstance(): DdSdkSessionStartedListener {
|
|
25
39
|
if (instance == null) {
|
|
26
40
|
instance = DdSdkSessionStartedListener()
|
|
@@ -28,26 +42,67 @@ internal class DdSdkSessionStartedListener private constructor(): RumSessionList
|
|
|
28
42
|
return instance!!
|
|
29
43
|
}
|
|
30
44
|
|
|
45
|
+
// Resets the singleton — used in tests and on host pause/destroy to release the
|
|
46
|
+
// React context reference. Does NOT reset isRnSdkInitialized, which tracks
|
|
47
|
+
// process-level JS-bridge registration state.
|
|
31
48
|
fun invalidate() {
|
|
32
49
|
instance = null
|
|
33
50
|
}
|
|
51
|
+
|
|
52
|
+
@TestOnly
|
|
53
|
+
fun resetIsRnSdkInitialized() {
|
|
54
|
+
isRnSdkInitialized = false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@TestOnly
|
|
58
|
+
fun isRnSdkInitializedForTests(): Boolean = isRnSdkInitialized
|
|
34
59
|
}
|
|
35
60
|
|
|
36
|
-
|
|
61
|
+
// Cached so it can be delivered once the bridge becomes available.
|
|
37
62
|
private var lastSessionId: String? = null
|
|
63
|
+
|
|
64
|
+
// Set from onHostResume; null until the React activity is first resumed.
|
|
65
|
+
private var reactContext: ReactContext? = null
|
|
66
|
+
// Overridable in tests — NativeArray cannot be instantiated without the native SO.
|
|
38
67
|
private var convertToNativeArray: ((array: Array<String>) -> NativeArray?)? = null
|
|
39
|
-
|
|
68
|
+
// Overridable in tests to assert on bridge exceptions without crashing.
|
|
69
|
+
private var exceptionHandler: ((error: Exception) -> Unit)? = null
|
|
70
|
+
// Lazily resolved from BuildConfig; overridable in tests.
|
|
40
71
|
private var isNewArchitecture: Boolean? = null
|
|
41
72
|
|
|
73
|
+
// Stores the session ID and attempts immediate delivery.
|
|
42
74
|
override fun onSessionStarted(sessionId: String, isDiscarded: Boolean) {
|
|
43
|
-
|
|
75
|
+
this.lastSessionId = sessionId
|
|
76
|
+
trySendSessionStartedToJS(sessionId)
|
|
44
77
|
}
|
|
45
78
|
|
|
79
|
+
// Stores the React context and schedules a catch-up delivery for any cached session
|
|
80
|
+
// ID on the UI thread. Called from:
|
|
81
|
+
// - DdSdk#onHostResume (both architectures) via the lifecycle listener
|
|
82
|
+
// - DdSdkImplementation#initialize (new-arch race fix — the TurboModule is lazy-
|
|
83
|
+
// instantiated, so the first onHostResume may have fired before its lifecycle
|
|
84
|
+
// listener was registered; setting the context here guarantees a non-null
|
|
85
|
+
// target for onRnSdkInitialized's replay)
|
|
86
|
+
//
|
|
87
|
+
// Delivery is dispatched to the UI thread because sendSessionIdWithBridge and
|
|
88
|
+
// sendSessionIdWithEventEmitter are @MainThread. The field assignment stays
|
|
89
|
+
// synchronous so callers that rely on reactContext being set immediately after
|
|
90
|
+
// this call (e.g. a same-stack onRnSdkInitialized) see the new value.
|
|
46
91
|
fun setReactContext(reactContext: ReactContext) {
|
|
47
92
|
this.reactContext = reactContext
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
93
|
+
val cached = this.lastSessionId ?: return
|
|
94
|
+
uiThreadExecutor.runOnUiThread { trySendSessionStartedToJS(cached) }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Called when the RN SDK is initialized from JS for the first time while the native
|
|
98
|
+
// SDK was already running. At this point DatadogInternalReactBridge is guaranteed to
|
|
99
|
+
// be registered, so it is safe to deliver any session ID that was stored before the
|
|
100
|
+
// React bridge was available. Delivery is posted to the UI thread for the same
|
|
101
|
+
// reason as setReactContext.
|
|
102
|
+
fun onRnSdkInitialized() {
|
|
103
|
+
isRnSdkInitialized = true
|
|
104
|
+
val cached = this.lastSessionId ?: return
|
|
105
|
+
uiThreadExecutor.runOnUiThread { trySendSessionStartedToJS(cached) }
|
|
51
106
|
}
|
|
52
107
|
|
|
53
108
|
@TestOnly
|
|
@@ -65,14 +120,28 @@ internal class DdSdkSessionStartedListener private constructor(): RumSessionList
|
|
|
65
120
|
this.isNewArchitecture = isNewArch
|
|
66
121
|
}
|
|
67
122
|
|
|
123
|
+
@TestOnly
|
|
124
|
+
fun setIsRnSdkInitialized(value: Boolean) {
|
|
125
|
+
isRnSdkInitialized = value
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@TestOnly
|
|
129
|
+
fun setUiThreadExecutor(executor: UiThreadExecutor) {
|
|
130
|
+
uiThreadExecutor = executor
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Returns true only when it is safe to call callFunction on the JS thread.
|
|
68
134
|
private fun hasValidBridge(): Boolean {
|
|
69
135
|
val context = reactContext ?: return false
|
|
70
136
|
val instance = context.catalystInstance ?: return false
|
|
71
137
|
return !isNewArchitecture() &&
|
|
72
138
|
!instance.isDestroyed &&
|
|
73
|
-
context.hasActiveReactInstance()
|
|
139
|
+
context.hasActiveReactInstance() &&
|
|
140
|
+
isRnSdkInitialized
|
|
74
141
|
}
|
|
75
142
|
|
|
143
|
+
// Lazily cached — BuildConfig is a compile-time constant but reading it through the
|
|
144
|
+
// nullable override lets tests inject the value without reflection.
|
|
76
145
|
private fun isNewArchitecture(): Boolean {
|
|
77
146
|
isNewArchitecture?.let { return it }
|
|
78
147
|
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED.let {
|
|
@@ -81,8 +150,8 @@ internal class DdSdkSessionStartedListener private constructor(): RumSessionList
|
|
|
81
150
|
}
|
|
82
151
|
}
|
|
83
152
|
|
|
84
|
-
|
|
85
|
-
|
|
153
|
+
// Routes delivery to the appropriate path based on arch and bridge readiness.
|
|
154
|
+
private fun trySendSessionStartedToJS(sessionId: String) {
|
|
86
155
|
if (hasValidBridge()) {
|
|
87
156
|
sendSessionIdWithBridge(sessionId)
|
|
88
157
|
} else {
|
|
@@ -90,30 +159,32 @@ internal class DdSdkSessionStartedListener private constructor(): RumSessionList
|
|
|
90
159
|
}
|
|
91
160
|
}
|
|
92
161
|
|
|
162
|
+
// Old-arch delivery path via BatchedBridge.
|
|
93
163
|
@MainThread
|
|
94
164
|
private fun sendSessionIdWithBridge(sessionId: String) {
|
|
95
165
|
@Suppress("TooGenericExceptionCaught")
|
|
96
166
|
try {
|
|
97
|
-
val args = arrayOf(sessionId)
|
|
98
|
-
val nativeArray = if (convertToNativeArray != null) {
|
|
99
|
-
convertToNativeArray?.invoke(args)
|
|
100
|
-
} else {
|
|
101
|
-
WritableNativeArray().apply {
|
|
102
|
-
pushString("RUMSessionStarted")
|
|
103
|
-
pushString(sessionId)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
167
|
+
val args = arrayOf("RUMSessionStarted", sessionId)
|
|
107
168
|
reactContext?.catalystInstance?.callFunction(
|
|
108
169
|
BRIDGE_MODULE_NAME,
|
|
109
170
|
BRIDGE_MODULE_METHOD,
|
|
110
|
-
|
|
171
|
+
buildBridgeArgs(args)
|
|
111
172
|
)
|
|
112
|
-
} catch(err: Exception) {
|
|
173
|
+
} catch (err: Exception) {
|
|
113
174
|
exceptionHandler?.invoke(err)
|
|
114
175
|
}
|
|
115
176
|
}
|
|
116
177
|
|
|
178
|
+
private fun buildBridgeArgs(args: Array<String>): NativeArray? {
|
|
179
|
+
if (convertToNativeArray != null) {
|
|
180
|
+
return convertToNativeArray?.invoke(args)
|
|
181
|
+
}
|
|
182
|
+
return WritableNativeArray().apply {
|
|
183
|
+
args.forEach { pushString(it) }
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// New-arch delivery path and fallback when the bridge is not active.
|
|
117
188
|
@MainThread
|
|
118
189
|
private fun sendSessionIdWithEventEmitter(sessionId: String) {
|
|
119
190
|
val context = reactContext ?: return
|
|
@@ -10,11 +10,11 @@ import android.view.Choreographer
|
|
|
10
10
|
|
|
11
11
|
internal class FrameRateProvider(
|
|
12
12
|
reactFrameRateCallback: ((Double) -> Unit),
|
|
13
|
-
|
|
13
|
+
jsThreadExecutor: JsThreadExecutor
|
|
14
14
|
) {
|
|
15
15
|
private val frameCallback: FpsFrameCallback = FpsFrameCallback(
|
|
16
16
|
reactFrameRateCallback,
|
|
17
|
-
|
|
17
|
+
jsThreadExecutor
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
fun start() {
|
|
@@ -29,7 +29,7 @@ internal class FrameRateProvider(
|
|
|
29
29
|
|
|
30
30
|
internal class FpsFrameCallback(
|
|
31
31
|
private val reactFrameRateCallback: ((Double) -> Unit),
|
|
32
|
-
private val
|
|
32
|
+
private val jsThreadExecutor: JsThreadExecutor
|
|
33
33
|
) : Choreographer.FrameCallback {
|
|
34
34
|
|
|
35
35
|
private var choreographer: Choreographer? = null
|
|
@@ -43,16 +43,24 @@ internal class FpsFrameCallback(
|
|
|
43
43
|
choreographer?.postFrameCallback(this)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
@Suppress("SwallowedException")
|
|
46
47
|
fun start() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
// Choreographer is thread-local: we register on the JS thread so frame callbacks
|
|
49
|
+
// measure JS frame timings, matching the iOS CADisplayLink-on-JS-RunLoop approach.
|
|
50
|
+
jsThreadExecutor.runOnJsThread {
|
|
51
|
+
try {
|
|
52
|
+
val instance = Choreographer.getInstance()
|
|
53
|
+
instance.removeFrameCallback(this@FpsFrameCallback)
|
|
54
|
+
choreographer = instance
|
|
55
|
+
instance.postFrameCallback(this@FpsFrameCallback)
|
|
56
|
+
} catch (e: IllegalStateException) {
|
|
57
|
+
// Choreographer requires a Looper; guard defensively in case the JS thread lacks one.
|
|
58
|
+
}
|
|
50
59
|
}
|
|
51
60
|
}
|
|
52
61
|
|
|
53
62
|
fun stop() {
|
|
54
|
-
|
|
55
|
-
choreographer = Choreographer.getInstance()
|
|
63
|
+
jsThreadExecutor.runOnJsThread {
|
|
56
64
|
choreographer?.removeFrameCallback(this@FpsFrameCallback)
|
|
57
65
|
}
|
|
58
66
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 com.facebook.react.bridge.ReactApplicationContext
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Simple JS Thread Executor. By default it is based on [ReactApplicationContext.runOnJSQueueThread].
|
|
13
|
+
*/
|
|
14
|
+
interface JsThreadExecutor {
|
|
15
|
+
/**
|
|
16
|
+
* Runs the given runnable on the JS Thread.
|
|
17
|
+
*/
|
|
18
|
+
fun runOnJsThread(runnable: Runnable)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
internal class ReactJsThreadExecutor(
|
|
22
|
+
private val reactContext: ReactApplicationContext
|
|
23
|
+
) : JsThreadExecutor {
|
|
24
|
+
override fun runOnJsThread(runnable: Runnable) {
|
|
25
|
+
reactContext.runOnJSQueueThread(runnable)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -104,19 +104,23 @@ class DdRum(
|
|
|
104
104
|
* Add a RUM Action.
|
|
105
105
|
* @param type The action type (tap, scroll, swipe, click, custom).
|
|
106
106
|
* @param name The action name.
|
|
107
|
+
* @param touch The native touch data for tap actions, or null for other action types.
|
|
108
|
+
* Currently unused on Android; reserved for heatmap support.
|
|
107
109
|
* @param context The additional context to send.
|
|
108
110
|
* @param timestampMs The timestamp when the action occurred (in milliseconds).
|
|
109
111
|
* If not provided, current timestamp will be used.
|
|
110
112
|
*/
|
|
113
|
+
@Suppress("LongParameterList")
|
|
111
114
|
@ReactMethod
|
|
112
115
|
override fun addAction(
|
|
113
116
|
type: String,
|
|
114
117
|
name: String,
|
|
118
|
+
touch: ReadableMap?,
|
|
115
119
|
context: ReadableMap,
|
|
116
120
|
timestampMs: Double,
|
|
117
121
|
promise: Promise
|
|
118
122
|
) {
|
|
119
|
-
implementation.addAction(type, name, context, timestampMs, promise)
|
|
123
|
+
implementation.addAction(type, name, touch, context, timestampMs, promise)
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
/**
|
|
@@ -97,18 +97,22 @@ class DdRum(
|
|
|
97
97
|
* Add a RUM Action.
|
|
98
98
|
* @param type The action type (tap, scroll, swipe, click, custom).
|
|
99
99
|
* @param name The action name.
|
|
100
|
+
* @param touch The native touch data for tap actions, or null for other action types.
|
|
101
|
+
* Currently unused on Android; reserved for heatmap support.
|
|
100
102
|
* @param context The additional context to send.
|
|
101
103
|
* @param timestampMs The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
|
|
102
104
|
*/
|
|
105
|
+
@Suppress("LongParameterList")
|
|
103
106
|
@ReactMethod
|
|
104
107
|
fun addAction(
|
|
105
108
|
type: String,
|
|
106
109
|
name: String,
|
|
110
|
+
touch: ReadableMap?,
|
|
107
111
|
context: ReadableMap,
|
|
108
112
|
timestampMs: Double,
|
|
109
113
|
promise: Promise
|
|
110
114
|
) {
|
|
111
|
-
implementation.addAction(type, name, context, timestampMs, promise)
|
|
115
|
+
implementation.addAction(type, name, touch, context, timestampMs, promise)
|
|
112
116
|
}
|
|
113
117
|
|
|
114
118
|
/**
|
|
@@ -137,6 +137,7 @@ internal class DdRumTest {
|
|
|
137
137
|
testedDdRum.addAction(
|
|
138
138
|
type.name,
|
|
139
139
|
name,
|
|
140
|
+
null,
|
|
140
141
|
fakeContext.toReadableMap(),
|
|
141
142
|
fakeTimestamp,
|
|
142
143
|
mockPromise
|
|
@@ -157,7 +158,14 @@ internal class DdRumTest {
|
|
|
157
158
|
}
|
|
158
159
|
|
|
159
160
|
// When
|
|
160
|
-
testedDdRum.addAction(
|
|
161
|
+
testedDdRum.addAction(
|
|
162
|
+
type,
|
|
163
|
+
name,
|
|
164
|
+
null,
|
|
165
|
+
fakeContext.toReadableMap(),
|
|
166
|
+
fakeTimestamp,
|
|
167
|
+
mockPromise
|
|
168
|
+
)
|
|
161
169
|
|
|
162
170
|
// Then
|
|
163
171
|
verify(mockRumMonitor).addAction(RumActionType.CUSTOM, name, updatedContext)
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
package com.datadog.reactnative
|
|
8
8
|
|
|
9
9
|
import android.content.pm.PackageInfo
|
|
10
|
+
import com.datadog.android.rum.RumMonitor
|
|
10
11
|
import com.datadog.tools.unit.GenericAssert.Companion.assertThat
|
|
11
12
|
import com.datadog.tools.unit.forge.BaseConfigurator
|
|
12
13
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
@@ -24,8 +25,12 @@ import org.mockito.Answers
|
|
|
24
25
|
import org.mockito.Mock
|
|
25
26
|
import org.mockito.junit.jupiter.MockitoExtension
|
|
26
27
|
import org.mockito.junit.jupiter.MockitoSettings
|
|
28
|
+
import org.mockito.kotlin.any
|
|
27
29
|
import org.mockito.kotlin.doReturn
|
|
28
30
|
import org.mockito.kotlin.isNull
|
|
31
|
+
import org.mockito.kotlin.mock
|
|
32
|
+
import org.mockito.kotlin.never
|
|
33
|
+
import org.mockito.kotlin.verify
|
|
29
34
|
import org.mockito.kotlin.whenever
|
|
30
35
|
import org.mockito.quality.Strictness
|
|
31
36
|
|
|
@@ -70,6 +75,9 @@ internal class DdSdkNativeInitializationTest {
|
|
|
70
75
|
mockDdTelemetry,
|
|
71
76
|
mockJSONFileReader
|
|
72
77
|
)
|
|
78
|
+
|
|
79
|
+
DdSdkSessionStartedListener.invalidate()
|
|
80
|
+
DdSdkSessionStartedListener.resetIsRnSdkInitialized()
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
// region getConfigurationFromJSONFile
|
|
@@ -202,4 +210,64 @@ internal class DdSdkNativeInitializationTest {
|
|
|
202
210
|
}
|
|
203
211
|
|
|
204
212
|
// endregion
|
|
213
|
+
|
|
214
|
+
// region initialize()
|
|
215
|
+
|
|
216
|
+
@Test
|
|
217
|
+
fun `𝕄 mark RN SDK initialized and catch up session 𝕎 initialize() { isCalledFromJs=true, datadog already initialized }`() { // ktlint-disable-line max-line-length
|
|
218
|
+
// Given
|
|
219
|
+
val mockRumMonitor: RumMonitor = mock()
|
|
220
|
+
whenever(mockDatadog.isInitialized()) doReturn true
|
|
221
|
+
whenever(mockDatadog.getRumMonitor()) doReturn mockRumMonitor
|
|
222
|
+
|
|
223
|
+
// When
|
|
224
|
+
testedNativeInitialization.initialize(
|
|
225
|
+
ddSdkConfiguration = minimalConfiguration(),
|
|
226
|
+
isCalledFromJs = true
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
// Then
|
|
230
|
+
assertThat(DdSdkSessionStartedListener.isRnSdkInitializedForTests()).isTrue()
|
|
231
|
+
verify(mockRumMonitor).getCurrentSessionId(any())
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@Test
|
|
235
|
+
fun `𝕄 mark RN SDK initialized without catch up 𝕎 initialize() { isCalledFromJs=true, datadog not initialized }`() { // ktlint-disable-line max-line-length
|
|
236
|
+
// Given
|
|
237
|
+
whenever(mockDatadog.isInitialized()) doReturn false
|
|
238
|
+
|
|
239
|
+
// When
|
|
240
|
+
testedNativeInitialization.initialize(
|
|
241
|
+
ddSdkConfiguration = minimalConfiguration(),
|
|
242
|
+
isCalledFromJs = true
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
// Then
|
|
246
|
+
assertThat(DdSdkSessionStartedListener.isRnSdkInitializedForTests()).isTrue()
|
|
247
|
+
verify(mockDatadog, never()).getRumMonitor()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
@Test
|
|
251
|
+
fun `𝕄 not mark RN SDK initialized or catch up 𝕎 initialize() { isCalledFromJs=false }`() {
|
|
252
|
+
// Given
|
|
253
|
+
whenever(mockDatadog.isInitialized()) doReturn true
|
|
254
|
+
|
|
255
|
+
// When
|
|
256
|
+
testedNativeInitialization.initialize(
|
|
257
|
+
ddSdkConfiguration = minimalConfiguration(),
|
|
258
|
+
isCalledFromJs = false
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
// Then
|
|
262
|
+
assertThat(DdSdkSessionStartedListener.isRnSdkInitializedForTests()).isFalse()
|
|
263
|
+
verify(mockDatadog, never()).getRumMonitor()
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// endregion
|
|
267
|
+
|
|
268
|
+
private fun minimalConfiguration(): DdSdkConfiguration = DdSdkConfiguration(
|
|
269
|
+
clientToken = "fake-client-token",
|
|
270
|
+
env = "fake-env",
|
|
271
|
+
additionalConfiguration = emptyMap()
|
|
272
|
+
)
|
|
205
273
|
}
|