File tree Expand file tree Collapse file tree 1 file changed +14
-13
lines changed
src/isolate/connections/grpc Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Original file line number Diff line number Diff line change 4444from isolate .connections .grpc .interface import from_grpc
4545
4646IDLE_TIMEOUT_SECONDS = int (os .getenv ("ISOLATE_AGENT_IDLE_TIMEOUT_SECONDS" , "0" ))
47+ CONTEXT_VAR_NAME_LOG = os .getenv ("ISOLATE_CONTEXT_VAR_NAME_LOG" , "" )
4748
4849
4950def get_log_context () -> dict [str , Any ]:
50- """Extract all contextvars that start with LOG_ prefix ."""
51- result = {}
52- for var in contextvars . copy_context ():
53- if var . name . startswith ( "LOG_" ):
54- key = var . name [ 4 :]. lower ()
55- try :
56- value = var . get ()
57- # Ellipsis is a placeholder to indicate it's not set
58- if value is not Ellipsis :
59- result [ key ] = var . get ()
60- except LookupError :
61- pass
62- return result
51+ """Extract the contextvar that is set to the ISOLATE_CONTEXT_VAR_NAME_LOG ."""
52+ if not CONTEXT_VAR_NAME_LOG :
53+ return {}
54+
55+ log_context = next (
56+ contextvars . ContextVar ( CONTEXT_VAR_NAME_LOG ). get (),
57+ None ,
58+ )
59+
60+ if not isinstance ( log_context , dict ):
61+ return {}
62+
63+ return log_context
6364
6465
6566class JsonStdoutProxy :
You can’t perform that action at this time.
0 commit comments