mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-10-04 09:11:03 +00:00
16 lines
377 B
Python
16 lines
377 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
from fastapi import Request
|
|
|
|
from backend.core.conf import settings
|
|
|
|
|
|
def get_request_trace_id(request: Request) -> str:
|
|
"""
|
|
从请求头中获取追踪 ID
|
|
|
|
:param request: FastAPI 请求对象
|
|
:return:
|
|
"""
|
|
return request.headers.get(settings.TRACE_ID_REQUEST_HEADER_KEY) or settings.LOG_CID_DEFAULT_VALUE
|