Skip to content

Commit

Permalink
feat: [WIP] Send eval context in events
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed Mar 28, 2024
1 parent e87e2ac commit 1037c36
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
5 changes: 4 additions & 1 deletion ConfidenceDemoApp/ConfidenceDemoApp/ConfidenceDemoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ let package = Package(
.package(url: "[email protected]:open-feature/swift-sdk.git", from: "0.1.0"),
],
targets: [
.target(
name: "Confidence",
dependencies: [],
plugins: []
),
.target(
name: "ConfidenceProvider",
dependencies: [
Expand All @@ -29,11 +34,6 @@ let package = Package(
],
plugins: []
),
.target(
name: "Confidence",
dependencies: [],
plugins: []
),
.testTarget(
name: "ConfidenceProviderTests",
dependencies: [
Expand Down
2 changes: 1 addition & 1 deletion Sources/Confidence/Confidence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class ConfidenceFeatureProvider: FeatureProvider {
}

if self.initializationStrategy == .activateAndFetchAsync {
confidence?.context = ["targeting_key": "CACHED"]
eventHandler.send(.ready)
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1037c36

Please sign in to comment.