Skip to content

fix(logging): emit explicit auth log line so user_email actually reaches stdout - #96

Merged
wonzz merged 1 commit into
mainfrom
fix/log-auth-request-line
Jul 3, 2026
Merged

wonzz merged 1 commit into
mainfrom
fix/log-auth-request-line

Conversation

@0206pdh

@0206pdh 0206pdh commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • 프로덕션 파드(utterai-api-blue) 로그를 kubectl logs로 직접 확인해보니 2시간 동안 JSON 포맷 로그가 0줄이었음 — 전부 uvicorn 기본 access log 포맷(INFO: ... "GET ..." 200 OK)
  • 원인: uvicorn CLI가 uvicorn/uvicorn.access/uvicorn.error 로거를 자체 핸들러 + plain-text 포매터로 구성하면서 propagate: False를 설정 → OtelJsonFormatter가 붙은 root logger를 완전히 우회
  • 게다가 앱 코드 어디에도 요청 단위 명시적 logger.info() 호출이 없어서, span attribute(user.email, fix(logging): read user_email from span attributes, not a ContextVar #95)는 정상 기록되고 있었지만 그걸 실제 stdout 로그 줄로 내보내는 지점 자체가 없었음 → RDS 접근 문제가 아니라(요청은 전부 200 OK) 애초에 로그 자체가 안 찍히는 문제였음
  • get_current_user()에서 span attribute 세팅 직후(span이 아직 활성 상태) 명시적으로 logger.info() 한 줄 추가

Test plan

  • 로컬에서 OtelJsonFormatter + span + logger.info() 전체 플로우 재현 → user_email 필드가 정확히 JSON에 포함되는 것 확인
  • 배포 후 kubectl logs로 실제 stdout에 "user_email": "..." JSON 라인이 찍히는지 확인
  • VOC UI Pod Logs에서 user.email 검색으로 실제 로그 조회되는지 확인

…hes stdout

프로덕션 파드 로그를 직접 확인해보니 2시간 동안 JSON 포맷 로그가 0줄이었다.
uvicorn CLI가 "uvicorn"/"uvicorn.access"/"uvicorn.error" 로거를 자체
핸들러+plain-text 포매터로 구성하면서 propagate=False로 설정하기 때문에,
모든 요청 로그(access log)가 OtelJsonFormatter가 붙은 root logger를
완전히 우회하고 있었다. 게다가 앱 코드 어디에도 요청 단위로 명시적인
logger.info() 호출이 없어서, span attribute(user.email)는 정상 기록되고
있었음에도(#95 이후) 그걸 실제 로그 줄로 내보내는 지점 자체가 없었다.

get_current_user()에서 span attribute를 세팅한 직후(=span이 아직 살아있는
시점) 명시적으로 로그 한 줄을 남기도록 추가. 로컬에서 OtelJsonFormatter를
직접 실행해 user_email 필드가 정확히 찍히는 것까지 확인함.
@wonzz
wonzz self-requested a review July 3, 2026 05:36
@wonzz
wonzz merged commit d4625ad into main Jul 3, 2026
1 check passed
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