From 9dc25d9abf849fee1273b629b0930614c8668072 Mon Sep 17 00:00:00 2001 From: jidekin <294297426@qq.com> Date: Fri, 23 Oct 2026 11:29:06 +0800 Subject: [PATCH] =?UTF-8?q?chore(metrics):=20=E8=A1=A5=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=20RID=20contextvar=EF=BC=882.9.0=20=E7=9A=84=20token=20?= =?UTF-8?q?=E4=BE=A7=E4=BF=A1=E9=81=93=E4=BE=9D=E8=B5=96=E5=AE=83=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上一个提交漏了本文件:main.py 的 RID.set(rid) 与 calllog.note_tokens 都依赖 app/metrics.py 里新加的 RID ContextVar,不同步提交会导致仓库检出后无法启动。 --- app/metrics.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/metrics.py b/app/metrics.py index eba4213..ff58c6c 100644 --- a/app/metrics.py +++ b/app/metrics.py @@ -20,6 +20,8 @@ log = logging.getLogger("api-gateway.metrics") # 普通账号只看自己名下(会话 + 自己的 API Key)产生的记录,admin 看全部。 ACCOUNT: ContextVar[str] = ContextVar("gw_account", default="anonymous") ROLE: ContextVar[str] = ContextVar("gw_role", default="member") +# 2026-10-23 调用日志落地:请求级 rid 上下文,供 token 记账关联到具体那条日志 +RID: ContextVar[str] = ContextVar("gw_rid", default="") # M4: 按 rid 暂存请求体摘要(由 main.py 中间件写入)。AccessLog.add() 用它给每条日志 # 附上「具体请求内容」,便于在日志页查看实际发了什么。有界缓存,防无界增长。