mirror of
https://github.com/outbackdingo/step-ca-webui.git
synced 2026-01-27 18:20:22 +00:00
21 lines
514 B
Python
21 lines
514 B
Python
import threading
|
|
import uuid
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
|
class TraceIdHandler:
|
|
_thread_local = threading.local()
|
|
|
|
@staticmethod
|
|
@asynccontextmanager
|
|
async def logging_scope():
|
|
TraceIdHandler._thread_local.trace_id = uuid.uuid4()
|
|
try:
|
|
yield
|
|
finally:
|
|
del TraceIdHandler._thread_local.trace_id
|
|
|
|
@staticmethod
|
|
def get_current_trace_id() -> uuid.UUID | None:
|
|
return getattr(TraceIdHandler._thread_local, "trace_id", None)
|