Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions app/services/recommendation/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,15 @@ async def get_recommendation(
)


async def run_recommendation_and_publish_to_kafka(member_id: int) -> None:
async def run_recommendation_and_publish_to_kafka(member_id: int, trace_id: str | None = None) -> None:
try:
resp = await get_recommendation(session=None, member_id=member_id)
await publish_recommendation_to_kafka(member_id, resp)
await publish_recommendation_to_kafka(member_id, resp, trace_id=trace_id)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

trace_id가 도입되었으나, get_recommendation 호출 시에는 전달되지 않고 있습니다. 전체 프로세스의 추적성(traceability)을 위해 get_recommendation 함수와 그 내부의 RecommendationService에서도 trace_id를 받아 로그에 포함할 수 있도록 개선하는 것이 좋습니다. (참고: get_recommendation 함수의 시그니처 변경도 함께 필요합니다.)

except Exception as e:
logger.error("recommendation: 백그라운드 추천/Kafka 실패 member_id=%s: %s", member_id, e, exc_info=True)
logger.error(
"recommendation: 백그라운드 추천/Kafka 실패 member_id=%s trace_id=%s: %s",
member_id,
(trace_id or "").strip(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

trace_idNone인 경우 (trace_id or "").strip()은 빈 문자열("")을 반환하여 로그에 trace_id=:와 같이 출력됩니다. trace_id를 직접 전달하면 None인 경우 trace_id=None:으로 출력되어 더 명확하며, 불필요한 strip() 호출도 줄일 수 있습니다.

Suggested change
(trace_id or "").strip(),
trace_id,

e,
exc_info=True,
)
Loading