refactor(logging): pass request entry into auth selection log

Avoid re-creating the request-scoped log entry in the helper and use a switch for account type dispatch.
This commit is contained in:
Michael Velbaum
2025-12-28 15:51:11 +02:00
parent 48f6d7abdf
commit 48f19aab51

View File

@@ -386,7 +386,10 @@ func (m *Manager) executeWithProvider(ctx context.Context, provider string, req
return cliproxyexecutor.Response{}, errPick return cliproxyexecutor.Response{}, errPick
} }
debugLogAuthSelection(ctx, auth, provider, req.Model) if log.IsLevelEnabled(log.DebugLevel) {
entry := logEntryWithRequestID(ctx)
debugLogAuthSelection(entry, auth, provider, req.Model)
}
tried[auth.ID] = struct{}{} tried[auth.ID] = struct{}{}
execCtx := ctx execCtx := ctx
@@ -432,7 +435,10 @@ func (m *Manager) executeCountWithProvider(ctx context.Context, provider string,
return cliproxyexecutor.Response{}, errPick return cliproxyexecutor.Response{}, errPick
} }
debugLogAuthSelection(ctx, auth, provider, req.Model) if log.IsLevelEnabled(log.DebugLevel) {
entry := logEntryWithRequestID(ctx)
debugLogAuthSelection(entry, auth, provider, req.Model)
}
tried[auth.ID] = struct{}{} tried[auth.ID] = struct{}{}
execCtx := ctx execCtx := ctx
@@ -478,7 +484,10 @@ func (m *Manager) executeStreamWithProvider(ctx context.Context, provider string
return nil, errPick return nil, errPick
} }
debugLogAuthSelection(ctx, auth, provider, req.Model) if log.IsLevelEnabled(log.DebugLevel) {
entry := logEntryWithRequestID(ctx)
debugLogAuthSelection(entry, auth, provider, req.Model)
}
tried[auth.ID] = struct{}{} tried[auth.ID] = struct{}{}
execCtx := ctx execCtx := ctx
@@ -1566,27 +1575,20 @@ func logEntryWithRequestID(ctx context.Context) *log.Entry {
return log.NewEntry(log.StandardLogger()) return log.NewEntry(log.StandardLogger())
} }
func debugLogAuthSelection(ctx context.Context, auth *Auth, provider string, model string) { func debugLogAuthSelection(entry *log.Entry, auth *Auth, provider string, model string) {
if !log.IsLevelEnabled(log.DebugLevel) { if entry == nil || auth == nil {
return return
} }
if auth == nil {
return
}
entry := logEntryWithRequestID(ctx)
accountType, accountInfo := auth.AccountInfo() accountType, accountInfo := auth.AccountInfo()
proxyInfo := auth.ProxyInfo() proxyInfo := auth.ProxyInfo()
if accountType == "api_key" { switch accountType {
case "api_key":
if proxyInfo != "" { if proxyInfo != "" {
entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), model, proxyInfo) entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), model, proxyInfo)
} else { return
}
entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), model) entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), model)
} case "oauth":
return
}
if accountType != "oauth" {
return
}
ident := formatOauthIdentity(auth, provider, accountInfo) ident := formatOauthIdentity(auth, provider, accountInfo)
if proxyInfo != "" { if proxyInfo != "" {
entry.Debugf("Use OAuth %s for model %s %s", ident, model, proxyInfo) entry.Debugf("Use OAuth %s for model %s %s", ident, model, proxyInfo)
@@ -1594,6 +1596,7 @@ func debugLogAuthSelection(ctx context.Context, auth *Auth, provider string, mod
} }
entry.Debugf("Use OAuth %s for model %s", ident, model) entry.Debugf("Use OAuth %s for model %s", ident, model)
} }
}
func formatOauthIdentity(auth *Auth, provider string, accountInfo string) string { func formatOauthIdentity(auth *Auth, provider string, accountInfo string) string {
if auth == nil { if auth == nil {