mirror of
https://github.com/dartdavros/chatballs.git
synced 2026-10-05 01:14:58 +03:00
15 lines
410 B
Python
15 lines
410 B
Python
from contextvars import ContextVar
|
|
from uuid import uuid4
|
|
|
|
correlation_id_var: ContextVar[str] = ContextVar("correlation_id", default="")
|
|
|
|
|
|
def ensure_correlation_id(value: str | None = None) -> str:
|
|
correlation_id = value or str(uuid4())
|
|
correlation_id_var.set(correlation_id)
|
|
return correlation_id
|
|
|
|
|
|
def get_correlation_id() -> str:
|
|
return correlation_id_var.get() or ensure_correlation_id()
|