From 48f6d7abdf8409fef1f67c5a3c5ff49123a500e1 Mon Sep 17 00:00:00 2001 From: Michael Velbaum Date: Sun, 28 Dec 2025 15:42:35 +0200 Subject: [PATCH] refactor(logging): dedupe auth selection debug logs Extract repeated debug logging for selected auth credentials into a helper so execute, count, and stream paths stay consistent. --- sdk/cliproxy/auth/conductor.go | 89 ++++++++++++---------------------- 1 file changed, 32 insertions(+), 57 deletions(-) diff --git a/sdk/cliproxy/auth/conductor.go b/sdk/cliproxy/auth/conductor.go index 281216ed..fe41ae01 100644 --- a/sdk/cliproxy/auth/conductor.go +++ b/sdk/cliproxy/auth/conductor.go @@ -386,25 +386,7 @@ func (m *Manager) executeWithProvider(ctx context.Context, provider string, req return cliproxyexecutor.Response{}, errPick } - entry := logEntryWithRequestID(ctx) - if log.IsLevelEnabled(log.DebugLevel) { - accountType, accountInfo := auth.AccountInfo() - proxyInfo := auth.ProxyInfo() - if accountType == "api_key" { - if proxyInfo != "" { - entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), req.Model, proxyInfo) - } else { - entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), req.Model) - } - } else if accountType == "oauth" { - ident := formatOauthIdentity(auth, provider, accountInfo) - if proxyInfo != "" { - entry.Debugf("Use OAuth %s for model %s %s", ident, req.Model, proxyInfo) - } else { - entry.Debugf("Use OAuth %s for model %s", ident, req.Model) - } - } - } + debugLogAuthSelection(ctx, auth, provider, req.Model) tried[auth.ID] = struct{}{} execCtx := ctx @@ -450,25 +432,7 @@ func (m *Manager) executeCountWithProvider(ctx context.Context, provider string, return cliproxyexecutor.Response{}, errPick } - entry := logEntryWithRequestID(ctx) - if log.IsLevelEnabled(log.DebugLevel) { - accountType, accountInfo := auth.AccountInfo() - proxyInfo := auth.ProxyInfo() - if accountType == "api_key" { - if proxyInfo != "" { - entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), req.Model, proxyInfo) - } else { - entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), req.Model) - } - } else if accountType == "oauth" { - ident := formatOauthIdentity(auth, provider, accountInfo) - if proxyInfo != "" { - entry.Debugf("Use OAuth %s for model %s %s", ident, req.Model, proxyInfo) - } else { - entry.Debugf("Use OAuth %s for model %s", ident, req.Model) - } - } - } + debugLogAuthSelection(ctx, auth, provider, req.Model) tried[auth.ID] = struct{}{} execCtx := ctx @@ -514,25 +478,7 @@ func (m *Manager) executeStreamWithProvider(ctx context.Context, provider string return nil, errPick } - entry := logEntryWithRequestID(ctx) - if log.IsLevelEnabled(log.DebugLevel) { - accountType, accountInfo := auth.AccountInfo() - proxyInfo := auth.ProxyInfo() - if accountType == "api_key" { - if proxyInfo != "" { - entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), req.Model, proxyInfo) - } else { - entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), req.Model) - } - } else if accountType == "oauth" { - ident := formatOauthIdentity(auth, provider, accountInfo) - if proxyInfo != "" { - entry.Debugf("Use OAuth %s for model %s %s", ident, req.Model, proxyInfo) - } else { - entry.Debugf("Use OAuth %s for model %s", ident, req.Model) - } - } - } + debugLogAuthSelection(ctx, auth, provider, req.Model) tried[auth.ID] = struct{}{} execCtx := ctx @@ -1620,6 +1566,35 @@ func logEntryWithRequestID(ctx context.Context) *log.Entry { return log.NewEntry(log.StandardLogger()) } +func debugLogAuthSelection(ctx context.Context, auth *Auth, provider string, model string) { + if !log.IsLevelEnabled(log.DebugLevel) { + return + } + if auth == nil { + return + } + entry := logEntryWithRequestID(ctx) + accountType, accountInfo := auth.AccountInfo() + proxyInfo := auth.ProxyInfo() + if accountType == "api_key" { + if proxyInfo != "" { + entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), model, proxyInfo) + } else { + entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), model) + } + return + } + if accountType != "oauth" { + return + } + ident := formatOauthIdentity(auth, provider, accountInfo) + if proxyInfo != "" { + entry.Debugf("Use OAuth %s for model %s %s", ident, model, proxyInfo) + return + } + entry.Debugf("Use OAuth %s for model %s", ident, model) +} + func formatOauthIdentity(auth *Auth, provider string, accountInfo string) string { if auth == nil { return ""