Skip to content

feat: add LLM request lifecycle logging with session correlation#1365

Closed
shudonglin wants to merge 1 commit intoWei-Shaw:mainfrom
shudonglin:feature/eng-review-optimization-plan
Closed

feat: add LLM request lifecycle logging with session correlation#1365
shudonglin wants to merge 1 commit intoWei-Shaw:mainfrom
shudonglin:feature/eng-review-optimization-plan

Conversation

@shudonglin
Copy link
Copy Markdown

Summary

  • Add session_hash, client_request_id, platform columns to usage_logs for conversation-level tracing
  • Create dedicated AccessLogger that emits structured JSON log lines per LLM request (session, routing, latency, tokens, retry context)
  • Wire access log into all 7 gateway handler methods (Anthropic x3, OpenAI x2, Gemini, Sora)
  • Add AccessLog config section (enable/disable, file path, body capture toggle, rotation)
  • Include engineering optimization plan doc from codebase review

Config

access_log:
  enabled: true
  include_body: false
  max_body_bytes: 10240

Or env: ACCESS_LOG_ENABLED=true

Test plan

  • Unit tests for AccessLogger (JSON output, nil safety)
  • Unit tests for BuildAccessLogEntry (field mapping, success/failure)
  • Existing repository unit tests pass with new columns
  • Docker build succeeds
  • Migration verified: 3 columns + 3 indexes on usage_logs
  • App starts healthy with access_log enabled

🤖 Generated with Claude Code

Add comprehensive per-request structured logging for all LLM gateway
requests, enabling conversation-level tracing across multi-turn sessions.

Changes:
- Add session_hash, client_request_id, platform columns to usage_logs
  table with partial indexes for efficient session queries
- Create dedicated AccessLogger (JSON file, rotated via lumberjack)
  that emits one structured log line per LLM request with full
  lifecycle data: session, routing, latency, tokens, retry context
- Wire access log emission into all 7 gateway handler methods
  (Anthropic x3, OpenAI x2, Gemini, Sora)
- Add AccessLog config (enabled, file_path, include_body, rotation)
- Include engineering optimization plan from codebase review

Enable with ACCESS_LOG_ENABLED=true or access_log.enabled: true in config.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant