Skip to content

feat: 异步将LLM调用原始日志写入 AWS S3 - #1

Merged
cuijinyu merged 1 commit into
mainfrom
codex/asynchronously-write-llm-logs-to-aws-s3
Mar 11, 2026
Merged

cuijinyu merged 1 commit into
mainfrom
codex/asynchronously-write-llm-logs-to-aws-s3

Conversation

@cuijinyu

Copy link
Copy Markdown
Owner

Motivation

  • 需要在不阻塞主请求链路的情况下捕获并持久化所有对上游 LLM 的原始请求/响应数据到 AWS S3 以便离线审计与调试。

Description

  • 新增 service/raw_log_s3.go 实现异步上传器,支持通过环境变量开关 RAW_LOG_S3_ENABLED 和相关 RAW_LOG_S3_* 配置(bucket/region/access key/secret/session token/prefix/队列长度/worker 数/最大日志字节数)。
  • 上传器使用队列+worker goroutine 异步入队并通过 SigV4 签名对 S3 发起 PUT 上传,上传失败仅记录系统错误,不影响请求响应。
  • 在 relay/channel/api_request.go 中为所有 HTTP relay 请求统一准备可重复读取的请求体(新增 prepareReusableBody,设置 req.GetBody/req.Body/ContentLength),并在 doRequest 成功返回上游响应后调用 service.AttachRawLogCapture 以捕获并异步上传原始日志。
  • 响应体通过 captureReadCloser 包装并按环境配置的最大字节数截断缓存,发送时将包含请求头、请求体、响应体、状态码、模型/渠道/用户等上下文信息,队列满时会记录 warn 并丢弃以保护主路径。

Testing

  • Ran go test ./service which completed successfully.
  • Ran go test ./relay/channel -run TestNonExistent for quick compile checks on modified package which completed successfully.
  • Ran go test ./relay/... -run TestNonExistent which reported failures in existing repository files (format/fmt usage) unrelated to these changes; those are pre-existing build issues and not introduced by this PR.

Codex Task

@cuijinyu
cuijinyu merged commit b57eeb8 into main Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant