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: Client Key in Resolve Debug logs #176

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Sources/Confidence/Confidence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ extension Confidence {
public func build() -> Confidence {
if debugLogger == nil {
if loggerLevel != LoggerLevel.NONE {
debugLogger = DebugLoggerImpl(loggerLevel: loggerLevel)
debugLogger = DebugLoggerImpl(loggerLevel: loggerLevel, clientKey: clientSecret)
debugLogger?.logContext(action: "InitialContext", context: initialContext)
}
}
Expand Down
6 changes: 4 additions & 2 deletions Sources/Confidence/DebugLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ private extension Logger {

internal class DebugLoggerImpl: DebugLogger {
private let encoder = JSONEncoder()
private let clientKey: String

func logResolveDebugURL(flagName: String, context: ConfidenceStruct) {
let ctxNetworkValue = TypeMapper.convert(structure: context)
if let ctxNetworkData = try? encoder.encode(ctxNetworkValue),
let ctxNetworkString = String(data: ctxNetworkData, encoding: .utf8) {
log(messageLevel: .DEBUG, message: "[Resolve Debug] https://app.confidence.spotify.com/flags/resolver-test?flag=flags/\(flagName)&context=\(ctxNetworkString)")
log(messageLevel: .DEBUG, message: "[Resolve Debug] https://app.confidence.spotify.com/flags/resolver-test?client-key=\(clientKey)&flag=flags/\(flagName)&context=\(ctxNetworkString)")
}
}

private let loggerLevel: LoggerLevel

init(loggerLevel: LoggerLevel) {
init(loggerLevel: LoggerLevel, clientKey: String) {
self.loggerLevel = loggerLevel
self.clientKey = clientKey
}

func logMessage(message: String, isWarning: Bool = false) {
Expand Down
Loading