@datadog/mobile-react-native 1.0.0-rc9 → 1.1.1

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 (112) 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 +14 -0
  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/index.js +14 -0
  52. package/lib/commonjs/index.js.map +1 -1
  53. package/lib/commonjs/nativeModulesTypes.js +36 -0
  54. package/lib/commonjs/nativeModulesTypes.js.map +1 -0
  55. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +4 -17
  56. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  57. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +4 -4
  58. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  59. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +7 -2
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
  61. package/lib/commonjs/types.js +26 -1
  62. package/lib/commonjs/types.js.map +1 -1
  63. package/lib/commonjs/version.js +1 -1
  64. package/lib/commonjs/version.js.map +1 -1
  65. package/lib/module/DdSdkReactNative.js +14 -0
  66. package/lib/module/DdSdkReactNative.js.map +1 -1
  67. package/lib/module/DdSdkReactNativeConfiguration.js +24 -0
  68. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  69. package/lib/module/foundation.js +36 -2
  70. package/lib/module/foundation.js.map +1 -1
  71. package/lib/module/index.js +2 -1
  72. package/lib/module/index.js.map +1 -1
  73. package/lib/module/nativeModulesTypes.js +26 -0
  74. package/lib/module/nativeModulesTypes.js.map +1 -0
  75. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +2 -14
  76. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  77. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +3 -4
  78. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  79. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +7 -2
  80. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
  81. package/lib/module/types.js +23 -0
  82. package/lib/module/types.js.map +1 -1
  83. package/lib/module/version.js +1 -1
  84. package/lib/module/version.js.map +1 -1
  85. package/lib/typescript/DdSdkReactNative.d.ts +2 -0
  86. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +20 -0
  87. package/lib/typescript/foundation.d.ts +3 -2
  88. package/lib/typescript/index.d.ts +2 -1
  89. package/lib/typescript/nativeModulesTypes.d.ts +168 -0
  90. package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +0 -15
  91. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +2 -1
  92. package/lib/typescript/types.d.ts +42 -7
  93. package/lib/typescript/version.d.ts +1 -1
  94. package/package.json +5 -4
  95. package/src/DdSdkReactNative.tsx +20 -0
  96. package/src/DdSdkReactNativeConfiguration.tsx +20 -0
  97. package/src/__tests__/DdSdkReactNative.test.tsx +76 -0
  98. package/src/__tests__/foundation.test.ts +79 -0
  99. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +8 -8
  100. package/src/foundation.tsx +40 -11
  101. package/src/index.tsx +3 -0
  102. package/src/nativeModulesTypes.ts +258 -0
  103. package/src/rum/instrumentation/DdEventsInterceptor.tsx +2 -17
  104. package/src/rum/instrumentation/DdRumErrorTracking.tsx +3 -4
  105. package/src/rum/instrumentation/resourceTracking/domain/__tests__/firstPartyHosts.test.ts +22 -0
  106. package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +8 -1
  107. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +2 -1
  108. package/src/types.tsx +62 -7
  109. package/src/version.ts +1 -1
  110. package/android/src/main/java/com/datadog/reactnative/DdRum.kt +0 -142
  111. package/android/src/main/java/com/datadog/reactnative/DdSdk.kt +0 -67
  112. package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +0 -51
@@ -5,46 +5,226 @@
5
5
  */
6
6
 
7
7
  import Foundation
8
- import DatadogSDKBridge
8
+ import Datadog
9
+ import DatadogCrashReporting
10
+
11
+ func getDefaultAppVersion() -> String {
12
+ let bundleShortVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
13
+ let bundleVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String
14
+ return bundleShortVersion ?? bundleVersion ?? "0.0.0"
15
+ }
9
16
 
10
17
  @objc(DdSdk)
