@datadog/mobile-react-native 1.5.1 → 1.6.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.
Files changed (104) hide show
  1. package/DatadogSDKReactNative.podspec +2 -2
  2. package/android/build.gradle +1 -1
  3. package/android/gradle.properties +1 -1
  4. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +4 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +6 -1
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdLogs.kt +162 -6
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdRum.kt +9 -0
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +4 -0
  9. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +5 -1
  10. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +4 -0
  11. package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +242 -2
  12. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +10 -0
  13. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +6 -2
  14. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +2 -0
  15. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +2 -2
  16. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +3 -1
  17. package/ios/Sources/Attributes.swift +7 -0
  18. package/ios/Sources/DdLogs.m +31 -0
  19. package/ios/Sources/DdLogs.swift +84 -4
  20. package/ios/Sources/DdRum.m +3 -0
  21. package/ios/Sources/DdRum.swift +7 -0
  22. package/ios/Sources/DdSdk.swift +2 -0
  23. package/ios/Sources/DdSdkConfiguration.swift +7 -1
  24. package/ios/Sources/RNDdSdkConfiguration.swift +5 -1
  25. package/lib/commonjs/DdSdkReactNative.js +5 -1
  26. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  27. package/lib/commonjs/InternalLog.js +6 -2
  28. package/lib/commonjs/InternalLog.js.map +1 -1
  29. package/lib/commonjs/errorUtils.js +20 -1
  30. package/lib/commonjs/errorUtils.js.map +1 -1
  31. package/lib/commonjs/logs/DdLogs.js +102 -11
  32. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  33. package/lib/commonjs/logs/eventMapper.js.map +1 -1
  34. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  35. package/lib/commonjs/rum/DdRum.js +6 -0
  36. package/lib/commonjs/rum/DdRum.js.map +1 -1
  37. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +60 -46
  38. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  39. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +2 -2
  40. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  41. package/lib/commonjs/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js +9 -1
  42. package/lib/commonjs/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js.map +1 -1
  43. package/lib/commonjs/rum/types.js.map +1 -1
  44. package/lib/commonjs/types.js.map +1 -1
  45. package/lib/commonjs/version.js +1 -1
  46. package/lib/commonjs/version.js.map +1 -1
  47. package/lib/module/DdSdkReactNative.js +5 -1
  48. package/lib/module/DdSdkReactNative.js.map +1 -1
  49. package/lib/module/InternalLog.js +2 -1
  50. package/lib/module/InternalLog.js.map +1 -1
  51. package/lib/module/errorUtils.js +15 -0
  52. package/lib/module/errorUtils.js.map +1 -1
  53. package/lib/module/logs/DdLogs.js +103 -12
  54. package/lib/module/logs/DdLogs.js.map +1 -1
  55. package/lib/module/logs/eventMapper.js.map +1 -1
  56. package/lib/module/nativeModulesTypes.js.map +1 -1
  57. package/lib/module/rum/DdRum.js +5 -0
  58. package/lib/module/rum/DdRum.js.map +1 -1
  59. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +61 -46
  60. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  61. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +2 -2
  62. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
  63. package/lib/module/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js +9 -1
  64. package/lib/module/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js.map +1 -1
  65. package/lib/module/rum/types.js.map +1 -1
  66. package/lib/module/types.js.map +1 -1
  67. package/lib/module/version.js +1 -1
  68. package/lib/module/version.js.map +1 -1
  69. package/lib/typescript/InternalLog.d.ts +1 -0
  70. package/lib/typescript/errorUtils.d.ts +2 -0
  71. package/lib/typescript/logs/DdLogs.d.ts +13 -5
  72. package/lib/typescript/logs/eventMapper.d.ts +5 -5
  73. package/lib/typescript/logs/types.d.ts +34 -8
  74. package/lib/typescript/nativeModulesTypes.d.ts +44 -4
  75. package/lib/typescript/rum/DdRum.d.ts +1 -0
  76. package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +3 -2
  77. package/lib/typescript/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts +1 -1
  78. package/lib/typescript/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.d.ts +5 -2
  79. package/lib/typescript/rum/types.d.ts +4 -0
  80. package/lib/typescript/types.d.ts +4 -0
  81. package/lib/typescript/version.d.ts +1 -1
  82. package/package.json +2 -2
  83. package/src/DdSdkReactNative.tsx +6 -1
  84. package/src/InternalLog.tsx +3 -1
  85. package/src/__tests__/errorUtils.test.ts +49 -0
  86. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +14 -14
  87. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +452 -109
  88. package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +18 -0
  89. package/src/errorUtils.ts +15 -0
  90. package/src/logs/DdLogs.ts +166 -16
  91. package/src/logs/__tests__/DdLogs.test.ts +169 -0
  92. package/src/logs/__tests__/eventMapper.test.ts +34 -0
  93. package/src/logs/eventMapper.ts +15 -4
  94. package/src/logs/types.ts +36 -8
  95. package/src/nativeModulesTypes.ts +73 -4
  96. package/src/rum/DdRum.ts +5 -0
  97. package/src/rum/__tests__/DdRum.test.ts +12 -27
  98. package/src/rum/instrumentation/DdRumErrorTracking.tsx +41 -10
  99. package/src/rum/instrumentation/interactionTracking/DdEventsInterceptor.tsx +7 -4
  100. package/src/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.ts +11 -3
  101. package/src/rum/types.ts +5 -0
  102. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -0
  103. package/src/types.tsx +2 -0
  104. package/src/version.ts +1 -1
