mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
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:
1 parent
79a208a467
commit
6c7dbfe6ab
2 files changed
+11
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user