@datadog/mobile-react-native 1.0.0-rc8 → 1.1.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 (192) hide show
  1. package/DatadogSDKReactNative.podspec +2 -1
  2. package/android/build.gradle +73 -3
  3. package/android/gradle.properties +1 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +54 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +86 -0
  6. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdLogs.kt +27 -11
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdRum.kt +305 -0
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +280 -0
  9. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkBridgeExt.kt +2 -2
  10. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +29 -0
  11. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkConfigurationExt.kt +2 -4
  12. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkReactNativePackage.kt +3 -0
  13. package/android/src/main/kotlin/com/datadog/reactnative/DdTrace.kt +86 -0
  14. package/android/src/main/kotlin/com/datadog/reactnative/GlobalState.kt +32 -0
  15. package/android/src/main/kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt +23 -0
  16. package/android/src/main/kotlin/com/datadog/reactnative/ProxyAuthenticator.kt +60 -0
  17. package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +170 -0
  18. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +408 -0
  19. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +1547 -0
  20. package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +306 -0
  21. package/android/src/test/kotlin/com/datadog/reactnative/GlobalStateTest.kt +118 -0
  22. package/android/src/test/kotlin/com/datadog/reactnative/ProxyAuthenticatorTest.kt +123 -0
  23. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +33 -0
  24. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +43 -0
  25. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +22 -0
  26. package/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt +267 -0
  27. package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +26 -0
  28. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +33 -0
  29. package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +20 -0
  30. package/android/src/test/kotlin/com/datadog/tools/unit/forge/Throwable.kt +31 -0
  31. package/android/src/test/kotlin/com/datadog/tools/unit/forge/ThrowableForgeryFactory.kt +21 -0
  32. package/android/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +1 -0
  33. package/datadog-sourcemaps.gradle +137 -0
  34. package/ios/Sources/AnyEncodable.swift +138 -0
  35. package/ios/Sources/Attributes.swift +101 -0
  36. package/ios/Sources/DdLogs.swift +35 -11
  37. package/ios/Sources/DdRum.m +3 -1
  38. package/ios/Sources/DdRum.swift +184 -22
  39. package/ios/Sources/DdSdk.swift +190 -10
  40. package/ios/Sources/DdSdkConfiguration.swift +51 -0
  41. package/ios/Sources/DdTrace.swift +41 -6
  42. package/ios/Sources/GlobalState.swift +28 -0
  43. package/ios/Sources/QueueHolder.swift +10 -0
  44. package/ios/Sources/RNDdSdkConfiguration.swift +5 -6
  45. package/lib/commonjs/DdSdkReactNative.js +16 -2
  46. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  47. package/lib/commonjs/DdSdkReactNativeConfiguration.js +24 -0
  48. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  49. package/lib/commonjs/foundation.js +36 -2
  50. package/lib/commonjs/foundation.js.map +1 -1
  51. package/lib/commonjs/nativeModulesTypes.js +36 -0
  52. package/lib/commonjs/nativeModulesTypes.js.map +1 -0
  53. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +4 -17
  54. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  55. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +4 -4
  56. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  57. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +73 -0
  58. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -0
  59. package/lib/commonjs/rum/instrumentation/{TraceIdentifier.js → resourceTracking/domain/distributedTracing.js} +40 -1
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -0
  61. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +51 -0
  62. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -0
  63. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js +25 -0
  64. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -0
  65. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.js +2 -0
  66. package/lib/commonjs/rum/instrumentation/{DdRumXhr.js.map → resourceTracking/domain/interfaces/RumResource.js.map} +0 -0
  67. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +57 -0
  68. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -0
  69. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js +49 -0
  70. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js.map +1 -0
  71. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js +45 -0
  72. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js.map +1 -0
  73. package/lib/commonjs/rum/instrumentation/{URLHostParser.js → resourceTracking/implementation/URLHostParser.js} +16 -7
  74. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/URLHostParser.js.map +1 -0
  75. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +167 -0
  76. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -0
  77. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/responseSize.js +97 -0
  78. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/responseSize.js.map +1 -0
  79. package/lib/commonjs/types.js +26 -1
  80. package/lib/commonjs/types.js.map +1 -1
  81. package/lib/commonjs/version.js +1 -1
  82. package/lib/commonjs/version.js.map +1 -1
  83. package/lib/module/DdSdkReactNative.js +15 -1
  84. package/lib/module/DdSdkReactNative.js.map +1 -1
  85. package/lib/module/DdSdkReactNativeConfiguration.js +24 -0
  86. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  87. package/lib/module/foundation.js +36 -2
  88. package/lib/module/foundation.js.map +1 -1
  89. package/lib/module/nativeModulesTypes.js +26 -0
  90. package/lib/module/nativeModulesTypes.js.map +1 -0
  91. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +2 -14
  92. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  93. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +3 -4
  94. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  95. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +61 -0
  96. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -0
  97. package/lib/module/rum/instrumentation/{TraceIdentifier.js → resourceTracking/domain/distributedTracing.js} +35 -1
  98. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -0
  99. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +34 -0
  100. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -0
  101. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js +16 -0
  102. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -0
  103. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.js +2 -0
  104. package/lib/module/rum/instrumentation/{DdRumXhr.js.map → resourceTracking/domain/interfaces/RumResource.js.map} +0 -0
  105. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +50 -0
  106. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -0
  107. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js +40 -0
  108. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.js.map +1 -0
  109. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js +36 -0
  110. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.js.map +1 -0
  111. package/{src/rum/instrumentation/URLHostParser.ts → lib/module/rum/instrumentation/resourceTracking/implementation/URLHostParser.js} +15 -8
  112. package/lib/module/rum/instrumentation/resourceTracking/implementation/URLHostParser.js.map +1 -0
  113. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +151 -0
  114. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -0
  115. package/lib/module/rum/instrumentation/resourceTracking/implementation/responseSize.js +86 -0
  116. package/lib/module/rum/instrumentation/resourceTracking/implementation/responseSize.js.map +1 -0
  117. package/lib/module/types.js +23 -0
  118. package/lib/module/types.js.map +1 -1
  119. package/lib/module/version.js +1 -1
  120. package/lib/module/version.js.map +1 -1
  121. package/lib/typescript/DdSdkReactNative.d.ts +2 -0
  122. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +20 -0
  123. package/lib/typescript/foundation.d.ts +3 -2
  124. package/lib/typescript/nativeModulesTypes.d.ts +168 -0
  125. package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +0 -15
  126. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +15 -0
  127. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +18 -0
  128. package/lib/typescript/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +6 -0
  129. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +8 -0
  130. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +20 -0
  131. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.d.ts +8 -0
  132. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.d.ts +6 -0
  133. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.d.ts +17 -0
  134. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/URLHostParser.d.ts +6 -0
  135. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +25 -0
  136. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +3 -0
  137. package/lib/typescript/types.d.ts +42 -7
  138. package/lib/typescript/version.d.ts +1 -1
  139. package/package.json +7 -5
  140. package/src/DdSdkReactNative.tsx +21 -1
  141. package/src/DdSdkReactNativeConfiguration.tsx +20 -0
  142. package/src/__tests__/DdSdkReactNative.test.tsx +87 -8
  143. package/src/__tests__/foundation.test.ts +79 -0
  144. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +9 -9
  145. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +1 -1
  146. package/src/foundation.tsx +40 -11
  147. package/src/nativeModulesTypes.ts +258 -0
  148. package/src/rum/instrumentation/DdEventsInterceptor.tsx +2 -17
  149. package/src/rum/instrumentation/DdRumErrorTracking.tsx +3 -4
  150. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +67 -0
  151. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +79 -0
  152. package/src/{__tests__/rum/instrumentation → rum/instrumentation/resourceTracking/__tests__}/__utils__/XMLHttpRequestMock.ts +0 -0
  153. package/src/{__tests__/rum/instrumentation/TraceIdentifier.test.tsx → rum/instrumentation/resourceTracking/domain/__tests__/distributedTracing.test.ts} +1 -1
  154. package/src/rum/instrumentation/resourceTracking/domain/__tests__/firstPartyHosts.test.ts +22 -0
  155. package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +87 -0
  156. package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +52 -0
  157. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.ts +15 -0
  158. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +27 -0
  159. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +78 -0
  160. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +83 -0
  161. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/__utils__/ResourceMockFactory.ts +45 -0
  162. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/internalDevResourceBlocklist.test.ts +69 -0
  163. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.ts +50 -0
  164. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.ts +70 -0
  165. package/src/rum/instrumentation/resourceTracking/implementation/URLHostParser.ts +30 -0
  166. package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +197 -0
  167. package/src/{__tests__/rum/instrumentation → rum/instrumentation/resourceTracking/implementation/__tests__}/URLHostParser.test.ts +3 -3
  168. package/src/{__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx → rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts} +83 -49
  169. package/src/rum/instrumentation/resourceTracking/implementation/responseSize.ts +83 -0
  170. package/src/types.tsx +62 -7
  171. package/src/version.ts +1 -1
  172. package/android/src/main/java/com/datadog/reactnative/DdRum.kt +0 -142
  173. package/android/src/main/java/com/datadog/reactnative/DdSdk.kt +0 -67
  174. package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +0 -51
  175. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +0 -356
  176. package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +0 -1
  177. package/lib/commonjs/rum/instrumentation/DdRumXhr.js +0 -2
  178. package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +0 -1
  179. package/lib/commonjs/rum/instrumentation/URLHostParser.js.map +0 -1
  180. package/lib/module/rum/instrumentation/DdRumResourceTracking.js +0 -331
  181. package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +0 -1
  182. package/lib/module/rum/instrumentation/DdRumXhr.js +0 -2
  183. package/lib/module/rum/instrumentation/TraceIdentifier.js.map +0 -1
  184. package/lib/module/rum/instrumentation/URLHostParser.js +0 -24
  185. package/lib/module/rum/instrumentation/URLHostParser.js.map +0 -1
  186. package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +0 -40
  187. package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +0 -23
  188. package/lib/typescript/rum/instrumentation/TraceIdentifier.d.ts +0 -1
  189. package/lib/typescript/rum/instrumentation/URLHostParser.d.ts +0 -6
  190. package/src/rum/instrumentation/DdRumResourceTracking.tsx +0 -426
  191. package/src/rum/instrumentation/DdRumXhr.tsx +0 -33
  192. package/src/rum/instrumentation/TraceIdentifier.tsx +0 -34
