@datadog/mobile-react-native 3.0.3 → 3.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 (93) hide show
  1. package/DatadogSDKReactNative.podspec +10 -9
  2. package/android/build.gradle +10 -8
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdFlagsImplementation.kt +237 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkBridgeExt.kt +262 -78
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +3 -3
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +18 -18
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +3 -2
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkReactNativePackage.kt +3 -1
  9. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  10. package/android/src/newarch/kotlin/com/datadog/reactnative/DdFlags.kt +66 -0
  11. package/android/src/oldarch/kotlin/com/datadog/reactnative/DdFlags.kt +63 -0
  12. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkBridgeExtTest.kt +242 -0
  13. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +4 -2
  14. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +6 -3
  15. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +3 -4
  16. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +38 -0
  17. package/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +3 -0
  18. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +1 -1
  19. package/android/src/test/resources/input/complete-configuration.json +10 -10
  20. package/ios/Sources/DatadogSDKReactNative.h +2 -0
  21. package/ios/Sources/DdFlags.h +24 -0
  22. package/ios/Sources/DdFlags.mm +83 -0
  23. package/ios/Sources/DdFlagsImplementation.swift +263 -0
  24. package/ios/Sources/DdSdkConfiguration.swift +4 -4
  25. package/ios/Sources/DdSdkNativeInitialization.swift +2 -2
  26. package/ios/Sources/RNDdSdkConfiguration.swift +11 -9
  27. package/ios/Sources/SdkVersion.swift +1 -1
  28. package/lib/commonjs/InternalLog.js +9 -7
  29. package/lib/commonjs/InternalLog.js.map +1 -1
  30. package/lib/commonjs/flags/DdFlags.js +51 -0
  31. package/lib/commonjs/flags/DdFlags.js.map +1 -0
  32. package/lib/commonjs/flags/FlagsClient.js +218 -0
  33. package/lib/commonjs/flags/FlagsClient.js.map +1 -0
  34. package/lib/commonjs/flags/internal.js +40 -0
  35. package/lib/commonjs/flags/internal.js.map +1 -0
  36. package/lib/commonjs/flags/types.js +6 -0
  37. package/lib/commonjs/flags/types.js.map +1 -0
  38. package/lib/commonjs/index.js +7 -0
  39. package/lib/commonjs/index.js.map +1 -1
  40. package/lib/commonjs/sdk/DatadogProvider/Buffer/BufferSingleton.js +10 -8
  41. package/lib/commonjs/sdk/DatadogProvider/Buffer/BufferSingleton.js.map +1 -1
  42. package/lib/commonjs/specs/NativeDdFlags.js +19 -0
  43. package/lib/commonjs/specs/NativeDdFlags.js.map +1 -0
  44. package/lib/commonjs/version.js +1 -1
  45. package/lib/module/InternalLog.js +9 -6
  46. package/lib/module/InternalLog.js.map +1 -1
  47. package/lib/module/flags/DdFlags.js +45 -0
  48. package/lib/module/flags/DdFlags.js.map +1 -0
  49. package/lib/module/flags/FlagsClient.js +211 -0
  50. package/lib/module/flags/FlagsClient.js.map +1 -0
  51. package/lib/module/flags/internal.js +33 -0
  52. package/lib/module/flags/internal.js.map +1 -0
  53. package/lib/module/flags/types.js +2 -0
  54. package/lib/module/flags/types.js.map +1 -0
  55. package/lib/module/index.js +2 -1
  56. package/lib/module/index.js.map +1 -1
  57. package/lib/module/sdk/DatadogProvider/Buffer/BufferSingleton.js +10 -7
  58. package/lib/module/sdk/DatadogProvider/Buffer/BufferSingleton.js.map +1 -1
  59. package/lib/module/specs/NativeDdFlags.js +17 -0
  60. package/lib/module/specs/NativeDdFlags.js.map +1 -0
  61. package/lib/module/version.js +1 -1
  62. package/lib/typescript/InternalLog.d.ts +6 -4
  63. package/lib/typescript/InternalLog.d.ts.map +1 -1
  64. package/lib/typescript/flags/DdFlags.d.ts +3 -0
  65. package/lib/typescript/flags/DdFlags.d.ts.map +1 -0
  66. package/lib/typescript/flags/FlagsClient.d.ts +114 -0
  67. package/lib/typescript/flags/FlagsClient.d.ts.map +1 -0
  68. package/lib/typescript/flags/internal.d.ts +14 -0
  69. package/lib/typescript/flags/internal.d.ts.map +1 -0
  70. package/lib/typescript/flags/types.d.ts +202 -0
  71. package/lib/typescript/flags/types.d.ts.map +1 -0
  72. package/lib/typescript/index.d.ts +5 -2
  73. package/lib/typescript/index.d.ts.map +1 -1
  74. package/lib/typescript/nativeModulesTypes.d.ts +5 -0
  75. package/lib/typescript/nativeModulesTypes.d.ts.map +1 -1
  76. package/lib/typescript/sdk/DatadogProvider/Buffer/BufferSingleton.d.ts +7 -5
  77. package/lib/typescript/sdk/DatadogProvider/Buffer/BufferSingleton.d.ts.map +1 -1
  78. package/lib/typescript/specs/NativeDdFlags.d.ts +15 -0
  79. package/lib/typescript/specs/NativeDdFlags.d.ts.map +1 -0
  80. package/lib/typescript/version.d.ts +1 -1
  81. package/package.json +2 -2
  82. package/src/InternalLog.tsx +14 -6
  83. package/src/flags/DdFlags.ts +59 -0
  84. package/src/flags/FlagsClient.ts +266 -0
  85. package/src/flags/__tests__/DdFlags.test.ts +65 -0
  86. package/src/flags/__tests__/FlagsClient.test.ts +320 -0
  87. package/src/flags/internal.ts +63 -0
  88. package/src/flags/types.ts +215 -0
  89. package/src/index.tsx +15 -1
  90. package/src/nativeModulesTypes.ts +6 -0
  91. package/src/sdk/DatadogProvider/Buffer/BufferSingleton.ts +16 -7
  92. package/src/specs/NativeDdFlags.ts +35 -0
  93. package/src/version.ts +1 -1
