@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
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
package com.datadog.reactnative
|
|
9
9
|
|
|
10
10
|
import com.datadog.tools.unit.GenericAssert.Companion.assertThat
|
|
11
|
+
import com.datadog.tools.unit.TestUiThreadExecutor
|
|
11
12
|
import com.datadog.tools.unit.forge.BaseConfigurator
|
|
12
13
|
import com.facebook.react.bridge.CatalystInstance
|
|
13
14
|
import com.facebook.react.bridge.NativeArray
|
|
@@ -55,6 +56,8 @@ internal class DdSdkSessionStartedListenerTest {
|
|
|
55
56
|
@BeforeEach
|
|
56
57
|
fun `set up`() {
|
|
57
58
|
DdSdkSessionStartedListener.invalidate()
|
|
59
|
+
DdSdkSessionStartedListener.getInstance().setUiThreadExecutor(TestUiThreadExecutor())
|
|
60
|
+
DdSdkSessionStartedListener.resetIsRnSdkInitialized()
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
@Test
|
|
@@ -91,6 +94,7 @@ internal class DdSdkSessionStartedListenerTest {
|
|
|
91
94
|
instance.setReactContext(mockReactContext)
|
|
92
95
|
instance.setExceptionHandler(mockExceptionHandler)
|
|
93
96
|
instance.setIsNewArchitecture(false)
|
|
97
|
+
instance.setIsRnSdkInitialized(true)
|
|
94
98
|
|
|
95
99
|
val passedArgs = mutableListOf<String>()
|
|
96
100
|
instance.setConvertToNativeArray {
|
|
@@ -111,6 +115,36 @@ internal class DdSdkSessionStartedListenerTest {
|
|
|
111
115
|
)
|
|
112
116
|
}
|
|
113
117
|
|
|
118
|
+
@Test
|
|
119
|
+
fun `𝕄 session ID is NOT sent via bridge W { setReactContext fires before onRnSdkInitialized }`() { // ktlint-disable-line max-line-length
|
|
120
|
+
// GIVEN — bridge looks valid but RN SDK has not called initialize() from JS yet
|
|
121
|
+
whenever(mockReactContext.hasActiveReactInstance()).thenReturn(true)
|
|
122
|
+
whenever(mockReactContext.catalystInstance).thenReturn(mockCatalystInstance)
|
|
123
|
+
whenever(mockCatalystInstance.isDestroyed).thenReturn(false)
|
|
124
|
+
whenever(mockReactContext.fabricUIManager).thenReturn(null)
|
|
125
|
+
|
|
126
|
+
val instance = DdSdkSessionStartedListener.getInstance()
|
|
127
|
+
|
|
128
|
+
val mockConvertToNativeArray = mock<(array: Array<String>) -> NativeArray?>()
|
|
129
|
+
instance.setConvertToNativeArray(mockConvertToNativeArray)
|
|
130
|
+
instance.setIsNewArchitecture(false)
|
|
131
|
+
|
|
132
|
+
// WHEN — native session starts and context becomes available before JS initialize()
|
|
133
|
+
instance.onSessionStarted("TEST-SESSION-ID", false)
|
|
134
|
+
instance.setReactContext(mockReactContext)
|
|
135
|
+
|
|
136
|
+
// THEN — bridge must NOT be called (DatadogInternalReactBridge not yet registered)
|
|
137
|
+
verifyNoInteractions(mockConvertToNativeArray)
|
|
138
|
+
|
|
139
|
+
// WHEN — JS initialize() runs, guaranteeing the callable module is registered
|
|
140
|
+
instance.onRnSdkInitialized()
|
|
141
|
+
|
|
142
|
+
// THEN — catch-up delivery is now safe and matches __datadogOnMessageReceived(eventName, data)
|
|
143
|
+
verify(mockConvertToNativeArray).invoke(
|
|
144
|
+
argWhere { it.size == 2 && it[0] == "RUMSessionStarted" && it[1] == "TEST-SESSION-ID" }
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
114
148
|
@Test
|
|
115
149
|
fun `𝕄 session ID event is delayed until context is available W { bridge }`() {
|
|
116
150
|
// GIVEN
|
|
@@ -134,9 +168,12 @@ internal class DdSdkSessionStartedListenerTest {
|
|
|
134
168
|
verifyNoInteractions(mockConvertToNativeArray)
|
|
135
169
|
|
|
136
170
|
// WHEN
|
|
171
|
+
instance.setIsRnSdkInitialized(true)
|
|
137
172
|
instance.setReactContext(mockReactContext)
|
|
138
173
|
|
|
139
174
|
// THEN
|
|
140
|
-
verify(mockConvertToNativeArray).invoke(
|
|
175
|
+
verify(mockConvertToNativeArray).invoke(
|
|
176
|
+
argWhere { it.size == 2 && it[0] == "RUMSessionStarted" && it[1] == "TEST-SESSION-ID" }
|
|
177
|
+
)
|
|
141
178
|
}
|
|
142
179
|
}
|
|
@@ -37,6 +37,7 @@ import com.datadog.android.trace.TraceConfiguration
|
|
|
37
37
|
import com.datadog.android.trace.TracingHeaderType
|
|
38
38
|
import com.datadog.tools.unit.GenericAssert.Companion.assertThat
|
|
39
39
|
import com.datadog.tools.unit.MockRumMonitor
|
|
40
|
+
import com.datadog.tools.unit.TestJsThreadExecutor
|
|
40
41
|
import com.datadog.tools.unit.TestUiThreadExecutor
|
|
41
42
|
import com.datadog.tools.unit.forge.BaseConfigurator
|
|
42
43
|
import com.datadog.tools.unit.setStaticValue
|
|
@@ -165,15 +166,12 @@ internal class DdSdkTest {
|
|
|
165
166
|
0
|
|
166
167
|
)
|
|
167
168
|
) doReturn mockPackageInfo
|
|
168
|
-
whenever(mockReactContext.runOnJSQueueThread(any())).thenAnswer { answer ->
|
|
169
|
-
answer.getArgument<Runnable>(0).run()
|
|
170
|
-
true
|
|
171
|
-
}
|
|
172
169
|
testedBridgeSdk = DdSdkImplementation(
|
|
173
170
|
mockReactContext,
|
|
174
171
|
mockDatadog,
|
|
175
172
|
mockDdTelemetry,
|
|
176
|
-
TestUiThreadExecutor()
|
|
173
|
+
TestUiThreadExecutor(),
|
|
174
|
+
TestJsThreadExecutor()
|
|
177
175
|
)
|
|
178
176
|
|
|
179
177
|
DatadogSDKWrapperStorage.onInitializedListeners.clear()
|
|
@@ -937,6 +935,66 @@ internal class DdSdkTest {
|
|
|
937
935
|
}
|
|
938
936
|
}
|
|
939
937
|
|
|
938
|
+
@Test
|
|
939
|
+
fun `𝕄 initialize native SDK 𝕎 initialize() {site=us2_fed}`(
|
|
940
|
+
forge: Forge
|
|
941
|
+
) {
|
|
942
|
+
// Given
|
|
943
|
+
val site = forge.randomizeCase("us2_fed")
|
|
944
|
+
val rumConfiguration = fakeConfiguration.rumConfiguration?.copy(
|
|
945
|
+
nativeCrashReportEnabled = true
|
|
946
|
+
)
|
|
947
|
+
fakeConfiguration = fakeConfiguration.copy(site = site, rumConfiguration = rumConfiguration)
|
|
948
|
+
val sdkConfigCaptor = argumentCaptor<Configuration>()
|
|
949
|
+
val rumConfigCaptor = argumentCaptor<RumConfiguration>()
|
|
950
|
+
val logsConfigCaptor = argumentCaptor<LogsConfiguration>()
|
|
951
|
+
val traceConfigCaptor = argumentCaptor<TraceConfiguration>()
|
|
952
|
+
|
|
953
|
+
val rumMock = org.mockito.Mockito.mockStatic(Rum::class.java)
|
|
954
|
+
val traceMock = org.mockito.Mockito.mockStatic(Trace::class.java)
|
|
955
|
+
val logsMock = org.mockito.Mockito.mockStatic(Logs::class.java)
|
|
956
|
+
|
|
957
|
+
try {
|
|
958
|
+
rumMock.`when`<Unit> { Rum.enable(any(), any()) }.then { }
|
|
959
|
+
logsMock.`when`<Unit> { Logs.enable(any(), any()) }.then { }
|
|
960
|
+
traceMock.`when`<Unit> { Trace.enable(any(), any()) }.then { }
|
|
961
|
+
|
|
962
|
+
// When
|
|
963
|
+
testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
964
|
+
|
|
965
|
+
// Then
|
|
966
|
+
inOrder(mockDatadog) {
|
|
967
|
+
verify(mockDatadog).initialize(
|
|
968
|
+
same(mockContext),
|
|
969
|
+
sdkConfigCaptor.capture(),
|
|
970
|
+
any()
|
|
971
|
+
)
|
|
972
|
+
rumMock.verify { Rum.enable(rumConfigCaptor.capture(), any()) }
|
|
973
|
+
traceMock.verify { Trace.enable(traceConfigCaptor.capture(), any()) }
|
|
974
|
+
logsMock.verify { Logs.enable(logsConfigCaptor.capture(), any()) }
|
|
975
|
+
}
|
|
976
|
+
assertThat(sdkConfigCaptor.firstValue)
|
|
977
|
+
.hasField("coreConfig") {
|
|
978
|
+
it.hasFieldEqualTo("needsClearTextHttp", false)
|
|
979
|
+
it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
|
|
980
|
+
it.hasFieldEqualTo("site", DatadogSite.US2_FED)
|
|
981
|
+
}
|
|
982
|
+
.hasFieldEqualTo("clientToken", fakeConfiguration.clientToken)
|
|
983
|
+
.hasFieldEqualTo("env", fakeConfiguration.env)
|
|
984
|
+
.hasFieldEqualTo("variant", "")
|
|
985
|
+
.hasFieldEqualTo(
|
|
986
|
+
"additionalConfig",
|
|
987
|
+
fakeConfiguration.additionalConfiguration?.filterValues { it != null }.orEmpty()
|
|
988
|
+
)
|
|
989
|
+
assertThat(rumConfigCaptor.firstValue)
|
|
990
|
+
.hasFieldEqualTo("applicationId", fakeConfiguration.rumConfiguration?.applicationId)
|
|
991
|
+
} finally {
|
|
992
|
+
rumMock.close()
|
|
993
|
+
logsMock.close()
|
|
994
|
+
traceMock.close()
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
|
|
940
998
|
@Test
|
|
941
999
|
fun `𝕄 initialize native SDK 𝕎 initialize() {site=eu1}`(
|
|
942
1000
|
forge: Forge
|
|
@@ -14,6 +14,8 @@ import com.datadog.android.rum.RumResourceKind
|
|
|
14
14
|
import com.datadog.android.rum.RumResourceMethod
|
|
15
15
|
import com.datadog.android.rum._RumInternalProxy
|
|
16
16
|
import com.datadog.android.rum.featureoperations.FailureReason
|
|
17
|
+
import com.datadog.android.rum.operations.FailureReason as OperationFailureReason
|
|
18
|
+
import com.datadog.android.rum.operations.OperationOptions
|
|
17
19
|
|
|
18
20
|
class MockRumMonitor : RumMonitor {
|
|
19
21
|
override var debug = false
|
|
@@ -148,6 +150,29 @@ class MockRumMonitor : RumMonitor {
|
|
|
148
150
|
attributes: Map<String, Any?>
|
|
149
151
|
) {}
|
|
150
152
|
|
|
153
|
+
@ExperimentalRumApi
|
|
154
|
+
override fun startOperation(
|
|
155
|
+
name: String,
|
|
156
|
+
operationKey: String?,
|
|
157
|
+
options: OperationOptions,
|
|
158
|
+
attributes: Map<String, Any?>
|
|
159
|
+
) {}
|
|
160
|
+
|
|
161
|
+
@ExperimentalRumApi
|
|
162
|
+
override fun succeedOperation(
|
|
163
|
+
name: String,
|
|
164
|
+
operationKey: String?,
|
|
165
|
+
attributes: Map<String, Any?>
|
|
166
|
+
) {}
|
|
167
|
+
|
|
168
|
+
@ExperimentalRumApi
|
|
169
|
+
override fun failOperation(
|
|
170
|
+
name: String,
|
|
171
|
+
operationKey: String?,
|
|
172
|
+
failureReason: OperationFailureReason,
|
|
173
|
+
attributes: Map<String, Any?>
|
|
174
|
+
) {}
|
|
175
|
+
|
|
151
176
|
@ExperimentalRumApi
|
|
152
177
|
override fun reportAppFullyDisplayed() {}
|
|
153
178
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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.tools.unit
|
|
8
|
+
|
|
9
|
+
import com.datadog.reactnative.JsThreadExecutor
|
|
10
|
+
|
|
11
|
+
internal class TestJsThreadExecutor : JsThreadExecutor {
|
|
12
|
+
override fun runOnJsThread(runnable: Runnable) {
|
|
13
|
+
// Run immediately in the same thread for tests
|
|
14
|
+
runnable.run()
|
|
15
|
+
}
|
|
16
|
+
}
|
package/ios/Sources/DdRum.mm
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
@implementation DdRum
|
|
16
16
|
|
|
17
|
+
@synthesize bridge = _bridge;
|
|
17
18
|
RCT_EXPORT_MODULE()
|
|
18
19
|
|
|
19
20
|
RCT_REMAP_METHOD(startView, withKey:(NSString*)key
|
|
@@ -57,12 +58,13 @@ RCT_REMAP_METHOD(stopAction, stopWithType:(NSString*)type
|
|
|
57
58
|
|
|
58
59
|
RCT_REMAP_METHOD(addAction, addWithType:(NSString*)type
|
|
59
60
|
withName:(NSString*)name
|
|
61
|
+
withTouch:(nullable NSDictionary*)touch
|
|
60
62
|
withContext:(NSDictionary*)context
|
|
61
63
|
withTimestampms:(double)timestampMs
|
|
62
64
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
63
65
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
64
66
|
{
|
|
65
|
-
[self addAction:type name:name context:context timestampMs:timestampMs resolve:resolve reject:reject];
|
|
67
|
+
[self addAction:type name:name touch:touch context:context timestampMs:timestampMs resolve:resolve reject:reject];
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
RCT_REMAP_METHOD(startResource, withKey:(NSString*)key
|
|
@@ -207,7 +209,7 @@ RCT_REMAP_METHOD(failFeatureOperation,
|
|
|
207
209
|
- (DdRumImplementation*)ddRumImplementation
|
|
208
210
|
{
|
|
209
211
|
if (_ddRumImplementation == nil) {
|
|
210
|
-
_ddRumImplementation = [[DdRumImplementation alloc]
|
|
212
|
+
_ddRumImplementation = [[DdRumImplementation alloc] initWithBridge:_bridge];
|
|
211
213
|
}
|
|
212
214
|
return _ddRumImplementation;
|
|
213
215
|
}
|
|
@@ -220,8 +222,8 @@ RCT_REMAP_METHOD(failFeatureOperation,
|
|
|
220
222
|
return [RNQueue getSharedQueue];
|
|
221
223
|
}
|
|
222
224
|
|
|
223
|
-
- (void)addAction:(NSString *)type name:(NSString *)name context:(NSDictionary *)context timestampMs:(double)timestampMs resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
224
|
-
[self.ddRumImplementation addActionWithType:type name:name context:context timestampMs:timestampMs resolve:resolve reject:reject];
|
|
225
|
+
- (void)addAction:(NSString *)type name:(NSString *)name touch:(nullable NSDictionary *)touch context:(NSDictionary *)context timestampMs:(double)timestampMs resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
226
|
+
[self.ddRumImplementation addActionWithType:type name:name touch:touch context:context timestampMs:timestampMs resolve:resolve reject:reject];
|
|
225
227
|
}
|
|
226
228
|
|
|
227
229
|
- (void)addError:(NSString *)message source:(NSString *)source stacktrace:(NSString *)stacktrace context:(NSDictionary *)context timestampMs:(double)timestampMs fingerprint:(NSString *)fingerprint resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
@@ -8,6 +8,7 @@ import Foundation
|
|
|
8
8
|
@_spi(Experimental)
|
|
9
9
|
import DatadogRUM
|
|
10
10
|
import DatadogInternal
|
|
11
|
+
import React
|
|
11
12
|
|
|
12
13
|
private extension RUMActionType {
|
|
13
14
|
init(from string: String) {
|
|
@@ -91,24 +92,41 @@ public class DdRumImplementation: NSObject {
|
|
|
91
92
|
|
|
92
93
|
lazy var nativeRUM: RUMMonitorProtocol = rumProvider()
|
|
93
94
|
lazy var rumInternal: RUMMonitorInternalProtocol? = rumInternalProvider()
|
|
95
|
+
lazy var heatmapIdentifierRegistry: HeatmapIdentifierRegistry? = heatmapIdentifierRegistryProvider()
|
|
96
|
+
private let mainDispatchQueue: DispatchQueueType
|
|
97
|
+
private let uiManager: RCTUIManager
|
|
98
|
+
private let rootViewProvider: () -> UIView?
|
|
99
|
+
private let heatmapIdentifierRegistryProvider: () -> HeatmapIdentifierRegistry?
|
|
94
100
|
private let rumProvider: () -> RUMMonitorProtocol
|
|
95
101
|
private let rumInternalProvider: () -> RUMMonitorInternalProtocol?
|
|
96
102
|
|
|
97
103
|
private typealias UserAction = (type: RUMActionType, name: String?)
|
|
98
104
|
|
|
99
105
|
internal init(
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
mainDispatchQueue: DispatchQueueType,
|
|
107
|
+
uiManager: RCTUIManager,
|
|
108
|
+
rootViewProvider: @escaping () -> UIView?,
|
|
109
|
+
heatmapIdentifierRegistryProvider: @escaping () -> HeatmapIdentifierRegistry?,
|
|
110
|
+
rumProvider: @escaping () -> RUMMonitorProtocol,
|
|
111
|
+
rumInternalProvider: @escaping () -> RUMMonitorInternalProtocol?
|
|
102
112
|
) {
|
|
113
|
+
self.mainDispatchQueue = mainDispatchQueue
|
|
114
|
+
self.uiManager = uiManager
|
|
115
|
+
self.rootViewProvider = rootViewProvider
|
|
116
|
+
self.heatmapIdentifierRegistryProvider = heatmapIdentifierRegistryProvider
|
|
103
117
|
self.rumProvider = rumProvider
|
|
104
118
|
self.rumInternalProvider = rumInternalProvider
|
|
105
119
|
}
|
|
106
120
|
|
|
107
121
|
@objc
|
|
108
|
-
public
|
|
122
|
+
public convenience init(bridge: RCTBridge) {
|
|
109
123
|
self.init(
|
|
110
|
-
|
|
111
|
-
|
|
124
|
+
mainDispatchQueue: DispatchQueue.main,
|
|
125
|
+
uiManager: bridge.uiManager,
|
|
126
|
+
rootViewProvider: { UIWindow.reactRootView() },
|
|
127
|
+
heatmapIdentifierRegistryProvider: { CoreRegistry.default.heatmapIdentifierRegistry },
|
|
128
|
+
rumProvider: { RUMMonitor.shared() },
|
|
129
|
+
rumInternalProvider: { RUMMonitor.shared()._internal }
|
|
112
130
|
)
|
|
113
131
|
}
|
|
114
132
|
|
|
@@ -137,8 +155,27 @@ public class DdRumImplementation: NSObject {
|
|
|
137
155
|
}
|
|
138
156
|
|
|
139
157
|
@objc
|
|
140
|
-
public func addAction(type: String, name: String, context: NSDictionary, timestampMs: Double, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
|
|
141
|
-
|
|
158
|
+
public func addAction(type: String, name: String, touch: NSDictionary?, context: NSDictionary, timestampMs: Double, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
|
|
159
|
+
if
|
|
160
|
+
let touch,
|
|
161
|
+
let reactTag = touch["reactTag"] as? NSNumber,
|
|
162
|
+
let x = touch["x"] as? NSNumber,
|
|
163
|
+
let y = touch["y"] as? NSNumber,
|
|
164
|
+
let pageX = touch["pageX"] as? NSNumber,
|
|
165
|
+
let pageY = touch["pageY"] as? NSNumber
|
|
166
|
+
{
|
|
167
|
+
addAction(
|
|
168
|
+
at: Date(timeIntervalSince1970: timestampMs / 1_000),
|
|
169
|
+
type: RUMActionType(from: type),
|
|
170
|
+
name: name,
|
|
171
|
+
reactTag: reactTag,
|
|
172
|
+
location: .init(x: CGFloat(truncating: x), y: CGFloat(truncating: y)),
|
|
173
|
+
pageLocation: .init(x: CGFloat(truncating: pageX), y: CGFloat(truncating: pageY)),
|
|
174
|
+
attributes: castAttributesToSwift(context)
|
|
175
|
+
)
|
|
176
|
+
} else {
|
|
177
|
+
nativeRUM.addAction(type: RUMActionType(from: type), name: name, attributes: attributes(from: context, with: timestampMs))
|
|
178
|
+
}
|
|
142
179
|
resolve(nil)
|
|
143
180
|
}
|
|
144
181
|
|
|
@@ -326,6 +363,44 @@ public class DdRumImplementation: NSObject {
|
|
|
326
363
|
}
|
|
327
364
|
}
|
|
328
365
|
|
|
366
|
+
private func addAction(
|
|
367
|
+
at time: Date,
|
|
368
|
+
type: RUMActionType,
|
|
369
|
+
name: String,
|
|
370
|
+
reactTag: NSNumber,
|
|
371
|
+
location: CGPoint,
|
|
372
|
+
pageLocation: CGPoint,
|
|
373
|
+
attributes: [AttributeKey: AttributeValue]
|
|
374
|
+
) {
|
|
375
|
+
mainDispatchQueue.async { [uiManager, rootViewProvider, heatmapIdentifierRegistry, rumInternal] in
|
|
376
|
+
var location = location
|
|
377
|
+
let view = uiManager.view(
|
|
378
|
+
forReactTag: reactTag,
|
|
379
|
+
location: &location,
|
|
380
|
+
pageLocation: pageLocation,
|
|
381
|
+
rootViewProvider: rootViewProvider
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
let heatmapAttributes: HeatmapAttributes? = view.flatMap { view in
|
|
385
|
+
guard let identifier = heatmapIdentifierRegistry?.heatmapIdentifier(for: ObjectIdentifier(view)) else {
|
|
386
|
+
return nil
|
|
387
|
+
}
|
|
388
|
+
return HeatmapAttributes(
|
|
389
|
+
identifier: identifier,
|
|
390
|
+
size: view.bounds.size,
|
|
391
|
+
location: location
|
|
392
|
+
)
|
|
393
|
+
}
|
|
394
|
+
rumInternal?.addAction(
|
|
395
|
+
at: time,
|
|
396
|
+
type: type,
|
|
397
|
+
name: name,
|
|
398
|
+
heatmapAttributes: heatmapAttributes,
|
|
399
|
+
attributes: attributes
|
|
400
|
+
)
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
329
404
|
private func timingValue(from timings: [String: Any], for timingName: String) -> (start: Date, end: Date)? {
|
|
330
405
|
let timing = timings[timingName] as? [String: NSNumber]
|
|
331
406
|
if let startInNs = timing?["startTime"]?.int64Value, let durationInNs = timing?["duration"]?.int64Value {
|
|
@@ -32,7 +32,7 @@ public class DdSdkNativeInitialization: NSObject {
|
|
|
32
32
|
self.jsonFileReader = jsonFileReader
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
internal func initialize(sdkConfiguration: DdSdkConfiguration) {
|
|
35
|
+
internal func initialize(sdkConfiguration: DdSdkConfiguration, isCalledFromJs: Bool = true) {
|
|
36
36
|
if Datadog.isInitialized(instanceName: CoreRegistry.defaultInstanceName) {
|
|
37
37
|
// Initializing the SDK twice results in Global.rum and Global.sharedTracer to be set to no-op instances
|
|
38
38
|
consolePrint("Datadog SDK is already initialized, skipping initialization.", .debug)
|
|
@@ -40,24 +40,31 @@ public class DdSdkNativeInitialization: NSObject {
|
|
|
40
40
|
id: "datadog_react_native: RN SDK was already initialized in native",
|
|
41
41
|
message: "RN SDK was already initialized in native"
|
|
42
42
|
)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
guard let id = sessionId else { return }
|
|
46
|
-
DdSdkSessionStartedListener.instance.rumSessionListener?(id, false)
|
|
47
|
-
}
|
|
43
|
+
} else {
|
|
44
|
+
self.setVerbosityLevel(configuration: sdkConfiguration)
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
let coreConfiguration = self.buildSDKConfiguration(configuration: sdkConfiguration)
|
|
47
|
+
DatadogSDKWrapper.shared.initialize(
|
|
48
|
+
coreConfiguration: coreConfiguration,
|
|
49
|
+
loggerConfiguration: DatadogLogs.Logger.Configuration(sdkConfiguration),
|
|
50
|
+
trackingConsent: sdkConfiguration.trackingConsent
|
|
51
|
+
)
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
coreConfiguration: coreConfiguration,
|
|
56
|
-
loggerConfiguration: DatadogLogs.Logger.Configuration(sdkConfiguration),
|
|
57
|
-
trackingConsent: sdkConfiguration.trackingConsent
|
|
58
|
-
)
|
|
53
|
+
self.enableFeatures(sdkConfiguration: sdkConfiguration)
|
|
54
|
+
}
|
|
59
55
|
|
|
60
|
-
|
|
56
|
+
if isCalledFromJs {
|
|
57
|
+
DdSdkSessionStartedListener.instance.onRnSdkInitialized()
|
|
58
|
+
// Handles the case in which the SDK was already initialized via initFromNative.
|
|
59
|
+
// Replay the current session ID so the listener can deliver it now that the
|
|
60
|
+
// JS-side DatadogInternalReactBridge module is guaranteed to be registered.
|
|
61
|
+
if Datadog.isInitialized(instanceName: CoreRegistry.defaultInstanceName) {
|
|
62
|
+
RUMMonitor.shared().currentSessionID { sessionId in
|
|
63
|
+
guard let id = sessionId else { return }
|
|
64
|
+
DdSdkSessionStartedListener.instance.rumSessionListener?(id, false)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
internal func getConfigurationFromJSONFile() -> DdSdkConfiguration? {
|
|
@@ -80,7 +87,7 @@ public class DdSdkNativeInitialization: NSObject {
|
|
|
80
87
|
@objc
|
|
81
88
|
public func initializeFromNative() {
|
|
82
89
|
if let configuration = getConfigurationFromJSONFile() {
|
|
83
|
-
self.initialize(sdkConfiguration: configuration)
|
|
90
|
+
self.initialize(sdkConfiguration: configuration, isCalledFromJs: false)
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
93
|
|
|
@@ -29,6 +29,11 @@ public class DdSdkSessionStartedListener: NSObject {
|
|
|
29
29
|
private static let BRIDGE_EVENT_NAME = "RUMSessionStarted"
|
|
30
30
|
private static var _instance: DdSdkSessionStartedListener?
|
|
31
31
|
|
|
32
|
+
// Process-level state — survives instance invalidate() because the JS-side
|
|
33
|
+
// DatadogInternalReactBridge registration survives bridge-lifecycle resets
|
|
34
|
+
// for the lifetime of the JS runtime / process.
|
|
35
|
+
private static var isRnSdkInitialized: Bool = false
|
|
36
|
+
|
|
32
37
|
private var rctBridge: RCTBridge?
|
|
33
38
|
private var rctEventEmitter: RCTEventEmitter?
|
|
34
39
|
private var lastSessionId: String?
|
|
@@ -57,11 +62,22 @@ public class DdSdkSessionStartedListener: NSObject {
|
|
|
57
62
|
tryToSendSessionId()
|
|
58
63
|
}
|
|
59
64
|
|
|
65
|
+
/// Called when the RN SDK is initialized from JS. At this point
|
|
66
|
+
/// DatadogInternalReactBridge (the JS-side callable module registered by
|
|
67
|
+
/// BatchedBridge.registerCallableModule) is guaranteed to be registered,
|
|
68
|
+
/// so it is safe to deliver any session ID that was buffered before the
|
|
69
|
+
/// bridge was usable.
|
|
70
|
+
@objc public func onRnSdkInitialized() {
|
|
71
|
+
Self.isRnSdkInitialized = true
|
|
72
|
+
tryToSendSessionId()
|
|
73
|
+
}
|
|
74
|
+
|
|
60
75
|
func invalidate() {
|
|
61
76
|
self.rctBridge = nil
|
|
62
77
|
self.listener = nil
|
|
63
78
|
self.hasListeners = false
|
|
64
79
|
self.lastSessionId = nil
|
|
80
|
+
// isRnSdkInitialized is intentionally NOT reset — see field comment.
|
|
65
81
|
}
|
|
66
82
|
|
|
67
83
|
private func tryToSendSessionId() {
|
|
@@ -71,9 +87,12 @@ public class DdSdkSessionStartedListener: NSObject {
|
|
|
71
87
|
|
|
72
88
|
if isBridgeless() {
|
|
73
89
|
sendToJsWithListener(sessionId: sessionId)
|
|
74
|
-
} else {
|
|
90
|
+
} else if Self.isRnSdkInitialized {
|
|
75
91
|
sendToJsWithBridge(sessionId: sessionId)
|
|
76
92
|
}
|
|
93
|
+
// else: bridge path is gated until JS DdSdk.initialize() runs, so that
|
|
94
|
+
// DatadogInternalReactBridge is guaranteed to be registered. The cached
|
|
95
|
+
// lastSessionId will be replayed when onRnSdkInitialized() fires.
|
|
77
96
|
}
|
|
78
97
|
|
|
79
98
|
private func sendToJsWithBridge(sessionId: String) {
|
|
@@ -102,4 +121,12 @@ public class DdSdkSessionStartedListener: NSObject {
|
|
|
102
121
|
private func isBridgeless() -> Bool {
|
|
103
122
|
return self.rctBridge == nil
|
|
104
123
|
}
|
|
124
|
+
|
|
125
|
+
static func resetIsRnSdkInitializedForTests() {
|
|
126
|
+
isRnSdkInitialized = false
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static func isRnSdkInitializedForTests() -> Bool {
|
|
130
|
+
return isRnSdkInitialized
|
|
131
|
+
}
|
|
105
132
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
import React
|
|
8
|
+
import UIKit
|
|
9
|
+
|
|
10
|
+
internal extension UIWindow {
|
|
11
|
+
/// Returns the React Native root view in the current app's key window, if any.
|
|
12
|
+
static func reactRootView() -> UIView? {
|
|
13
|
+
return UIApplication.shared.activeKeyWindow?.findReactRootView()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private func findReactRootView() -> UIView? {
|
|
17
|
+
return findReactRootView(in: self)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private func findReactRootView(in view: UIView) -> UIView? {
|
|
21
|
+
if view.isReactRootView() {
|
|
22
|
+
return view
|
|
23
|
+
}
|
|
24
|
+
for subview in view.subviews {
|
|
25
|
+
if let root = findReactRootView(in: subview) {
|
|
26
|
+
return root
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return nil
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private extension UIApplication {
|
|
34
|
+
var activeKeyWindow: UIWindow? {
|
|
35
|
+
if #available(iOS 13.0, *) {
|
|
36
|
+
let activeScene = connectedScenes
|
|
37
|
+
.compactMap { $0 as? UIWindowScene }
|
|
38
|
+
.first(where: { $0.activationState == .foregroundActive })
|
|
39
|
+
if #available(iOS 15.0, *) {
|
|
40
|
+
return activeScene?.keyWindow
|
|
41
|
+
}
|
|
42
|
+
return activeScene?.windows.first(where: { $0.isKeyWindow })
|
|
43
|
+
} else {
|
|
44
|
+
return windows.first(where: { $0.isKeyWindow })
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
internal extension RCTUIManager {
|
|
50
|
+
/// Returns the view for a given `reactTag`, with a hit-test fallback when the tag cannot be resolved.
|
|
51
|
+
///
|
|
52
|
+
/// Tries `view(forReactTag:)` first (fast path). If it returns `nil`, falls back to a hit-test
|
|
53
|
+
/// on the RN root view using `pageLocation` and overwrites `location` with the tap point in
|
|
54
|
+
/// the hit-tested view's coordinate space. This hardens the integration against RN potentially
|
|
55
|
+
/// deprecating `reactTag` view lookup on Fabric.
|
|
56
|
+
///
|
|
57
|
+
/// - Parameters:
|
|
58
|
+
/// - reactTag: The reactTag reported by the JS `GestureResponderEvent`.
|
|
59
|
+
/// - location: On input, the tap location in the original target view's coordinate space
|
|
60
|
+
/// (from `locationX/Y`). On output, the tap location in the resolved view's coordinate
|
|
61
|
+
/// space — unchanged on the fast path, recomputed when the fallback is used.
|
|
62
|
+
/// - pageLocation: The tap location in the RN root view's coordinate space (from `pageX/Y`).
|
|
63
|
+
/// RN computes these by converting the touch point from window to root-view coordinates,
|
|
64
|
+
/// so no additional conversion is needed before hit-testing.
|
|
65
|
+
/// - rootViewProvider: Closure returning the RN root view to hit-test against.
|
|
66
|
+
func view(
|
|
67
|
+
forReactTag reactTag: NSNumber,
|
|
68
|
+
location: inout CGPoint,
|
|
69
|
+
pageLocation: CGPoint,
|
|
70
|
+
rootViewProvider: () -> UIView?
|
|
71
|
+
) -> UIView? {
|
|
72
|
+
if let view = view(forReactTag: reactTag) {
|
|
73
|
+
return view
|
|
74
|
+
}
|
|
75
|
+
DdTelemetry.telemetryDebug(
|
|
76
|
+
id: "datadog_react_native:heatmap_fallback",
|
|
77
|
+
message: "Heatmap view resolution fell back to hit-test"
|
|
78
|
+
)
|
|
79
|
+
guard
|
|
80
|
+
let rootView = rootViewProvider(),
|
|
81
|
+
let hitView = rootView.hitTest(pageLocation, with: nil)
|
|
82
|
+
else {
|
|
83
|
+
return nil
|
|
84
|
+
}
|
|
85
|
+
location = rootView.convert(pageLocation, to: hitView)
|
|
86
|
+
return hitView
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -42,6 +42,14 @@ public protocol RUMMonitorInternalProtocol {
|
|
|
42
42
|
requestBodySize: (encoded: Int64, decoded: Int64)?,
|
|
43
43
|
attributes: [AttributeKey: AttributeValue]
|
|
44
44
|
)
|
|
45
|
+
|
|
46
|
+
func addAction(
|
|
47
|
+
at time: Date,
|
|
48
|
+
type: RUMActionType,
|
|
49
|
+
name: String,
|
|
50
|
+
heatmapAttributes: HeatmapAttributes?,
|
|
51
|
+
attributes: [AttributeKey: AttributeValue]
|
|
52
|
+
)
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
extension DatadogInternalInterface: RUMMonitorInternalProtocol {}
|