Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Resolve Debug at DEBUG level logging #174

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion Sources/Confidence/Confidence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion Sources/Confidence/ConfidenceClientOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
13 changes: 12 additions & 1 deletion Sources/Confidence/RemoteResolveConfidenceClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
fabriziodemaria marked this conversation as resolved.
Show resolved Hide resolved
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)",
fabriziodemaria marked this conversation as resolved.
Show resolved Hide resolved
isWarning: false)
}
}

do {
let result: HttpClientResult<ResolveFlagsResponse> =
try await self.httpClient.post(path: ":resolve", data: request)
Expand Down
Loading