@@ -0,0 +1,101 @@
1
+
2
+ /*
3
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
4
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
5
+ * Copyright 2019-2020 Datadog, Inc.
6
+ */
7
+
8
+ import Foundation
9
+
10
+ /// Internal attributes, passed to the iOS SDK.
11
+ /// Keep in sync with https://github.com/DataDog/dd-sdk-ios/blob/develop/Sources/Datadog/Core/Attributes/Attributes.swift.
12
+ internal struct CrossPlatformAttributes {
13
+ /// Custom app version passed from CP SDK. Used for all events issued by the SDK (both coming from cross-platform SDK and produced internally, like RUM long tasks).
14
+ /// It should replace the default native `version` read from `Info.plist`.
15
+ /// Expects `String` value (semantic version).
16
+ static let version: String = "_dd.version"
17
+
18
+ /// Custom SDK version passed from bridge SDK. Used for all events issued by the SDK (both coming from cross-platform SDK and produced internally, like RUM long tasks).
19
+ /// It should replace the default native `sdkVersion`.
20
+ /// Expects `String` value (semantic version).
21
+ static let sdkVersion: String = "_dd.sdk_version"
22
+
23
+ /// Custom SDK `source` passed from bridge SDK. Used for all events issued by the SDK (both coming from cross-platform SDK and produced internally, like RUM long tasks).
24
+ /// It should replace the default native `ddsource` value (`"ios"`).
25
+ /// Expects `String` value.
26
+ static let ddsource: String = "_dd.source"
27
+
28
+ /// Event timestamp passed from bridge SDK. Used for all RUM events issued by cross platform SDK.
29
+ /// It should replace event time obtained from `DateProvider` to ensure that events are not skewed due to time difference in native and cross-platform SDKs.
30
+ /// Expects `Int64` value (milliseconds).
31
+ static let timestampInMilliseconds = "_dd.timestamp"
32
+
33
+ /// Custom "source type" of the error passed from bridge SDK. Used in RUM errors reported by cross platform SDK.
34
+ /// It names the language or platform of the RUM error stack trace, so the SCI backend knows how to symbolicate it.
35
+ /// Expects `String` value.
36
+ static let errorSourceType = "_dd.error.source_type"
37
+
38
+ /// Custom attribute of the error passed from bridge SDK. Used in RUM errors reported by cross platform SDK.
39
+ /// It flags the error has being fatal for the host application.
40
+ /// Expects `Bool` value.
41
+ static let errorIsCrash = "_dd.error.is_crash"
42
+
43
+ /// Trace ID passed from bridge SDK. Used in RUM resources created by cross platform SDK.
44
+ /// When cross-platform SDK injects tracing headers to intercepted resource, we pass tracing information through this attribute
45
+ /// and send it within the RUM resource, so the RUM backend can issue corresponding APM span on behalf of the mobile app.
46
+ /// Expects `String` value.
47
+ static let traceID = "_dd.trace_id"
48
+
49
+ /// Span ID passed from bridge SDK. Used in RUM resources created by cross platform SDK.
50
+ /// When cross-platform SDK injects tracing headers to intercepted resource, we pass tracing information through this attribute
51
+ /// and send it within the RUM resource, so the RUM backend can issue corresponding APM span on behalf of the mobile app.
52
+ /// Expects `String` value.
53
+ static let spanID = "_dd.span_id"
54
+ }
55
+
56
+ /// Internal attributes used to configure the proxy.
57
+ internal struct ProxyAttributes {
58
+ /// Expects `String?` value.
59
+ static let address = "_dd.proxy.address"
60
+
61
+ /// Expects `String?` value
62
+ static let username = "_dd.proxy.username"
63
+
64
+ /// Expects `String?` value
65
+ static let password = "_dd.proxy.password"
66
+
67
+ /// Expects `String?` value
68
+ static let type = "_dd.proxy.type"
69
+
70
+ /// Expects `String?` or `Int?` value
71
+ static let port = "_dd.proxy.port"
72
+ }
73
+
74
+ /// Internal attributes used by the bridge only, passed from the javascript.
75
+ internal struct InternalConfigurationAttributes {
76
+ /// Enables native view tracking.
77
+ /// Expects `Bool?` value
78
+ static let nativeViewTracking = "_dd.native_view_tracking"
79
+
80
+ /// Enable overriding the service name.
81
+ /// Expects `String?` value
82
+ static let serviceName = "_dd.service_name"
83
+
84
+ /// Enable overriding the long task threshold for long task detection.
85
+ /// Expects `Double?` value
86
+ static let longTaskThreshold = "_dd.long_task.threshold"
87
+
88
+ /// Specify first party hosts for distributed tracing.
89
+ /// Even if the requests are intercepted at the javascript level, we have to pass this parameter to make sure the headers are
90
+ /// correctly set when sending the traces to the intake.
91
+ /// Expects `[String]?` value
92
+ static let firstPartyHosts = "_dd.first_party_hosts"
93
+
94
+ /// Specify native SDK verbosity
95
+ /// Expects `NSString?` value
96
+ static let sdkVerbosity = "_dd.sdk_verbosity"
97
+
98
+ /// Specify version suffix.
99
+ /// Expects `NSString?` value
100
+ static let versionSuffix = "_dd.version_suffix"
101
+ }
@@ -5,7 +5,15 @@
5
5
  */
