@datadog/mobile-react-native 2.2.0 → 2.3.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.
- package/DatadogSDKReactNative.podspec +2 -1
- package/android/build.gradle +1 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +2 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +11 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt +5 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +64 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +165 -5
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +6 -354
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +351 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkReactNativePackage.kt +5 -3
- package/android/src/main/kotlin/com/datadog/reactnative/DdTraceImplementation.kt +10 -0
- package/android/src/main/kotlin/com/datadog/reactnative/JSONFileReader.kt +20 -0
- package/android/src/main/kotlin/com/datadog/reactnative/ProxyAuthenticator.kt +4 -1
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +10 -0
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdLogs.kt +3 -2
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdRum.kt +5 -2
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdSdk.kt +3 -2
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkConfigurationTest.kt +196 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +181 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +12 -271
- package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +10 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +29 -2
- package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +24 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +9 -1
- package/android/src/test/resources/input/complete-configuration.json +48 -0
- package/android/src/test/resources/input/malformed-configuration.json +5 -0
- package/android/src/test/resources/input/minimal-configuration.json +8 -0
- package/datadog-configuration.gradle +57 -0
- package/datadog-configuration.schema.json +200 -0
- package/ios/Sources/DatadogSDKWrapper.swift +16 -13
- package/ios/Sources/DdLogsImplementation.swift +14 -0
- package/ios/Sources/DdSdk.h +2 -0
- package/ios/Sources/DdSdk.mm +6 -1
- package/ios/Sources/DdSdkConfiguration.swift +47 -56
- package/ios/Sources/DdSdkImplementation.swift +10 -279
- package/ios/Sources/DdSdkNativeInitialization.swift +218 -0
- package/ios/Sources/DdTraceImplementation.swift +3 -1
- package/ios/Sources/GlobalState.swift +1 -1
- package/ios/Sources/JSONFileReader.swift +28 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +227 -9
- package/ios/Sources/SdkVersion.swift +10 -0
- package/lib/commonjs/DdSdkReactNative.js +24 -66
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +24 -4
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/ProxyConfiguration.js +15 -2
- package/lib/commonjs/ProxyConfiguration.js.map +1 -1
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeModulesTypes.js +2 -2
- package/lib/commonjs/nativeModulesTypes.js.map +1 -1
- package/lib/commonjs/sdk/DatadogProvider/DatadogProvider.js.map +1 -1
- package/lib/commonjs/sdk/FileBasedConfiguration/FileBasedConfiguration.js +214 -0
- package/lib/commonjs/sdk/FileBasedConfiguration/FileBasedConfiguration.js.map +1 -0
- package/lib/commonjs/types.js +10 -2
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +23 -65
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +22 -4
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/ProxyConfiguration.js +15 -2
- package/lib/module/ProxyConfiguration.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeModulesTypes.js +2 -2
- package/lib/module/nativeModulesTypes.js.map +1 -1
- package/lib/module/sdk/DatadogProvider/DatadogProvider.js.map +1 -1
- package/lib/module/sdk/FileBasedConfiguration/FileBasedConfiguration.js +197 -0
- package/lib/module/sdk/FileBasedConfiguration/FileBasedConfiguration.js.map +1 -0
- package/lib/module/types.js +10 -2
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts +0 -9
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +43 -3
- package/lib/typescript/ProxyConfiguration.d.ts +4 -12
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/nativeModulesTypes.d.ts +2 -2
- package/lib/typescript/sdk/DatadogProvider/DatadogProvider.d.ts +2 -1
- package/lib/typescript/sdk/FileBasedConfiguration/FileBasedConfiguration.d.ts +31 -0
- package/lib/typescript/types.d.ts +29 -3
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +7 -4
- package/src/DdSdkReactNative.tsx +58 -101
- package/src/DdSdkReactNativeConfiguration.tsx +26 -7
- package/src/ProxyConfiguration.tsx +17 -3
- package/src/__tests__/DdSdkReactNative.test.tsx +134 -112
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +19 -10
- package/src/__tests__/mock.test.ts +0 -9
- package/src/index.tsx +2 -0
- package/src/nativeModulesTypes.ts +1 -1
- package/src/sdk/DatadogProvider/DatadogProvider.tsx +3 -1
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +12 -5
- package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +1 -2
- package/src/sdk/FileBasedConfiguration/FileBasedConfiguration.ts +235 -0
- package/src/sdk/FileBasedConfiguration/__tests__/FileBasedConfiguration.test.ts +245 -0
- package/src/sdk/FileBasedConfiguration/__tests__/__fixtures__/configuration-all-fields.json +22 -0
- package/src/sdk/FileBasedConfiguration/__tests__/__fixtures__/malformed-configuration.json +5 -0
- package/src/types.tsx +21 -2
- package/src/version.ts +1 -1
|
@@ -60,54 +60,14 @@ public class DdSdkImplementation: NSObject {
|
|
|
60
60
|
// Using @escaping RCTPromiseResolveBlock type will result in an issue when compiling the Swift header file.
|
|
61
61
|
@objc
|
|
62
62
|
public func initialize(configuration: NSDictionary, resolve:@escaping ((Any?) -> Void), reject:RCTPromiseRejectBlock) -> Void {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
let sdkConfiguration = configuration.asDdSdkConfiguration()
|
|
66
|
-
|
|
67
|
-
// TODO: see if this `if` is still needed
|
|
68
|
-
if DatadogSDKWrapper.shared.isInitialized() {
|
|
69
|
-
// Initializing the SDK twice results in Global.rum and
|
|
70
|
-
// Global.sharedTracer to be set to no-op instances
|
|
71
|
-
consolePrint("Datadog SDK is already initialized, skipping initialization.", .debug)
|
|
72
|
-
DatadogSDKWrapper.shared.telemetryDebug(id: "datadog_react_native: RN SDK was already initialized in native", message: "RN SDK was already initialized in native")
|
|
73
|
-
|
|
74
|
-
// This block is called when SDK is reinitialized and the javascript has been wiped out.
|
|
75
|
-
// In this case, we need to restart the refresh rate monitor, as the javascript thread
|
|
76
|
-
// appears to change at that moment.
|
|
77
|
-
self.startJSRefreshRateMonitoring(sdkConfiguration: sdkConfiguration)
|
|
78
|
-
resolve(nil)
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
self.setVerbosityLevel(additionalConfig: sdkConfiguration.additionalConfig)
|
|
82
|
-
|
|
83
|
-
let sdkConfig = self.buildSDKConfiguration(configuration: sdkConfiguration)
|
|
84
|
-
let consent = self.buildTrackingConsent(consent: sdkConfiguration.trackingConsent)
|
|
85
|
-
DatadogSDKWrapper.shared.initialize(with: sdkConfig, trackingConsent: consent)
|
|
86
|
-
|
|
87
|
-
self.enableFeatures(sdkConfiguration: sdkConfiguration)
|
|
88
|
-
self.startJSRefreshRateMonitoring(sdkConfiguration: sdkConfiguration)
|
|
89
|
-
|
|
90
|
-
resolve(nil)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
func enableFeatures(sdkConfiguration: DdSdkConfiguration) {
|
|
95
|
-
let rumConfig = buildRUMConfiguration(configuration: sdkConfiguration)
|
|
96
|
-
DatadogSDKWrapper.shared.enableRUM(with: rumConfig)
|
|
97
|
-
|
|
98
|
-
let logsConfig = buildLogsConfiguration(configuration: sdkConfiguration)
|
|
99
|
-
DatadogSDKWrapper.shared.enableLogs(with: logsConfig)
|
|
100
|
-
|
|
101
|
-
let traceConfig = buildTraceConfiguration(configuration: sdkConfiguration)
|
|
102
|
-
DatadogSDKWrapper.shared.enableTrace(with: traceConfig)
|
|
63
|
+
let sdkConfiguration = configuration.asDdSdkConfiguration()
|
|
64
|
+
let nativeInitialization = DdSdkNativeInitialization()
|
|
103
65
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
DatadogSDKWrapper.shared.enableWebviewTracking()
|
|
66
|
+
nativeInitialization.initialize(sdkConfiguration: sdkConfiguration)
|
|
67
|
+
self.startJSRefreshRateMonitoring(sdkConfiguration: sdkConfiguration)
|
|
68
|
+
self.overrideReactNativeTelemetry(rnConfiguration: sdkConfiguration)
|
|
109
69
|
|
|
110
|
-
|
|
70
|
+
resolve(nil)
|
|
111
71
|
}
|
|
112
72
|
|
|
113
73
|
@objc
|
|
@@ -135,7 +95,7 @@ public class DdSdkImplementation: NSObject {
|
|
|
135
95
|
|
|
136
96
|
@objc
|
|
137
97
|
public func setTrackingConsent(trackingConsent: NSString, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
|
|
138
|
-
Datadog.set(trackingConsent:
|
|
98
|
+
Datadog.set(trackingConsent: (trackingConsent as NSString?).asTrackingConsent())
|
|
139
99
|
resolve(nil)
|
|
140
100
|
}
|
|
141
101
|
|
|
@@ -147,7 +107,7 @@ public class DdSdkImplementation: NSObject {
|
|
|
147
107
|
|
|
148
108
|
@objc
|
|
149
109
|
public func telemetryError(message: NSString, stack: NSString, kind: NSString, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
|
|
150
|
-
DatadogSDKWrapper.shared.telemetryError(id: "datadog_react_native:\(String(describing: kind)):\(message)", message: message as String, kind: kind as
|
|
110
|
+
DatadogSDKWrapper.shared.telemetryError(id: "datadog_react_native:\(String(describing: kind)):\(message)", message: message as String, kind: kind as String, stack: stack as String)
|
|
151
111
|
resolve(nil)
|
|
152
112
|
}
|
|
153
113
|
|
|
@@ -166,7 +126,7 @@ public class DdSdkImplementation: NSObject {
|
|
|
166
126
|
DatadogSDKWrapper.shared.clearAllData()
|
|
167
127
|
resolve(nil)
|
|
168
128
|
}
|
|
169
|
-
|
|
129
|
+
|
|
170
130
|
func overrideReactNativeTelemetry(rnConfiguration: DdSdkConfiguration) -> Void {
|
|
171
131
|
DatadogSDKWrapper.shared.overrideTelemetryConfiguration(
|
|
172
132
|
initializationType: rnConfiguration.configurationForTelemetry?.initializationType as? String,
|
|
@@ -182,235 +142,6 @@ public class DdSdkImplementation: NSObject {
|
|
|
182
142
|
)
|
|
183
143
|
}
|
|
184
144
|
|
|
185
|
-
func buildSDKConfiguration(configuration: DdSdkConfiguration, defaultAppVersion: String = getDefaultAppVersion()) -> Datadog.Configuration {
|
|
186
|
-
var config = Datadog.Configuration(
|
|
187
|
-
clientToken: configuration.clientToken,
|
|
188
|
-
env: configuration.env,
|
|
189
|
-
site: configuration.site,
|
|
190
|
-
service: configuration.additionalConfig?[InternalConfigurationAttributes.serviceName] as? String ?? nil,
|
|
191
|
-
batchSize: configuration.batchSize,
|
|
192
|
-
uploadFrequency: configuration.uploadFrequency,
|
|
193
|
-
proxyConfiguration: buildProxyConfiguration(config: configuration.additionalConfig)
|
|
194
|
-
)
|
|
195
|
-
|
|
196
|
-
if var additionalConfiguration = configuration.additionalConfig as? [String: Any] {
|
|
197
|
-
if let versionSuffix = additionalConfiguration[InternalConfigurationAttributes.versionSuffix] as? String {
|
|
198
|
-
let datadogVersion = defaultAppVersion + versionSuffix
|
|
199
|
-
additionalConfiguration[CrossPlatformAttributes.version] = datadogVersion
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
config._internal_mutation {
|
|
203
|
-
$0.additionalConfiguration = additionalConfiguration
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return config
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
func buildRUMConfiguration(configuration: DdSdkConfiguration) -> RUM.Configuration {
|
|
211
|
-
var longTaskThreshold: TimeInterval? = nil
|
|
212
|
-
if let threshold = configuration.nativeLongTaskThresholdMs as? TimeInterval {
|
|
213
|
-
if (threshold != 0) {
|
|
214
|
-
// `nativeLongTaskThresholdMs` attribute is in milliseconds
|
|
215
|
-
longTaskThreshold = threshold / 1_000
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
var uiKitViewsPredicate: UIKitRUMViewsPredicate? = nil
|
|
220
|
-
if let enableViewTracking = configuration.additionalConfig?[InternalConfigurationAttributes.nativeViewTracking] as? Bool, enableViewTracking {
|
|
221
|
-
uiKitViewsPredicate = DefaultUIKitRUMViewsPredicate()
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
var uiKitActionsPredicate: UIKitRUMActionsPredicate? = nil
|
|
225
|
-
if let enableInteractionTracking = configuration.additionalConfig?[InternalConfigurationAttributes.nativeInteractionTracking] as? Bool, enableInteractionTracking {
|
|
226
|
-
uiKitActionsPredicate = DefaultUIKitRUMActionsPredicate()
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
var urlSessionTracking: RUM.Configuration.URLSessionTracking? = nil
|
|
230
|
-
if let firstPartyHosts = configuration.additionalConfig?[InternalConfigurationAttributes.firstPartyHosts] as? NSArray {
|
|
231
|
-
// We will always fall under this condition as firstPartyHosts is an empty array by default
|
|
232
|
-
urlSessionTracking = RUM.Configuration.URLSessionTracking(
|
|
233
|
-
firstPartyHostsTracing: .traceWithHeaders(
|
|
234
|
-
hostsWithHeaders: firstPartyHosts.asFirstPartyHosts(),
|
|
235
|
-
sampleRate: 100.0
|
|
236
|
-
)
|
|
237
|
-
)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
var customRUMEndpointURL: URL? = nil
|
|
241
|
-
if let customRUMEndpoint = configuration.customEndpoints?.rum as? NSString {
|
|
242
|
-
if (customRUMEndpoint != "") {
|
|
243
|
-
customRUMEndpointURL = URL(string: "\(customRUMEndpoint)/api/v2/rum" as String)
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return RUM.Configuration(
|
|
248
|
-
applicationID: configuration.applicationId,
|
|
249
|
-
sessionSampleRate: (configuration.sampleRate as? NSNumber)?.floatValue ?? 100.0,
|
|
250
|
-
uiKitViewsPredicate: uiKitViewsPredicate,
|
|
251
|
-
uiKitActionsPredicate: uiKitActionsPredicate,
|
|
252
|
-
urlSessionTracking: urlSessionTracking,
|
|
253
|
-
trackFrustrations: configuration.trackFrustrations ?? true,
|
|
254
|
-
trackBackgroundEvents: configuration.trackBackgroundEvents ?? false,
|
|
255
|
-
longTaskThreshold: longTaskThreshold,
|
|
256
|
-
vitalsUpdateFrequency: buildVitalsUpdateFrequency(frequency: configuration.vitalsUpdateFrequency),
|
|
257
|
-
resourceEventMapper: { resourceEvent in
|
|
258
|
-
if resourceEvent.context?.contextInfo[InternalConfigurationAttributes.dropResource] != nil {
|
|
259
|
-
return nil
|
|
260
|
-
}
|
|
261
|
-
return resourceEvent
|
|
262
|
-
},
|
|
263
|
-
actionEventMapper: { actionEvent in
|
|
264
|
-
if actionEvent.context?.contextInfo[InternalConfigurationAttributes.dropResource] != nil {
|
|
265
|
-
return nil
|
|
266
|
-
}
|
|
267
|
-
return actionEvent
|
|
268
|
-
},
|
|
269
|
-
customEndpoint: customRUMEndpointURL,
|
|
270
|
-
telemetrySampleRate: (configuration.telemetrySampleRate as? NSNumber)?.floatValue ?? 20.0
|
|
271
|
-
)
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
func buildLogsConfiguration(configuration: DdSdkConfiguration) -> Logs.Configuration {
|
|
275
|
-
var customLogsEndpointURL: URL? = nil
|
|
276
|
-
if let customLogsEndpoint = configuration.customEndpoints?.logs as? NSString {
|
|
277
|
-
if (customLogsEndpoint != "") {
|
|
278
|
-
customLogsEndpointURL = URL(string: "\(customLogsEndpoint)/api/v2/logs" as String)
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return Logs.Configuration(customEndpoint: customLogsEndpointURL)
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
func buildTraceConfiguration(configuration: DdSdkConfiguration) -> Trace.Configuration {
|
|
287
|
-
var customTraceEndpointURL: URL? = nil
|
|
288
|
-
if let customTraceEndpoint = configuration.customEndpoints?.trace as? NSString {
|
|
289
|
-
if (customTraceEndpoint != "") {
|
|
290
|
-
customTraceEndpointURL = URL(string: "\(customTraceEndpoint)/api/v2/spans" as String)
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return Trace.Configuration(customEndpoint: customTraceEndpointURL)
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
func buildProxyConfiguration(config: NSDictionary?) -> [AnyHashable: Any]? {
|
|
298
|
-
guard let address = config?[ProxyAttributes.address] as? String else {
|
|
299
|
-
return nil
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
var proxy: [AnyHashable: Any] = [:]
|
|
303
|
-
proxy[kCFProxyUsernameKey] = config?[ProxyAttributes.username]
|
|
304
|
-
proxy[kCFProxyPasswordKey] = config?[ProxyAttributes.password]
|
|
305
|
-
|
|
306
|
-
let type = config?[ProxyAttributes.type] as? String
|
|
307
|
-
var port = config?[ProxyAttributes.port] as? Int
|
|
308
|
-
if let string = config?[ProxyAttributes.port] as? String {
|
|
309
|
-
port = Int(string)
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
switch type {
|
|
313
|
-
case "http", "https":
|
|
314
|
-
// CFNetwork support HTTP and tunneling HTTPS proxies.
|
|
315
|
-
// As intakes will most likely be https, we enable both channels.
|
|
316
|
-
//
|
|
317
|
-
// We use constants string keys because there is an issue with
|
|
318
|
-
// cross-platform availability for proxy configuration symbols.
|
|
319
|
-
// see. https://developer.apple.com/forums/thread/19356?answerId=131709022#131709022
|
|
320
|
-
proxy["HTTPEnable"] = 1
|
|
321
|
-
proxy["HTTPProxy"] = address
|
|
322
|
-
proxy["HTTPPort"] = port
|
|
323
|
-
proxy["HTTPSEnable"] = 1
|
|
324
|
-
proxy["HTTPSProxy"] = address
|
|
325
|
-
proxy["HTTPSPort"] = port
|
|
326
|
-
case "socks":
|
|
327
|
-
proxy["SOCKSEnable"] = 1
|
|
328
|
-
proxy["SOCKSProxy"] = address
|
|
329
|
-
proxy["SOCKSPort"] = port
|
|
330
|
-
default:
|
|
331
|
-
break
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
return proxy
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
func buildTrackingConsent(consent: NSString?) -> TrackingConsent {
|
|
338
|
-
let trackingConsent: TrackingConsent
|
|
339
|
-
switch consent?.lowercased {
|
|
340
|
-
case "pending":
|
|
341
|
-
trackingConsent = .pending
|
|
342
|
-
case "granted":
|
|
343
|
-
trackingConsent = .granted
|
|
344
|
-
case "not_granted":
|
|
345
|
-
trackingConsent = .notGranted
|
|
346
|
-
default:
|
|
347
|
-
trackingConsent = .pending
|
|
348
|
-
}
|
|
349
|
-
return trackingConsent
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
func buildVitalsUpdateFrequency(frequency: NSString?) -> RUM.Configuration.VitalsFrequency? {
|
|
353
|
-
switch frequency?.lowercased {
|
|
354
|
-
case "never":
|
|
355
|
-
return nil
|
|
356
|
-
case "rare":
|
|
357
|
-
return .rare
|
|
358
|
-
case "average":
|
|
359
|
-
return .average
|
|
360
|
-
case "frequent":
|
|
361
|
-
return .frequent
|
|
362
|
-
default:
|
|
363
|
-
return .average
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
func buildUploadFrequency(frequency: NSString?) -> Datadog.Configuration.UploadFrequency {
|
|
368
|
-
let uploadFrequency: Datadog.Configuration.UploadFrequency
|
|
369
|
-
switch frequency?.lowercased {
|
|
370
|
-
case "rare":
|
|
371
|
-
uploadFrequency = .rare
|
|
372
|
-
case "average":
|
|
373
|
-
uploadFrequency = .average
|
|
374
|
-
case "frequent":
|
|
375
|
-
uploadFrequency = .frequent
|
|
376
|
-
default:
|
|
377
|
-
uploadFrequency = .average
|
|
378
|
-
}
|
|
379
|
-
return uploadFrequency
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
func buildBatchSize(batchSize: NSString?) -> Datadog.Configuration.BatchSize {
|
|
383
|
-
let size: Datadog.Configuration.BatchSize
|
|
384
|
-
switch batchSize?.lowercased {
|
|
385
|
-
case "small":
|
|
386
|
-
size = .small
|
|
387
|
-
case "medium":
|
|
388
|
-
size = .medium
|
|
389
|
-
case "large":
|
|
390
|
-
size = .large
|
|
391
|
-
default:
|
|
392
|
-
size = .medium
|
|
393
|
-
}
|
|
394
|
-
return size
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
func setVerbosityLevel(additionalConfig: NSDictionary?) {
|
|
398
|
-
let verbosityLevel = (additionalConfig?[InternalConfigurationAttributes.sdkVerbosity]) as? NSString
|
|
399
|
-
switch verbosityLevel?.lowercased {
|
|
400
|
-
case "debug":
|
|
401
|
-
Datadog.verbosityLevel = .debug
|
|
402
|
-
case "info":
|
|
403
|
-
// .info is mapped to .debug
|
|
404
|
-
Datadog.verbosityLevel = .debug
|
|
405
|
-
case "warn":
|
|
406
|
-
Datadog.verbosityLevel = .warn
|
|
407
|
-
case "error":
|
|
408
|
-
Datadog.verbosityLevel = .error
|
|
409
|
-
default:
|
|
410
|
-
Datadog.verbosityLevel = nil
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
145
|
func startJSRefreshRateMonitoring(sdkConfiguration: DdSdkConfiguration) {
|
|
415
146
|
if let frameTimeCallback = buildFrameTimeCallback(sdkConfiguration: sdkConfiguration) {
|
|
416
147
|
// Falling back to mainDispatchQueue if bridge is nil is only useful for tests
|
|
@@ -419,7 +150,7 @@ public class DdSdkImplementation: NSObject {
|
|
|
419
150
|
}
|
|
420
151
|
|
|
421
152
|
func buildFrameTimeCallback(sdkConfiguration: DdSdkConfiguration)-> ((Double) -> ())? {
|
|
422
|
-
let jsRefreshRateMonitoringEnabled =
|
|
153
|
+
let jsRefreshRateMonitoringEnabled = sdkConfiguration.vitalsUpdateFrequency != nil
|
|
423
154
|
let jsLongTaskMonitoringEnabled = sdkConfiguration.longTaskThresholdMs != 0
|
|
424
155
|
|
|
425
156
|
if (!jsRefreshRateMonitoringEnabled && !jsLongTaskMonitoringEnabled) {
|
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
import DatadogCore
|
|
9
|
+
import DatadogRUM
|
|
10
|
+
import DatadogLogs
|
|
11
|
+
import DatadogTrace
|
|
12
|
+
import DatadogCrashReporting
|
|
13
|
+
import DatadogWebViewTracking
|
|
14
|
+
import DatadogInternal
|
|
15
|
+
import React
|
|
16
|
+
|
|
17
|
+
@objc
|
|
18
|
+
public class DdSdkNativeInitialization: NSObject {
|
|
19
|
+
let jsonFileReader: ResourceFileReader
|
|
20
|
+
|
|
21
|
+
@objc
|
|
22
|
+
public convenience override init() {
|
|
23
|
+
self.init(jsonFileReader: JSONFileReader())
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
init(
|
|
27
|
+
jsonFileReader: ResourceFileReader
|
|
28
|
+
) {
|
|
29
|
+
self.jsonFileReader = jsonFileReader
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
internal func initialize(sdkConfiguration: DdSdkConfiguration) {
|
|
33
|
+
// TODO: see if this `if` is still needed
|
|
34
|
+
if DatadogSDKWrapper.shared.isInitialized() {
|
|
35
|
+
// Initializing the SDK twice results in Global.rum and
|
|
36
|
+
// Global.sharedTracer to be set to no-op instances
|
|
37
|
+
consolePrint("Datadog SDK is already initialized, skipping initialization.", .debug)
|
|
38
|
+
DatadogSDKWrapper.shared.telemetryDebug(id: "datadog_react_native: RN SDK was already initialized in native", message: "RN SDK was already initialized in native")
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
self.setVerbosityLevel(configuration: sdkConfiguration)
|
|
42
|
+
|
|
43
|
+
let coreConfiguration = self.buildSDKConfiguration(configuration: sdkConfiguration)
|
|
44
|
+
DatadogSDKWrapper.shared.initialize(
|
|
45
|
+
coreConfiguration: coreConfiguration,
|
|
46
|
+
loggerConfiguration: DatadogLogs.Logger.Configuration(sdkConfiguration),
|
|
47
|
+
trackingConsent: sdkConfiguration.trackingConsent
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
self.enableFeatures(sdkConfiguration: sdkConfiguration)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
internal func getConfigurationFromJSONFile() -> DdSdkConfiguration? {
|
|
54
|
+
if let jsonResult = jsonFileReader.parseResourceFile(resourcePath: "datadog-configuration") as? Dictionary<String, AnyObject> {
|
|
55
|
+
do {
|
|
56
|
+
return try jsonResult.asDdSdkConfigurationFromJSON()
|
|
57
|
+
} catch {
|
|
58
|
+
consolePrint("Error parsing datadog-configuration.json file: \(error)", .critical)
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
consolePrint("datadog-configuration.json file cannot be parsed. Make sure it is valid.", .critical)
|
|
62
|
+
}
|
|
63
|
+
return nil
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@objc
|
|
67
|
+
public func initializeFromNative() -> Void {
|
|
68
|
+
if let configuration = getConfigurationFromJSONFile() {
|
|
69
|
+
self.initialize(sdkConfiguration: configuration)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
func enableFeatures(sdkConfiguration: DdSdkConfiguration) {
|
|
74
|
+
let rumConfig = buildRUMConfiguration(configuration: sdkConfiguration)
|
|
75
|
+
DatadogSDKWrapper.shared.enableRUM(with: rumConfig)
|
|
76
|
+
|
|
77
|
+
let logsConfig = buildLogsConfiguration(configuration: sdkConfiguration)
|
|
78
|
+
DatadogSDKWrapper.shared.enableLogs(with: logsConfig)
|
|
79
|
+
|
|
80
|
+
let traceConfig = buildTraceConfiguration(configuration: sdkConfiguration)
|
|
81
|
+
DatadogSDKWrapper.shared.enableTrace(with: traceConfig)
|
|
82
|
+
|
|
83
|
+
if sdkConfiguration.nativeCrashReportEnabled ?? false {
|
|
84
|
+
DatadogSDKWrapper.shared.enableCrashReporting()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
DatadogSDKWrapper.shared.enableWebviewTracking()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
func buildSDKConfiguration(configuration: DdSdkConfiguration, defaultAppVersion: String = getDefaultAppVersion()) -> Datadog.Configuration {
|
|
91
|
+
var config = Datadog.Configuration(
|
|
92
|
+
clientToken: configuration.clientToken,
|
|
93
|
+
env: configuration.env,
|
|
94
|
+
site: configuration.site,
|
|
95
|
+
service: configuration.serviceName as? String,
|
|
96
|
+
batchSize: configuration.batchSize,
|
|
97
|
+
uploadFrequency: configuration.uploadFrequency,
|
|
98
|
+
proxyConfiguration: configuration.proxyConfig
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
if var additionalConfiguration = configuration.additionalConfig as? [String: Any] {
|
|
102
|
+
if let versionSuffix = additionalConfiguration[InternalConfigurationAttributes.versionSuffix] as? String {
|
|
103
|
+
let datadogVersion = defaultAppVersion + versionSuffix
|
|
104
|
+
additionalConfiguration[CrossPlatformAttributes.version] = datadogVersion
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
config._internal_mutation {
|
|
108
|
+
$0.additionalConfiguration = additionalConfiguration
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return config
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
func buildRUMConfiguration(configuration: DdSdkConfiguration) -> RUM.Configuration {
|
|
116
|
+
var longTaskThreshold: TimeInterval? = nil
|
|
117
|
+
if let threshold = configuration.nativeLongTaskThresholdMs {
|
|
118
|
+
if (threshold != 0) {
|
|
119
|
+
// `nativeLongTaskThresholdMs` attribute is in milliseconds
|
|
120
|
+
longTaskThreshold = threshold / 1_000
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
var uiKitViewsPredicate: UIKitRUMViewsPredicate? = nil
|
|
125
|
+
if let enableViewTracking = configuration.nativeViewTracking, enableViewTracking {
|
|
126
|
+
uiKitViewsPredicate = DefaultUIKitRUMViewsPredicate()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
var uiKitActionsPredicate: UIKitRUMActionsPredicate? = nil
|
|
130
|
+
if let enableInteractionTracking = configuration.nativeInteractionTracking, enableInteractionTracking {
|
|
131
|
+
uiKitActionsPredicate = DefaultUIKitRUMActionsPredicate()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
var urlSessionTracking: RUM.Configuration.URLSessionTracking? = nil
|
|
135
|
+
if let firstPartyHosts = configuration.firstPartyHosts {
|
|
136
|
+
// This is applied to make sure we also add headers to requests made on the native side.
|
|
137
|
+
// The sampling rate here does not impact the sampling rate for JS requests.
|
|
138
|
+
urlSessionTracking = RUM.Configuration.URLSessionTracking(
|
|
139
|
+
firstPartyHostsTracing: .traceWithHeaders(
|
|
140
|
+
hostsWithHeaders: firstPartyHosts,
|
|
141
|
+
sampleRate: (configuration.resourceTracingSamplingRate as? NSNumber)?.floatValue ?? Float(DefaultConfiguration.resourceTracingSamplingRate)
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
var customRUMEndpointURL: URL? = nil
|
|
147
|
+
if let customRUMEndpoint = configuration.customEndpoints?.rum as? NSString {
|
|
148
|
+
if (customRUMEndpoint != "") {
|
|
149
|
+
customRUMEndpointURL = URL(string: "\(customRUMEndpoint)/api/v2/rum" as String)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return RUM.Configuration(
|
|
154
|
+
applicationID: configuration.applicationId,
|
|
155
|
+
sessionSampleRate: (configuration.sampleRate as? NSNumber)?.floatValue ?? Float(DefaultConfiguration.sessionSamplingRate),
|
|
156
|
+
uiKitViewsPredicate: uiKitViewsPredicate,
|
|
157
|
+
uiKitActionsPredicate: uiKitActionsPredicate,
|
|
158
|
+
urlSessionTracking: urlSessionTracking,
|
|
159
|
+
trackFrustrations: configuration.trackFrustrations ?? true,
|
|
160
|
+
trackBackgroundEvents: configuration.trackBackgroundEvents ?? false,
|
|
161
|
+
longTaskThreshold: longTaskThreshold,
|
|
162
|
+
vitalsUpdateFrequency: configuration.vitalsUpdateFrequency,
|
|
163
|
+
resourceEventMapper: { resourceEvent in
|
|
164
|
+
if resourceEvent.context?.contextInfo[InternalConfigurationAttributes.dropResource] != nil {
|
|
165
|
+
return nil
|
|
166
|
+
}
|
|
167
|
+
return resourceEvent
|
|
168
|
+
},
|
|
169
|
+
actionEventMapper: { actionEvent in
|
|
170
|
+
if actionEvent.context?.contextInfo[InternalConfigurationAttributes.dropResource] != nil {
|
|
171
|
+
return nil
|
|
172
|
+
}
|
|
173
|
+
return actionEvent
|
|
174
|
+
},
|
|
175
|
+
customEndpoint: customRUMEndpointURL,
|
|
176
|
+
telemetrySampleRate: (configuration.telemetrySampleRate as? NSNumber)?.floatValue ?? Float(DefaultConfiguration.telemetrySampleRate)
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
func buildLogsConfiguration(configuration: DdSdkConfiguration) -> Logs.Configuration {
|
|
181
|
+
var customLogsEndpointURL: URL? = nil
|
|
182
|
+
if let customLogsEndpoint = configuration.customEndpoints?.logs as? NSString {
|
|
183
|
+
if (customLogsEndpoint != "") {
|
|
184
|
+
customLogsEndpointURL = URL(string: "\(customLogsEndpoint)/api/v2/logs" as String)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return Logs.Configuration(customEndpoint: customLogsEndpointURL)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
func buildTraceConfiguration(configuration: DdSdkConfiguration) -> Trace.Configuration {
|
|
193
|
+
var customTraceEndpointURL: URL? = nil
|
|
194
|
+
if let customTraceEndpoint = configuration.customEndpoints?.trace as? NSString {
|
|
195
|
+
if (customTraceEndpoint != "") {
|
|
196
|
+
customTraceEndpointURL = URL(string: "\(customTraceEndpoint)/api/v2/spans" as String)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return Trace.Configuration(customEndpoint: customTraceEndpointURL)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
func setVerbosityLevel(configuration: DdSdkConfiguration) {
|
|
204
|
+
switch configuration.verbosity?.lowercased {
|
|
205
|
+
case "debug":
|
|
206
|
+
Datadog.verbosityLevel = .debug
|
|
207
|
+
case "info":
|
|
208
|
+
// .info is mapped to .debug
|
|
209
|
+
Datadog.verbosityLevel = .debug
|
|
210
|
+
case "warn":
|
|
211
|
+
Datadog.verbosityLevel = .warn
|
|
212
|
+
case "error":
|
|
213
|
+
Datadog.verbosityLevel = .error
|
|
214
|
+
default:
|
|
215
|
+
Datadog.verbosityLevel = nil
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -29,12 +29,14 @@ public class DdTraceImplementation: NSObject {
|
|
|
29
29
|
let startDate = Date(timeIntervalSince1970: timeIntervalSince1970)
|
|
30
30
|
|
|
31
31
|
objc_sync_enter(self)
|
|
32
|
-
|
|
32
|
+
let span = tracer.startSpan(
|
|
33
33
|
operationName: operation,
|
|
34
34
|
childOf: nil,
|
|
35
35
|
tags: castAttributesToSwift(context).mergeWithGlobalAttributes(),
|
|
36
36
|
startTime: startDate
|
|
37
37
|
)
|
|
38
|
+
span.setActive()
|
|
39
|
+
spanDictionary[id] = span
|
|
38
40
|
objc_sync_exit(self)
|
|
39
41
|
|
|
40
42
|
resolve(id)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
3
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
-
* Copyright 2019-
|
|
4
|
+
* Copyright 2019-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import Foundation
|
|
@@ -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 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import Foundation
|
|
8
|
+
import DatadogInternal
|
|
9
|
+
|
|
10
|
+
public class JSONFileReader: ResourceFileReader {
|
|
11
|
+
public func parseResourceFile(resourcePath: String) -> Any? {
|
|
12
|
+
if let path = Bundle.main.path(forResource: resourcePath, ofType: "json") {
|
|
13
|
+
do {
|
|
14
|
+
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
|
|
15
|
+
return try JSONSerialization.jsonObject(with: data, options: .mutableLeaves)
|
|
16
|
+
} catch {
|
|
17
|
+
consolePrint("Error parsing \(resourcePath).json file: \(error)", .critical)
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
consolePrint("\(resourcePath).json file has not been added as Xcode resource.", .critical)
|
|
21
|
+
}
|
|
22
|
+
return nil
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public protocol ResourceFileReader {
|
|
27
|
+
func parseResourceFile(resourcePath: String) -> Any?
|
|
28
|
+
}
|