@@ -157,6 +157,7 @@ def handle_event_request(
157157 cognito_identity_json ,
158158 invoked_function_arn ,
159159 epoch_deadline_time_in_ms ,
160+ tenant_id ,
160161 log_sink ,
161162):
162163 error_result = None
@@ -167,6 +168,7 @@ def handle_event_request(
167168 epoch_deadline_time_in_ms ,
168169 invoke_id ,
169170 invoked_function_arn ,
171+ tenant_id ,
170172 )
171173 event = lambda_runtime_client .marshaller .unmarshal_request (
172174 event_body , content_type
@@ -198,9 +200,7 @@ def handle_event_request(
198200 )
199201
200202 if error_result is not None :
201- from .lambda_literals import lambda_unhandled_exception_warning_message
202203
203- logging .warning (lambda_unhandled_exception_warning_message )
204204 log_error (error_result , log_sink )
205205 lambda_runtime_client .post_invocation_error (
206206 invoke_id , to_json (error_result ), to_json (xray_fault )
@@ -228,6 +228,7 @@ def create_lambda_context(
228228 epoch_deadline_time_in_ms ,
229229 invoke_id ,
230230 invoked_function_arn ,
231+ tenant_id ,
231232):
232233 client_context = None
233234 if client_context_json :
@@ -242,6 +243,7 @@ def create_lambda_context(
242243 cognito_identity ,
243244 epoch_deadline_time_in_ms ,
244245 invoked_function_arn ,
246+ tenant_id ,
245247 )
246248
247249
@@ -336,6 +338,7 @@ def emit(self, record):
336338class LambdaLoggerFilter (logging .Filter ):
337339 def filter (self , record ):
338340 record .aws_request_id = _GLOBAL_AWS_REQUEST_ID or ""
341+ record .tenant_id = _GLOBAL_TENANT_ID
339342 return True
340343
341344
@@ -444,6 +447,7 @@ def create_log_sink():
444447
445448
446449_GLOBAL_AWS_REQUEST_ID = None
450+ _GLOBAL_TENANT_ID = None
447451
448452
449453def _setup_logging (log_format , log_level , log_sink ):
@@ -486,11 +490,9 @@ def run(app_root, handler, lambda_runtime_api_addr):
486490
487491 try :
488492 _setup_logging (_AWS_LAMBDA_LOG_FORMAT , _AWS_LAMBDA_LOG_LEVEL , log_sink )
489- global _GLOBAL_AWS_REQUEST_ID
493+ global _GLOBAL_AWS_REQUEST_ID , _GLOBAL_TENANT_ID
490494
491495 request_handler = _get_handler (handler )
492-
493- # import and initialize the LambdaRuntimeClient lazily.
494496 from .lambda_runtime_client import LambdaRuntimeClient
495497 lambda_runtime_client = LambdaRuntimeClient (lambda_runtime_api_addr , use_thread_for_polling_next )
496498 except FaultException as e :
@@ -501,8 +503,11 @@ def run(app_root, handler, lambda_runtime_api_addr):
501503 )
502504 except Exception :
503505 error_result = build_fault_result (sys .exc_info (), None )
504-
506+
505507 if error_result is not None :
508+ from .lambda_literals import lambda_unhandled_exception_warning_message
509+
510+ logging .warning (lambda_unhandled_exception_warning_message )
506511 log_error (error_result , log_sink )
507512 lambda_runtime_client .post_init_error (error_result )
508513
@@ -515,6 +520,7 @@ def run(app_root, handler, lambda_runtime_api_addr):
515520 event_request = lambda_runtime_client .wait_next_invocation ()
516521
517522 _GLOBAL_AWS_REQUEST_ID = event_request .invoke_id
523+ _GLOBAL_TENANT_ID = event_request .tenant_id
518524
519525 update_xray_env_variable (event_request .x_amzn_trace_id )
520526
@@ -528,5 +534,6 @@ def run(app_root, handler, lambda_runtime_api_addr):
528534 event_request .cognito_identity ,
529535 event_request .invoked_function_arn ,
530536 event_request .deadline_time_in_ms ,
537+ event_request .tenant_id ,
531538 log_sink ,
532539 )
0 commit comments