@@ -0,0 +1,83 @@
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 this first to prevent require cycles
8
+ #if __has_include("DatadogSDKReactNative-Swift.h")
9
+ #import <DatadogSDKReactNative-Swift.h>
10
+ #else
11
+ #import <DatadogSDKReactNative/DatadogSDKReactNative-Swift.h>
12
+ #endif
13
+ #import "DdFlags.h"
14
+
15
+
16
+ @implementation DdFlags
17
+
18
+ RCT_EXPORT_MODULE()
19
+
20
+ RCT_EXPORT_METHOD(enable:(NSDictionary *)configuration
21
+ withResolver:(RCTPromiseResolveBlock)resolve
22
+ withRejecter:(RCTPromiseRejectBlock)reject)
23
+ {
24
+ [self enable:configuration resolve:resolve reject:reject];
25
+ }
26
+
27
+ RCT_EXPORT_METHOD(setEvaluationContext:(NSString *)clientName
28
+ targetingKey:(NSString *)targetingKey
29
+ attributes:(NSDictionary *)attributes
30
+ withResolver:(RCTPromiseResolveBlock)resolve
31
+ withRejecter:(RCTPromiseRejectBlock)reject)
32
+ {
33
+ [self setEvaluationContext:clientName targetingKey:targetingKey attributes:attributes resolve:resolve reject:reject];
34
+ }
35
+
36
+ RCT_EXPORT_METHOD(trackEvaluation:(NSString *)clientName
37
+ withKey:(NSString *)key
38
+ withRawFlag:(NSDictionary *)rawFlag
39
+ targetingKey:(NSString *)targetingKey
40
+ attributes:(NSDictionary *)attributes
41
+ withResolver:(RCTPromiseResolveBlock)resolve
42
+ withRejecter:(RCTPromiseRejectBlock)reject)
43
+ {
44
+ [self trackEvaluation:clientName key:key rawFlag:rawFlag targetingKey:targetingKey attributes:attributes resolve:resolve reject:reject];
45
+ }
46
+
47
+ // Thanks to this guard, we won't compile this code when we build for the new architecture.
48
+ #ifdef RCT_NEW_ARCH_ENABLED
49
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
50
+ (const facebook::react::ObjCTurboModule::InitParams &)params
51
+ {
52
+ return std::make_shared<facebook::react::NativeDdFlagsSpecJSI>(params);
53
+ }
54
+ #endif
55
+
56
+ - (DdFlagsImplementation*)ddFlagsImplementation
57
+ {
58
+ if (_ddFlagsImplementation == nil) {
59
+ _ddFlagsImplementation = [[DdFlagsImplementation alloc] init];
60
+ }
61
+ return _ddFlagsImplementation;
62
+ }
63
+
64
+ + (BOOL)requiresMainQueueSetup {
65
+ return NO;
66
+ }
67
+
68
+ - (dispatch_queue_t)methodQueue {
69
+ return [RNQueue getSharedQueue];
70
+ }
71
+
72
+ - (void)enable:(NSDictionary *)configuration resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
73
+ [self.ddFlagsImplementation enable:configuration resolve:resolve reject:reject];
74
+ }
75
+
76
+ - (void)setEvaluationContext:(NSString *)clientName targetingKey:(NSString *)targetingKey attributes:(NSDictionary *)attributes resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
77
+ [self.ddFlagsImplementation setEvaluationContext:clientName targetingKey:targetingKey attributes:attributes resolve:resolve reject:reject];
78
+ }
79
+
80
+ - (void)trackEvaluation:(NSString *)clientName key:(NSString *)key rawFlag:(NSDictionary *)rawFlag targetingKey:(NSString *)targetingKey attributes:(NSDictionary *)attributes resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
81
+ [self.ddFlagsImplementation trackEvaluation:clientName key:key rawFlag:rawFlag targetingKey:targetingKey attributes:attributes resolve:resolve reject:reject];
82
+ }
83
+ @end
@@ -0,0 +1,263 @@
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
+ @_spi(Internal)
10
+ import DatadogFlags
11
+
12
+ @objc
13
+ public class DdFlagsImplementation: NSObject {
14
+ private let core: DatadogCoreProtocol
15
+
16
+ internal var clientProviders: [String: () -> FlagsClientProtocol] = [:]
17
+
18
+ /// Exposing this initializer for testing purposes. React Native will always use the default initializer.
19
+ internal init(core: DatadogCoreProtocol) {
20
+ self.core = core
21
+ }
22
+
23
+ @objc
24
+ public override convenience init() {
25
+ self.init(core: CoreRegistry.default)
26
+ }
27
+
28
+ @objc
29
+ public func enable(_ configuration: NSDictionary, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
30
+ // Client providers become stale upon subsequent enable calls (which can happen e.g. in case of a React Native hot reload).
31
+ clientProviders.removeAll()
32
+
33
+ if let config = configuration.asFlagsConfiguration() {
34
+ Flags.enable(with: config)
35
+ } else {
36
+ consolePrint("Invalid configuration provided for Flags. Feature initialization skipped.", .error)
37
+ }
38
+
39
+ resolve(nil)
40
+ }
41
+
42
+ /// Retrieve a `FlagsClient` instance in a non-interruptive way for usage in methods bridged to React Native.
43
+ ///
44
+ /// We create a simple registry of client providers by client name holding closures for retrieving a client since client references are kept internally in the flagging SDK.
45
+ /// This is motivated by the fact that it is impossible to create a bridged synchronous `FlagsClient` creation; thus, we create a client instance dynamically on-demand.
46
+ private func getClient(name: String) -> FlagsClientProtocol {
47
+ if let provider = clientProviders[name] {
48
+ return provider()
49
+ }
50
+
51
+ let client = FlagsClient.create(name: name, in: self.core)
52
+ clientProviders[name] = { FlagsClient.shared(named: name, in: self.core) }
53
+ return client
54
+ }
55
+
56
+ // Using @escaping RCTPromiseResolveBlock type will result in an issue when compiling the Swift header file.
57
+ @objc
58
+ public func setEvaluationContext(_ clientName: String, targetingKey: String, attributes: NSDictionary, resolve: @escaping ((Any?) -> Void), reject: @escaping ((String?, String?, NSError?) -> Void)) {
59
+ let client = getClient(name: clientName)
60
+ guard let clientInternal = client as? FlagsClientInternal else {
61
+ reject("CLIENT_NOT_INITIALIZED", "Flags client '\(clientName)' is not properly initialized. Make sure the Datadog SDK has been initialized and Flags.enable() has been called.", nil)
62
+ return
63
+ }
64
+
65
+ let evaluationContext = buildEvaluationContext(targetingKey: targetingKey, attributes: attributes)
66
+
67
+ client.setEvaluationContext(evaluationContext) { result in
68
+ switch result {
69
+ case .success:
70
+ guard let flagsSnapshot = clientInternal.getFlagAssignments() else {
71
+ reject("CLIENT_NOT_INITIALIZED", "Failed to retrieve feature flags for client '\(clientName)'. Make sure the client has been properly initialized.", nil)
72
+ return
73
+ }
74
+
75
+ let serializedFlagsSnapshot = Dictionary(
76
+ uniqueKeysWithValues: flagsSnapshot.map { key, flagAssignment in
77
+ (key, flagAssignment.asDictionary(flagKey: key))
78
+ }
79
+ )
80
+
81
+ resolve(serializedFlagsSnapshot)
82
+ case .failure(let error):
83
+ var errorCode: String
84
+ var errorMessage: String
85
+ switch (error) {
86
+ case .clientNotInitialized:
87
+ errorCode = "CLIENT_NOT_INITIALIZED"
88
+ errorMessage = "Failed to retrieve feature flags for client '\(clientName)'. Make sure the client has been properly initialized."
89
+ case .invalidConfiguration:
90
+ errorCode = "INVALID_CONFIGURATION"
91
+ errorMessage = "The flags configuration for client '\(clientName)' is invalid. Check that all required parameters are provided."
92
+ case .invalidResponse:
93
+ errorCode = "INVALID_RESPONSE"
94
+ errorMessage = "The flags service returned an invalid response for client '\(clientName)'."
95
+ case .networkError:
96
+ errorCode = "NETWORK_ERROR"
97
+ errorMessage = "A network error occurred while fetching feature flags for client '\(clientName)'."
98
+ }
99
+ reject(errorCode, errorMessage, error as NSError)
100
+ }
101
+ }
102
+ }
103
+
104
+ @objc
105
+ public func trackEvaluation(_ clientName: String, key: String, rawFlag: NSDictionary, targetingKey: String, attributes: NSDictionary, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
106
+ guard let client = getClient(name: clientName) as? FlagsClientInternal else {
107
+ reject("CLIENT_NOT_INITIALIZED", "Flags client '\(clientName)' is not properly initialized. Make sure the Datadog SDK has been initialized and Flags.enable() has been called.", nil)
108
+ return
109
+ }
110
+ guard let flagAssignment = rawFlag.asFlagAssignment() else {
111
+ reject("INVALID_FLAG_ASSIGNMENT", "Failed to parse correct flag assignment from the provided raw flag data.", nil)
112
+ return
113
+ }
114
+
115
+ let evaluationContext = buildEvaluationContext(targetingKey: targetingKey, attributes: attributes)
116
+
117
+ client.sendFlagEvaluation(key: key, assignment: flagAssignment, context: evaluationContext)
118
+
119
+ resolve(nil)
120
+ }
121
+
122
+ /// Construct an `FlagsEvaluationContext` from a targeting key and a dictionary of attributes.
123
+ private func buildEvaluationContext(targetingKey: String, attributes: NSDictionary) -> FlagsEvaluationContext {
124
+ let dict = attributes as? [String: Any] ?? [:]
125
+
126
+ let parsedAttributes = dict.compactMapValues { value in AnyValue.wrap(value) }
127
+
128
+ return FlagsEvaluationContext(targetingKey: targetingKey, attributes: parsedAttributes)
129
+ }
130
+ }
131
+
132
+ extension NSDictionary {
133
+ func asFlagsConfiguration() -> Flags.Configuration? {
134
+ let enabled = object(forKey: "enabled") as? Bool ?? false
135
+
136
+ if !enabled {
137
+ return nil
138
+ }
139
+
140
+ // Hard set `gracefulModeEnabled` to `true` because this misconfiguration is handled on JS side.
141
+ let gracefulModeEnabled = true
142
+
143
+ let trackExposures = object(forKey: "trackExposures") as? Bool
144
+ let rumIntegrationEnabled = object(forKey: "rumIntegrationEnabled") as? Bool
145
+
146
+ var customFlagsEndpointURL: URL? = nil
147
+ if let customFlagsEndpoint = object(forKey: "customFlagsEndpoint") as? String {
148
+ customFlagsEndpointURL = URL(string: "\(customFlagsEndpoint)/precompute-assignments" as String)
149
+ }
150
+ var customExposureEndpointURL: URL? = nil
151
+ if let customExposureEndpoint = object(forKey: "customExposureEndpoint") as? String {
152
+ customExposureEndpointURL = URL(string: "\(customExposureEndpoint)/api/v2/exposures" as String)
153
+ }
154
+
155
+ return Flags.Configuration(
156
+ gracefulModeEnabled: gracefulModeEnabled,
157
+ customFlagsEndpoint: customFlagsEndpointURL,
158
+ customExposureEndpoint: customExposureEndpointURL,
159
+ trackExposures: trackExposures ?? true,
160
+ rumIntegrationEnabled: rumIntegrationEnabled ?? true
161
+ )
162
+ }
163
+ }
164
+
165
+ extension FlagAssignment {
166
+ public func asDictionary(flagKey: String) -> [String: Any] {
167
+ let value = switch self.variation {
168
+ case .boolean(let v): v
169
+ case .string(let v): v
170
+ case .integer(let v): v
171
+ case .double(let v): v
172
+ case .object(let v): v.unwrap()
173
+ case .unknown: NSNull()
174
+ }
175
+
176
+ return [
177
+ "key": flagKey,
178
+ "value": value,
179
+ "allocationKey": allocationKey,
180
+ "variationKey": variationKey,
181
+ "reason": reason,
182
+ "doLog": doLog,
183
+ // Parity with Android. We don't use the following properties in iOS SDK.
184
+ "variationType": "",
185
+ "variationValue": "",
186
+ "extraLogging": [:],
187
+ ]
188
+ }
189
+ }
190
+
191
+ extension NSDictionary {
192
+ func asFlagAssignment() -> FlagAssignment? {
193
+ guard
194
+ let allocationKey = object(forKey: "allocationKey") as? String,
195
+ let variationKey = object(forKey: "variationKey") as? String,
196
+ let reason = object(forKey: "reason") as? String,
197
+ let doLog = object(forKey: "doLog") as? Bool,
198
+ let value = object(forKey: "value")
199
+ else {
200
+ return nil
201
+ }
202
+
203
+ let variation: FlagAssignment.Variation = switch value {
204
+ case let boolValue as Bool: .boolean(boolValue)
205
+ case let stringValue as String: .string(stringValue)
206
+ case let intValue as Int: .integer(intValue)
207
+ case let doubleValue as Double: .double(doubleValue)
208
+ case let dictValue as [String: Any]: .object(AnyValue.wrap(dictValue))
209
+ default: .unknown(String(describing: value))
210
+ }
211
+
212
+ return FlagAssignment(
213
+ allocationKey: allocationKey,
214
+ variationKey: variationKey,
215
+ variation: variation,
216
+ reason: reason,
217
+ doLog: doLog
218
+ )
219
+ }
220
+ }
221
+
222
+ extension AnyValue {
223
+ static func wrap(_ value: Any) -> AnyValue {
224
+ if value is NSNull {
225
+ return .null
226
+ }
227
+
228
+ if let value = value as? String {
229
+ return .string(value)
230
+ } else if let value = value as? Bool {
231
+ return .bool(value)
232
+ } else if let value = value as? Int {
233
+ return .int(value)
234
+ } else if let value = value as? Double {
235
+ return .double(value)
236
+ } else if let value = value as? [String: Any] {
237
+ return .dictionary(value.mapValues(AnyValue.wrap))
238
+ } else if let value = value as? [Any] {
239
+ return .array(value.map(AnyValue.wrap))
240
+ } else {
241
+ return .null
242
+ }
243
+ }
244
+
245
+ func unwrap() -> Any {
246
+ switch self {
247
+ case .string(let value):
248
+ return value
249
+ case .bool(let value):
250
+ return value
251
+ case .int(let value):
252
+ return value
253
+ case .double(let value):
254
+ return value
255
+ case .dictionary(let dict):
256
+ return dict.mapValues { $0.unwrap() }
257
+ case .array(let array):
258
+ return array.map { $0.unwrap() }
259
+ case .null:
260
+ return NSNull()
261
+ }
262
+ }
263
+ }
@@ -23,7 +23,6 @@ import Foundation
23
23
  /// - batchSize: The preferred size of batches sent to Datadog.
