From 3b76b770b96897d953e005f9f35e4f543c10804a Mon Sep 17 00:00:00 2001 From: feitianbubu Date: Tue, 3 Feb 2026 18:42:14 +0800 Subject: [PATCH] feat: add useTimeSeconds in error log --- controller/relay.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/controller/relay.go b/controller/relay.go index 78d21e54f..5310a9fba 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -8,6 +8,7 @@ import ( "log" "net/http" "strings" + "time" "github.com/QuantumNous/new-api/common" "github.com/QuantumNous/new-api/constant" @@ -373,7 +374,12 @@ func processChannelError(c *gin.Context, channelError types.ChannelError, err *t } service.AppendChannelAffinityAdminInfo(c, adminInfo) other["admin_info"] = adminInfo - model.RecordErrorLog(c, userId, channelId, modelName, tokenName, err.MaskSensitiveErrorWithStatusCode(), tokenId, 0, false, userGroup, other) + startTime := common.GetContextKeyTime(c, constant.ContextKeyRequestStartTime) + if startTime.IsZero() { + startTime = time.Now() + } + useTimeSeconds := int(time.Since(startTime).Seconds()) + model.RecordErrorLog(c, userId, channelId, modelName, tokenName, err.MaskSensitiveErrorWithStatusCode(), tokenId, useTimeSeconds, false, userGroup, other) } }