diff --git a/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift b/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift index 073efd95..6d79beb7 100644 --- a/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift +++ b/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift @@ -20,7 +20,10 @@ struct ConfidenceDemoApp: App { WindowGroup { let secret = ProcessInfo.processInfo.environment["CLIENT_SECRET"] ?? "" let confidence = Confidence.Builder(clientSecret: secret, loggerLevel: .TRACE) - .withContext(initialContext: ["targeting_key": ConfidenceValue(string: UUID.init().uuidString)]) + .withContext(initialContext: [ + "targeting_key": ConfidenceValue(string: UUID.init().uuidString), + "user_id": .init(string: "user2") + ]) .build() let status = Status() diff --git a/Sources/Confidence/Confidence.swift b/Sources/Confidence/Confidence.swift index f5e5dc75..e0e4d255 100644 --- a/Sources/Confidence/Confidence.swift +++ b/Sources/Confidence/Confidence.swift @@ -397,7 +397,8 @@ extension Confidence { let options = ConfidenceClientOptions( credentials: ConfidenceClientCredentials.clientSecret(secret: clientSecret), region: region, - timeoutIntervalForRequest: timeout) + timeoutIntervalForRequest: timeout, + debugLogger: debugLogger) let metadata = ConfidenceMetadata( name: sdkId, version: "1.0.1") // x-release-please-version diff --git a/Sources/Confidence/ConfidenceClientOptions.swift b/Sources/Confidence/ConfidenceClientOptions.swift index fe64d3bb..b46c797d 100644 --- a/Sources/Confidence/ConfidenceClientOptions.swift +++ b/Sources/Confidence/ConfidenceClientOptions.swift @@ -5,17 +5,24 @@ struct ConfidenceClientOptions { public var region: ConfidenceRegion public var initializationStrategy: InitializationStrategy public var timeoutIntervalForRequest: Double + private let debugLogger: DebugLogger? public init( credentials: ConfidenceClientCredentials, region: ConfidenceRegion? = nil, initializationStrategy: InitializationStrategy = .fetchAndActivate, - timeoutIntervalForRequest: Double + timeoutIntervalForRequest: Double, + debugLogger: DebugLogger? = nil ) { self.credentials = credentials self.region = region ?? .global self.initializationStrategy = initializationStrategy self.timeoutIntervalForRequest = timeoutIntervalForRequest + self.debugLogger = debugLogger + } + + func getLogger() -> DebugLogger? { + return debugLogger } } diff --git a/Sources/Confidence/RemoteResolveConfidenceClient.swift b/Sources/Confidence/RemoteResolveConfidenceClient.swift index 479dead8..a9747365 100644 --- a/Sources/Confidence/RemoteResolveConfidenceClient.swift +++ b/Sources/Confidence/RemoteResolveConfidenceClient.swift @@ -26,14 +26,25 @@ class RemoteConfidenceResolveClient: ConfidenceResolveClient { // MARK: Resolver public func resolve(flags: [String], ctx: ConfidenceStruct) async throws -> ResolvesResult { + let ctxNetworkValue = TypeMapper.convert(structure: ctx) let request = ResolveFlagsRequest( flags: flags.map { "flags/\($0)" }, - evaluationContext: TypeMapper.convert(structure: ctx), + evaluationContext: ctxNetworkValue, clientSecret: options.credentials.getSecret(), apply: applyOnResolve, sdk: Sdk(id: metadata.name, version: metadata.version) ) + if let debugLogger = options.getLogger() { + let encoder = JSONEncoder() + if let jsonData = try? encoder.encode(ctxNetworkValue), + let jsonCtx = String(data: jsonData, encoding: .utf8) { + debugLogger.logMessage( + message: "[Resolve Debug] https://app.confidence.spotify.com/flags/resolver-test?context=\(jsonCtx)", + isWarning: false) + } + } + do { let result: HttpClientResult = try await self.httpClient.post(path: ":resolve", data: request)