@@ -86,6 +86,31 @@ 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+ {
100+ "name" : "responseLatency" ,
101+ "start" : "2026-01-08T18:22:35.342Z" ,
102+ "durationMs" : 0.642 ,
103+ },
104+ {
105+ "name" : "responseDuration" ,
106+ "start" : "2026-01-08T18:22:35.343Z" ,
107+ "durationMs" : 0.075 ,
108+ },
109+ ],
110+ "status" : "success" ,
111+ },
112+ }
113+ )
89114
90115 def test_parse_lambda_tags_from_arn (self ):
91116 verify_as_json (
@@ -129,6 +154,21 @@ def test_parse_metrics_from_timeout_json_report_log(self):
129154 parsed_metrics = parse_metrics_from_json_report_log (self .timeout_json_report )
130155 verify_as_json (parsed_metrics )
131156
157+ def test_parse_metrics_from_partial_metrics_json_report_log (self ):
158+ """Test that JSON report logs with partial/incomplete metrics don't raise KeyError"""
159+ parsed_metrics = parse_metrics_from_json_report_log (
160+ self .managed_instances_metrics_json_report
161+ )
162+ # Should only return metrics that are present (duration in this case)
163+ # Should not raise KeyError for missing billedDurationMs, maxMemoryUsedMB, memorySizeMB
164+ assert len (parsed_metrics ) == 1 # Only duration metric
165+ assert parsed_metrics [0 ].name == "aws.lambda.enhanced.duration"
166+ # Duration should be converted from ms to seconds (2.524 * 0.001 = 0.002524)
167+ assert parsed_metrics [0 ].value == 0.002524
168+ # Tags should include cold_start:false but NOT memorysize since it's missing
169+ assert "cold_start:false" in parsed_metrics [0 ].tags
170+ assert not any (tag .startswith ("memorysize:" ) for tag in parsed_metrics [0 ].tags )
171+
132172 def test_create_out_of_memory_enhanced_metric (self ):
133173 go_out_of_memory_error = "fatal error: runtime: out of memory"
134174 self .assertEqual (
0 commit comments