希望将请求体落盘
目前请求体仅在 Redis 中记录,并且设置了 TTL,过期后数据会被自动删除。建议增加一个配置开关,用于控制是否持久化保存请求体,将请求体保存到数据库或文件。
Thank you for this feature suggestion.
Current Architecture Analysis:
Based on my investigation of the codebase, request bodies are currently stored only in Redis with TTL, not in the database:
-
Redis Storage (
src/lib/session-manager.ts:965-994):- Request messages are stored with keys like
session:{sessionId}:messagesorsession:{sessionId}:req:{sequence}:messages - TTL is controlled by
SESSION_TTLenvironment variable (default: 300 seconds / 5 minutes) - The
STORE_SESSION_MESSAGESconfig controls whether content is redacted ([REDACTED]) or stored in original form
- Request messages are stored with keys like
-
Database Storage (
src/drizzle/schema.ts:429-475):- The
message_requesttable stores request metadata (provider_id, user_id, model, cost, tokens, session_id, status_code, etc.) - It does NOT currently have columns for request body or response body content
- The
Implementation Considerations:
-
Schema Extension: Adding
request_body(JSONB) and optionallyresponse_body(JSONB) columns to themessage_requesttable would be the logical approach for database persistence. -
Configuration: A new environment variable (e.g.,
PERSIST_REQUEST_BODY=true/false) could control this feature independently from the existing Redis caching. -
Storage Size: Request bodies can be large, especially with long conversations or multi-modal content. This would significantly increase database storage requirements.
-
Privacy: The existing
STORE_SESSION_MESSAGESredaction logic insrc/lib/utils/message-redaction.tsshould be respected - when disabled, content should be redacted before persistence. -
Performance Impact: Writing large JSON blobs to PostgreSQL on every request may impact throughput. Consider async write mode (similar to existing
MESSAGE_REQUEST_WRITE_MODE=async).
Related Code:
- Session message storage:
src/lib/session-manager.ts:965-994 - Request metadata persistence:
src/repository/message.ts:19-72 - Message redaction:
src/lib/utils/message-redaction.ts - Environment config:
src/lib/config/env.schema.ts:101-109
Automated response from Claude AI
你好,当前提供了langfuse集成,可参考官网文档完成配置接入。并交由langfuse完成请求体记录。
由于请求体体积过大,不建议保存到本地。