@@ -157,6 +157,7 @@ def handle_event_request(
157
157
cognito_identity_json ,
158
158
invoked_function_arn ,
159
159
epoch_deadline_time_in_ms ,
160
+ tenant_id ,
160
161
log_sink ,
161
162
):
162
163
error_result = None
@@ -167,6 +168,7 @@ def handle_event_request(
167
168
epoch_deadline_time_in_ms ,
168
169
invoke_id ,
169
170
invoked_function_arn ,
171
+ tenant_id ,
170
172
)
171
173
event = lambda_runtime_client .marshaller .unmarshal_request (
172
174
event_body , content_type
@@ -198,9 +200,7 @@ def handle_event_request(
198
200
)
199
201
200
202
if error_result is not None :
201
- from .lambda_literals import lambda_unhandled_exception_warning_message
202
203
203
- logging .warning (lambda_unhandled_exception_warning_message )
204
204
log_error (error_result , log_sink )
205
205
lambda_runtime_client .post_invocation_error (
206
206
invoke_id , to_json (error_result ), to_json (xray_fault )
@@ -228,6 +228,7 @@ def create_lambda_context(
228
228
epoch_deadline_time_in_ms ,
229
229
invoke_id ,
230
230
invoked_function_arn ,
231
+ tenant_id ,
231
232
):
232
233
client_context = None
233
234
if client_context_json :
@@ -242,6 +243,7 @@ def create_lambda_context(
242
243
cognito_identity ,
243
244
epoch_deadline_time_in_ms ,
244
245
invoked_function_arn ,
246
+ tenant_id ,
245
247
)
246
248
247
249
@@ -336,6 +338,7 @@ def emit(self, record):
336
338
class LambdaLoggerFilter (logging .Filter ):
337
339
def filter (self , record ):
338
340
record .aws_request_id = _GLOBAL_AWS_REQUEST_ID or ""
341
+ record .tenant_id = _GLOBAL_TENANT_ID
339
342
return True
340
343
341
344
@@ -444,6 +447,7 @@ def create_log_sink():
444
447
445
448
446
449
_GLOBAL_AWS_REQUEST_ID = None
450
+ _GLOBAL_TENANT_ID = None
447
451
448
452
449
453
def _setup_logging (log_format , log_level , log_sink ):
@@ -486,11 +490,9 @@ def run(app_root, handler, lambda_runtime_api_addr):
486
490
487
491
try :
488
492
_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
490
494
491
495
request_handler = _get_handler (handler )
492
-
493
- # import and initialize the LambdaRuntimeClient lazily.
494
496
from .lambda_runtime_client import LambdaRuntimeClient
495
497
lambda_runtime_client = LambdaRuntimeClient (lambda_runtime_api_addr , use_thread_for_polling_next )
496
498
except FaultException as e :
@@ -501,8 +503,11 @@ def run(app_root, handler, lambda_runtime_api_addr):
501
503
)
502
504
except Exception :
503
505
error_result = build_fault_result (sys .exc_info (), None )
504
-
506
+
505
507
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 )
506
511
log_error (error_result , log_sink )
507
512
lambda_runtime_client .post_init_error (error_result )
508
513
@@ -515,6 +520,7 @@ def run(app_root, handler, lambda_runtime_api_addr):
515
520
event_request = lambda_runtime_client .wait_next_invocation ()
516
521
517
522
_GLOBAL_AWS_REQUEST_ID = event_request .invoke_id
523
+ _GLOBAL_TENANT_ID = event_request .tenant_id
518
524
519
525
update_xray_env_variable (event_request .x_amzn_trace_id )
520
526
@@ -528,5 +534,6 @@ def run(app_root, handler, lambda_runtime_api_addr):
528
534
event_request .cognito_identity ,
529
535
event_request .invoked_function_arn ,
530
536
event_request .deadline_time_in_ms ,
537
+ event_request .tenant_id ,
531
538
log_sink ,
532
539
)
0 commit comments