log: name upstream error class and skipped fallback tiers

Log a 240-char snippet of non-2xx upstream bodies (upstream_error_body)
so the 400 class is visible without dumping full payloads; the hub
redactor scrubs configured secrets. Also log skipped fallback tiers
(fallback_tier_skipped) at debug when a non-preferred tier's request
shape fails to prepare, instead of silently dropping the tier.
This commit is contained in:
sk-dev-ai committed 2026-10-04 19:55:42 +05:30
1 parent 79a208a467
commit 6c7dbfe6ab
2 files changed
+11

No files matched your search

+1
View File
@@ -401,6 +401,7 @@ func (g *Gateway) prepareRouteBodies(from wire.Protocol, route models.Route, inp
// preferred tier. Do not reject a request before the preferred
// upstream has even been tried; that tier is attempted only if
// the request actually falls back.
g.logger.Debug("skipping fallback tier with incompatible request shape", "component", "conversion", "event", "fallback_tier_skipped", "model", jsonutil.StringAt(input, "model"), "tier", tier, "protocol", protocol, "error", err)
continue
}
return nil, fmt.Errorf("prepare %s upstream request: %w", tier, err)
+10
View File
@@ -73,6 +73,16 @@ func (g *Gateway) doUpstream(ctx context.Context, route models.Route, bodies map
// Restore the body so downstream error handling still sees the original
// payload when no retry happens below.
resp.Body = io.NopCloser(bytes.NewReader(errBody))
// Log a capped snippet of the upstream error body so the 400 class is
// visible without dumping full payloads. Bodies stay out of attempt
// records; the hub redactor scrubs configured secrets from log output.
if len(errBody) > 0 {
snippet := string(errBody)
if len(snippet) > 240 {
snippet = snippet[:240]
}
g.logger.Info("upstream error returned or retried", "component", "upstream", "event", "upstream_error_body", "request_id", ids.Request, "model", route.ID, "status", resp.StatusCode, "snippet", snippet)
}
if !isStaleReasoningReference(errBody) {
return resp, effectiveRoute, nil
}