Files
fastapi-best-architecture/backend/utils/trace_id.py
T
Wu Clan 6a065797f5 Update request state usage to context variable (#853)
* Update request state usage to context variable

* Update context to custom ctx

* Fix the exception interception in opera log

* restore elapsed
2025-10-16 10:23:39 +08:00

8 lines
250 B
Python

from backend.common.context import ctx
from backend.core.conf import settings
def get_request_trace_id() -> str:
"""从请求头中获取追踪 ID"""
return ctx.get(settings.TRACE_ID_REQUEST_HEADER_KEY, settings.TRACE_ID_LOG_DEFAULT_VALUE)