Skip to content

[Feat] PB-119 @Async 경계 MDC(requestId/userId) 전파 - #230

Merged
PHJ2000 merged 5 commits into
mainfrom
feat/PB-119-mdc2-async-mdc-propagation
Jun 11, 2026
Merged

PHJ2000 merged 5 commits into
mainfrom
feat/PB-119-mdc2-async-mdc-propagation

Conversation

@geonusp

@geonusp geonusp commented Jun 8, 2026 •

Copy link
Copy Markdown
Collaborator

✨ Feature PR

🔗 이슈 링크 (필수)

PR 제목: [Feat] PB-119 @Async 경계 MDC(requestId/userId) 전파


🧩 이 PR의 변경사항 (필수)

전체 중 위치 (Stacked PR 시)

  • Single PR (Stacked 아님). 선행 PB-116(MDC1, 머지 완료) 위에서 진행
  • 선행 PR: [chore] PB-116 로깅 표준 적용 #227 (PB-116 로깅 표준, 머지 완료)
  • 후속 PR: 도메인 로그 키 / 스케줄러 MDC ADR 및 PR

이 PR에서 변경한 것

  • global/logging/MdcTaskDecorator.java (신규): TaskDecorator 구현. 제출 시점 부모 MDC 복사 → worker thread 주입 → 실행 후 복원/정리
  • global/config/AsyncConfig.java (수정): emailTaskExecutor에 setTaskDecorator(new MdcTaskDecorator()) 적용 (initialize() 전 호출)
  • test/.../logging/MdcTaskDecoratorTest.java (신규): 전파/정리/예외/복원 단위 테스트
  • test/.../config/AsyncConfigTest.java (신규): ApplicationContextRunner로 실 executor 경유 전파 + 제출 스레드 MDC 유지 검증

✅ 이 PR이 커버하는 AC (필수)

Covers (이 PR에서 완료)

  • AC1: 부모 스레드 MDC(requestId/userId)가 decorated runnable 내부에서 동일하게 보임
  • AC2: runnable 실행 후 worker thread MDC 정리 (부모 MDC가 비면 clear)
  • AC3: runnable 예외 시에도 finally에서 worker thread MDC 정리/복원
  • AC4: worker thread 기존 MDC가 있으면 실행 후 그 값으로 복원
  • AC5: emailTaskExecutor에 MdcTaskDecorator 적용 확인 (통합 테스트)
  • AC6: 인증 요청 파생 비동기 작업은 userId 유지 / 비인증은 비어 있음 (전파 로직상 보장)

Not covered (후속 작업)

  • 도메인 식별자(notificationId/outboxEventId 등) 로그 정책 → 별도 ADR로 정책 결정 후 후속 PR
  • 스케줄러 jobId/schedulerName 정책 → 별도 ADR로 정책 결정 후 후속 PR
  • traceId/spanId 자동 주입 → ADR-0XX 트레이싱 도입 범위

🧪 테스트 결과 (필수)

로컬

./gradlew spotlessApply test --tests "com.beachcheck.global.logging.MdcTaskDecoratorTest" --tests "com.beachcheck.global.config.AsyncConfigTest"
  • ✅ 결과: BUILD SUCCESSFUL (단위 테스트 4종 + 통합 테스트 1종 통과)
  • 비고: AsyncConfigTest는 ApplicationContextRunner 사용으로 Testcontainers/Docker 불필요

CI

  • (자동 첨부)

Smoke 테스트

  • 시나리오: 회원가입/이메일 재발송 요청 → 요청 스레드와 email-* worker thread 로그에 동일 requestId 노출, 다음 비동기 작업에 이전 requestId/userId 미누수 확인
  • 결과: 수동 검증 예정 (운영/로컬 로그 확인 영역)

🧭 영향 범위 체크 (필수)

  • API 변경 (요약: )
  • DB 변경 (마이그레이션: )
  • 설정 변경 (항목: emailTaskExecutor 빈에 TaskDecorator 적용 — 외부 설정/환경변수 변경 없음)
  • Breaking change (무엇: ) — 로그 컨텍스트 보강만, 동작/응답 불변

💬 리뷰 포인트 (필수)

  • 집중해서 볼 파일/라인:
    • MdcTaskDecorator#decorate — finally의 previousContext 복원/clear 분기 (worker thread 재사용 누수 차단 지점)
    • AsyncConfig#emailTaskExecutor — setTaskDecorator(...)가 initialize() 이전에 호출되는지
  • 트레이드오프/대안:
    • worker MDC를 단순 clear가 아니라 previousContext로 복원 — 같은 스레드에 프레임워크/테스트가 미리 넣어둔 값까지 안전하게 보존하기 위함
    • 새 로그 키는 만들지 않고 MDC1 표준 키(requestId/userId)만 전파 (도메인/스케줄러 키는 ADR 선행)

- MdcTaskDecorator 신규 추가: 작업 제출 시점의 부모 MDC를 worker thread 실행 직전 주입하고 종료 후 원래 값으로 복원
- 부모 MDC가 비어 있으면 worker thread MDC를 clear해 스레드풀 재사용 시 이전 작업 컨텍스트 누수 차단
- emailTaskExecutor에 MdcTaskDecorator 적용해 비동기 이메일 작업 로그에도 동일 requestId/userId가 찍히도록 전파
- MdcTaskDecorator 단위 테스트 추가: 전파/정리/예외 시 정리/worker 기존 MDC 복원 검증
- ApplicationContextRunner로 실제 emailTaskExecutor 경유 전파 및 제출 스레드 MDC 유지 통합 테스트 추가

Refs: #229
@geonusp geonusp changed the title feat: PB-119 @Async 경계 MDC(requestId/userId) 전파 [Feat] PB-119 @Async 경계 MDC(requestId/userId) 전파 Jun 8, 2026
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c06180ad-535d-4352-a4ce-00430f65af4e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/PB-119-mdc2-async-mdc-propagation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@geonusp geonusp self-assigned this Jun 8, 2026
@geonusp geonusp added the feat label Jun 8, 2026
@geonusp
geonusp requested a review from PHJ2000 June 8, 2026 18:46
@PHJ2000

PHJ2000 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

수고하셨습니다

@PHJ2000
PHJ2000 merged commit 5a979ec into main Jun 11, 2026
2 checks passed
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.

[feat] PB-119 MDC2: @Async 실행 경계 MDC(requestId/userId) 전파

2 participants