From d2f805ae3acccfcf6b0cdbeb6583dd9396e03b37 Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Wed, 27 Mar 2024 16:48:03 +0100 Subject: [PATCH] [WIP] Send eval context in events --- ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift | 5 ++++- Sources/Confidence/Confidence.swift | 2 +- Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift b/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift index 1e7f25e5..024de9fe 100644 --- a/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift +++ b/ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift @@ -36,6 +36,9 @@ extension ConfidenceDemoApp { // NOTE: Using a random UUID for each app start is not advised and can result in getting stale values. let ctx = MutableContext(targetingKey: UUID.init().uuidString, structure: MutableStructure()) - OpenFeatureAPI.shared.setProvider(provider: provider, initialContext: ctx) + Task { + await OpenFeatureAPI.shared.setProviderAndWait(provider: provider, initialContext: ctx) + confidence.send(eventName: "my_event") + } } } diff --git a/Sources/Confidence/Confidence.swift b/Sources/Confidence/Confidence.swift index a701b5de..38408893 100644 --- a/Sources/Confidence/Confidence.swift +++ b/Sources/Confidence/Confidence.swift @@ -12,7 +12,7 @@ public class Confidence: ConfidenceEventSender { } public func send(eventName: String) { - print("Sending \(eventName)") + print("Sending \(eventName) - Targeting key: \(context["targeting_key"] ?? "UNKNOWN")") } public func updateContextEntry(key: String, value: String) { diff --git a/Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift b/Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift index 0cf289a0..9e6b76c2 100644 --- a/Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift +++ b/Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift @@ -54,6 +54,7 @@ public class ConfidenceFeatureProvider: FeatureProvider { } if self.initializationStrategy == .activateAndFetchAsync { + confidence?.context = ["targeting_key": "CACHED"] eventHandler.send(.ready) } @@ -70,6 +71,7 @@ public class ConfidenceFeatureProvider: FeatureProvider { // signal the provider is ready after the network request is done if self.initializationStrategy == .fetchAndActivate { + confidence?.context = ["targeting_key": initialContext.getTargetingKey()] eventHandler.send(.ready) } } catch { @@ -111,6 +113,7 @@ public class ConfidenceFeatureProvider: FeatureProvider { // update the storage try await store(with: newContext, resolveResult: resolveResult, refreshCache: true) eventHandler.send(ProviderEvent.ready) + confidence?.context = ["targeting_key": newContext.getTargetingKey()] } catch { eventHandler.send(ProviderEvent.ready) // do nothing