@datadog/mobile-react-native 3.1.0 → 3.1.2

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.
Files changed (57) hide show
  1. package/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt +20 -43
  2. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +3 -3
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +18 -18
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +3 -2
  5. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  6. package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +18 -125
  7. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +4 -2
  8. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +6 -3
  9. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +3 -4
  10. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +1 -1
  11. package/android/src/test/resources/input/complete-configuration.json +10 -10
  12. package/ios/Sources/DdLogsImplementation.swift +13 -3
  13. package/ios/Sources/DdSdkConfiguration.swift +4 -4
  14. package/ios/Sources/DdSdkNativeInitialization.swift +2 -2
  15. package/ios/Sources/RNDdSdkConfiguration.swift +9 -8
  16. package/ios/Sources/SdkVersion.swift +1 -1
  17. package/lib/commonjs/InternalLog.js +9 -7
  18. package/lib/commonjs/InternalLog.js.map +1 -1
  19. package/lib/commonjs/logs/DdLogs.js +14 -44
  20. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  21. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +2 -2
  22. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  23. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +25 -3
  24. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  25. package/lib/commonjs/sdk/DatadogProvider/Buffer/BufferSingleton.js +10 -8
  26. package/lib/commonjs/sdk/DatadogProvider/Buffer/BufferSingleton.js.map +1 -1
  27. package/lib/commonjs/version.js +1 -1
  28. package/lib/module/InternalLog.js +9 -6
  29. package/lib/module/InternalLog.js.map +1 -1
  30. package/lib/module/logs/DdLogs.js +15 -45
  31. package/lib/module/logs/DdLogs.js.map +1 -1
  32. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +2 -2
  33. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  34. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +25 -3
  35. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  36. package/lib/module/sdk/DatadogProvider/Buffer/BufferSingleton.js +10 -7
  37. package/lib/module/sdk/DatadogProvider/Buffer/BufferSingleton.js.map +1 -1
  38. package/lib/module/version.js +1 -1
  39. package/lib/typescript/InternalLog.d.ts +6 -4
  40. package/lib/typescript/InternalLog.d.ts.map +1 -1
  41. package/lib/typescript/logs/DdLogs.d.ts +0 -5
  42. package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
  43. package/lib/typescript/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts +9 -0
  44. package/lib/typescript/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts.map +1 -1
  45. package/lib/typescript/sdk/DatadogProvider/Buffer/BufferSingleton.d.ts +7 -5
  46. package/lib/typescript/sdk/DatadogProvider/Buffer/BufferSingleton.d.ts.map +1 -1
  47. package/lib/typescript/version.d.ts +1 -1
  48. package/package.json +2 -2
  49. package/src/InternalLog.tsx +14 -6
  50. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +89 -0
  51. package/src/logs/DdLogs.ts +25 -58
  52. package/src/logs/__tests__/DdLogs.test.ts +2 -21
  53. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +3 -3
  54. package/src/rum/instrumentation/interactionTracking/DdEventsInterceptor.tsx +25 -3
  55. package/src/sdk/DatadogProvider/Buffer/BufferSingleton.ts +16 -7
  56. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +13 -0
  57. package/src/version.ts +1 -1
@@ -16,20 +16,30 @@ import com.facebook.react.bridge.ReadableMap
16
16
  * The entry point to use Datadog's Logs feature.
17
17
  */
