21 lines
620 B
Python
21 lines
620 B
Python
|
|
"""Memoir Phase1→Phase2→post-commit 链路的 trace id(日志与 compaction context 关联)。"""
|
|||
|
|
|
|||
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
import uuid
|
|||
|
|
|
|||
|
|
|
|||
|
|
def new_memoir_correlation_id() -> str:
|
|||
|
|
return str(uuid.uuid4())
|
|||
|
|
|
|||
|
|
|
|||
|
|
def effective_correlation_id(
|
|||
|
|
*, explicit: str | None, celery_task_id: str | None
|
|||
|
|
) -> str:
|
|||
|
|
"""优先使用 Phase1 传入的 id,否则退化为 Celery task id。"""
|
|||
|
|
if explicit and str(explicit).strip():
|
|||
|
|
return str(explicit).strip()
|
|||
|
|
if celery_task_id and str(celery_task_id).strip():
|
|||
|
|
return str(celery_task_id).strip()
|
|||
|
|
return new_memoir_correlation_id()
|