Skip to content

feat:为 usage_logs 持久化脱敏后的用户输入摘要 - #3530

Open
c99180013-sys wants to merge 1 commit into
Wei-Shaw:mainfrom
c99180013-sys:feat/usage-input-excerpt
Open

feat:为 usage_logs 持久化脱敏后的用户输入摘要#3530
c99180013-sys wants to merge 1 commit into
Wei-Shaw:mainfrom
c99180013-sys:feat/usage-input-excerpt

Conversation

@c99180013-sys

Copy link
Copy Markdown

变更说明

本 PR 为 usage_logs 增加了用户输入摘要的持久化能力,方便在排查请求问题、复现异常输入、定位计费或风控争议时,能够直接看到一段经过脱敏和截断处理后的输入摘要。

主要改动

  • usage_logs 新增 input_excerpt 字段
  • 新增数据库迁移:
    • backend/migrations/154_add_usage_log_input_excerpt.sql
  • 增加统一的输入摘要提取逻辑,支持多种请求格式:
    • Chat Completions messages
    • Responses input
    • Embeddings input
    • Images prompt
    • Gemini/兼容协议 contents
  • 对提取出的摘要做统一处理:
    • 敏感信息脱敏
    • 长文本截断
    • 尽量只保留用户可读文本,不保留大块二进制/base64内容
  • input_excerpt 接入 usage log 主链路落库
  • input_excerpt 暴露到 usage log DTO
  • 补充了对应测试

实现细节

  • 复用了现有内容审计相关的脱敏思路,避免把 token、secret、Bearer、URL 等敏感信息原样写入日志
  • 摘要字段通过统一提取器生成,避免在各个 handler 中散落重复逻辑
  • 管理后台可查看该字段,便于排查问题

使用价值

这个字段主要用于:

  • 排查用户具体发了什么 prompt
  • 定位异常计费、异常拦截、异常请求
  • 辅助复现上下游兼容性问题
  • 降低只靠 request_id 排查时的信息缺失

注意事项

@github-actions

github-actions Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@c99180013-sys

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jun 27, 2026
@c99180013-sys c99180013-sys changed the title feat;为 usage_logs 持久化脱敏后的用户输入摘要 feat:为 usage_logs 持久化脱敏后的用户输入摘要 Jun 27, 2026
@yingjianjian

Copy link
Copy Markdown

When can this feature be launched

muneebhashone pushed a commit to muneebhashone/sub2api that referenced this pull request Aug 25, 2026
muneebhashone pushed a commit to muneebhashone/sub2api that referenced this pull request Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants