@@ -86,6 +86,23 @@ class TestEnhancedLambdaMetrics(unittest.TestCase):
8686 },
8787 }
8888 )
89+ managed_instances_metrics_json_report = json .dumps (
90+ {
91+ "time" : "2026-01-08T18:22:35.343Z" ,
92+ "type" : "platform.report" ,
93+ "record" : {
94+ "requestId" : "4f423807-598d-47ae-9652-4f7ee31d4d10" ,
95+ "metrics" : {
96+ "durationMs" : 2.524 ,
97+ },
98+ "spans" : [
99+ {"name" : "responseLatency" , "start" : "2026-01-08T18:22:35.342Z" , "durationMs" : 0.642 },
100+ {"name" : "responseDuration" , "start" : "2026-01-08T18:22:35.343Z" , "durationMs" : 0.075 },
101+ ],
102+ "status" : "success" ,
103+ },
104+ }
105+ )
89106
90107 def test_parse_lambda_tags_from_arn (self ):
91108 verify_as_json (
@@ -129,6 +146,19 @@ def test_parse_metrics_from_timeout_json_report_log(self):
129146 parsed_metrics = parse_metrics_from_json_report_log (self .timeout_json_report )
130147 verify_as_json (parsed_metrics )
131148
149+ def test_parse_metrics_from_partial_metrics_json_report_log (self ):
150+ """Test that JSON report logs with partial/incomplete metrics don't raise KeyError"""
151+ parsed_metrics = parse_metrics_from_json_report_log (self .managed_instances_metrics_json_report )
152+ # Should only return metrics that are present (duration in this case)
153+ # Should not raise KeyError for missing billedDurationMs, maxMemoryUsedMB, memorySizeMB
154+ assert len (parsed_metrics ) == 1 # Only duration metric
155+ assert parsed_metrics [0 ].name == "aws.lambda.enhanced.duration"
156+ # Duration should be converted from ms to seconds (2.524 * 0.001 = 0.002524)
157+ assert parsed_metrics [0 ].value == 0.002524
158+ # Tags should include cold_start:false but NOT memorysize since it's missing
159+ assert "cold_start:false" in parsed_metrics [0 ].tags
160+ assert not any (tag .startswith ("memorysize:" ) for tag in parsed_metrics [0 ].tags )
161+
132162 def test_create_out_of_memory_enhanced_metric (self ):
133163 go_out_of_memory_error = "fatal error: runtime: out of memory"
134164 self .assertEqual (
0 commit comments