6
6
 
7
7
  import Foundation
8
- import DatadogSDKBridge
8
+ import Datadog
9
+
10
+ extension Logger: NativeLogger { }
11
+ internal protocol NativeLogger {
12
+ func debug(_ message: String, error: Error?, attributes: [String: Encodable]?)
13
+ func info(_ message: String, error: Error?, attributes: [String: Encodable]?)
14
+ func warn(_ message: String, error: Error?, attributes: [String: Encodable]?)
15
+ func error(_ message: String, error: Error?, attributes: [String: Encodable]?)
16
+ }
9
17
 
10
18
  @objc(DdLogs)
11
19
  class RNDdLogs: NSObject {
@@ -15,32 +23,48 @@ class RNDdLogs: NSObject {
15
23
  return false
16
24
  }
17
25
 
18
- let nativeInstance: DdLogs = Bridge.getDdLogs()
19
-
20
26
  @objc(methodQueue)
21
27
  let methodQueue: DispatchQueue = sharedQueue
22
28
 
29
+ private lazy var logger: NativeLogger = loggerProvider()
30
+ private let loggerProvider: () -> NativeLogger
31
+
32
+ internal init(_ loggerProvider: @escaping () -> NativeLogger) {
33
+ self.loggerProvider = loggerProvider
34
+ }
35
+
36
+ override public convenience init() {
37
+ let builder = Logger.builder
38
+ .sendNetworkInfo(true)
39
+ .printLogsToConsole(true)
40
+ self.init { builder.build() }
41
+ }
42
+
23
43
  @objc(debug:withContext:withResolver:withRejecter:)
24
- func debug(message: NSString, context: NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
25
- nativeInstance.debug(message: message, context: context)
44
+ func debug(message: String, context: NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
45
+ let attributes = castAttributesToSwift(context).mergeWithGlobalAttributes()
46
+ logger.debug(message, error: nil, attributes: attributes)
26
47
  resolve(nil)
27
48
  }
28
49
 
29
50
  @objc(info:withContext:withResolver:withRejecter:)
30
- func info(message: NSString, context: NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
31
- nativeInstance.info(message: message, context: context)
51
+ func info(message: String, context: NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
52
+ let attributes = castAttributesToSwift(context).mergeWithGlobalAttributes()
53
+ logger.info(message, error: nil, attributes: attributes)
32
54
  resolve(nil)
33
55
  }
34
56
 
35
57
  @objc(warn:withContext:withResolver:withRejecter:)
36
- func warn(message: NSString, context: NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
37
- nativeInstance.warn(message: message, context: context)
58
+ func warn(message: String, context: NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
59
+ let attributes = castAttributesToSwift(context).mergeWithGlobalAttributes()
60
+ logger.warn(message, error: nil, attributes: attributes)
38
61
  resolve(nil)
39
62
  }
40
63
 
41
64
  @objc(error:withContext:withResolver:withRejecter:)
42
- func error(message: NSString, context: NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
43
- nativeInstance.error(message: message, context: context)
65
+ func error(message: String, context: NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
66
+ let attributes = castAttributesToSwift(context).mergeWithGlobalAttributes()
67
+ logger.error(message, error: nil, attributes: attributes)
44
68
  resolve(nil)
45
69
  }
46
70
 
@@ -28,7 +28,9 @@ RCT_EXTERN_METHOD(startAction:(NSString)type
28
28
  withResolver:(RCTPromiseResolveBlock)resolve
29
29
  withRejecter:(RCTPromiseRejectBlock)reject)
30
30
 
31
- RCT_EXTERN_METHOD(stopAction:(NSDictionary)context
31
+ RCT_EXTERN_METHOD(stopAction:(NSString)type
32
+ withName:(NSString)name
33
+ withContext:(NSDictionary)context
32
34
  withTimestampms:(NSInteger)timestampMs
33
35
  withResolver:(RCTPromiseResolveBlock)resolve
34
36
  withRejecter:(RCTPromiseRejectBlock)reject)
@@ -5,73 +5,235 @@
5
5
  */
6
6
 
7
7
  import Foundation
8
- import DatadogSDKBridge
8
+ import Datadog
9
+
10
+ extension DDRUMMonitor: NativeRUM { }
11
+ internal protocol NativeRUM {
12
+ func startView(key: String, name: String?, attributes: [String: Encodable])
13
+ func stopView(key: String, attributes: [String: Encodable])
14
+ func addError(message: String, type: String?, source: RUMErrorSource, stack: String?, attributes: [String: Encodable], file: StaticString?, line: UInt?)
15
+ func startResourceLoading(resourceKey: String, httpMethod: RUMMethod, urlString: String, attributes: [String: Encodable])
16
+ func stopResourceLoading(resourceKey: String, statusCode: Int?, kind: RUMResourceType, size: Int64?, attributes: [String: Encodable])
17
+ func startUserAction(type: RUMUserActionType, name: String, attributes: [String: Encodable])
18
+ func stopUserAction(type: RUMUserActionType, name: String?, attributes: [String: Encodable])
19
+ func addUserAction(type: RUMUserActionType, name: String, attributes: [String: Encodable])
20
+ func addTiming(name: String)
21
+ func addResourceMetrics(resourceKey: String,
22
+ fetch: (start: Date, end: Date),
23
+ redirection: (start: Date, end: Date)?,
24
+ dns: (start: Date, end: Date)?,
25
+ connect: (start: Date, end: Date)?,
26
+ ssl: (start: Date, end: Date)?,
27
+ firstByte: (start: Date, end: Date)?,
28
+ download: (start: Date, end: Date)?,
29
+ responseSize: Int64?,
30
+ attributes: [AttributeKey: AttributeValue])
31
+ }
32
+
33
+ private extension RUMUserActionType {
34
+ init(from string: String) {
35
+ switch string.lowercased() {
36
+ case "tap": self = .tap
37
+ case "scroll": self = .scroll
38
+ case "swipe": self = .swipe
39
+ default: self = .custom
40
+ }
41
+ }
42
+ }
43
+
44
+ internal extension RUMErrorSource {
45
+ init(from string: String) {
46
+ switch string.lowercased() {
47
+ case "source": self = .source
48
+ case "network": self = .network
49
+ case "webview": self = .webview
50
+ case "console": self = .console
51
+ default: self = .custom
52
+ }
53
+ }
54
+ }
55
+
56
+ private extension RUMResourceType {
57
+ init(from string: String) {
58
+ switch string {
59
+ case "image": self = .image
60
+ case "xhr": self = .xhr
61
+ case "beacon": self = .beacon
62
+ case "css": self = .css
63
+ case "document": self = .document
64
+ case "fetch": self = .fetch
65
+ case "font": self = .font
66
+ case "js": self = .js
67
+ case "media": self = .media
68
+ default: self = .other
69
+ }
70
+ }
71
+ }
72
+
73
+ private extension RUMMethod {
74
+ init(from string: String) {
75
+ switch string.uppercased() {
76
+ case "POST": self = .post
77
+ case "GET": self = .get
78
+ case "HEAD": self = .head
79
+ case "PUT": self = .put
80
+ case "DELETE": self = .delete
81
+ case "PATCH": self = .patch
82
+ default: self = .get
83
+ }
84
+ }
85
+ }
9
86
 
10
87
  @objc(DdRum)
11
88
  class RNDdRum: NSObject {
89
+ internal static let timestampKey = "_dd.timestamp"
90
+ internal static let resourceTimingsKey = "_dd.resource_timings"
91
+
92
+ internal static let fetchTimingKey = "fetch"
93
+ internal static let redirectTimingKey = "redirect"
94
+ internal static let dnsTimingKey = "dns"
95
+ internal static let connectTimingKey = "connect"
96
+ internal static let sslTimingKey = "ssl"
97
+ internal static let firstByteTimingKey = "firstByte"
98
+ internal static let downloadTimingKey = "download"
99
+
100
+ internal static let missingResourceSize = -1
101
+
102
+ lazy var nativeRUM: NativeRUM = rumProvider()
103
+ private let rumProvider: () -> NativeRUM
104
+
105
+ private typealias UserAction = (type: RUMUserActionType, name: String?)
106
+
107
+ internal init(_ rumProvider: @escaping () -> NativeRUM) {
108
+ self.rumProvider = rumProvider
109
+ }
110
+
111
+ override convenience init() {
112
+ self.init { Global.rum }
113
+ }
12
114
 
13
115
  @objc(requiresMainQueueSetup)
14
116
  static func requiresMainQueueSetup() -> Bool {
15
117
  return false
16
118
  }
17
119
 
18
- let nativeInstance: DdRum = Bridge.getDdRum()
19
-
20
120
  @objc(methodQueue)
21
121
  let methodQueue: DispatchQueue = sharedQueue
22
122
 
23
123
  @objc(startView:withName:withContext:withTimestampms:withResolver:withRejecter:)
24
- func startView(key: NSString, name: NSString, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
25
- nativeInstance.startView(key: key, name: name, context: context, timestampMs: timestampMs)
124
+ func startView(key: String, name: String, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
125
+ nativeRUM.startView(key: key, name: name, attributes: attributes(from: context, with: timestampMs))
26
126
  resolve(nil)
27
127
  }
28
128
 
29
129
  @objc(stopView:withContext:withTimestampms:withResolver:withRejecter:)
30
- func stopView(key: NSString, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
31
- nativeInstance.stopView(key: key, context: context, timestampMs: timestampMs)
130
+ func stopView(key: String, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
131
+ nativeRUM.stopView(key: key, attributes: attributes(from: context, with: timestampMs))
32
132
  resolve(nil)
33
133
  }
34
134
 
35
135
  @objc(startAction:withName:withContext:withTimestampms:withResolver:withRejecter:)
36
- func startAction(type: NSString, name: NSString, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
37
- nativeInstance.startAction(type: type, name: name, context: context, timestampMs: timestampMs)
136
+ func startAction(type: String, name: String, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
137
+ nativeRUM.startUserAction(type: RUMUserActionType(from: type), name: name, attributes: attributes(from: context, with: timestampMs))
38
138
  resolve(nil)
39
139
  }
40
140
 
41
- @objc(stopAction:withTimestampms:withResolver:withRejecter:)
42
- func stopAction(context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
43
- nativeInstance.stopAction(context: context, timestampMs: timestampMs)
141
+ @objc(stopAction:withName:withContext:withTimestampms:withResolver:withRejecter:)
142
+ func stopAction(type: String, name: String, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
143
+ nativeRUM.stopUserAction(type: RUMUserActionType(from: type), name: name, attributes: attributes(from: context, with: timestampMs))
44
144
  resolve(nil)
45
145
  }
46
146
 
47
147
  @objc(addAction:withName:withContext:withTimestampms:withResolver:withRejecter:)
48
- func addAction(type: NSString, name: NSString, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
49
- nativeInstance.addAction(type: type, name: name, context: context, timestampMs: timestampMs)
148
+ func addAction(type: String, name: String, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
149
+ nativeRUM.addUserAction(type: RUMUserActionType(from: type), name: name, attributes: attributes(from: context, with: timestampMs))
50
150
  resolve(nil)
51
151
  }
52
152
 
53
153
  @objc(startResource:withMethod:withUrl:withContext:withTimestampms:withResolver:withRejecter:)
54
- func startResource(key: NSString, method: NSString, url: NSString, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
55
- nativeInstance.startResource(key: key, method: method, url: url, context: context, timestampMs: timestampMs)
154
+ func startResource(key: String, method: String, url: String, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
155
+ nativeRUM.startResourceLoading(resourceKey: key, httpMethod: RUMMethod(from: method), urlString: url, attributes: attributes(from: context, with: timestampMs))
56
156
  resolve(nil)
57
157
  }
58
158
 
59
159
  @objc(stopResource:withStatuscode:withKind:withSize:withContext:withTimestampms:withResolver:withRejecter:)
60
- func stopResource(key: NSString, statusCode: Int64, kind: NSString, size: Int64, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
61
- nativeInstance.stopResource(key: key, statusCode: statusCode, kind: kind, size: size, context: context, timestampMs: timestampMs)
160
+ func stopResource(key: String, statusCode: Int64, kind: String, size: Int64, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
161
+ let mutableContext = NSMutableDictionary(dictionary: context)
162
+ if let resourceTimings = mutableContext.object(forKey: Self.resourceTimingsKey) as? [String: Any] {
163
+ mutableContext.removeObject(forKey: Self.resourceTimingsKey)
164
+
165
+ addResourceMetrics(key: key, resourceTimings: resourceTimings)
166
+ }
167
+
168
+ nativeRUM.stopResourceLoading(
169
+ resourceKey: key,
170
+ statusCode: Int(statusCode),
171
+ kind: RUMResourceType(from: kind),
172
+ size: size == Self.missingResourceSize ? nil : size,
173
+ attributes: attributes(from: mutableContext, with: timestampMs)
174
+ )
62
175
  resolve(nil)
63
176
  }
64
177
 
65
178
  @objc(addError:withSource:withStacktrace:withContext:withTimestampms:withResolver:withRejecter:)
66
- func addError(message: NSString, source: NSString, stacktrace: NSString, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
67
- nativeInstance.addError(message: message, source: source, stacktrace: stacktrace, context: context, timestampMs: timestampMs)
179
+ func addError(message: String, source: String, stacktrace: String, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
180
+ nativeRUM.addError(message: message, type: nil, source: RUMErrorSource(from: source), stack: stacktrace, attributes: attributes(from: context, with: timestampMs), file: nil, line: nil)
68
181
  resolve(nil)
69
182
  }
70
183
 
71
184
  @objc(addTiming:withResolver:withRejecter:)
72
- func addTiming(name: NSString, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
73
- nativeInstance.addTiming(name: name)
185
+ func addTiming(name: String, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
186
+ nativeRUM.addTiming(name: name)
74
187
  resolve(nil)
75
188
  }
76
189
 
190
+ // MARK: - Private methods
191
+
192
+ private func attributes(from context: NSDictionary, with timestampMs: Int64) -> [String: Encodable] {
193
+ var context = context as? [String: Any] ?? [:]
194
+ context[Self.timestampKey] = timestampMs
195
+ return castAttributesToSwift(context)
196
+ }
197
+
198
+ private func addResourceMetrics(key: String, resourceTimings: [String: Any]) {
199
+ let fetch = timingValue(from: resourceTimings, for: Self.fetchTimingKey)
200
+ let redirect = timingValue(from: resourceTimings, for: Self.redirectTimingKey)
201
+ let dns = timingValue(from: resourceTimings, for: Self.dnsTimingKey)
202
+ let connect = timingValue(from: resourceTimings, for: Self.connectTimingKey)
203
+ let ssl = timingValue(from: resourceTimings, for: Self.sslTimingKey)
204
+ let firstByte = timingValue(from: resourceTimings, for: Self.firstByteTimingKey)
205
+ let download = timingValue(from: resourceTimings, for: Self.downloadTimingKey)
206
+
207
+ if let fetch = fetch {
208
+ nativeRUM.addResourceMetrics(
209
+ resourceKey: key,
210
+ fetch: fetch,
211
+ redirection: redirect,
212
+ dns: dns,
213
+ connect: connect,
214
+ ssl: ssl,
215
+ firstByte: firstByte,
216
+ download: download,
217
+ // no need to define the size here, because if it is missing,
218
+ // it will be taken from the command
219
+ responseSize: nil,
220
+ attributes: [:]
221
+ )
222
+ }
223
+ }
224
+
225
+ private func timingValue(from timings: [String: Any], for timingName: String) -> (start: Date, end: Date)? {
226
+ let timing = timings[timingName] as? [String: NSNumber]
227
+ if let startInNs = timing?["startTime"]?.int64Value, let durationInNs = timing?["duration"]?.int64Value {
228
+ return (
229
+ Date(timeIntervalSince1970: TimeInterval(fromNs: startInNs)),
230
+ Date(timeIntervalSince1970: TimeInterval(fromNs: startInNs + durationInNs))
231
+ )
232
+ }
233
+ return nil
234
+ }
235
+ }
236
+
237
+ internal extension TimeInterval {
238
+ init(fromNs ns: Int64) { self = TimeInterval(Double(ns) / 1_000_000_000) }
77
239
  }