feat(agent-runtime): 补全测试替身编排闭环
This commit is contained in:
+10
-1
@@ -12,6 +12,15 @@ request_id_context: contextvars.ContextVar[str] = contextvars.ContextVar(
|
||||
SENSITIVE_KEYS = {"api_key", "authorization", "cookie", "password", "secret", "token"}
|
||||
|
||||
|
||||
def _is_sensitive_key(key: object) -> bool:
|
||||
"""识别常见秘密字段,同时避免把 `token_count` 等统计字段误判为秘密。"""
|
||||
|
||||
normalized = str(key).strip().lower().replace("-", "_")
|
||||
if normalized in SENSITIVE_KEYS:
|
||||
return True
|
||||
return normalized.endswith(("_api_key", "_password", "_secret", "_cookie", "_token"))
|
||||
|
||||
|
||||
class RequestContextFilter(logging.Filter):
|
||||
"""向每条日志补充请求关联标识,后台任务没有请求时使用短横线。"""
|
||||
|
||||
@@ -25,7 +34,7 @@ def sanitize_summary(value: Any) -> Any:
|
||||
|
||||
if isinstance(value, Mapping):
|
||||
return {
|
||||
str(key): "***" if str(key).lower() in SENSITIVE_KEYS else sanitize_summary(item)
|
||||
str(key): "***" if _is_sensitive_key(key) else sanitize_summary(item)
|
||||
for key, item in value.items()
|
||||
}
|
||||
if isinstance(value, list):
|
||||
|
||||
Reference in New Issue
Block a user