@@ -17,8 +17,8 @@ Pod::Spec.new do |s|
17
17
  s.source_files = "ios/Sources/*.{h,m,mm,swift}"
18
18
 
19
19
  s.dependency "React-Core"
20
- s.dependency 'DatadogSDK', '~> 1.16.0'
21
- s.dependency 'DatadogSDKCrashReporting', '~> 1.16.0'
20
+ s.dependency 'DatadogSDK', '~> 1.19.0'
21
+ s.dependency 'DatadogSDKCrashReporting', '~> 1.19.0'
22
22
 
23
23
  s.test_spec 'Tests' do |test_spec|
24
24
  test_spec.source_files = 'ios/Tests/*.swift'
@@ -146,7 +146,7 @@ dependencies {
146
146
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
147
147
  compileOnly "com.squareup.okhttp3:okhttp:3.12.13"
148
148
 
149
- implementation "com.datadoghq:dd-sdk-android:1.18.1"
149
+ implementation "com.datadoghq:dd-sdk-android:1.19.0"
150
150
  testImplementation "org.junit.platform:junit-platform-launcher:1.6.2"
151
151
  testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
152
152
  testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2"
@@ -1,4 +1,4 @@
1
- DdSdkReactNative_kotlinVersion=1.5.31
1
+ DdSdkReactNative_kotlinVersion=1.6.21
2
2
  DdSdkReactNative_compileSdkVersion=31
3
3
  DdSdkReactNative_buildToolsVersion=31.0.0
4
4
  DdSdkReactNative_targetSdkVersion=31
@@ -67,4 +67,8 @@ internal class DatadogSDKWrapper : DatadogWrapper {
67
67
  override fun consumeWebviewEvent(message: String) {
68
68
  Datadog._internal.consumeWebviewEvent(message)
69
69
  }
70
+
71
+ override fun isInitialized(): Boolean {
72
+ return Datadog.isInitialized()
73
+ }
70
74
  }
@@ -16,7 +16,7 @@ import java.lang.IllegalArgumentException
16
16
  /**
17
17
  * Wrapper around [Datadog].
18
18
  */
19
- @Suppress("ComplexInterface")
19
+ @Suppress("ComplexInterface", "TooManyFunctions")
20
20
  interface DatadogWrapper {
21
21
 
22
22
  /**
@@ -104,4 +104,9 @@ interface DatadogWrapper {
104
104
  * Sends Webview events.
105
105
  */
106
106
  fun consumeWebviewEvent(message: String)
107
+
108
+ /**
109
+ * Returns whether the SDK is initialized.
110
+ */
111
+ fun isInitialized(): Boolean
107
112
  }
@@ -6,6 +6,7 @@
6
6
 
7
7
  package com.datadog.reactnative
8
8
 
9
+ import android.util.Log as AndroidLog
9
10
  import com.datadog.android.log.Logger
10
11
  import com.facebook.react.bridge.Promise
11
12
  import com.facebook.react.bridge.ReactApplicationContext
@@ -16,8 +17,11 @@ import com.facebook.react.bridge.ReadableMap
16
17
  /**
17
18
  * The entry point to use Datadog's Logs feature.
18
19
  */
19
- class DdLogs(reactContext: ReactApplicationContext, logger: Logger? = null) :
20
- ReactContextBaseJavaModule(reactContext) {
20
+ class DdLogs(
21
+ reactContext: ReactApplicationContext,
22
+ logger: Logger? = null,
23
+ private val datadog: DatadogWrapper = DatadogSDKWrapper()
24
+ ) : ReactContextBaseJavaModule(reactContext) {
21
25
 
22
26
  override fun getName(): String = "DdLogs"
23
27
 
@@ -30,12 +34,16 @@ class DdLogs(reactContext: ReactApplicationContext, logger: Logger? = null) :
30
34
  }
31
35
 
32
36
  /**
33
- * Send a log with level debug.
37
+ * Send a log with Debug level.
34
38
  * @param message The message to send.
35
39
  * @param context The additional context to send.
36
40
  */
37
41
  @ReactMethod
38
42
  fun debug(message: String, context: ReadableMap, promise: Promise) {
43
+ if (!datadog.isInitialized()) {
44
+ promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
45
+ return
46
+ }
39
47
  reactNativeLogger.d(
40
48
  message = message,
41
49
  attributes = context.toHashMap() + GlobalState.globalAttributes
@@ -44,12 +52,16 @@ class DdLogs(reactContext: ReactApplicationContext, logger: Logger? = null) :
44
52
  }
45
53
 
46
54
  /**
47
- * Send a log with level info.
55
+ * Send a log with Info level.
48
56
  * @param message The message to send.
49
57
  * @param context The additional context to send.
50
58
  */
51
59
  @ReactMethod
52
60
  fun info(message: String, context: ReadableMap, promise: Promise) {
61
+ if (!datadog.isInitialized()) {
62
+ promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
63
+ return
64
+ }
53
65
  reactNativeLogger.i(
54
66
  message = message,
55
67
  attributes = context.toHashMap() + GlobalState.globalAttributes
@@ -58,12 +70,16 @@ class DdLogs(reactContext: ReactApplicationContext, logger: Logger? = null) :
58
70
  }
59
71
 
60
72
  /**
61
- * Send a log with level warn.
73
+ * Send a log with Warn level.
62
74
  * @param message The message to send.
63
75
  * @param context The additional context to send.
64
76
  */
65
77
  @ReactMethod
66
78
  fun warn(message: String, context: ReadableMap, promise: Promise) {
79
+ if (!datadog.isInitialized()) {
80
+ promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
81
+ return
82
+ }
67
83
  reactNativeLogger.w(
68
84
  message = message,
69
85
  attributes = context.toHashMap() + GlobalState.globalAttributes
@@ -72,16 +88,156 @@ class DdLogs(reactContext: ReactApplicationContext, logger: Logger? = null) :
72
88
  }
73
89
 
74
90
  /**
75
- * Send a log with level error.
91
+ * Send a log with Error level.
76
92
  * @param message The message to send.
77
93
  * @param context The additional context to send.
78
94
  */
79
95
  @ReactMethod
80
96
  fun error(message: String, context: ReadableMap, promise: Promise) {
97
+ if (!datadog.isInitialized()) {
98
+ promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
99
+ return
100
+ }
81
101
  reactNativeLogger.e(
82
102
  message = message,
83
103
  attributes = context.toHashMap() + GlobalState.globalAttributes
84
104
  )
85
105
  promise.resolve(null)
86
106
  }
107
+
108
+ /**
109
+ * Send a log containing an error with Debug level.
110
+ * @param message The message to send.
111
+ * @param errorKind The error kind to send.
112
+ * @param errorMessage The error message to send.
113
+ * @param stacktrace The error stacktrace to send.
114
+ * @param context The additional context to send.
115
+ */
116
+ @Suppress("LongParameterList")
117
+ @ReactMethod
118
+ fun debugWithError(
119
+ message: String,
120
+ errorKind: String?,
121
+ errorMessage: String?,
122
+ stacktrace: String?,
123
+ context: ReadableMap,
124
+ promise: Promise
125
+ ) {
126
+ if (!datadog.isInitialized()) {
127
+ promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
128
+ return
129
+ }
130
+ reactNativeLogger.log(
131
+ priority = AndroidLog.DEBUG,
132
+ message = message,
133
+ errorKind = errorKind,
134
+ errorMessage = errorMessage,
135
+ errorStacktrace = stacktrace,
136
+ attributes = context.toHashMap() + GlobalState.globalAttributes
137
+ )
138
+ promise.resolve(null)
139
+ }
140
+
141
+ /**
142
+ * Send a log with containing an error with Info level.
143
+ * @param message The message to send.
144
+ * @param errorKind The error kind to send.
145
+ * @param errorMessage The error message to send.
146
+ * @param stacktrace The error stacktrace to send.
147
+ * @param context The additional context to send.
148
+ */
149
+ @Suppress("LongParameterList")
150
+ @ReactMethod
151
+ fun infoWithError(
152
+ message: String,
153
+ errorKind: String?,
154
+ errorMessage: String?,
155
+ stacktrace: String?,
156
+ context: ReadableMap,
157
+ promise: Promise
158
+ ) {
159
+ if (!datadog.isInitialized()) {
160
+ promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
161
+ return
162
+ }
163
+ reactNativeLogger.log(
164
+ priority = AndroidLog.INFO,
165
+ message = message,
166
+ errorKind = errorKind,
167
+ errorMessage = errorMessage,
168
+ errorStacktrace = stacktrace,
169
+ attributes = context.toHashMap() + GlobalState.globalAttributes
170
+ )
171
+ promise.resolve(null)
172
+ }
173
+
174
+ /**
175
+ * Send a log containing an error with Warn level.
176
+ * @param message The message to send.
177
+ * @param errorKind The error kind to send.
178
+ * @param errorMessage The error message to send.
179
+ * @param stacktrace The error stacktrace to send.
180
+ * @param context The additional context to send.
181
+ */
182
+ @Suppress("LongParameterList")
183
+ @ReactMethod
184
+ fun warnWithError(
185
+ message: String,
186
+ errorKind: String?,
187
+ errorMessage: String?,
188
+ stacktrace: String?,
189
+ context: ReadableMap,
190
+ promise: Promise
191
+ ) {
192
+ if (!datadog.isInitialized()) {
193
+ promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
194
+ return
195
+ }
196
+ reactNativeLogger.log(
197
+ priority = AndroidLog.WARN,
198
+ message = message,
199
+ errorKind = errorKind,
200
+ errorMessage = errorMessage,
201
+ errorStacktrace = stacktrace,
202
+ attributes = context.toHashMap() + GlobalState.globalAttributes
203
+ )
204
+ promise.resolve(null)
205
+ }
206
+
207
+ /**
208
+ * Send a log containing an error with Error level.
209
+ * @param message The message to send.
210
+ * @param errorKind The error kind to send.
211
+ * @param errorMessage The error message to send.
212
+ * @param stacktrace The error stacktrace to send.
213
+ * @param context The additional context to send.
214
+ */
215
+ @Suppress("LongParameterList")
216
+ @ReactMethod
217
+ fun errorWithError(
218
+ message: String,
219
+ errorKind: String?,
220
+ errorMessage: String?,
221
+ stacktrace: String?,
222
+ context: ReadableMap,
223
+ promise: Promise
224
+ ) {
225
+ if (!datadog.isInitialized()) {
226
+ promise.reject(IllegalStateException(SDK_NOT_INITIALIZED_MESSAGE))
227
+ return
228
+ }
229
+ reactNativeLogger.log(
230
+ priority = AndroidLog.ERROR,
231
+ message = message,
232
+ errorKind = errorKind,
233
+ errorMessage = errorMessage,
234
+ errorStacktrace = stacktrace,
235
+ attributes = context.toHashMap() + GlobalState.globalAttributes
236
+ )
237
+ promise.resolve(null)
238
+ }
239
+
240
+ companion object {
241
+ private const val SDK_NOT_INITIALIZED_MESSAGE = "DD_INTERNAL_LOG_SENT_BEFORE_SDK_INIT"
242
+ }
87
243
  }
@@ -255,6 +255,15 @@ class DdRum(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(
255
255
  promise.resolve(null)
256
256
  }
257
257
 
258
+ /**
259
+ * Stops the current RUM Session.
260
+ */
261
+ @ReactMethod
262
+ fun stopSession(promise: Promise) {
263
+ GlobalRum.get().stopSession()
264
+ promise.resolve(null)
265
+ }
266
+
258
267
  // region Internal
259
268
 
260
269
  private fun String.asRumActionType(): RumActionType {
@@ -303,6 +303,10 @@ class DdSdk(
303
303
  configuration.configurationForTelemetry?.trackNetworkRequests
304
304
  event.telemetry.configuration.trackNetworkRequests =
305
305
  configuration.configurationForTelemetry?.trackNetworkRequests
306
+ event.telemetry.configuration.reactVersion =
307
+ configuration.configurationForTelemetry?.reactVersion
308
+ event.telemetry.configuration.reactNativeVersion =
309
+ configuration.configurationForTelemetry?.reactNativeVersion
306
310
 
307
311
  return event
308
312
  }
@@ -46,10 +46,14 @@ data class DdSdkConfiguration(
46
46
  * @param trackErrors Whether JS errors are tracked.
47
47
  * @param trackInteractions Whether interactions are tracked.
48
48
  * @param trackNetworkRequests Whether network requests are tracked.
49
+ * @param reactVersion Version of react used in app.
50
+ * @param reactNativeVersion Version of react-native used in app.
49
51
  */
50
52
  data class ConfigurationForTelemetry(
51
53
  val initializationType: String? = null,
52
54
  val trackErrors: Boolean? = null,
53
55
  val trackInteractions: Boolean? = null,
54
- val trackNetworkRequests: Boolean? = null
56
+ val trackNetworkRequests: Boolean? = null,
57
+ val reactVersion: String? = null,
58
+ val reactNativeVersion: String? = null
55
59
  )
@@ -38,6 +38,8 @@ internal fun ReadableMap.asConfigurationForTelemetry(): ConfigurationForTelemetr
38
38
  trackErrors = getBoolean("trackErrors"),
39
39
  trackInteractions = getBoolean("trackInteractions"),
40
40
  trackNetworkRequests = getBoolean("trackNetworkRequests"),
41
+ reactVersion = getString("reactVersion"),
42
+ reactNativeVersion = getString("reactNativeVersion"),
41
43
  )
42
44
  }
43
45
 
@@ -78,5 +80,7 @@ internal fun ConfigurationForTelemetry.toReadableMap(): ReadableMap {
78
80
  trackErrors?.let { map.putBoolean("trackErrors", it) }
79
81
  trackInteractions?.let { map.putBoolean("trackInteractions", it) }
80
82
  trackNetworkRequests?.let { map.putBoolean("trackNetworkRequests", it) }
83
+ reactVersion?.let { map.putString("reactVersion", it) }
84
+ reactNativeVersion?.let { map.putString("reactNativeVersion", it) }
81
85
  return map
82
86
  }
@@ -6,11 +6,19 @@
6
6
 
7
7
  package com.datadog.reactnative
8
8
 
9
+ import android.util.Log
9
10
  import com.datadog.android.log.Logger
11
+ import com.datadog.tools.unit.GenericAssert.Companion.assertThat
10
12
  import com.facebook.react.bridge.Promise
11
13
  import com.facebook.react.bridge.ReactApplicationContext
12
14
  import com.facebook.react.bridge.ReadableMap
15
+ import com.nhaarman.mockitokotlin2.argumentCaptor
16
+ import com.nhaarman.mockitokotlin2.doReturn
17
+ import com.nhaarman.mockitokotlin2.times
13
18
  import com.nhaarman.mockitokotlin2.verify
19
+ import com.nhaarman.mockitokotlin2.verifyZeroInteractions
20
+ import com.nhaarman.mockitokotlin2.whenever
21
+ import fr.xgouchet.elmyr.Forge
14
22
  import fr.xgouchet.elmyr.annotation.AdvancedForgery
15
23
  import fr.xgouchet.elmyr.annotation.MapForgery
16
24
  import fr.xgouchet.elmyr.annotation.StringForgery
@@ -41,9 +49,18 @@ internal class DdLogsTest {
41
49
  @StringForgery
42
50
  lateinit var fakeMessage: String
43
51
 
52
+ private var fakeErrorKind: String? = null
53
+
54
+ private var fakeErrorMessage: String? = null
55
+
56
+ private var fakeStacktrace: String? = null
57
+
44
58
  @Mock
45
59
  lateinit var mockPromise: Promise
46
60
 
61
+ @Mock
62
+ lateinit var mockDatadog: DatadogWrapper
63
+
47
64
  @Mock
48
65
  lateinit var mockReactContext: ReactApplicationContext
49
66
 
@@ -63,8 +80,12 @@ internal class DdLogsTest {
63
80
  lateinit var fakeGlobalState: Map<String, String>
64
81
 
65
82
  @BeforeEach
66
- fun `set up`() {
67
- testedLogs = DdLogs(mockReactContext, mockLogger)
83
+ fun `set up`(forge: Forge) {
84
+ whenever(mockDatadog.isInitialized()) doReturn true
85
+ testedLogs = DdLogs(mockReactContext, mockLogger, mockDatadog)
86
+ fakeErrorKind = forge.aNullable { forge.aString() }
87
+ fakeErrorMessage = forge.aNullable { forge.aString() }
88
+ fakeStacktrace = forge.aNullable { forge.aString() }
68
89
  }
69
90
 
70
91
  @AfterEach
@@ -167,4 +188,223 @@ internal class DdLogsTest {
167
188
  // Then
168
189
  verify(mockLogger).e(fakeMessage, attributes = expectedAttributes)
169
190
  }
191
+
192
+ @Test
193
+ fun `M forward debug log with error W debugWithError()`() {
194
+ // When
195
+ testedLogs.debugWithError(
196
+ fakeMessage,
197
+ fakeErrorKind,
198
+ fakeErrorMessage,
199
+ fakeStacktrace,
200
+ mockContext,
201
+ mockPromise
202
+ )
203
+
204
+ // Then
205
+ verify(mockLogger).log(
206
+ Log.DEBUG,
207
+ fakeMessage,
208
+ fakeErrorKind,
209
+ fakeErrorMessage,
210
+ fakeStacktrace,
211
+ attributes = mockContext.toHashMap()
212
+ )
213
+ }
214
+
215
+ @Test
216
+ fun `M forward info log with error W infoWithError()`() {
217
+ // When
218
+ testedLogs.infoWithError(
219
+ fakeMessage,
220
+ fakeErrorKind,
221
+ fakeErrorMessage,
222
+ fakeStacktrace,
223
+ mockContext,
224
+ mockPromise
225
+ )
226
+
227
+ // Then
228
+ verify(mockLogger).log(
229
+ Log.INFO,
230
+ fakeMessage,
231
+ fakeErrorKind,
232
+ fakeErrorMessage,
233
+ fakeStacktrace,
234
+ attributes = mockContext.toHashMap()
235
+ )
236
+ }
237
+
238
+ @Test
239
+ fun `M forward warn log with error W warnWithError()`() {
240
+ // When
241
+ testedLogs.warnWithError(
242
+ fakeMessage,
243
+ fakeErrorKind,
244
+ fakeErrorMessage,
245
+ fakeStacktrace,
246
+ mockContext,
247
+ mockPromise
248
+ )
249
+
250
+ // Then
251
+ verify(mockLogger).log(
252
+ Log.WARN,
253
+ fakeMessage,
254
+ fakeErrorKind,
255
+ fakeErrorMessage,
256
+ fakeStacktrace,
257
+ attributes = mockContext.toHashMap()
258
+ )
259
+ }
260
+
261
+ @Test
262
+ fun `M forward error log with error W errorWithError()`() {
263
+ // When
264
+ testedLogs.errorWithError(
265
+ fakeMessage,
266
+ fakeErrorKind,
267
+ fakeErrorMessage,
268
+ fakeStacktrace,
269
+ mockContext,
270
+ mockPromise
271
+ )
272
+
273
+ // Then
274
+ verify(mockLogger).log(
275
+ Log.ERROR,
276
+ fakeMessage,
277
+ fakeErrorKind,
278
+ fakeErrorMessage,
279
+ fakeStacktrace,
280
+ attributes = mockContext.toHashMap()
281
+ )
282
+ }
283
+
284
+ @Test
285
+ fun `M not forward logs W SDK is not initialized`() {
286
+ // When
287
+ whenever(mockDatadog.isInitialized()) doReturn false
288
+ var newTestedLogs = DdLogs(mockReactContext, mockLogger, mockDatadog)
289
+ newTestedLogs.debug(fakeMessage, mockContext, mockPromise)
290
+ newTestedLogs.info(fakeMessage, mockContext, mockPromise)
291
+ newTestedLogs.warn(fakeMessage, mockContext, mockPromise)
292
+ newTestedLogs.error(fakeMessage, mockContext, mockPromise)
293
+ testedLogs.debugWithError(
294
+ fakeMessage,
295
+ fakeErrorKind,
296
+ fakeErrorMessage,
297
+ fakeStacktrace,
298
+ mockContext,
299
+ mockPromise
300
+ )
301
+ testedLogs.infoWithError(
302
+ fakeMessage,
303
+ fakeErrorKind,
304
+ fakeErrorMessage,
305
+ fakeStacktrace,
306
+ mockContext,
307
+ mockPromise
308
+ )
309
+ testedLogs.warnWithError(
310
+ fakeMessage,
311
+ fakeErrorKind,
312
+ fakeErrorMessage,
313
+ fakeStacktrace,
314
+ mockContext,
315
+ mockPromise
316
+ )
317
+ testedLogs.errorWithError(
318
+ fakeMessage,
319
+ fakeErrorKind,
320
+ fakeErrorMessage,
321
+ fakeStacktrace,
322
+ mockContext,
323
+ mockPromise
324
+ )
325
+
326
+ // Then
327
+ verifyZeroInteractions(mockLogger)
328
+ val exceptionCaptor = argumentCaptor<IllegalStateException>()
329
+ verify(mockPromise, times(8)).reject(exceptionCaptor.capture())
330
+ assertThat(exceptionCaptor.firstValue.message)
331
+ .isEqualTo("DD_INTERNAL_LOG_SENT_BEFORE_SDK_INIT")
332
+
333
+ // When SDK is finally initialized
334
+ whenever(mockDatadog.isInitialized()) doReturn true
335
+ newTestedLogs.debug(fakeMessage, mockContext, mockPromise)
336
+ newTestedLogs.info(fakeMessage, mockContext, mockPromise)
337
+ newTestedLogs.warn(fakeMessage, mockContext, mockPromise)
338
+ newTestedLogs.error(fakeMessage, mockContext, mockPromise)
339
+ testedLogs.debugWithError(
340
+ fakeMessage,
341
+ fakeErrorKind,
342
+ fakeErrorMessage,
343
+ fakeStacktrace,
344
+ mockContext,
345
+ mockPromise
346
+ )
347
+ testedLogs.infoWithError(
348
+ fakeMessage,
349
+ fakeErrorKind,
350
+ fakeErrorMessage,
351
+ fakeStacktrace,
352
+ mockContext,
353
+ mockPromise
354
+ )
355
+ testedLogs.warnWithError(
356
+ fakeMessage,
357
+ fakeErrorKind,
358
+ fakeErrorMessage,
359
+ fakeStacktrace,
360
+ mockContext,
361
+ mockPromise
362
+ )
363
+ testedLogs.errorWithError(
364
+ fakeMessage,
365
+ fakeErrorKind,
366
+ fakeErrorMessage,
367
+ fakeStacktrace,
368
+ mockContext,
369
+ mockPromise
370
+ )
371
+
372
+ // Then
373
+ verify(mockLogger).i(fakeMessage, attributes = mockContext.toHashMap())
374
+ verify(mockLogger).d(fakeMessage, attributes = mockContext.toHashMap())
375
+ verify(mockLogger).w(fakeMessage, attributes = mockContext.toHashMap())
376
+ verify(mockLogger).e(fakeMessage, attributes = mockContext.toHashMap())
377
+ verify(mockLogger).log(
378
+ Log.DEBUG,
379
+ fakeMessage,
380
+ fakeErrorKind,
381
+ fakeErrorMessage,
382
+ fakeStacktrace,
383
+ attributes = mockContext.toHashMap()
384
+ )
385
+ verify(mockLogger).log(
386
+ Log.INFO,
387
+ fakeMessage,
388
+ fakeErrorKind,
389
+ fakeErrorMessage,
390
+ fakeStacktrace,
391
+ attributes = mockContext.toHashMap()
392
+ )
393
+ verify(mockLogger).log(
394
+ Log.WARN,
395
+ fakeMessage,
396
+ fakeErrorKind,
397
+ fakeErrorMessage,
398
+ fakeStacktrace,
399
+ attributes = mockContext.toHashMap()
400
+ )
401
+ verify(mockLogger).log(
402
+ Log.ERROR,
403
+ fakeMessage,
404
+ fakeErrorKind,
405
+ fakeErrorMessage,
406
+ fakeStacktrace,
407
+ attributes = mockContext.toHashMap()
408
+ )
409
+ }
170
410
  }
@@ -410,4 +410,14 @@ internal class DdRumTest {
410
410
  // Then
411
411
  verify(mockRumMonitor).addTiming(timing)
412
412
  }
413
+
414
+ @Test
415
+ fun `M call stopSession W stopSession()`() {
416
+
417
+ // When
418
+ testedDdRum.stopSession(mockPromise)
419
+
420
+ // Then
421
+ verify(mockRumMonitor).stopSession()
422
+ }
413
423
  }
@@ -1827,7 +1827,9 @@ internal class DdSdkTest {
1827
1827
  @StringForgery initializationType: String,
1828
1828
  @BoolForgery trackInteractions: Boolean,
1829
1829
  @BoolForgery trackErrors: Boolean,
1830
- @BoolForgery trackNetworkRequests: Boolean
1830
+ @BoolForgery trackNetworkRequests: Boolean,
1831
+ @StringForgery reactVersion: String,
1832
+ @StringForgery reactNativeVersion: String
1831
1833
  ) {
1832
1834
  // Given
1833
1835
  val bridgeConfiguration = configuration.copy(
@@ -1838,7 +1840,9 @@ internal class DdSdkTest {
1838
1840
  initializationType = initializationType,
1839
1841
  trackErrors = trackErrors,
1840
1842
  trackInteractions = trackInteractions,
1841
- trackNetworkRequests = trackNetworkRequests
1843
+ trackNetworkRequests = trackNetworkRequests,
1844
+ reactVersion = reactVersion,
1845
+ reactNativeVersion = reactNativeVersion
1842
1846
  )
1843
1847
  )
1844
1848
  val configCaptor = argumentCaptor<Configuration>()
@@ -73,5 +73,7 @@ internal fun ConfigurationForTelemetry.toReadableJavaOnlyMap(): ReadableMap {
73
73
  trackErrors?.let { map.put("trackErrors", it) }
74
74
  trackInteractions?.let { map.put("trackInteractions", it) }
75
75
  trackNetworkRequests?.let { map.put("trackNetworkRequests", it) }
76
+ reactVersion?.let { map.put("reactVersion", it) }
77
+ reactNativeVersion?.let { map.put("reactNativeVersion", it) }
76
78
  return map.toReadableMap()
77
79
  }
@@ -9,7 +9,7 @@ package com.datadog.tools.unit
9
9
  import org.assertj.core.api.AbstractAssert
10
10
  import org.assertj.core.api.Assertions.assertThat
11
11
 
12
- class GenericAssert(actual: Any) :
12
+ class GenericAssert(actual: Any?) :
13
13
  AbstractAssert<GenericAssert, Any>(actual, GenericAssert::class.java) {
14
14
 
15
15
  fun doesNotHaveField(name: String): GenericAssert {
@@ -62,7 +62,7 @@ class GenericAssert(actual: Any) :
62
62
  }
63
63
 
64
64
  companion object {
65
- fun assertThat(actual: Any): GenericAssert {
65
+ fun assertThat(actual: Any?): GenericAssert {
66
66
  return GenericAssert(actual)
67
67
  }
68
68
  }