18
18
  class DdLogsImplementation(
19
- logger: Logger? = null,
20
- private val datadog: DatadogWrapper = DatadogSDKWrapper()
21
- ) {
22
- private val reactNativeLogger: Logger by lazy {
23
- val bundleLogsWithRum = datadog.bundleLogsWithRum
24
- val bundleLogsWithTraces = datadog.bundleLogsWithTraces
25
-
26
- logger ?: Logger.Builder(Datadog.getInstance())
19
+ private val datadog: DatadogWrapper = DatadogSDKWrapper(),
20
+ private val logger: () -> Logger = {
21
+ Logger.Builder(Datadog.getInstance())
27
22
  .setLogcatLogsEnabled(true)
28
- .setBundleWithRumEnabled(bundleLogsWithRum)
29
- .setBundleWithTraceEnabled(bundleLogsWithTraces)
23
+ .setBundleWithRumEnabled(datadog.bundleLogsWithRum)
24
+ .setBundleWithTraceEnabled(datadog.bundleLogsWithTraces)
30
25
  .setName("DdLogs")
31
26
  .build()
32
27
  }
28
+ ) {
29
+ private var loggerInstance: Logger? = null
30
+ private val reactNativeLogger: Logger
31
+ get() {
32
+ if (loggerInstance == null) {
33
+ loggerInstance = logger()
34
+ }
35
+ return loggerInstance!!
36
+ }
37
+
38
+ init {
39
+ DatadogSDKWrapperStorage.addOnInitializedListener {
40
+ loggerInstance = null
41
+ }
42
+ }
33
43
 
34
44
  /**
35
45
  * Send a log with Debug level.
@@ -37,10 +47,6 @@ class DdLogsImplementation(
37
47
  * @param context The additional context to send.
38
48
  */
39
49
  fun debug(message: String, context: ReadableMap, promise: Promise) {
40
- if (!datadog.isInitialized()) {
41
- promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
42
- return
43
- }
44
50
  reactNativeLogger.d(
45
51
  message = message,
46
52
  attributes = context.toHashMap() + GlobalState.globalAttributes
@@ -54,10 +60,6 @@ class DdLogsImplementation(
54
60
  * @param context The additional context to send.
55
61
  */
56
62
  fun info(message: String, context: ReadableMap, promise: Promise) {
57
- if (!datadog.isInitialized()) {
58
- promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
59
- return
60
- }
61
63
  reactNativeLogger.i(
62
64
  message = message,
63
65
  attributes = context.toHashMap() + GlobalState.globalAttributes
@@ -71,10 +73,6 @@ class DdLogsImplementation(
71
73
  * @param context The additional context to send.
72
74
  */
73
75
  fun warn(message: String, context: ReadableMap, promise: Promise) {
74
- if (!datadog.isInitialized()) {
75
- promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
76
- return
77
- }
78
76
  reactNativeLogger.w(
79
77
  message = message,
80
78
  attributes = context.toHashMap() + GlobalState.globalAttributes
@@ -88,10 +86,6 @@ class DdLogsImplementation(
88
86
  * @param context The additional context to send.
89
87
  */
90
88
  fun error(message: String, context: ReadableMap, promise: Promise) {
91
- if (!datadog.isInitialized()) {
92
- promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
93
- return
94
- }
95
89
  reactNativeLogger.e(
96
90
  message = message,
97
91
  attributes = context.toHashMap() + GlobalState.globalAttributes
@@ -116,10 +110,6 @@ class DdLogsImplementation(
116
110
  context: ReadableMap,
117
111
  promise: Promise
118
112
  ) {
119
- if (!datadog.isInitialized()) {
120
- promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
121
- return
122
- }
123
113
  reactNativeLogger.log(
124
114
  priority = AndroidLog.DEBUG,
125
115
  message = message,
@@ -148,10 +138,6 @@ class DdLogsImplementation(
148
138
  context: ReadableMap,
149
139
  promise: Promise
150
140
  ) {
151
- if (!datadog.isInitialized()) {
152
- promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
153
- return
154
- }
155
141
  reactNativeLogger.log(
156
142
  priority = AndroidLog.INFO,
157
143
  message = message,
@@ -180,10 +166,6 @@ class DdLogsImplementation(
180
166
  context: ReadableMap,
181
167
  promise: Promise
182
168
  ) {
183
- if (!datadog.isInitialized()) {
184
- promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
185
- return
186
- }
187
169
  reactNativeLogger.log(
188
170
  priority = AndroidLog.WARN,
189
171
  message = message,
@@ -212,10 +194,6 @@ class DdLogsImplementation(
212
194
  context: ReadableMap,
213
195
  promise: Promise
214
196
  ) {
215
- if (!datadog.isInitialized()) {
216
- promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
217
- return
218
- }
219
197
  reactNativeLogger.log(
220
198
  priority = AndroidLog.ERROR,
221
199
  message = message,
@@ -228,7 +206,6 @@ class DdLogsImplementation(
228
206
  }
229
207
 
230
208
  internal companion object {
231
- private const val SDK_NOT_INITIALIZED_MESSAGE = "DD_INTERNAL_LOG_SENT_BEFORE_SDK_INIT"
232
209
  internal const val NAME = "DdLogs"
233
210
  }
234
211
  }
@@ -24,7 +24,6 @@ import java.net.Proxy
24
24
  * @param batchSize The preferred size for uploaded batches of data (can be 'SMALL', 'MEDIUM' (default), 'LARGE')
25
25
  * @param batchProcessingLevel The preferred number of batches of data that will be sent in a single upload (can be 'LOW', 'MEDIUM' (default), 'HIGH')
26
26
  * @param proxyConfiguration Configuration for proxying SDK data.
27
- * @param firstPartyHosts List of backend hosts to enable tracing with.
28
27
  * @param rumConfiguration Configuration for the RUM feature module, including RUM application ID and RUM-specific options.
29
28
  * @param logsConfiguration Configuration for the Logs feature module.
30
29
  * @param traceConfiguration Configuration for the Traces (APM) feature module.
@@ -42,7 +41,6 @@ data class DdSdkConfiguration(
42
41
  val batchSize: String? = null,
43
42
  val batchProcessingLevel: String? = null,
44
43
  val proxyConfiguration: Pair<Proxy, ProxyAuthenticator?>? = null,
45
- val firstPartyHosts: Map<String, Set<TracingHeaderType>>? = null,
46
44
  val rumConfiguration: RumConfiguration? = null,
47
45
  val logsConfiguration: LogsConfiguration? = null,
48
46
  val traceConfiguration: TraceConfiguration? = null,
@@ -63,6 +61,7 @@ data class DdSdkConfiguration(
63
61
  * @param nativeLongTaskThresholdMs The threshold for native long tasks reporting in milliseconds.
64
62
  * @param nativeViewTracking Enables/Disables tracking RUM Views on the native level.
65
63
  * @param nativeInteractionTracking Enables/Disables tracking RUM Actions on the native level.
64
+ * @param firstPartyHosts List of backend hosts to enable tracing with.
66
65
  * @param trackNonFatalAnrs Enables tracking of non-fatal ANRs on Android.
67
66
  * @param initialResourceThreshold The amount of time after a view starts where a Resource should be considered when calculating Time to Network-Settled (TNS).
68
67
  * @param telemetrySampleRate The sample rate (between 0 and 100) of telemetry events.
@@ -80,6 +79,7 @@ data class RumConfiguration(
80
79
  val nativeLongTaskThresholdMs: Double? = null,
81
80
  val nativeViewTracking: Boolean? = null,
82
81
  val nativeInteractionTracking: Boolean? = null,
82
+ val firstPartyHosts: Map<String, Set<TracingHeaderType>>? = null,
83
83
  val trackNonFatalAnrs: Boolean? = null,
84
84
  val initialResourceThreshold: Double? = null,
85
85
  val telemetrySampleRate: Double? = null,
@@ -127,7 +127,6 @@ internal data class JSONDdSdkConfiguration(
127
127
  val version: String? = null,
128
128
  val versionSuffix: String? = null,
129
129
  val site: String? = null,
130
- val firstPartyHosts: List<JSONFirstPartyHost>? = null,
131
130
  val rumConfiguration: JSONRumConfiguration? = null,
132
131
  val logsConfiguration: JSONLogsConfiguration? = null,
133
132
  val traceConfiguration: JSONTraceConfiguration? = null
@@ -140,6 +139,7 @@ internal data class JSONRumConfiguration(
140
139
  val trackResources: Boolean? = null,
141
140
  val trackErrors: Boolean? = null,
142
141
  val actionNameAttribute: String? = null,
142
+ val firstPartyHosts: List<JSONFirstPartyHost>? = null,
143
143
  val appHangThreshold: Double? = null,
144
144
  val initialResourceThreshold: Double? = null,
145
145
 
@@ -41,6 +41,7 @@ internal fun ReadableMap.asDdSdkConfiguration(): DdSdkConfiguration {
41
41
  nativeLongTaskThresholdMs = rm.getDoubleOrNull("nativeLongTaskThresholdMs"),
42
42
  nativeViewTracking = rm.getBooleanOrNull("nativeViewTracking"),
43
43
  nativeInteractionTracking = rm.getBooleanOrNull("nativeInteractionTracking"),
44
+ firstPartyHosts = rm.getArray("firstPartyHosts")?.asFirstPartyHosts(),
44
45
  trackNonFatalAnrs = rm.getBooleanOrNull("trackNonFatalAnrs"),
45
46
  initialResourceThreshold = rm.getDoubleOrNull("initialResourceThreshold"),
46
47
  telemetrySampleRate = rm.getDoubleOrNull("telemetrySampleRate"),
@@ -77,7 +78,6 @@ internal fun ReadableMap.asDdSdkConfiguration(): DdSdkConfiguration {
77
78
  batchSize = getString("batchSize"),
78
79
  batchProcessingLevel = getString("batchProcessingLevel"),
79
80
  proxyConfiguration = getMap("proxyConfiguration")?.asProxyConfig(),
80
- firstPartyHosts = getArray("firstPartyHosts")?.asFirstPartyHosts(),
81
81
  rumConfiguration = rumConfiguration,
82
82
  logsConfiguration = logsConfiguration,
83
83
  traceConfiguration = traceConfiguration,
@@ -182,6 +182,7 @@ internal fun JSONDdSdkConfiguration.asDdSdkConfiguration(): DdSdkConfiguration {
182
182
  nativeLongTaskThresholdMs = rum.nativeLongTaskThresholdMs ?: DefaultConfiguration.nativeLongTaskThresholdMs,
183
183
  nativeViewTracking = rum.nativeViewTracking ?: DefaultConfiguration.nativeViewTracking,
184
184
  nativeInteractionTracking = rum.nativeInteractionTracking ?: DefaultConfiguration.nativeInteractionTracking,
185
+ firstPartyHosts = rum.firstPartyHosts?.asFirstPartyHosts(),
185
186
  trackNonFatalAnrs = rum.trackNonFatalAnrs,
186
187
  initialResourceThreshold = rum.initialResourceThreshold ?: DefaultConfiguration.initialResourceThreshold,
187
188
  telemetrySampleRate = rum.telemetrySampleRate?.toDouble()
@@ -220,7 +221,6 @@ internal fun JSONDdSdkConfiguration.asDdSdkConfiguration(): DdSdkConfiguration {
220
221
  batchSize = this.batchSize?: DefaultConfiguration.batchSize,
221
222
  batchProcessingLevel = this.batchProcessingLevel,
222
223
  proxyConfiguration = this.proxyConfiguration?.asProxyConfig(),
223
- firstPartyHosts = this.firstPartyHosts?.asFirstPartyHosts(),
224
224
  rumConfiguration = rumConfiguration,
225
225
  logsConfiguration = logsConfiguration,
226
226
  traceConfiguration = traceConfiguration,
@@ -269,7 +269,7 @@ internal fun List<String>.asTracingHeaderTypes(): Set<TracingHeaderType> {
269
269
  }.toSet()
270
270
  }
271
271
 
272
- @Suppress("LongMethod", "CyclomaticComplexMethod")
272
+ @Suppress("LongMethod", "CyclomaticComplexMethod", "NestedBlockDepth")
273
273
  internal fun DdSdkConfiguration.toReadableMap(): ReadableMap {
274
274
  val map = WritableNativeMap()
275
275
 
@@ -300,25 +300,11 @@ internal fun DdSdkConfiguration.toReadableMap(): ReadableMap {
300
300
  )
301
301
  map.putMap("proxyConfiguration", proxyMap)
302
302
  }
303
- firstPartyHosts?.let { hosts ->
304
- val hostsArray = WritableNativeArray()
305
- hosts.forEach { (match, types) ->
306
- val hostMap = WritableNativeMap()
307
- hostMap.putString("match", match)
308
- val propagatorsArray = WritableNativeArray()
309
- types.forEach { type ->
310
- propagatorsArray.pushString(type.toString())
311
- }
312
- hostMap.putArray("propagatorTypes", propagatorsArray)
313
- hostsArray.pushMap(hostMap)
314
- }
315
- map.putArray("firstPartyHosts", hostsArray)
316
- }
317
303
  rumConfiguration?.let { rum ->
318
304
  val rumMap = WritableNativeMap()
319
305
  rumMap.putString("applicationId", rum.applicationId)
320
306
  rum.trackFrustrations?.let { rumMap.putBoolean("trackFrustrations", it) }
321
- rum.longTaskThresholdMs?.let { map.putDouble("longTaskThresholdMs", it) }
307
+ rum.longTaskThresholdMs?.let { rumMap.putDouble("longTaskThresholdMs", it) }
322
308
  rum.sessionSampleRate?.let { rumMap.putDouble("sessionSampleRate", it) }
323
309
  rum.resourceTraceSampleRate?.let { rumMap.putDouble("resourceTraceSampleRate", it) }
324
310
  rum.vitalsUpdateFrequency?.let { rumMap.putString("vitalsUpdateFrequency", it) }
@@ -328,6 +314,20 @@ internal fun DdSdkConfiguration.toReadableMap(): ReadableMap {
328
314
  rum.nativeViewTracking?.let { rumMap.putBoolean("nativeViewTracking", it) }
329
315
  rum.nativeInteractionTracking?.let { rumMap.putBoolean("nativeInteractionTracking", it) }
330
316
  rum.trackNonFatalAnrs?.let { rumMap.putBoolean("trackNonFatalAnrs", it) }
317
+ rum.firstPartyHosts?.let { hosts ->
318
+ val hostsArray = WritableNativeArray()
319
+ hosts.forEach { (match, types) ->
320
+ val hostMap = WritableNativeMap()
321
+ hostMap.putString("match", match)
322
+ val propagatorsArray = WritableNativeArray()
323
+ types.forEach { type ->
324
+ propagatorsArray.pushString(type.toString())
325
+ }
326
+ hostMap.putArray("propagatorTypes", propagatorsArray)
327
+ hostsArray.pushMap(hostMap)
328
+ }
329
+ rumMap.putArray("firstPartyHosts", hostsArray)
330
+ }
331
331
  rum.initialResourceThreshold?.let { rumMap.putDouble("initialResourceThreshold", it) }
332
332
  rum.telemetrySampleRate?.let { rumMap.putDouble("telemetrySampleRate", it) }
333
333
  rum.customEndpoint?.let { rumMap.putString("customEndpoint", it) }
@@ -306,8 +306,9 @@ class DdSdkNativeInitialization internal constructor(
306
306
  configBuilder.setProxy(proxy, authenticator)
307
307
  }
308
308
 
309
- if (configuration.firstPartyHosts != null) {
310
- configBuilder.setFirstPartyHostsWithHeaderType(configuration.firstPartyHosts)
309
+ val firstPartyHosts = configuration.rumConfiguration?.firstPartyHosts
310
+ if (firstPartyHosts != null) {
311
+ configBuilder.setFirstPartyHostsWithHeaderType(firstPartyHosts)
311
312
  }
312
313
 
313
314
  configBuilder.setBatchProcessingLevel(buildBatchProcessingLevel(configuration.batchProcessingLevel))
@@ -7,4 +7,4 @@
7
7
  package com.datadog.reactnative
8
8
 
9
9
  // This is automatically updated by the update-version.sh script
10
- internal const val SDK_VERSION = "3.1.0"
10
+ internal const val SDK_VERSION = "3.1.2"
@@ -8,7 +8,6 @@ package com.datadog.reactnative
8
8
 
9
9
  import android.util.Log
10
10
  import com.datadog.android.log.Logger
11
- import com.datadog.tools.unit.GenericAssert.Companion.assertThat
12
11
  import com.facebook.react.bridge.Promise
13
12
  import com.facebook.react.bridge.ReadableMap
14
13
  import fr.xgouchet.elmyr.Forge
@@ -25,11 +24,9 @@ import org.junit.jupiter.api.extension.Extensions
25
24
  import org.mockito.Mock
26
25
  import org.mockito.junit.jupiter.MockitoExtension
27
26
  import org.mockito.junit.jupiter.MockitoSettings
28
- import org.mockito.kotlin.argumentCaptor
29
- import org.mockito.kotlin.doReturn
27
+ import org.mockito.kotlin.mock
30
28
  import org.mockito.kotlin.times
31
29
  import org.mockito.kotlin.verify
32
- import org.mockito.kotlin.verifyNoInteractions
33
30
  import org.mockito.kotlin.whenever
34
31
  import org.mockito.quality.Strictness
35
32
 
@@ -71,8 +68,7 @@ internal class DdLogsTest {
71
68
 
72
69
  @BeforeEach
73
70
  fun `set up`(forge: Forge) {
74
- whenever(mockDatadog.isInitialized()) doReturn true
75
- testedLogs = DdLogsImplementation(mockLogger, mockDatadog)
71
+ testedLogs = DdLogsImplementation(datadog = mockDatadog, logger = { mockLogger })
76
72
  fakeErrorKind = forge.aNullable { forge.aString() }
77
73
  fakeErrorMessage = forge.aNullable { forge.aString() }
78
74
  fakeStacktrace = forge.aNullable { forge.aString() }
@@ -272,129 +268,26 @@ internal class DdLogsTest {
272
268
  }
273
269
 
274
270
  @Test
275
- fun `M not forward logs W SDK is not initialized`() {
276
- // When
277
- whenever(mockDatadog.isInitialized()) doReturn false
278
- var newTestedLogs = DdLogsImplementation(mockLogger, mockDatadog)
279
- newTestedLogs.debug(fakeMessage, mockContext, mockPromise)
280
- newTestedLogs.info(fakeMessage, mockContext, mockPromise)
281
- newTestedLogs.warn(fakeMessage, mockContext, mockPromise)
282
- newTestedLogs.error(fakeMessage, mockContext, mockPromise)
283
- testedLogs.debugWithError(
284
- fakeMessage,
285
- fakeErrorKind,
286
- fakeErrorMessage,
287
- fakeStacktrace,
288
- mockContext,
289
- mockPromise
290
- )
291
- testedLogs.infoWithError(
292
- fakeMessage,
293
- fakeErrorKind,
294
- fakeErrorMessage,
295
- fakeStacktrace,
296
- mockContext,
297
- mockPromise
298
- )
299
- testedLogs.warnWithError(
300
- fakeMessage,
301
- fakeErrorKind,
302
- fakeErrorMessage,
303
- fakeStacktrace,
304
- mockContext,
305
- mockPromise
306
- )
307
- testedLogs.errorWithError(
308
- fakeMessage,
309
- fakeErrorKind,
310
- fakeErrorMessage,
311
- fakeStacktrace,
312
- mockContext,
313
- mockPromise
271
+ fun `M recreate logger W SDK is initialized`() {
272
+ // Given
273
+ val mockLoggerFactory = mock<() -> Logger>()
274
+ whenever(mockLoggerFactory()).thenReturn(mockLogger)
275
+ val testedLogs = DdLogsImplementation(
276
+ datadog = mockDatadog,
277
+ logger = mockLoggerFactory
314
278
  )
315
279
 
280
+ // When
281
+ testedLogs.debug(fakeMessage, mockContext, mockPromise)
282
+
316
283
  // Then
317
- verifyNoInteractions(mockLogger)
318
- val exceptionCaptor = argumentCaptor<IllegalStateException>()
319
- verify(mockPromise, times(8)).reject(exceptionCaptor.capture())
320
- assertThat(exceptionCaptor.firstValue.message)
321
- .isEqualTo("DD_INTERNAL_LOG_SENT_BEFORE_SDK_INIT")
322
-
323
- // When SDK is finally initialized
324
- whenever(mockDatadog.isInitialized()) doReturn true
325
- newTestedLogs.debug(fakeMessage, mockContext, mockPromise)
326
- newTestedLogs.info(fakeMessage, mockContext, mockPromise)
327
- newTestedLogs.warn(fakeMessage, mockContext, mockPromise)
328
- newTestedLogs.error(fakeMessage, mockContext, mockPromise)
329
- testedLogs.debugWithError(
330
- fakeMessage,
331
- fakeErrorKind,
332
- fakeErrorMessage,
333
- fakeStacktrace,
334
- mockContext,
335
- mockPromise
336
- )
337
- testedLogs.infoWithError(
338
- fakeMessage,
339
- fakeErrorKind,
340
- fakeErrorMessage,
341
- fakeStacktrace,
342
- mockContext,
343
- mockPromise
344
- )
345
- testedLogs.warnWithError(
346
- fakeMessage,
347
- fakeErrorKind,
348
- fakeErrorMessage,
349
- fakeStacktrace,
350
- mockContext,
351
- mockPromise
352
- )
353
- testedLogs.errorWithError(
354
- fakeMessage,
355
- fakeErrorKind,
356
- fakeErrorMessage,
357
- fakeStacktrace,
358
- mockContext,
359
- mockPromise
360
- )
284
+ verify(mockLoggerFactory, times(1)).invoke()
285
+
286
+ // When
287
+ DatadogSDKWrapperStorage.notifyOnInitializedListeners(mock())
361
288
 
362
289
  // Then
363
- verify(mockLogger).i(fakeMessage, attributes = mockContext.toHashMap())
364
- verify(mockLogger).d(fakeMessage, attributes = mockContext.toHashMap())
365
- verify(mockLogger).w(fakeMessage, attributes = mockContext.toHashMap())
366
- verify(mockLogger).e(fakeMessage, attributes = mockContext.toHashMap())
367
- verify(mockLogger).log(
368
- Log.DEBUG,
369
- fakeMessage,
370
- fakeErrorKind,
371
- fakeErrorMessage,
372
- fakeStacktrace,
373
- attributes = mockContext.toHashMap()
374
- )
375
- verify(mockLogger).log(
376
- Log.INFO,
377
- fakeMessage,
378
- fakeErrorKind,
379
- fakeErrorMessage,
380
- fakeStacktrace,
381
- attributes = mockContext.toHashMap()
382
- )
383
- verify(mockLogger).log(
384
- Log.WARN,
385
- fakeMessage,
386
- fakeErrorKind,
387
- fakeErrorMessage,
388
- fakeStacktrace,
389
- attributes = mockContext.toHashMap()
390
- )
391
- verify(mockLogger).log(
392
- Log.ERROR,
393
- fakeMessage,
394
- fakeErrorKind,
395
- fakeErrorMessage,
396
- fakeStacktrace,
397
- attributes = mockContext.toHashMap()
398
- )
290
+ testedLogs.debug(fakeMessage, mockContext, mockPromise)
291
+ verify(mockLoggerFactory, times(2)).invoke()
399
292
  }
400
293
  }
@@ -131,7 +131,8 @@ internal class DdSdkNativeInitializationTest {
131
131
  }
132
132
  assertThat(configuration.proxyConfiguration?.second?.username).isEqualTo("proxyusername")
133
133
  assertThat(configuration.proxyConfiguration?.second?.password).isEqualTo("proxypassword")
134
- assertThat(configuration.firstPartyHosts?.get("example.com").toString()).isEqualTo(
134
+ val firstPartyHosts = configuration.rumConfiguration?.firstPartyHosts?.get("example.com")
135
+ assertThat(firstPartyHosts.toString()).isEqualTo(
135
136
  "[B3MULTI, TRACECONTEXT]"
136
137
  )
137
138
  assertThat(configuration.rumConfiguration?.initialResourceThreshold).isEqualTo(0.5)
@@ -155,7 +156,7 @@ internal class DdSdkNativeInitializationTest {
155
156
  assertThat(configuration.verbosity).isNull()
156
157
  assertThat(configuration.service).isNull()
157
158
  assertThat(configuration.proxyConfiguration).isNull()
158
- assertThat(configuration.firstPartyHosts).isNull()
159
+
159
160
  assertThat(configuration.site).isEqualTo("US1")
160
161
  assertThat(configuration.uploadFrequency).isEqualTo("AVERAGE")
161
162
  assertThat(configuration.batchSize).isEqualTo("MEDIUM")
@@ -180,6 +181,7 @@ internal class DdSdkNativeInitializationTest {
180
181
  assertThat(configuration.rumConfiguration?.nativeLongTaskThresholdMs).isEqualTo(200.0)
181
182
  assertThat(configuration.rumConfiguration?.nativeViewTracking).isEqualTo(false)
182
183
  assertThat(configuration.rumConfiguration?.nativeInteractionTracking).isEqualTo(false)
184
+ assertThat(configuration.rumConfiguration?.firstPartyHosts).isNull()
183
185
  assertThat(configuration.logsConfiguration?.customEndpoint).isNull()
184
186
  assertThat(configuration.traceConfiguration?.customEndpoint).isNull()
185
187
  }
@@ -1772,9 +1772,10 @@ internal class DdSdkTest {
1772
1772
  }
1773
1773
 
1774
1774
  // Given
1775
- val bridgeConfiguration = configuration.copy(
1775
+ val rumConfiguration = configuration.rumConfiguration?.copy(
1776
1776
  firstPartyHosts = firstPartyHosts.toReadableArray().asFirstPartyHosts()
1777
1777
  )
1778
+ val bridgeConfiguration = configuration.copy(rumConfiguration = rumConfiguration)
1778
1779
  val sdkConfigCaptor = argumentCaptor<Configuration>()
1779
1780
  val rumConfigCaptor = argumentCaptor<RumConfiguration>()
1780
1781
  val logsConfigCaptor = argumentCaptor<LogsConfiguration>()
@@ -1845,9 +1846,10 @@ internal class DdSdkTest {
1845
1846
  }
1846
1847
 
1847
1848
  // Given
1848
- val bridgeConfiguration = configuration.copy(
1849
+ val rumConfiguration = configuration.rumConfiguration?.copy(
1849
1850
  firstPartyHosts = firstPartyHosts.toReadableArray().asFirstPartyHosts()
1850
1851
  )
1852
+ val bridgeConfiguration = configuration.copy(rumConfiguration = rumConfiguration)
1851
1853
  val sdkConfigCaptor = argumentCaptor<Configuration>()
1852
1854
  val rumConfigCaptor = argumentCaptor<RumConfiguration>()
1853
1855
  val logsConfigCaptor = argumentCaptor<LogsConfiguration>()
@@ -1925,9 +1927,10 @@ internal class DdSdkTest {
1925
1927
  )
1926
1928
 
1927
1929
  // Given
1928
- val bridgeConfiguration = configuration.copy(
1930
+ val rumConfiguration = configuration.rumConfiguration?.copy(
1929
1931
  firstPartyHosts = firstPartyHosts.toReadableArray().asFirstPartyHosts()
1930
1932
  )
1933
+ val bridgeConfiguration = configuration.copy(rumConfiguration = rumConfiguration)
1931
1934
  val sdkConfigCaptor = argumentCaptor<Configuration>()
1932
1935
  val rumConfigCaptor = argumentCaptor<RumConfiguration>()
1933
1936
  val logsConfigCaptor = argumentCaptor<LogsConfiguration>()
@@ -40,10 +40,6 @@ fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
40
40
  map["proxyConfiguration"] = proxyPair.toReadableMap()
41
41
  }
42
42
 
43
- firstPartyHosts?.let {
44
- map["firstPartyHosts"] = it.toFirstPartyHostsReadableArray()
45
- }
46
-
47
43
  additionalConfiguration?.let {
48
44
  map["additionalConfiguration"] = it.toReadableMap()
49
45
  }
@@ -65,6 +61,9 @@ fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
65
61
  rum?.nativeViewTracking?.let { rumMap["nativeViewTracking"] = it }
66
62
  rum?.nativeInteractionTracking?.let { rumMap["nativeInteractionTracking"] = it }
67
63
  rum?.trackNonFatalAnrs?.let { rumMap["trackNonFatalAnrs"] = it }
64
+ rum?.firstPartyHosts?.let {
65
+ rumMap["firstPartyHosts"] = it.toFirstPartyHostsReadableArray()
66
+ }
68
67
  rumMap["initialResourceThreshold"] = rum?.initialResourceThreshold ?: 0.1
69
68
  rumMap["telemetrySampleRate"] = rum?.telemetrySampleRate ?: 20.0
70
69
  rum?.customEndpoint?.let { rumMap["customEndpoint"] = it }
@@ -56,7 +56,6 @@ class DdSdkConfigurationForgeryFactory : ForgeryFactory<DdSdkConfiguration> {
56
56
  )
57
57
  },
58
58
  proxyConfiguration = null,
59
- firstPartyHosts = null,
60
59
  rumConfiguration = RumConfiguration(
61
60
  applicationId = forge.getForgery<UUID>().toString(),
62
61
  trackFrustrations = forge.aNullable { aBool() },
@@ -71,6 +70,7 @@ class DdSdkConfigurationForgeryFactory : ForgeryFactory<DdSdkConfiguration> {
71
70
  nativeLongTaskThresholdMs = forge.aNullable { aDouble(100.0, 5000.0) },
72
71
  nativeViewTracking = forge.aNullable { aBool() },
73
72
  nativeInteractionTracking = forge.aNullable { aBool() },
73
+ firstPartyHosts = null,
74
74
  trackNonFatalAnrs = forge.aNullable { aBool() },
75
75
  initialResourceThreshold = forge.aNullable { aDouble(0.0, 2.0) },
76
76
  telemetrySampleRate = forge.aNullable { aDouble(0.0, 100.0) },
@@ -29,7 +29,16 @@
29
29
  "sessionSampleRate": 80,
30
30
  "resourceTraceSampleRate": 33,
31
31
  "trackBackgroundEvents": true,
32
- "trackFrustrations": false
32
+ "trackFrustrations": false,
33
+ "firstPartyHosts": [
34
+ {
35
+ "match": "example.com",
36
+ "propagatorTypes": [
37
+ "B3MULTI",
38
+ "TRACECONTEXT"
39
+ ]
40
+ }
41
+ ]
33
42
  },
34
43
  "logsConfiguration": {
35
44
  "customEndpoint": "https://logs.example.com"
@@ -37,15 +46,6 @@
37
46
  "traceConfiguration": {
38
47
  "customEndpoint": "https://trace.example.com"
39
48
  },
40
- "firstPartyHosts": [
41
- {
42
- "match": "example.com",
43
- "propagatorTypes": [
44
- "B3MULTI",
45
- "TRACECONTEXT"
46
- ]
47
- }
48
- ],
49
49
  "proxyConfiguration": {
50
50
  "address": "1.1.1.1",
51
51
  "port": 4444,
@@ -11,11 +11,21 @@ import DatadogCore
11
11
 
12
12
  @objc
13
13
  public class DdLogsImplementation: NSObject {
14
- private lazy var logger: LoggerProtocol = loggerProvider()
14
+ private var loggerInstance: LoggerProtocol?
15
+ private var logger: LoggerProtocol {
16
+ if loggerInstance == nil {
17
+ loggerInstance = loggerProvider()
18
+ }
19
+ return loggerInstance!
20
+ }
15
21
  private let loggerProvider: () -> LoggerProtocol
16
-
22
+
17
23
  internal init(_ loggerProvider: @escaping () -> LoggerProtocol) {
18
24
  self.loggerProvider = loggerProvider
25
+ super.init()
26
+ DatadogSDKWrapper.shared.addOnSdkInitializedListener { [weak self] _ in
27
+ self?.loggerInstance = nil
28
+ }
19
29
  }
20
30
 
21
31
  @objc
@@ -94,4 +104,4 @@ internal extension DatadogLogs.Logger.Configuration {
94
104
  consoleLogFormat: .short
95
105
  )
96
106
  }
97
- }
107
+ }