mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
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.
This commit is contained in:
1 parent
79a208a467
commit
4c4e6b10d7
1 file changed
+20
@@ -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
|
||||
|
||||
Reference in new issue
Block a user