Repository navigation
[feature] 요청별 traceId MDC 로깅 도입 - #164
Merged
Merged
Conversation
요청마다 traceId를 MDC에 심어 모든 로그에 노출한다.
- MdcFilter를 최우선 순서로 등록해 Security 필터체인보다 먼저 실행(401·예외 로그도 포함)
- nginx의 X-Request-Id를 우선 사용(길이·문자 검증), 없거나 부적합하면 생성
- 로그 패턴에 %X{traceId} 추가
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
요약
요청마다 traceId를 MDC에 심어 모든 로그에 노출하고, nginx의 X-Request-Id를 재사용해 nginx와 앱 로그를 같은 id로 연결한다.
What — 무엇을 바꿨나
common/logging/MdcFilter추가: 요청 진입 시 traceId를 MDC에 세팅, 종료 시MDC.clear()@Order(HIGHEST_PRECEDENCE)로 Security 필터체인보다 먼저 실행 → 401·예외 로그에도 traceId가 남음X-Request-Id헤더 우선 사용(길이 64·[A-Za-z0-9-]검증), 없거나 부적합하면 UUID 생성application.yml에logging.pattern.level: "%5p [%X{traceId:-}]"추가 (전 프로파일 상속)MdcFilterTest추가 (순수 단위)Why — 왜 필요한가
How — 어떻게 구현했나
logging.pattern.level만 확장해 최소 변경으로 traceId를 노출(%X{traceId:-}로 traceId 없는 스레드는[]처리)@Async메서드 내부 로그로의 전파(스레드 경계 넘김)는 후속 이슈(@async 풀 분리 + MDC TaskDecorator)에서 처리한다. 머지 시점에 async 로그의 traceId가 비어 있는 것은 정상체크리스트
./gradlew test)관련 이슈
기타 / 리뷰 포인트
X-Request-Id를 받도록 구현했고, nginx↔앱 상관관계를 완성하려면 배포 서버 nginx에 아래 반영이 필요하다.