From 4c4e6b10d792734b7f90d6d7ecbba54dc4ac647c Mon Sep 17 00:00:00 2001 From: sk-dev-ai Date: Sun, 4 Oct 2026 19:57:11 +0530 Subject: [PATCH] log: record per-attempt legs on the request line Fill in the Legs field the request log already renders: append one key:status:ms entry per upstream attempt (anonymized label for the public lane, redacted key suffix otherwise; timeout/transport markers for errors). A multi-attempt turn now reads as a single chain instead of requiring attempt-log correlation. --- internal/gateway/upstream.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/gateway/upstream.go b/internal/gateway/upstream.go index e2ba172..6114bbe 100644 --- a/internal/gateway/upstream.go +++ b/internal/gateway/upstream.go @@ -11,6 +11,7 @@ import ( "io" "net/http" "sort" + "strconv" "strings" "time" @@ -767,6 +768,25 @@ func (g *Gateway) recordUpstreamAttempt(ctx context.Context, route models.Route, if meta := telemetry.MetaFromContext(ctx); meta != nil { meta.AttemptOutcome = outcome meta.Protocol = route.Protocol + // Append a per-attempt leg (key:status:ms, anonymized for the + // public lane) so the request log shows the whole attempt chain + // at a glance. Only the redacted key suffix is retained. + label := keyID + if anonymous { + label = "anon" + } + leg := label + ":" + if err != nil { + if errors.Is(err, context.DeadlineExceeded) { + leg += "timeout" + } else { + leg += "transport" + } + } else { + leg += strconv.Itoa(status) + } + leg += ":" + strconv.FormatInt(max(duration.Milliseconds(), 0), 10) + "ms" + meta.Legs = append(meta.Legs, leg) } if g.monitor == nil { return