24
24
  /// - batchProcessingLevel: Maximum number of batches processed sequentially before applying a delay.
25
25
  /// - proxyConfiguration: Configuration for proxying SDK data (proxy type, address, port, etc.).
26
- /// - firstPartyHosts: List of backend hosts considered first-party for network tracing.
27
26
  /// - rumConfiguration: Configuration for the RUM feature module.
28
27
  /// - logsConfiguration: Configuration for the Logs feature module.
29
28
  /// - traceConfiguration: Configuration for the Traces feature module.
@@ -41,7 +40,6 @@ public class DdSdkConfiguration: NSObject {
41
40
  public var batchSize: Datadog.Configuration.BatchSize
42
41
  public var batchProcessingLevel: Datadog.Configuration.BatchProcessingLevel
43
42
  public var proxyConfiguration: [AnyHashable: Any]? = nil
44
- public var firstPartyHosts: [String: Set<TracingHeaderType>]? = nil
45
43
  public var rumConfiguration: RumConfiguration? = nil
46
44
  public var logsConfiguration: LogsConfiguration? = nil
47
45
  public var traceConfiguration: TraceConfiguration? = nil
@@ -59,7 +57,6 @@ public class DdSdkConfiguration: NSObject {
59
57
  batchSize: Datadog.Configuration.BatchSize,
60
58
  batchProcessingLevel: Datadog.Configuration.BatchProcessingLevel,
61
59
  proxyConfiguration: [AnyHashable: Any]?,
62
- firstPartyHosts: [String: Set<TracingHeaderType>]?,
63
60
  rumConfiguration: RumConfiguration?,
64
61
  logsConfiguration: LogsConfiguration?,
65
62
  traceConfiguration: TraceConfiguration?,
@@ -76,7 +73,6 @@ public class DdSdkConfiguration: NSObject {
76
73
  self.batchSize = batchSize
77
74
  self.batchProcessingLevel = batchProcessingLevel
78
75
  self.proxyConfiguration = proxyConfiguration
79
- self.firstPartyHosts = firstPartyHosts
80
76
  self.rumConfiguration = rumConfiguration
81
77
  self.logsConfiguration = logsConfiguration
82
78
  self.traceConfiguration = traceConfiguration
@@ -99,6 +95,7 @@ public class DdSdkConfiguration: NSObject {
99
95
  /// - nativeLongTaskThresholdMs: The threshold for reporting native long tasks in milliseconds.
100
96
  /// - nativeViewTracking: Enables tracking of native iOS/Android UI views.
101
97
  /// - nativeInteractionTracking: Enables tracking of native UI interactions.
98
+ /// - firstPartyHosts: List of backend hosts considered first-party for network tracing.
102
99
  /// - appHangThreshold: Threshold in seconds for reporting non-fatal app hangs (iOS only).
103
100
  /// - trackWatchdogTerminations: Whether the SDK should track application terminations
104
101
  /// caused by the iOS watchdog.
@@ -118,6 +115,7 @@ public class RumConfiguration: NSObject {
118
115
  public var nativeLongTaskThresholdMs: Double? = nil
119
116
  public var nativeViewTracking: Bool? = nil
120
117
  public var nativeInteractionTracking: Bool? = nil
118
+ public var firstPartyHosts: [String: Set<TracingHeaderType>]? = nil
121
119
  public var appHangThreshold: Double? = nil
122
120
  public var trackWatchdogTerminations: Bool
123
121
  public var initialResourceThreshold: Double? = nil
@@ -137,6 +135,7 @@ public class RumConfiguration: NSObject {
137
135
  nativeLongTaskThresholdMs: Double? = nil,
138
136
  nativeViewTracking: Bool?,
139
137
  nativeInteractionTracking: Bool?,
138
+ firstPartyHosts: [String: Set<TracingHeaderType>]?,
140
139
  appHangThreshold: Double?,
141
140
  trackWatchdogTerminations: Bool,
142
141
  initialResourceThreshold: Double?,
@@ -155,6 +154,7 @@ public class RumConfiguration: NSObject {
155
154
  self.nativeLongTaskThresholdMs = nativeLongTaskThresholdMs
156
155
  self.nativeViewTracking = nativeViewTracking
157
156
  self.nativeInteractionTracking = nativeInteractionTracking
157
+ self.firstPartyHosts = firstPartyHosts
158
158
  self.appHangThreshold = appHangThreshold
159
159
  self.trackWatchdogTerminations = trackWatchdogTerminations
160
160
  self.initialResourceThreshold = initialResourceThreshold
@@ -162,7 +162,7 @@ public class DdSdkNativeInitialization: NSObject {
162
162
  }
163
163
 
164
164
  var urlSessionTracking: RUM.Configuration.URLSessionTracking? = nil
165
- if let firstPartyHosts = configuration.firstPartyHosts {
165
+ if let firstPartyHosts = rumConfig.firstPartyHosts {
166
166
  urlSessionTracking = RUM.Configuration.URLSessionTracking(
167
167
  firstPartyHostsTracing: .traceWithHeaders(
168
168
  hostsWithHeaders: firstPartyHosts,
@@ -272,4 +272,4 @@ public class DdSdkNativeInitialization: NSObject {
272
272
  Datadog.verbosityLevel = nil
273
273
  }
274
274
  }
275
- }
275
+ }
@@ -5,6 +5,7 @@
5
5
  */
6
6
 
7
7
  import DatadogCore
8
+ import DatadogFlags
8
9
  import DatadogInternal
9
10
  import DatadogRUM
10
11
  import Foundation
@@ -38,8 +39,6 @@ extension NSDictionary {
38
39
  let proxyConfigurationDict = self["proxyConfiguration"] as? NSDictionary
39
40
  let proxyConfiguration = proxyConfigurationDict?.asProxyConfiguration()
40
41
 
41
- let firstPartyHostsArray = self["firstPartyHosts"] as? NSArray
42
- let firstPartyHosts = firstPartyHostsArray?.asFirstPartyHosts()
43
42
 
44
43
  // MARK: - RUM configuration
45
44
 
@@ -61,6 +60,9 @@ extension NSDictionary {
61
60
  let nativeLongTaskThresholdMs = rumDict["nativeLongTaskThresholdMs"] as? Double
62
61
  let nativeViewTracking = rumDict["nativeViewTracking"] as? Bool
63
62
  let nativeInteractionTracking = rumDict["nativeInteractionTracking"] as? Bool
63
+
64
+ let firstPartyHostsArray = rumDict["firstPartyHosts"] as? NSArray
65
+ let firstPartyHosts = firstPartyHostsArray?.asFirstPartyHosts()
64
66
 
65
67
  let appHangThreshold = rumDict["appHangThreshold"] as? Double
66
68
  let trackWatchdogTerminations = rumDict["trackWatchdogTerminations"] as? Bool
@@ -87,6 +89,7 @@ extension NSDictionary {
87
89
  nativeViewTracking: nativeViewTracking ?? DefaultConfiguration.nativeViewTracking,
88
90
  nativeInteractionTracking: nativeInteractionTracking
89
91
  ?? DefaultConfiguration.nativeInteractionTracking,
92
+ firstPartyHosts: firstPartyHosts,
90
93
  appHangThreshold: appHangThreshold,
91
94
  trackWatchdogTerminations: trackWatchdogTerminations
92
95
  ?? DefaultConfiguration.trackWatchdogTerminations,
@@ -153,7 +156,6 @@ extension NSDictionary {
153
156
  batchSize: batchSize,
154
157
  batchProcessingLevel: batchProcessingLevel,
155
158
  proxyConfiguration: proxyConfiguration,
156
- firstPartyHosts: firstPartyHosts,
157
159
  rumConfiguration: rumConfiguration,
158
160
  logsConfiguration: logsConfiguration,
159
161
  traceConfiguration: traceConfiguration,
@@ -178,7 +180,7 @@ extension NSDictionary {
178
180
  reactNativeVersion: reactNativeVersion
179
181
  )
180
182
  }
181
-
183
+
182
184
  func asProxyConfiguration() -> [AnyHashable: Any]? {
183
185
  guard let address = object(forKey: "address") as? String else {
184
186
  return nil
@@ -316,10 +318,6 @@ extension Dictionary where Key == String, Value == AnyObject {
316
318
  let proxyDict = configuration["proxyConfiguration"] as? NSDictionary
317
319
  let proxyConfiguration = proxyDict?.asProxyConfiguration()
318
320
 
319
- let firstPartyHostsArray = configuration["firstPartyHosts"] as? NSArray
320
- let firstPartyHosts =
321
- firstPartyHostsArray?.asFirstPartyHosts() ?? DefaultConfiguration.firstPartyHosts
322
-
323
321
  // MARK: - RUM configuration
324
322
 
325
323
  let rumDict = configuration["rumConfiguration"] as? [String: Any?]
@@ -354,6 +352,10 @@ extension Dictionary where Key == String, Value == AnyObject {
354
352
  if let v = nativeLongTaskRaw as? Int { return Double(v) }
355
353
  return nil
356
354
  }()
355
+
356
+ let firstPartyHostsArray = rum["firstPartyHosts"] as? NSArray
357
+ let firstPartyHosts =
358
+ firstPartyHostsArray?.asFirstPartyHosts() ?? DefaultConfiguration.firstPartyHosts
357
359
 
358
360
  rumConfiguration = RumConfiguration(
359
361
  applicationId: applicationId,
@@ -376,6 +378,7 @@ extension Dictionary where Key == String, Value == AnyObject {
376
378
  ?? DefaultConfiguration.nativeViewTracking,
377
379
  nativeInteractionTracking: rum["nativeInteractionTracking"] as? Bool
378
380
  ?? DefaultConfiguration.nativeInteractionTracking,
381
+ firstPartyHosts: firstPartyHosts,
379
382
  appHangThreshold: rum["appHangThreshold"] as? Double,
380
383
  trackWatchdogTerminations: rum["trackWatchdogTerminations"] as? Bool
381
384
  ?? DefaultConfiguration.trackWatchdogTerminations,
@@ -437,7 +440,6 @@ extension Dictionary where Key == String, Value == AnyObject {
437
440
  batchSize: batchSize,
438
441
  batchProcessingLevel: batchProcessingLevel,
439
442
  proxyConfiguration: proxyConfiguration,
440
- firstPartyHosts: firstPartyHosts,
441
443
  rumConfiguration: rumConfiguration,
442
444
  logsConfiguration: logsConfiguration,
443
445
  traceConfiguration: traceConfiguration,
@@ -7,4 +7,4 @@
7
7
  import Foundation
8
8
 
9
9
  // This is automatically updated by the update-version.sh script
10
- let SdkVersion = "3.0.3"
10
+ let SdkVersion = "3.1.1"
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.InternalLog = exports.DATADOG_MESSAGE_PREFIX = void 0;
7
7
  var _SdkVerbosity = require("./config/types/SdkVerbosity");
8
+ var _singletonUtils = require("./utils/singletonUtils");
8
9
  /*
9
10
  * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
10
11
  * This product includes software developed at Datadog (https://www.datadoghq.com/).
@@ -12,21 +13,22 @@ var _SdkVerbosity = require("./config/types/SdkVerbosity");
12
13
  */
13
14
 
14
15
  const DATADOG_MESSAGE_PREFIX = exports.DATADOG_MESSAGE_PREFIX = 'DATADOG:';
16
+ const INTERNAL_LOG_MODULE = 'com.datadog.reactnative.internal_log';
15
17
 
16
18
  /**
17
19
  * /!\ DO NOT USE THIS IN YOUR APP /!\\
18
20
  *
19
21
  * This logger is only for debugging the Datadog SDK.
20
22
  */
21
- class InternalLog {
22
- static levelMap = new Map([[_SdkVerbosity.SdkVerbosity.DEBUG, 1], [_SdkVerbosity.SdkVerbosity.INFO, 2], [_SdkVerbosity.SdkVerbosity.WARN, 3], [_SdkVerbosity.SdkVerbosity.ERROR, 4]]);
23
- static verbosity = undefined;
24
- static log(message, verbosity) {
25
- if (InternalLog.verbosity === undefined) {
23
+ class _InternalLog {
24
+ levelMap = new Map([[_SdkVerbosity.SdkVerbosity.DEBUG, 1], [_SdkVerbosity.SdkVerbosity.INFO, 2], [_SdkVerbosity.SdkVerbosity.WARN, 3], [_SdkVerbosity.SdkVerbosity.ERROR, 4]]);
25
+ verbosity = undefined;
26
+ log(message, verbosity) {
27
+ if (this.verbosity === undefined) {
26
28
  return;
27
29
  }
28
30
  const requiredLevel = InternalLog.levelMap.get(verbosity);
29
- const allowedLevel = InternalLog.levelMap.get(InternalLog.verbosity);
31
+ const allowedLevel = InternalLog.levelMap.get(this.verbosity);
30
32
  if (allowedLevel === undefined || requiredLevel === undefined) {
31
33
  return;
32
34
  }
@@ -45,5 +47,5 @@ class InternalLog {
45
47
  }
46
48
  }
47
49
  }
48
- exports.InternalLog = InternalLog;
50
+ const InternalLog = exports.InternalLog = (0, _singletonUtils.getGlobalInstance)(INTERNAL_LOG_MODULE, () => new _InternalLog());
49
51
  //# sourceMappingURL=InternalLog.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_SdkVerbosity","require","DATADOG_MESSAGE_PREFIX","exports","InternalLog","levelMap","Map","SdkVerbosity","DEBUG","INFO","WARN","ERROR","verbosity","undefined","log","message","requiredLevel","get","allowedLevel","prefixedMessage","console","error","warn","info","debug"],"sourceRoot":"../../src","sources":["InternalLog.tsx"],"mappings":";;;;;;AAMA,IAAAA,aAAA,GAAAC,OAAA;AANA;AACA;AACA;AACA;AACA;;AAIO,MAAMC,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,GAAG,UAAU;;AAEhD;AACA;AACA;AACA;AACA;AACO,MAAME,WAAW,CAAC;EACrB,OAAeC,QAAQ,GAAG,IAAIC,GAAG,CAAuB,CACpD,CAACC,0BAAY,CAACC,KAAK,EAAE,CAAC,CAAC,EACvB,CAACD,0BAAY,CAACE,IAAI,EAAE,CAAC,CAAC,EACtB,CAACF,0BAAY,CAACG,IAAI,EAAE,CAAC,CAAC,EACtB,CAACH,0BAAY,CAACI,KAAK,EAAE,CAAC,CAAC,CAC1B,CAAC;EAEF,OAAcC,SAAS,GAA6BC,SAAS;EAE7D,OAAcC,GAAGA,CAACC,OAAe,EAAEH,SAAuB,EAAQ;IAC9D,IAAIR,WAAW,CAACQ,SAAS,KAAKC,SAAS,EAAE;MACrC;IACJ;IACA,MAAMG,aAAa,GAAGZ,WAAW,CAACC,QAAQ,CAACY,GAAG,CAACL,SAAS,CAAC;IACzD,MAAMM,YAAY,GAAGd,WAAW,CAACC,QAAQ,CAACY,GAAG,CAACb,WAAW,CAACQ,SAAS,CAAC;IACpE,IAAIM,YAAY,KAAKL,SAAS,IAAIG,aAAa,KAAKH,SAAS,EAAE;MAC3D;IACJ;IACA,MAAMM,eAAe,GAAG,GAAGjB,sBAAsB,IAAIa,OAAO,EAAE;IAC9D,IAAIH,SAAS,KAAKL,0BAAY,CAACI,KAAK,IAAIK,aAAa,IAAIE,YAAY,EAAE;MACnEE,OAAO,CAACC,KAAK,CAACF,eAAe,CAAC;IAClC;IAEA,IAAIP,SAAS,KAAKL,0BAAY,CAACG,IAAI,IAAIM,aAAa,IAAIE,YAAY,EAAE;MAClEE,OAAO,CAACE,IAAI,CAACH,eAAe,CAAC;IACjC;IAEA,IAAIP,SAAS,KAAKL,0BAAY,CAACE,IAAI,IAAIO,aAAa,IAAIE,YAAY,EAAE;MAClEE,OAAO,CAACG,IAAI,CAACJ,eAAe,CAAC;IACjC;IAEA,IAAIP,SAAS,KAAKL,0BAAY,CAACC,KAAK,IAAIQ,aAAa,IAAIE,YAAY,EAAE;MACnEE,OAAO,CAACI,KAAK,CAACL,eAAe,CAAC;IAClC;EACJ;AACJ;AAAChB,OAAA,CAAAC,WAAA,GAAAA,WAAA","ignoreList":[]}
1
+ {"version":3,"names":["_SdkVerbosity","require","_singletonUtils","DATADOG_MESSAGE_PREFIX","exports","INTERNAL_LOG_MODULE","_InternalLog","levelMap","Map","SdkVerbosity","DEBUG","INFO","WARN","ERROR","verbosity","undefined","log","message","requiredLevel","InternalLog","get","allowedLevel","prefixedMessage","console","error","warn","info","debug","getGlobalInstance"],"sourceRoot":"../../src","sources":["InternalLog.tsx"],"mappings":";;;;;;AAMA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAPA;AACA;AACA;AACA;AACA;;AAKO,MAAME,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,GAAG,UAAU;AAEhD,MAAME,mBAAmB,GAAG,sCAAsC;;AAElE;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAY,CAAC;EACPC,QAAQ,GAAG,IAAIC,GAAG,CAAuB,CAC7C,CAACC,0BAAY,CAACC,KAAK,EAAE,CAAC,CAAC,EACvB,CAACD,0BAAY,CAACE,IAAI,EAAE,CAAC,CAAC,EACtB,CAACF,0BAAY,CAACG,IAAI,EAAE,CAAC,CAAC,EACtB,CAACH,0BAAY,CAACI,KAAK,EAAE,CAAC,CAAC,CAC1B,CAAC;EAEKC,SAAS,GAA6BC,SAAS;EAE/CC,GAAGA,CAACC,OAAe,EAAEH,SAAuB,EAAQ;IACvD,IAAI,IAAI,CAACA,SAAS,KAAKC,SAAS,EAAE;MAC9B;IACJ;IACA,MAAMG,aAAa,GAAGC,WAAW,CAACZ,QAAQ,CAACa,GAAG,CAACN,SAAS,CAAC;IACzD,MAAMO,YAAY,GAAGF,WAAW,CAACZ,QAAQ,CAACa,GAAG,CAAC,IAAI,CAACN,SAAS,CAAC;IAC7D,IAAIO,YAAY,KAAKN,SAAS,IAAIG,aAAa,KAAKH,SAAS,EAAE;MAC3D;IACJ;IACA,MAAMO,eAAe,GAAG,GAAGnB,sBAAsB,IAAIc,OAAO,EAAE;IAC9D,IAAIH,SAAS,KAAKL,0BAAY,CAACI,KAAK,IAAIK,aAAa,IAAIG,YAAY,EAAE;MACnEE,OAAO,CAACC,KAAK,CAACF,eAAe,CAAC;IAClC;IAEA,IAAIR,SAAS,KAAKL,0BAAY,CAACG,IAAI,IAAIM,aAAa,IAAIG,YAAY,EAAE;MAClEE,OAAO,CAACE,IAAI,CAACH,eAAe,CAAC;IACjC;IAEA,IAAIR,SAAS,KAAKL,0BAAY,CAACE,IAAI,IAAIO,aAAa,IAAIG,YAAY,EAAE;MAClEE,OAAO,CAACG,IAAI,CAACJ,eAAe,CAAC;IACjC;IAEA,IAAIR,SAAS,KAAKL,0BAAY,CAACC,KAAK,IAAIQ,aAAa,IAAIG,YAAY,EAAE;MACnEE,OAAO,CAACI,KAAK,CAACL,eAAe,CAAC;IAClC;EACJ;AACJ;AAEO,MAAMH,WAAW,GAAAf,OAAA,CAAAe,WAAA,GAAG,IAAAS,iCAAiB,EACxCvB,mBAAmB,EACnB,MAAM,IAAIC,YAAY,CAAC,CAC3B,CAAC","ignoreList":[]}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DdFlags = void 0;
7
+ var _InternalLog = require("../InternalLog");
8
+ var _SdkVerbosity = require("../config/types/SdkVerbosity");
9
+ var _singletonUtils = require("../utils/singletonUtils");
10
+ var _FlagsClient = require("./FlagsClient");
11
+ /*
12
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
13
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
14
+ * Copyright 2016-Present Datadog, Inc.
15
+ */
16
+
17
+ const FLAGS_MODULE = 'com.datadog.reactnative.flags';
18
+
19
+ /**
20
+ * Implementation class for {@link DdFlagsType}. Please see the interface for documentation.
21
+ */
22
+ class DdFlagsWrapper {
23
+ // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
24
+ nativeFlags = require('../specs/NativeDdFlags').default;
25
+ isFeatureEnabled = false;
26
+
27
+ /**
28
+ * A map of client names to their corresponding {@link FlagsClient} instances.
29
+ *
30
+ * Each of these clients hold their own context and flags state.
31
+ */
32
+ clients = {};
33
+ enable = async (configuration = {}) => {
34
+ await this.nativeFlags.enable({
35
+ enabled: true,
36
+ ...configuration
37
+ });
38
+ this.isFeatureEnabled = true;
39
+ };
40
+ getClient = (clientName = 'default') => {
41
+ if (!this.isFeatureEnabled) {
42
+ _InternalLog.InternalLog.log('`DdFlags.getClient()` called before Datadog Flags feature have been enabled. Client will fall back to serving default flag values.', _SdkVerbosity.SdkVerbosity.ERROR);
43
+ }
44
+ if (!this.clients[clientName]) {
45
+ this.clients[clientName] = new _FlagsClient.FlagsClient(clientName);
46
+ }
47
+ return this.clients[clientName];
48
+ };
49
+ }
50
+ const DdFlags = exports.DdFlags = (0, _singletonUtils.getGlobalInstance)(FLAGS_MODULE, () => new DdFlagsWrapper());
51
+ //# sourceMappingURL=DdFlags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_InternalLog","require","_SdkVerbosity","_singletonUtils","_FlagsClient","FLAGS_MODULE","DdFlagsWrapper","nativeFlags","default","isFeatureEnabled","clients","enable","configuration","enabled","getClient","clientName","InternalLog","log","SdkVerbosity","ERROR","FlagsClient","DdFlags","exports","getGlobalInstance"],"sourceRoot":"../../../src","sources":["flags/DdFlags.ts"],"mappings":";;;;;;AAMA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAEA,IAAAE,eAAA,GAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AAXA;AACA;AACA;AACA;AACA;;AAUA,MAAMI,YAAY,GAAG,+BAA+B;;AAEpD;AACA;AACA;AACA,MAAMC,cAAc,CAAwB;EACxC;EACQC,WAAW,GAAsBN,OAAO,CAAC,wBAAwB,CAAC,CACrEO,OAAO;EAEJC,gBAAgB,GAAG,KAAK;;EAEhC;AACJ;AACA;AACA;AACA;EACYC,OAAO,GAAgC,CAAC,CAAC;EAEjDC,MAAM,GAAG,MAAAA,CAAOC,aAAiC,GAAG,CAAC,CAAC,KAAoB;IACtE,MAAM,IAAI,CAACL,WAAW,CAACI,MAAM,CAAC;MAAEE,OAAO,EAAE,IAAI;MAAE,GAAGD;IAAc,CAAC,CAAC;IAElE,IAAI,CAACH,gBAAgB,GAAG,IAAI;EAChC,CAAC;EAEDK,SAAS,GAAGA,CAACC,UAAkB,GAAG,SAAS,KAAkB;IACzD,IAAI,CAAC,IAAI,CAACN,gBAAgB,EAAE;MACxBO,wBAAW,CAACC,GAAG,CACX,oIAAoI,EACpIC,0BAAY,CAACC,KACjB,CAAC;IACL;IAEA,IAAI,CAAC,IAAI,CAACT,OAAO,CAACK,UAAU,CAAC,EAAE;MAC3B,IAAI,CAACL,OAAO,CAACK,UAAU,CAAC,GAAG,IAAIK,wBAAW,CAACL,UAAU,CAAC;IAC1D;IAEA,OAAO,IAAI,CAACL,OAAO,CAACK,UAAU,CAAC;EACnC,CAAC;AACL;AAEO,MAAMM,OAAoB,GAAAC,OAAA,CAAAD,OAAA,GAAG,IAAAE,iCAAiB,EACjDlB,YAAY,EACZ,MAAM,IAAIC,cAAc,CAAC,CAC7B,CAAC","ignoreList":[]}