@@ -88,6 +88,7 @@ def test_handle_event_request_happy_case(self):
88
88
{},
89
89
"invoked_function_arn" ,
90
90
0 ,
91
+ "tenant_id" ,
91
92
bootstrap .StandardLogSink (),
92
93
)
93
94
self .lambda_runtime .post_invocation_result .assert_called_once_with (
@@ -111,6 +112,7 @@ def test_handle_event_request_invalid_client_context(self):
111
112
{},
112
113
"invoked_function_arn" ,
113
114
0 ,
115
+ "tenant_id" ,
114
116
bootstrap .StandardLogSink (),
115
117
)
116
118
args , _ = self .lambda_runtime .post_invocation_error .call_args
@@ -152,6 +154,7 @@ def test_handle_event_request_invalid_cognito_idenity(self):
152
154
"invalid_cognito_identity" ,
153
155
"invoked_function_arn" ,
154
156
0 ,
157
+ "tenant_id" ,
155
158
bootstrap .StandardLogSink (),
156
159
)
157
160
args , _ = self .lambda_runtime .post_invocation_error .call_args
@@ -194,6 +197,7 @@ def test_handle_event_request_invalid_event_body(self):
194
197
{},
195
198
"invoked_function_arn" ,
196
199
0 ,
200
+ "tenant_id" ,
197
201
bootstrap .StandardLogSink (),
198
202
)
199
203
args , _ = self .lambda_runtime .post_invocation_error .call_args
@@ -238,6 +242,7 @@ def invalid_json_response(json_input, lambda_context):
238
242
{},
239
243
"invoked_function_arn" ,
240
244
0 ,
245
+ "tenant_id" ,
241
246
bootstrap .StandardLogSink (),
242
247
)
243
248
args , _ = self .lambda_runtime .post_invocation_error .call_args
@@ -283,6 +288,7 @@ def __init__(self, message):
283
288
{},
284
289
"invoked_function_arn" ,
285
290
0 ,
291
+ "tenant_id" ,
286
292
bootstrap .StandardLogSink (),
287
293
)
288
294
args , _ = self .lambda_runtime .post_invocation_error .call_args
@@ -335,6 +341,7 @@ def __init__(self, message):
335
341
{},
336
342
"invoked_function_arn" ,
337
343
0 ,
344
+ "tenant_id" ,
338
345
bootstrap .StandardLogSink (),
339
346
)
340
347
args , _ = self .lambda_runtime .post_invocation_error .call_args
@@ -386,6 +393,7 @@ def unable_to_import_module(json_input, lambda_context):
386
393
{},
387
394
"invoked_function_arn" ,
388
395
0 ,
396
+ "tenant_id" ,
389
397
bootstrap .StandardLogSink (),
390
398
)
391
399
args , _ = self .lambda_runtime .post_invocation_error .call_args
@@ -425,6 +433,7 @@ def raise_exception_handler(json_input, lambda_context):
425
433
{},
426
434
"invoked_function_arn" ,
427
435
0 ,
436
+ "tenant_id" ,
428
437
bootstrap .StandardLogSink (),
429
438
)
430
439
args , _ = self .lambda_runtime .post_invocation_error .call_args
@@ -475,6 +484,7 @@ def raise_exception_handler(json_input, lambda_context):
475
484
{},
476
485
"invoked_function_arn" ,
477
486
0 ,
487
+ "tenant_id" ,
478
488
bootstrap .StandardLogSink (),
479
489
)
480
490
@@ -514,6 +524,7 @@ def raise_exception_handler(json_input, lambda_context):
514
524
{},
515
525
"invoked_function_arn" ,
516
526
0 ,
527
+ "tenant_id" ,
517
528
bootstrap .StandardLogSink (),
518
529
)
519
530
error_logs = (
@@ -546,6 +557,7 @@ def raise_exception_handler(json_input, lambda_context):
546
557
{},
547
558
"invoked_function_arn" ,
548
559
0 ,
560
+ "tenant_id" ,
549
561
bootstrap .StandardLogSink (),
550
562
)
551
563
error_logs = (
@@ -578,6 +590,7 @@ def raise_exception_handler(json_input, lambda_context):
578
590
{},
579
591
"invoked_function_arn" ,
580
592
0 ,
593
+ "tenant_id" ,
581
594
bootstrap .StandardLogSink (),
582
595
)
583
596
error_logs = (
@@ -619,6 +632,7 @@ def raise_exception_handler(json_input, lambda_context):
619
632
{},
620
633
"invoked_function_arn" ,
621
634
0 ,
635
+ "tenant_id" ,
622
636
bootstrap .StandardLogSink (),
623
637
)
624
638
error_logs = lambda_unhandled_exception_warning_message + "\n [ERROR]\r "
@@ -652,6 +666,7 @@ def raise_exception_handler(json_input, lambda_context):
652
666
{},
653
667
"invoked_function_arn" ,
654
668
0 ,
669
+ "tenant_id" ,
655
670
bootstrap .StandardLogSink (),
656
671
)
657
672
@@ -868,6 +883,7 @@ def test_application_json(self):
868
883
cognito_identity_json = None ,
869
884
invoked_function_arn = "invocation-arn" ,
870
885
epoch_deadline_time_in_ms = 1415836801003 ,
886
+ tenant_id = None ,
871
887
log_sink = bootstrap .StandardLogSink (),
872
888
)
873
889
@@ -887,6 +903,7 @@ def test_binary_request_binary_response(self):
887
903
cognito_identity_json = None ,
888
904
invoked_function_arn = "invocation-arn" ,
889
905
epoch_deadline_time_in_ms = 1415836801003 ,
906
+ tenant_id = None ,
890
907
log_sink = bootstrap .StandardLogSink (),
891
908
)
892
909
@@ -906,6 +923,7 @@ def test_json_request_binary_response(self):
906
923
cognito_identity_json = None ,
907
924
invoked_function_arn = "invocation-arn" ,
908
925
epoch_deadline_time_in_ms = 1415836801003 ,
926
+ tenant_id = None ,
909
927
log_sink = bootstrap .StandardLogSink (),
910
928
)
911
929
@@ -924,6 +942,7 @@ def test_binary_with_application_json(self):
924
942
cognito_identity_json = None ,
925
943
invoked_function_arn = "invocation-arn" ,
926
944
epoch_deadline_time_in_ms = 1415836801003 ,
945
+ tenant_id = None ,
927
946
log_sink = bootstrap .StandardLogSink (),
928
947
)
929
948
@@ -1357,6 +1376,31 @@ def test_json_formatter(self, mock_stderr):
1357
1376
)
1358
1377
self .assertEqual (mock_stderr .getvalue (), "" )
1359
1378
1379
+ @patch ("awslambdaric.bootstrap._GLOBAL_TENANT_ID" , "test-tenant-id" )
1380
+ @patch ("sys.stderr" , new_callable = StringIO )
1381
+ def test_json_formatter_with_tenant_id (self , mock_stderr ):
1382
+ logger = logging .getLogger ("a.b" )
1383
+ level = logging .INFO
1384
+ message = "Test json formatting with tenant id"
1385
+ expected = {
1386
+ "level" : "INFO" ,
1387
+ "logger" : "a.b" ,
1388
+ "message" : message ,
1389
+ "requestId" : "" ,
1390
+ "tenantId" : "test-tenant-id" ,
1391
+ }
1392
+
1393
+ with patch ("sys.stdout" , new_callable = StringIO ) as mock_stdout :
1394
+ logger .log (level , message )
1395
+
1396
+ data = json .loads (mock_stdout .getvalue ())
1397
+ data .pop ("timestamp" )
1398
+ self .assertEqual (
1399
+ data ,
1400
+ expected ,
1401
+ )
1402
+ self .assertEqual (mock_stderr .getvalue (), "" )
1403
+
1360
1404
@patch ("sys.stdout" , new_callable = StringIO )
1361
1405
@patch ("sys.stderr" , new_callable = StringIO )
1362
1406
def test_exception (self , mock_stderr , mock_stdout ):
0 commit comments