11
18
  class RNDdSdk: NSObject {
12
-
13
19
  @objc(requiresMainQueueSetup)
14
20
  static func requiresMainQueueSetup() -> Bool {
15
21
  return false
16
22
  }
17
-
18
- let nativeInstance: DdSdk = Bridge.getDdSdk()
19
-
23
+
24
+ let mainDispatchQueue: DispatchQueueType
20
25
  @objc(methodQueue)
21
26
  let methodQueue: DispatchQueue = sharedQueue
27
+
28
+ convenience override init() {
29
+ self.init(mainDispatchQueue: DispatchQueue.main)
30
+ }
31
+
32
+ init(mainDispatchQueue: DispatchQueueType) {
33
+ self.mainDispatchQueue = mainDispatchQueue
34
+ super.init()
35
+ }
36
+
22
37
 
23
38
  @objc(initialize:withResolver:withRejecter:)
24
39
  func initialize(configuration: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
25
40
  // Datadog SDK init needs to happen on the main thread: https://github.com/DataDog/dd-sdk-reactnative/issues/198
26
- DispatchQueue.main.async {
27
- self.nativeInstance.initialize(configuration: configuration.asDdSdkConfiguration())
41
+ self.mainDispatchQueue.async {
42
+ if Datadog.isInitialized {
43
+ // Initializing the SDK twice results in Global.rum and
44
+ // Global.sharedTracer to be set to no-op instances
45
+ consolePrint("Datadog SDK is already initialized, skipping initialization.")
46
+ return
47
+ }
48
+ let sdkConfiguration = configuration.asDdSdkConfiguration()
49
+ self.setVerbosityLevel(additionalConfig: sdkConfiguration.additionalConfig)
50
+
51
+ let ddConfig = self.buildConfiguration(configuration: sdkConfiguration)
52
+ let consent = self.buildTrackingConsent(consent: sdkConfiguration.trackingConsent)
53
+ Datadog.initialize(appContext: Datadog.AppContext(), trackingConsent: consent, configuration: ddConfig)
54
+
55
+ Global.rum = RUMMonitor.initialize()
56
+
28
57
  resolve(nil)
29
58
  }
30
59
  }
31
60
 
32
61
  @objc(setAttributes:withResolver:withRejecter:)
33
62
  func setAttributes(attributes: NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
34
- nativeInstance.setAttributes(attributes: attributes)
63
+ let castedAttributes = castAttributesToSwift(attributes)
64
+ for (key, value) in castedAttributes {
65
+ Global.rum.addAttribute(forKey: key, value: value)
66
+ GlobalState.addAttribute(forKey: key, value: value)
67
+ }
68
+
35
69
  resolve(nil)
36
70
  }
37
71
 
38
72
  @objc(setUser:withResolver:withRejecter:)
39
73
  func setUser(user: NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
40
- nativeInstance.setUser(user: user)
74
+ var castedUser = castAttributesToSwift(user)
75
+ let id = castedUser.removeValue(forKey: "id") as? String
76
+ let name = castedUser.removeValue(forKey: "name") as? String
77
+ let email = castedUser.removeValue(forKey: "email") as? String
78
+ let extraInfo: [String: Encodable] = castedUser // everything what's left is an `extraInfo`
79
+
80
+ Datadog.setUserInfo(id: id, name: name, email: email, extraInfo: extraInfo)
41
81
  resolve(nil)
42
82
  }
43
83
 
44
84
  @objc(setTrackingConsent:withResolver:withRejecter:)
45
85
  func setTrackingConsent(trackingConsent: NSString, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
46
- nativeInstance.setTrackingConsent(trackingConsent: trackingConsent)
86
+ Datadog.set(trackingConsent: buildTrackingConsent(consent: trackingConsent))
47
87
  resolve(nil)
48
88
  }
49
89
 
90
+ func buildConfiguration(configuration: DdSdkConfiguration, defaultAppVersion: String = getDefaultAppVersion()) -> Datadog.Configuration {
91
+ let ddConfigBuilder: Datadog.Configuration.Builder
92
+ if let rumAppID = configuration.applicationId {
93
+ ddConfigBuilder = Datadog.Configuration.builderUsing(
94
+ rumApplicationID: rumAppID,
95
+ clientToken: configuration.clientToken,
96
+ environment: configuration.env
97
+ )
98
+ .set(rumSessionsSamplingRate: Float(configuration.sampleRate ?? 100.0))
99
+ } else {
100
+ ddConfigBuilder = Datadog.Configuration.builderUsing(
101
+ clientToken: configuration.clientToken,
102
+ environment: configuration.env
103
+ )
104
+ }
105
+
106
+ switch configuration.site?.lowercased ?? "us" {
107
+ case "us1", "us":
108
+ _ = ddConfigBuilder.set(endpoint: .us1)
109
+ case "eu1", "eu":
110
+ _ = ddConfigBuilder.set(endpoint: .eu1)
111
+ case "us3":
112
+ _ = ddConfigBuilder.set(endpoint: .us3)
113
+ case "us5":
114
+ _ = ddConfigBuilder.set(endpoint: .us5)
115
+ case "us1_fed", "gov":
116
+ _ = ddConfigBuilder.set(endpoint: .us1_fed)
117
+ default:
118
+ _ = ddConfigBuilder.set(endpoint: .us1)
119
+ }
120
+
121
+ let additionalConfig = configuration.additionalConfig
122
+
123
+ if var additionalConfiguration = additionalConfig as? [String: Any] {
124
+ if let versionSuffix = additionalConfig?[InternalConfigurationAttributes.versionSuffix] as? String {
125
+ let datadogVersion = defaultAppVersion + versionSuffix
126
+ additionalConfiguration[CrossPlatformAttributes.version] = datadogVersion
127
+ }
128
+
129
+ _ = ddConfigBuilder.set(additionalConfiguration: additionalConfiguration)
130
+ }
131
+
132
+ if let enableViewTracking = additionalConfig?[InternalConfigurationAttributes.nativeViewTracking] as? Bool, enableViewTracking {
133
+ _ = ddConfigBuilder.trackUIKitRUMViews()
134
+ }
135
+
136
+ if let serviceName = additionalConfig?[InternalConfigurationAttributes.serviceName] as? String {
137
+ _ = ddConfigBuilder.set(serviceName: serviceName)
138
+ }
139
+
140
+ if let threshold = additionalConfig?[InternalConfigurationAttributes.longTaskThreshold] as? TimeInterval {
141
+ // `_dd.long_task.threshold` attribute is in milliseconds
142
+ _ = ddConfigBuilder.trackRUMLongTasks(threshold: threshold / 1_000)
143
+ }
144
+
145
+ if let firstPartyHosts = additionalConfig?[InternalConfigurationAttributes.firstPartyHosts] as? [String] {
146
+ _ = ddConfigBuilder.trackURLSession(firstPartyHosts: Set(firstPartyHosts))
147
+ }
148
+
149
+ if let proxyConfiguration = buildProxyConfiguration(config: additionalConfig) {
150
+ _ = ddConfigBuilder.set(proxyConfiguration: proxyConfiguration)
151
+ }
152
+
153
+ if configuration.nativeCrashReportEnabled ?? false {
154
+ _ = ddConfigBuilder.enableCrashReporting(using: DDCrashReportingPlugin())
155
+ }
156
+
157
+ return ddConfigBuilder.build()
158
+ }
159
+
160
+ func buildProxyConfiguration(config: NSDictionary?) -> [AnyHashable: Any]? {
161
+ guard let address = config?[ProxyAttributes.address] as? String else {
162
+ return nil
163
+ }
164
+
165
+ var proxy: [AnyHashable: Any] = [:]
166
+ proxy[kCFProxyUsernameKey] = config?[ProxyAttributes.username]
167
+ proxy[kCFProxyPasswordKey] = config?[ProxyAttributes.password]
168
+
169
+ let type = config?[ProxyAttributes.type] as? String
170
+ var port = config?[ProxyAttributes.port] as? Int
171
+ if let string = config?[ProxyAttributes.port] as? String {
172
+ port = Int(string)
173
+ }
174
+
175
+ switch type {
176
+ case "http", "https":
177
+ // CFNetwork support HTTP and tunneling HTTPS proxies.
178
+ // As intakes will most likely be https, we enable both channels.
179
+ //
180
+ // We use constants string keys because there is an issue with
181
+ // cross-platform availability for proxy configuration symbols.
182
+ // see. https://developer.apple.com/forums/thread/19356?answerId=131709022#131709022
183
+ proxy["HTTPEnable"] = 1
184
+ proxy["HTTPProxy"] = address
185
+ proxy["HTTPPort"] = port
186
+ proxy["HTTPSEnable"] = 1
187
+ proxy["HTTPSProxy"] = address
188
+ proxy["HTTPSPort"] = port
189
+ case "socks":
190
+ proxy["SOCKSEnable"] = 1
191
+ proxy["SOCKSProxy"] = address
192
+ proxy["SOCKSPort"] = port
193
+ default:
194
+ break
195
+ }
196
+
197
+ return proxy
198
+ }
199
+
200
+ func buildTrackingConsent(consent: NSString?) -> TrackingConsent {
201
+ let trackingConsent: TrackingConsent
202
+ switch consent?.lowercased {
203
+ case "pending":
204
+ trackingConsent = .pending
205
+ case "granted":
206
+ trackingConsent = .granted
207
+ case "not_granted":
208
+ trackingConsent = .notGranted
209
+ default:
210
+ trackingConsent = .pending
211
+ }
212
+ return trackingConsent
213
+ }
214
+
215
+ func setVerbosityLevel(additionalConfig: NSDictionary?) {
216
+ let verbosityLevel = (additionalConfig?[InternalConfigurationAttributes.sdkVerbosity]) as? NSString
217
+ switch verbosityLevel?.lowercased {
218
+ case "debug":
219
+ Datadog.verbosityLevel = .debug
220
+ case "info":
221
+ Datadog.verbosityLevel = .info
222
+ case "warn":
223
+ Datadog.verbosityLevel = .warn
224
+ case "error":
225
+ Datadog.verbosityLevel = .error
226
+ default:
227
+ Datadog.verbosityLevel = nil
228
+ }
229
+ }
50
230
  }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ import Foundation
8
+
9
+ /**
10
+ A configuration object to initialize Datadog's features.
11
+ - Parameters:
12
+ - clientToken: A valid Datadog client token.
13
+ - env: The application’s environment, for example: prod, pre-prod, staging, etc.
14
+ - applicationId: The RUM application ID.
15
+ - nativeCrashReportEnabled: Whether the SDK should track native (pure iOS or pure Android) crashes (default is false).
16
+ - sampleRate: The sample rate (between 0 and 100) of RUM sessions kept.
17
+ - site: The Datadog site of your organization (can be 'US1', 'US1_FED', 'US3', 'US5', or 'EU1', default is 'US1').
18
+ - trackingConsent: Consent, which can take one of the following values: 'pending', 'granted', 'not_granted'.
19
+ - additionalConfig: Additional configuration parameters.
20
+ */
21
+ @objc(DdSdkConfiguration)
22
+ public class DdSdkConfiguration: NSObject {
23
+ public var clientToken: String = ""
24
+ public var env: String = ""
25
+ public var applicationId: String? = nil
26
+ public var nativeCrashReportEnabled: Bool? = nil
27
+ public var sampleRate: Double? = nil
28
+ public var site: NSString? = nil
29
+ public var trackingConsent: NSString? = nil
30
+ public var additionalConfig: NSDictionary? = nil
31
+
32
+ public init(
33
+ clientToken: String,
34
+ env: String,
35
+ applicationId: String?,
36
+ nativeCrashReportEnabled: Bool?,
37
+ sampleRate: Double?,
38
+ site: NSString?,
39
+ trackingConsent: NSString?,
40
+ additionalConfig: NSDictionary?
41
+ ) {
42
+ self.clientToken = clientToken
43
+ self.env = env
44
+ self.applicationId = applicationId
45
+ self.nativeCrashReportEnabled = nativeCrashReportEnabled
46
+ self.sampleRate = sampleRate
47
+ self.site = site
48
+ self.trackingConsent = trackingConsent
49
+ self.additionalConfig = additionalConfig
50
+ }
51
+ }
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import Foundation
8
- import DatadogSDKBridge
8
+ import Datadog
9
9
 
10
10
  @objc(DdTrace)
11
11
  class RNDdTrace: NSObject {
@@ -15,21 +15,56 @@ class RNDdTrace: NSObject {
15
15
  return false
16
16
  }
17
17
 
18
- let nativeInstance: DdTrace = Bridge.getDdTrace()
18
+ private lazy var tracer: OTTracer = tracerProvider()
19
+ private let tracerProvider: () -> OTTracer
20
+ private(set) var spanDictionary = [NSString: OTSpan]()
19
21
 
22
+ internal init(_ tracerProvider: @escaping () -> OTTracer) {
23
+ self.tracerProvider = tracerProvider
24
+ }
25
+
26
+ override convenience init() {
27
+ self.init { Tracer.initialize(configuration: Tracer.Configuration()) }
28
+ }
20
29
  @objc(methodQueue)
21
30
  let methodQueue: DispatchQueue = sharedQueue
22
31
 
23
32
  @objc(startSpan:withContext:withTimestampms:withResolver:withRejecter:)
24
- func startSpan(operation: NSString, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
25
- let result = nativeInstance.startSpan(operation: operation, context: context, timestampMs: timestampMs)
26
- resolve(result)
33
+ func startSpan(operation: String, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
34
+ let id = UUID().uuidString as NSString
35
+ let timeIntervalSince1970: TimeInterval = Double(timestampMs) / 1_000
36
+ let startDate = Date(timeIntervalSince1970: timeIntervalSince1970)
37
+
38
+ objc_sync_enter(self)
39
+ spanDictionary[id] = tracer.startSpan(
40
+ operationName: operation,
41
+ childOf: nil,
42
+ tags: castAttributesToSwift(context).mergeWithGlobalAttributes(),
43
+ startTime: startDate
44
+ )
45
+ objc_sync_exit(self)
46
+
47
+ resolve(id)
27
48
  }
28
49
 
29
50
  @objc(finishSpan:withContext:withTimestampms:withResolver:withRejecter:)
30
51
  func finishSpan(spanId: NSString, context: NSDictionary, timestampMs: Int64, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
31
- nativeInstance.finishSpan(spanId: spanId, context: context, timestampMs: timestampMs)
52
+ objc_sync_enter(self)
53
+ let optionalSpan = spanDictionary.removeValue(forKey: spanId)
54
+ objc_sync_exit(self)
55
+
56
+ if let span = optionalSpan {
57
+ set(tags: castAttributesToSwift(context).mergeWithGlobalAttributes(), to: span)
58
+ let timeIntervalSince1970: TimeInterval = Double(timestampMs) / 1_000
59
+ span.finish(at: Date(timeIntervalSince1970: timeIntervalSince1970))
60
+ }
61
+
32
62
  resolve(nil)
33
63
  }
34
64
 
65
+ private func set(tags: [String: Encodable], to span: OTSpan) {
66
+ for (key, value) in tags {
67
+ span.setTag(key: key, value: value)
68
+ }
69
+ }
35
70
  }
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2019-2021 Datadog, Inc.
5
+ */
6
+
7
+ import Foundation
8
+
9
+ internal struct GlobalState {
10
+ /// Holds global attributes to be used with Logs and Traces, because they don't expose Global instances, unlike RUM
11
+ internal static var globalAttributes: [String: Encodable] = [:]
12
+
13
+ internal static func addAttribute(forKey: String, value: Encodable?) {
14
+ GlobalState.globalAttributes[forKey] = value
15
+ }
16
+
17
+ internal static func removeAttribute(key: String) {
18
+ GlobalState.globalAttributes.removeValue(forKey: key)
19
+ }
20
+ }
21
+
22
+ internal extension Dictionary where Key == String, Value == Encodable {
23
+ func mergeWithGlobalAttributes() -> [String: Encodable] {
24
+ // values of current attributes are more important than values of global attributes,
25
+ // because they are coming with a current call
26
+ return merging(GlobalState.globalAttributes) { current, _ in current }
27
+ }
28
+ }
@@ -7,3 +7,13 @@
7
7
  import Foundation
8
8
 
9
9
  internal let sharedQueue = DispatchQueue(label: "dd-react-native-sdk")
10
+
11
+ protocol DispatchQueueType {
12
+ func async(execute work: @escaping @convention(block) () -> Void)
13
+ }
14
+
15
+ extension DispatchQueue: DispatchQueueType {
16
+ func async(execute work: @escaping @convention(block) () -> Void) {
17
+ async(group: nil, qos: .unspecified, flags: [], execute: work)
18
+ }
19
+ }
@@ -5,22 +5,21 @@
5
5
  */
6
6
 
7
7
  import Foundation
8
- import DatadogSDKBridge
9
8
 
10
9
  extension NSDictionary {
11
10
 
12
11
  func asDdSdkConfiguration() -> DdSdkConfiguration {
13
- let clientToken = object(forKey: "clientToken") as? NSString
14
- let env = object(forKey: "env") as? NSString
15
- let applicationId = object(forKey: "applicationId") as? NSString
12
+ let clientToken = object(forKey: "clientToken") as? String
13
+ let env = object(forKey: "env") as? String
14
+ let applicationId = object(forKey: "applicationId") as? String
16
15
  let nativeCrashReportEnabled = object(forKey: "nativeCrashReportEnabled") as? Bool
17
16
  let sampleRate = object(forKey: "sampleRate") as? Double
18
17
  let site = object(forKey: "site") as? NSString
19
18
  let trackingConsent = object(forKey: "trackingConsent") as? NSString
20
19
  let additionalConfig = object(forKey: "additionalConfig") as? NSDictionary
21
20
  return DdSdkConfiguration(
22
- clientToken: (clientToken != nil) ? clientToken! : NSString(),
23
- env: (env != nil) ? env! : NSString(),
21
+ clientToken: (clientToken != nil) ? clientToken! : String(),
22
+ env: (env != nil) ? env! : String(),
24
23
  applicationId: applicationId,
25
24
  nativeCrashReportEnabled: nativeCrashReportEnabled,
26
25
  sampleRate: sampleRate,
@@ -75,6 +75,16 @@ class DdSdkReactNative {
75
75
  configuration.additionalConfig[DdSdkReactNative.DD_SERVICE_NAME] = configuration.serviceName;
76
76
  }
77
77
 
78
+ if (configuration.version) {
79
+ configuration.additionalConfig[DdSdkReactNative.DD_VERSION] = `${configuration.version}${configuration.versionSuffix ? `-${configuration.versionSuffix}` : ''}`;
80
+ } // If both version and version suffix are provided, we merge them into the version field.
81
+ // To avoid adding it in again the native part, we only set it if the version isn't set.
82
+
83
+
84
+ if (configuration.versionSuffix && !configuration.version) {
85
+ configuration.additionalConfig[DdSdkReactNative.DD_VERSION_SUFFIX] = `-${configuration.versionSuffix}`;
86
+ }
87
+
78
88
  configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;
79
89
  configuration.additionalConfig['_dd.first_party_hosts'] = configuration.firstPartyHosts;
80
90
 
@@ -159,6 +169,10 @@ _defineProperty(DdSdkReactNative, "DD_SDK_VERBOSITY_KEY", '_dd.sdk_verbosity');
159
169
 
160
170
  _defineProperty(DdSdkReactNative, "DD_NATIVE_VIEW_TRACKING_KEY", '_dd.native_view_tracking');
161
171
 
172
+ _defineProperty(DdSdkReactNative, "DD_VERSION", '_dd.version');
173
+
174
+ _defineProperty(DdSdkReactNative, "DD_VERSION_SUFFIX", '_dd.version_suffix');
175
+
162
176
  _defineProperty(DdSdkReactNative, "DD_PROXY_TYPE_KEY", '_dd.proxy.type');
163
177
 
164
178
  _defineProperty(DdSdkReactNative, "DD_PROXY_ADDRESS_KEY", '_dd.proxy.address');
@@ -1 +1 @@
1
- {"version":3,"sources":["DdSdkReactNative.tsx"],"names":["DdSdkReactNative","initialize","configuration","Promise","resolve","reject","wasInitialized","InternalLog","log","SdkVerbosity","WARN","verbosity","additionalConfig","DD_SOURCE_KEY","DD_SDK_VERSION","sdkVersion","DD_NATIVE_VIEW_TRACKING_KEY","nativeViewTracking","DD_SDK_VERBOSITY_KEY","proxyConfig","DD_PROXY_TYPE_KEY","type","DD_PROXY_ADDRESS_KEY","address","DD_PROXY_PORT_KEY","port","username","password","ProxyType","SOCKS","console","warn","DD_PROXY_USERNAME_KEY","DD_PROXY_PASSWORD_KEY","serviceName","DD_SERVICE_NAME","DD_NATIVE_LONG_TASK_THRESHOLD_KEY","NATIVE_LONG_TASK_THRESHOLD_MS","firstPartyHosts","DdSdk","DdSdkConfiguration","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","undefined","sessionSamplingRate","site","trackingConsent","then","INFO","enableFeatures","rejection","setAttributes","attributes","JSON","stringify","DEBUG","setUser","user","setTrackingConsent","consent","trackInteractions","DdRumUserInteractionTracking","startTracking","trackResources","DdRumResourceTracking","tracingSamplingRate","resourceTracingSamplingRate","trackErrors","DdRumErrorTracking"],"mappings":";;;;;;;AAOA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAEA;AACA;AACA;AACO,MAAMA,gBAAN,CAAuB;AAQ1B;;AAaA;AACJ;AACA;AACA;AACA;AACqB,SAAVC,UAAU,CACbC,aADa,EAEA;AACb,WAAO,IAAIC,OAAJ,CAAkB,CAACC,OAAD,EAAUC,MAAV,KAAqB;AAC1C,UAAIL,gBAAgB,CAACM,cAArB,EAAqC;AACjCC,iCAAYC,GAAZ,CACI,uDADJ,EAEIC,2BAAaC,IAFjB;;AAIAN,QAAAA,OAAO;AACP;AACH;;AAEDG,+BAAYI,SAAZ,GAAwBT,aAAa,CAACS,SAAtC;AAEAT,MAAAA,aAAa,CAACU,gBAAd,CAA+BZ,gBAAgB,CAACa,aAAhD,IACI,cADJ;AAEAX,MAAAA,aAAa,CAACU,gBAAd,CACIZ,gBAAgB,CAACc,cADrB,IAEIC,gBAFJ;AAGAb,MAAAA,aAAa,CAACU,gBAAd,CACIZ,gBAAgB,CAACgB,2BADrB,IAEId,aAAa,CAACe,kBAFlB;;AAGA,UAAIf,aAAa,CAACS,SAAlB,EAA6B;AACzBT,QAAAA,aAAa,CAACU,gBAAd,CACIZ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B,kBAAMsB,kBAAN,CAAyBC,OAAzB,CAAP;AACH;;AAE4B,SAAdV,cAAc,CACzBlD,aADyB,EAE3B;AACE,QAAIA,aAAa,CAAC6D,iBAAlB,EAAqC;AACjCC,iEAA6BC,aAA7B;AACH;;AAED,QAAI/D,aAAa,CAACgE,cAAlB,EAAkC;AAC9BC,mDAAsBF,aAAtB,CAAoC;AAChCG,QAAAA,mBAAmB,EAAElE,aAAa,CAACmE,2BADH;AAEhC/B,QAAAA,eAAe,EAAEpC,aAAa,CAACoC;AAFC,OAApC;AAIH;;AAED,QAAIpC,aAAa,CAACoE,WAAlB,EAA+B;AAC3BC,6CAAmBN,aAAnB;AACH;AACJ;;AAnLyB;;;;gBAAjBjE,gB,mBAC+B,Y;;gBAD/BA,gB,oBAEgC,iB;;gBAFhCA,gB,qBAGiC,kB;;gBAHjCA,gB,0BAIsC,mB;;gBAJtCA,gB,iCAML,0B;;gBANKA,gB,uBASmC,gB;;gBATnCA,gB,0BAUsC,mB;;gBAVtCA,gB,uBAWmC,gB;;gBAXnCA,gB,2BAYuC,oB;;gBAZvCA,gB,2BAauC,oB;;gBAbvCA,gB,uCAgBL,yB;;gBAhBKA,gB,mCAiB+C,G;;gBAjB/CA,gB,oBAmBuB,K","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';\nimport { InternalLog } from './InternalLog';\nimport { ProxyType } from './ProxyConfiguration';\nimport { SdkVerbosity } from './SdkVerbosity';\nimport type { TrackingConsent } from './TrackingConsent';\nimport { DdSdk } from './foundation';\nimport { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking';\nimport { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';\nimport { DdRumResourceTracking } from './rum/instrumentation/resourceTracking/DdRumResourceTracking';\nimport { DdSdkConfiguration } from './types';\nimport { version as sdkVersion } from './version';\n\n/**\n * This class initializes the Datadog SDK, and sets up communication with the server.\n */\nexport class DdSdkReactNative {\n private static readonly DD_SOURCE_KEY = '_dd.source';\n private static readonly DD_SDK_VERSION = '_dd.sdk_version';\n private static readonly DD_SERVICE_NAME = '_dd.service_name';\n private static readonly DD_SDK_VERBOSITY_KEY = '_dd.sdk_verbosity';\n private static readonly DD_NATIVE_VIEW_TRACKING_KEY =\n '_dd.native_view_tracking';\n\n // Proxy\n private static readonly DD_PROXY_TYPE_KEY = '_dd.proxy.type';\n private static readonly DD_PROXY_ADDRESS_KEY = '_dd.proxy.address';\n private static readonly DD_PROXY_PORT_KEY = '_dd.proxy.port';\n private static readonly DD_PROXY_USERNAME_KEY = '_dd.proxy.username';\n private static readonly DD_PROXY_PASSWORD_KEY = '_dd.proxy.password';\n\n private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY =\n '_dd.long_task.threshold';\n private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200;\n\n private static wasInitialized = false;\n\n /**\n * Initializes the Datadog SDK.\n * @param configuration the configuration for the SDK library\n * @returns a Promise.\n */\n static initialize(\n configuration: DdSdkReactNativeConfiguration\n ): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (DdSdkReactNative.wasInitialized) {\n InternalLog.log(\n \"Can't initialize Datadog, SDK was already initialized\",\n SdkVerbosity.WARN\n );\n resolve();\n return;\n }\n\n InternalLog.verbosity = configuration.verbosity;\n\n configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] =\n 'react-native';\n configuration.additionalConfig[\n DdSdkReactNative.DD_SDK_VERSION\n ] = sdkVersion;\n configuration.additionalConfig[\n DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY\n ] = configuration.nativeViewTracking;\n if (configuration.verbosity) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_SDK_VERBOSITY_KEY\n ] = configuration.verbosity;\n }\n\n if (configuration.proxyConfig) {\n const additionalConfig = configuration.additionalConfig;\n const proxyConfig = configuration.proxyConfig;\n\n additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] =\n proxyConfig.type;\n additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] =\n proxyConfig.address;\n additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] =\n proxyConfig.port;\n if (proxyConfig.username && proxyConfig.password) {\n if (proxyConfig.type === ProxyType.SOCKS) {\n console.warn(\n \"SOCKS proxy configuration doesn't support Basic authentication.\"\n );\n } else {\n additionalConfig[\n DdSdkReactNative.DD_PROXY_USERNAME_KEY\n ] = proxyConfig.username;\n additionalConfig[\n DdSdkReactNative.DD_PROXY_PASSWORD_KEY\n ] = proxyConfig.password;\n }\n }\n }\n\n if (configuration.serviceName) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_SERVICE_NAME\n ] = configuration.serviceName;\n }\n\n configuration.additionalConfig[\n DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY\n ] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;\n\n configuration.additionalConfig['_dd.first_party_hosts'] =\n configuration.firstPartyHosts;\n\n DdSdk.initialize(\n new DdSdkConfiguration(\n configuration.clientToken,\n configuration.env,\n configuration.applicationId,\n configuration.nativeCrashReportEnabled,\n configuration.sampleRate === undefined\n ? configuration.sessionSamplingRate\n : configuration.sampleRate,\n configuration.site,\n configuration.trackingConsent,\n configuration.additionalConfig\n )\n ).then(\n () => {\n InternalLog.log(\n 'Datadog SDK was initialized',\n SdkVerbosity.INFO\n );\n DdSdkReactNative.enableFeatures(configuration);\n DdSdkReactNative.wasInitialized = true;\n resolve();\n },\n rejection => {\n reject(rejection);\n }\n );\n });\n }\n\n /**\n * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.\n * @param attributes: The global context attributes.\n * @returns a Promise.\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n static setAttributes(attributes: object): Promise<void> {\n InternalLog.log(\n `Setting attributes ${JSON.stringify(attributes)}`,\n SdkVerbosity.DEBUG\n );\n return DdSdk.setAttributes(attributes);\n }\n\n /**\n * Set the user information.\n * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).\n * @returns a Promise.\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n static setUser(user: object): Promise<void> {\n InternalLog.log(\n `Setting user ${JSON.stringify(user)}`,\n SdkVerbosity.DEBUG\n );\n return DdSdk.setUser(user);\n }\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: One of TrackingConsent values.\n * @returns a Promise.\n */\n static setTrackingConsent(consent: TrackingConsent): Promise<void> {\n InternalLog.log(`Setting consent ${consent}`, SdkVerbosity.DEBUG);\n return DdSdk.setTrackingConsent(consent);\n }\n\n private static enableFeatures(\n configuration: DdSdkReactNativeConfiguration\n ) {\n if (configuration.trackInteractions) {\n DdRumUserInteractionTracking.startTracking();\n }\n\n if (configuration.trackResources) {\n DdRumResourceTracking.startTracking({\n tracingSamplingRate: configuration.resourceTracingSamplingRate,\n firstPartyHosts: configuration.firstPartyHosts\n });\n }\n\n if (configuration.trackErrors) {\n DdRumErrorTracking.startTracking();\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["DdSdkReactNative.tsx"],"names":["DdSdkReactNative","initialize","configuration","Promise","resolve","reject","wasInitialized","InternalLog","log","SdkVerbosity","WARN","verbosity","additionalConfig","DD_SOURCE_KEY","DD_SDK_VERSION","sdkVersion","DD_NATIVE_VIEW_TRACKING_KEY","nativeViewTracking","DD_SDK_VERBOSITY_KEY","proxyConfig","DD_PROXY_TYPE_KEY","type","DD_PROXY_ADDRESS_KEY","address","DD_PROXY_PORT_KEY","port","username","password","ProxyType","SOCKS","console","warn","DD_PROXY_USERNAME_KEY","DD_PROXY_PASSWORD_KEY","serviceName","DD_SERVICE_NAME","version","DD_VERSION","versionSuffix","DD_VERSION_SUFFIX","DD_NATIVE_LONG_TASK_THRESHOLD_KEY","NATIVE_LONG_TASK_THRESHOLD_MS","firstPartyHosts","DdSdk","DdSdkConfiguration","clientToken","env","applicationId","nativeCrashReportEnabled","sampleRate","undefined","sessionSamplingRate","site","trackingConsent","then","INFO","enableFeatures","rejection","setAttributes","attributes","JSON","stringify","DEBUG","setUser","user","setTrackingConsent","consent","trackInteractions","DdRumUserInteractionTracking","startTracking","trackResources","DdRumResourceTracking","tracingSamplingRate","resourceTracingSamplingRate","trackErrors","DdRumErrorTracking"],"mappings":";;;;;;;AAOA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAEA;AACA;AACA;AACO,MAAMA,gBAAN,CAAuB;AAU1B;;AAaA;AACJ;AACA;AACA;AACA;AACqB,SAAVC,UAAU,CACbC,aADa,EAEA;AACb,WAAO,IAAIC,OAAJ,CAAkB,CAACC,OAAD,EAAUC,MAAV,KAAqB;AAC1C,UAAIL,gBAAgB,CAACM,cAArB,EAAqC;AACjCC,iCAAYC,GAAZ,CACI,uDADJ,EAEIC,2BAAaC,IAFjB;;AAIAN,QAAAA,OAAO;AACP;AACH;;AAEDG,+BAAYI,SAAZ,GAAwBT,aAAa,CAACS,SAAtC;AAEAT,MAAAA,aAAa,CAACU,gBAAd,CAA+BZ,gBAAgB,CAACa,aAAhD,IACI,cADJ;AAEAX,MAAAA,aAAa,CAACU,gBAAd,CACIZ,gBAAgB,CAACc,cADrB,IAEIC,gBAFJ;AAGAb,MAAAA,aAAa,CAACU,gBAAd,CACIZ,gBAAgB,CAACgB,2BADrB,IAEId,aAAa,CAACe,kBAFlB;;AAGA,UAAIf,aAAa,CAACS,SAAlB,EAA6B;AACzBT,QAAAA,aAAa,CAACU,gBAAd,CACIZ,gBAAgB,CAACkB,oBADrB,IAEIhB,aAAa,CAACS,SAFlB;AAGH;;AAED,UAAIT,aAAa,CAACiB,WAAlB,EAA+B;AAC3B,cAAMP,gBAAgB,GAAGV,aAAa,CAACU,gBAAvC;AACA,cAAMO,WAAW,GAAGjB,aAAa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,CAAqB,EADzC,EAEIvD,2BAAaqD,KAFjB;;AAIA,WAAOnB,kBAAMoB,OAAN,CAAcC,IAAd,CAAP;AACH;AAED;AACJ;AACA;AACA;AACA;;;AAC6B,SAAlBC,kBAAkB,CAACC,OAAD,EAA0C;AAC/D3D,6BAAYC,GAAZ,CAAiB,mBAAkB0D,OAAQ,EAA3C,EAA8CzD,2BAAaqD,KAA3D;;AACA,WAAOnB,kBAAMsB,kBAAN,CAAyBC,OAAzB,CAAP;AACH;;AAE4B,SAAdV,cAAc,CACzBtD,aADyB,EAE3B;AACE,QAAIA,aAAa,CAACiE,iBAAlB,EAAqC;AACjCC,iEAA6BC,aAA7B;AACH;;AAED,QAAInE,aAAa,CAACoE,cAAlB,EAAkC;AAC9BC,mDAAsBF,aAAtB,CAAoC;AAChCG,QAAAA,mBAAmB,EAAEtE,aAAa,CAACuE,2BADH;AAEhC/B,QAAAA,eAAe,EAAExC,aAAa,CAACwC;AAFC,OAApC;AAIH;;AAED,QAAIxC,aAAa,CAACwE,WAAlB,EAA+B;AAC3BC,6CAAmBN,aAAnB;AACH;AACJ;;AAvMyB;;;;gBAAjBrE,gB,mBAC+B,Y;;gBAD/BA,gB,oBAEgC,iB;;gBAFhCA,gB,qBAGiC,kB;;gBAHjCA,gB,0BAIsC,mB;;gBAJtCA,gB,iCAML,0B;;gBANKA,gB,gBAO4B,a;;gBAP5BA,gB,uBAQmC,oB;;gBARnCA,gB,uBAWmC,gB;;gBAXnCA,gB,0BAYsC,mB;;gBAZtCA,gB,uBAamC,gB;;gBAbnCA,gB,2BAcuC,oB;;gBAdvCA,gB,2BAeuC,oB;;gBAfvCA,gB,uCAkBL,yB;;gBAlBKA,gB,mCAmB+C,G;;gBAnB/CA,gB,oBAqBuB,K","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { DdSdkReactNativeConfiguration } from './DdSdkReactNativeConfiguration';\nimport { InternalLog } from './InternalLog';\nimport { ProxyType } from './ProxyConfiguration';\nimport { SdkVerbosity } from './SdkVerbosity';\nimport type { TrackingConsent } from './TrackingConsent';\nimport { DdSdk } from './foundation';\nimport { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking';\nimport { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInteractionTracking';\nimport { DdRumResourceTracking } from './rum/instrumentation/resourceTracking/DdRumResourceTracking';\nimport { DdSdkConfiguration } from './types';\nimport { version as sdkVersion } from './version';\n\n/**\n * This class initializes the Datadog SDK, and sets up communication with the server.\n */\nexport class DdSdkReactNative {\n private static readonly DD_SOURCE_KEY = '_dd.source';\n private static readonly DD_SDK_VERSION = '_dd.sdk_version';\n private static readonly DD_SERVICE_NAME = '_dd.service_name';\n private static readonly DD_SDK_VERBOSITY_KEY = '_dd.sdk_verbosity';\n private static readonly DD_NATIVE_VIEW_TRACKING_KEY =\n '_dd.native_view_tracking';\n private static readonly DD_VERSION = '_dd.version';\n private static readonly DD_VERSION_SUFFIX = '_dd.version_suffix';\n\n // Proxy\n private static readonly DD_PROXY_TYPE_KEY = '_dd.proxy.type';\n private static readonly DD_PROXY_ADDRESS_KEY = '_dd.proxy.address';\n private static readonly DD_PROXY_PORT_KEY = '_dd.proxy.port';\n private static readonly DD_PROXY_USERNAME_KEY = '_dd.proxy.username';\n private static readonly DD_PROXY_PASSWORD_KEY = '_dd.proxy.password';\n\n private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY =\n '_dd.long_task.threshold';\n private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200;\n\n private static wasInitialized = false;\n\n /**\n * Initializes the Datadog SDK.\n * @param configuration the configuration for the SDK library\n * @returns a Promise.\n */\n static initialize(\n configuration: DdSdkReactNativeConfiguration\n ): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (DdSdkReactNative.wasInitialized) {\n InternalLog.log(\n \"Can't initialize Datadog, SDK was already initialized\",\n SdkVerbosity.WARN\n );\n resolve();\n return;\n }\n\n InternalLog.verbosity = configuration.verbosity;\n\n configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] =\n 'react-native';\n configuration.additionalConfig[\n DdSdkReactNative.DD_SDK_VERSION\n ] = sdkVersion;\n configuration.additionalConfig[\n DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY\n ] = configuration.nativeViewTracking;\n if (configuration.verbosity) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_SDK_VERBOSITY_KEY\n ] = configuration.verbosity;\n }\n\n if (configuration.proxyConfig) {\n const additionalConfig = configuration.additionalConfig;\n const proxyConfig = configuration.proxyConfig;\n\n additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] =\n proxyConfig.type;\n additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] =\n proxyConfig.address;\n additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] =\n proxyConfig.port;\n if (proxyConfig.username && proxyConfig.password) {\n if (proxyConfig.type === ProxyType.SOCKS) {\n console.warn(\n \"SOCKS proxy configuration doesn't support Basic authentication.\"\n );\n } else {\n additionalConfig[\n DdSdkReactNative.DD_PROXY_USERNAME_KEY\n ] = proxyConfig.username;\n additionalConfig[\n DdSdkReactNative.DD_PROXY_PASSWORD_KEY\n ] = proxyConfig.password;\n }\n }\n }\n\n if (configuration.serviceName) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_SERVICE_NAME\n ] = configuration.serviceName;\n }\n\n if (configuration.version) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_VERSION\n ] = `${configuration.version}${\n configuration.versionSuffix\n ? `-${configuration.versionSuffix}`\n : ''\n }`;\n }\n\n // If both version and version suffix are provided, we merge them into the version field.\n // To avoid adding it in again the native part, we only set it if the version isn't set.\n if (configuration.versionSuffix && !configuration.version) {\n configuration.additionalConfig[\n DdSdkReactNative.DD_VERSION_SUFFIX\n ] = `-${configuration.versionSuffix}`;\n }\n\n configuration.additionalConfig[\n DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY\n ] = DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS;\n\n configuration.additionalConfig['_dd.first_party_hosts'] =\n configuration.firstPartyHosts;\n\n DdSdk.initialize(\n new DdSdkConfiguration(\n configuration.clientToken,\n configuration.env,\n configuration.applicationId,\n configuration.nativeCrashReportEnabled,\n configuration.sampleRate === undefined\n ? configuration.sessionSamplingRate\n : configuration.sampleRate,\n configuration.site,\n configuration.trackingConsent,\n configuration.additionalConfig\n )\n ).then(\n () => {\n InternalLog.log(\n 'Datadog SDK was initialized',\n SdkVerbosity.INFO\n );\n DdSdkReactNative.enableFeatures(configuration);\n DdSdkReactNative.wasInitialized = true;\n resolve();\n },\n rejection => {\n reject(rejection);\n }\n );\n });\n }\n\n /**\n * Sets the global context (set of attributes) attached with all future Logs, Spans and RUM events.\n * @param attributes: The global context attributes.\n * @returns a Promise.\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n static setAttributes(attributes: object): Promise<void> {\n InternalLog.log(\n `Setting attributes ${JSON.stringify(attributes)}`,\n SdkVerbosity.DEBUG\n );\n return DdSdk.setAttributes(attributes);\n }\n\n /**\n * Set the user information.\n * @param user: The user object (use builtin attributes: 'id', 'email', 'name', and/or any custom attribute).\n * @returns a Promise.\n */\n // eslint-disable-next-line @typescript-eslint/ban-types\n static setUser(user: object): Promise<void> {\n InternalLog.log(\n `Setting user ${JSON.stringify(user)}`,\n SdkVerbosity.DEBUG\n );\n return DdSdk.setUser(user);\n }\n\n /**\n * Set the tracking consent regarding the data collection.\n * @param trackingConsent: One of TrackingConsent values.\n * @returns a Promise.\n */\n static setTrackingConsent(consent: TrackingConsent): Promise<void> {\n InternalLog.log(`Setting consent ${consent}`, SdkVerbosity.DEBUG);\n return DdSdk.setTrackingConsent(consent);\n }\n\n private static enableFeatures(\n configuration: DdSdkReactNativeConfiguration\n ) {\n if (configuration.trackInteractions) {\n DdRumUserInteractionTracking.startTracking();\n }\n\n if (configuration.trackResources) {\n DdRumResourceTracking.startTracking({\n tracingSamplingRate: configuration.resourceTracingSamplingRate,\n firstPartyHosts: configuration.firstPartyHosts\n });\n }\n\n if (configuration.trackErrors) {\n DdRumErrorTracking.startTracking();\n }\n }\n}\n"]}
@@ -25,6 +25,26 @@ class DdSdkReactNativeConfiguration {
25
25
  /**
26
26
  * Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.
27
27
  */
28
+
29
+ /**
30
+ * Overrides the reported version of the app.
31
+ * Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.
32
+ * Other special characters are converted to underscores.
33
+ *
34
+ * See https://docs.datadoghq.com/getting_started/tagging/#define-tags for more information on the format.
35
+ *
36
+ * Make sure you set it correctly, as it will have to match the one specified during the upload of your source maps and other mapping files.
37
+ */
38
+
39
+ /**
40
+ * Add a suffix to the reported version of the app.
41
+ * Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.
42
+ * Other special characters are converted to underscores.
43
+ *
44
+ * See https://docs.datadoghq.com/getting_started/tagging/#define-tags for more information on the format.
45
+ *
46
+ * A dash (`-`) will be automatically added between the version and the suffix
47
+ */
28
48
  constructor(clientToken, env, applicationId, trackInteractions = false, trackResources = false, trackErrors = false, trackingConsent = _TrackingConsent.TrackingConsent.GRANTED) {
29
49
  this.clientToken = clientToken;
30
50
  this.env = env;
@@ -54,6 +74,10 @@ class DdSdkReactNativeConfiguration {
54
74
 
55
75
  _defineProperty(this, "firstPartyHosts", []);
56
76
 
77
+ _defineProperty(this, "version", void 0);
78
+
79
+ _defineProperty(this, "versionSuffix", void 0);
80
+
57
81
  _defineProperty(this, "additionalConfig", {});
58
82
  }
59
83
 
@@ -1 +1 @@
1
- {"version":3,"sources":["DdSdkReactNativeConfiguration.tsx"],"names":["DdSdkReactNativeConfiguration","constructor","clientToken","env","applicationId","trackInteractions","trackResources","trackErrors","trackingConsent","TrackingConsent","GRANTED","undefined"],"mappings":";;;;;;;AAQA;;;;AAEA;AACA;AACA;AACA;AACO,MAAMA,6BAAN,CAAoC;AAEvC;AACJ;AACA;;AAEI;AACJ;AACA;;AAEI;AACJ;AACA;AAWIC,EAAAA,WAAW,CACEC,WADF,EAEEC,GAFF,EAGEC,aAHF,EAIEC,iBAA0B,GAAG,KAJ/B,EAKEC,cAAuB,GAAG,KAL5B,EAMEC,WAAoB,GAAG,KANzB,EAOEC,eAAgC,GAAGC,iCAAgBC,OAPrD,EAQT;AAAA,SAPWR,WAOX,GAPWA,WAOX;AAAA,SANWC,GAMX,GANWA,GAMX;AAAA,SALWC,aAKX,GALWA,aAKX;AAAA,SAJWC,iBAIX,GAJWA,iBAIX;AAAA,SAHWC,cAGX,GAHWA,cAGX;AAAA,SAFWC,WAEX,GAFWA,WAEX;AAAA,SADWC,eACX,GADWA,eACX;;AAAA,sDA9ByC,KA8BzC;;AAAA;;AAAA,iDAtBmC,KAsBnC;;AAAA,yDAlB2C,IAkB3C;;AAAA,kCAjBoB,IAiBpB;;AAAA,uCAhB2CG,SAgB3C;;AAAA,gDAfmC,KAenC;;AAAA,yCAdwCA,SAcxC;;AAAA,yCAb4BA,SAa5B;;AAAA,6CAZiC,EAYjC;;AAAA,8CAV8C,EAU9C;AAAE;;AA/BmC","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { ProxyConfiguration } from './ProxyConfiguration';\nimport type { SdkVerbosity } from './SdkVerbosity';\nimport { TrackingConsent } from './TrackingConsent';\n\n/**\n * The SDK configuration class.\n * It will be used to configure the SDK functionality at initialization.\n */\nexport class DdSdkReactNativeConfiguration {\n public nativeCrashReportEnabled: boolean = false;\n /**\n * @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.\n */\n public sampleRate?: number;\n /**\n * Percentage of sampled RUM sessions. Range `0`-`100`.\n */\n public sessionSamplingRate: number = 100.0;\n /**\n * Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.\n */\n public resourceTracingSamplingRate: number = 20.0;\n public site: string = 'US';\n public verbosity: SdkVerbosity | undefined = undefined;\n public nativeViewTracking: boolean = false;\n public proxyConfig?: ProxyConfiguration = undefined;\n public serviceName?: string = undefined;\n public firstPartyHosts: string[] = [];\n\n public additionalConfig: { [k: string]: any } = {};\n\n constructor(\n readonly clientToken: string,\n readonly env: string,\n readonly applicationId: string,\n readonly trackInteractions: boolean = false,\n readonly trackResources: boolean = false,\n readonly trackErrors: boolean = false,\n readonly trackingConsent: TrackingConsent = TrackingConsent.GRANTED\n ) {}\n}\n"]}
1
+ {"version":3,"sources":["DdSdkReactNativeConfiguration.tsx"],"names":["DdSdkReactNativeConfiguration","constructor","clientToken","env","applicationId","trackInteractions","trackResources","trackErrors","trackingConsent","TrackingConsent","GRANTED","undefined"],"mappings":";;;;;;;AAQA;;;;AAEA;AACA;AACA;AACA;AACO,MAAMA,6BAAN,CAAoC;AAEvC;AACJ;AACA;;AAEI;AACJ;AACA;;AAEI;AACJ;AACA;;AAQI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKIC,EAAAA,WAAW,CACEC,WADF,EAEEC,GAFF,EAGEC,aAHF,EAIEC,iBAA0B,GAAG,KAJ/B,EAKEC,cAAuB,GAAG,KAL5B,EAMEC,WAAoB,GAAG,KANzB,EAOEC,eAAgC,GAAGC,iCAAgBC,OAPrD,EAQT;AAAA,SAPWR,WAOX,GAPWA,WAOX;AAAA,SANWC,GAMX,GANWA,GAMX;AAAA,SALWC,aAKX,GALWA,aAKX;AAAA,SAJWC,iBAIX,GAJWA,iBAIX;AAAA,SAHWC,cAGX,GAHWA,cAGX;AAAA,SAFWC,WAEX,GAFWA,WAEX;AAAA,SADWC,eACX,GADWA,eACX;;AAAA,sDAlDyC,KAkDzC;;AAAA;;AAAA,iDA1CmC,KA0CnC;;AAAA,yDAtC2C,IAsC3C;;AAAA,kCArCoB,IAqCpB;;AAAA,uCApC2CG,SAoC3C;;AAAA,gDAnCmC,KAmCnC;;AAAA,yCAlCwCA,SAkCxC;;AAAA,yCAjC4BA,SAiC5B;;AAAA,6CAhCiC,EAgCjC;;AAAA;;AAAA;;AAAA,8CAV8C,EAU9C;AAAE;;AAnDmC","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport type { ProxyConfiguration } from './ProxyConfiguration';\nimport type { SdkVerbosity } from './SdkVerbosity';\nimport { TrackingConsent } from './TrackingConsent';\n\n/**\n * The SDK configuration class.\n * It will be used to configure the SDK functionality at initialization.\n */\nexport class DdSdkReactNativeConfiguration {\n public nativeCrashReportEnabled: boolean = false;\n /**\n * @deprecated `sampleRate` has been replaced by `sessionSamplingRate` to avoid confusion with `resourceTracingSamplingRate` and will be removed in a future release.\n */\n public sampleRate?: number;\n /**\n * Percentage of sampled RUM sessions. Range `0`-`100`.\n */\n public sessionSamplingRate: number = 100.0;\n /**\n * Percentage of tracing integrations for network calls between your app and your backend. Range `0`-`100`.\n */\n public resourceTracingSamplingRate: number = 20.0;\n public site: string = 'US';\n public verbosity: SdkVerbosity | undefined = undefined;\n public nativeViewTracking: boolean = false;\n public proxyConfig?: ProxyConfiguration = undefined;\n public serviceName?: string = undefined;\n public firstPartyHosts: string[] = [];\n /**\n * Overrides the reported version of the app.\n * Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.\n * Other special characters are converted to underscores.\n *\n * See https://docs.datadoghq.com/getting_started/tagging/#define-tags for more information on the format.\n *\n * Make sure you set it correctly, as it will have to match the one specified during the upload of your source maps and other mapping files.\n */\n public version?: string;\n /**\n * Add a suffix to the reported version of the app.\n * Accepted characters are alphanumerics and `_`, `-`, `:`, `.`, `/`.\n * Other special characters are converted to underscores.\n *\n * See https://docs.datadoghq.com/getting_started/tagging/#define-tags for more information on the format.\n *\n * A dash (`-`) will be automatically added between the version and the suffix\n */\n public versionSuffix?: string;\n\n public additionalConfig: { [k: string]: any } = {};\n\n constructor(\n readonly clientToken: string,\n readonly env: string,\n readonly applicationId: string,\n readonly trackInteractions: boolean = false,\n readonly trackResources: boolean = false,\n readonly trackErrors: boolean = false,\n readonly trackingConsent: TrackingConsent = TrackingConsent.GRANTED\n ) {}\n}\n"]}
@@ -77,9 +77,37 @@ class DdTraceWrapper {
77
77
 
78
78
  }
79
79
 
80
+ const isNewStopActionAPI = args => {
81
+ return typeof args[0] === 'string';
82
+ };
83
+
84
+ const isOldStopActionAPI = args => {
85
+ return typeof args[0] === 'object' || typeof args[0] === 'undefined';
86
+ };
87
+
80
88
  class DdRumWrapper {
81
89
  constructor() {
82
90
  _defineProperty(this, "nativeRum", _reactNative.NativeModules.DdRum);
91
+
92
+ _defineProperty(this, "lastActionData", void 0);
93
+
94
+ _defineProperty(this, "getStopActionNativeCall", args => {
95
+ if (isNewStopActionAPI(args)) {
96
+ return this.nativeRum.stopAction(args[0], args[1], args[2] || {}, args[3] || timeProvider.now());
97
+ }
98
+
99
+ if (isOldStopActionAPI(args)) {
100
+ if (this.lastActionData) {
101
+ return this.nativeRum.stopAction(this.lastActionData.type, this.lastActionData.name, args[0] || {}, args[1] || timeProvider.now());
102
+ }
103
+
104
+ _InternalLog.InternalLog.log("DdRum.startAction needs to be called before DdRum.stopAction", _SdkVerbosity.SdkVerbosity.WARN);
105
+ } else {
106
+ _InternalLog.InternalLog.log("DdRum.stopAction was called with wrong arguments", _SdkVerbosity.SdkVerbosity.WARN);
107
+ }
108
+
109
+ return new Promise(resolve => resolve());
110
+ });
83
111
  }
84
112
 
85
113
  startView(key, name, context = {}, timestampMs = timeProvider.now()) {
@@ -97,13 +125,19 @@ class DdRumWrapper {
97
125
  startAction(type, name, context = {}, timestampMs = timeProvider.now()) {
98
126
  _InternalLog.InternalLog.log("Starting RUM Action “" + name + "” (" + type + ")", _SdkVerbosity.SdkVerbosity.DEBUG);
99
127
 
128
+ this.lastActionData = {
129
+ type,
130
+ name
131
+ };
100
132
  return this.nativeRum.startAction(type, name, context, timestampMs);
101
133
  }
102
134
 
103
- stopAction(context = {}, timestampMs = timeProvider.now()) {
135
+ stopAction(...args) {
104
136
  _InternalLog.InternalLog.log("Stopping current RUM Action", _SdkVerbosity.SdkVerbosity.DEBUG);
105
137
 
106
- return this.nativeRum.stopAction(context, timestampMs);
138
+ let returnPromise = this.getStopActionNativeCall(args);
139
+ this.lastActionData = undefined;
140
+ return returnPromise;
107
141
  }
108
142
 
109
143
  addAction(type, name, context = {}, timestampMs = timeProvider.now()) {