MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / request_context

Function request_context

logging_utils/core/logger.py:95–116  ·  view source on GitHub ↗

Context manager for request lifecycle. Sets request ID and source for all logs within the context. Usage: with request_context("akvdate", source="WORKR"): logger.info("Processing...")

(
    request_id: str, source: str = "WORKR"
)

Source from the content-addressed store, hash-verified

93
94@contextmanager
95def request_context(
96 request_id: str, source: str = "WORKR"
97) -> Generator[None, None, None]:
98 """
99 Context manager for request lifecycle.
100
101 Sets request ID and source for all logs within the context.
102
103 Usage:
104 with request_context("akvdate", source="WORKR"):
105 logger.info("Processing...")
106 """
107 # Set context variables
108 id_token = request_id_var.set(request_id)
109 source_token = source_var.set(source)
110
111 try:
112 yield
113 finally:
114 # Reset context variables
115 request_id_var.reset(id_token)
116 source_var.reset(source_token)
117
118
119# =============================================================================

Calls 2

setMethod · 0.80
resetMethod · 0.80