You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
448 B
Python
19 lines
448 B
Python
from contextvars import ContextVar
|
|
from typing import Optional, Final
|
|
|
|
REQUEST_ID_CTX_KEY: Final[str] = "request_id"
|
|
_request_id_ctx_var: ContextVar[Optional[str]] = ContextVar(
|
|
REQUEST_ID_CTX_KEY, default=None)
|
|
|
|
|
|
def get_request_id() -> Optional[str]:
|
|
return _request_id_ctx_var.get()
|
|
|
|
|
|
def set_request_id(request_id: str):
|
|
return _request_id_ctx_var.set(request_id)
|
|
|
|
|
|
def reset_request_id(token):
|
|
_request_id_ctx_var.reset(token)
|