File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
tests/functional/metrics/required_dependencies Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 1919 SchemaValidationError ,
2020 single_metric ,
2121)
22+ from aws_lambda_powertools .metrics .base import SingleMetric
2223from aws_lambda_powertools .metrics .provider .cloudwatch_emf .cloudwatch import (
2324 AmazonCloudWatchEMFProvider ,
2425)
@@ -1612,3 +1613,21 @@ def lambda_handler(evt, context):
16121613 # THEN ColdStart metric should use function_name from unwrapped lambda context
16131614 assert output ["ColdStart" ] == [1.0 ]
16141615 assert output ["function_name" ] == "example_fn"
1616+
1617+
1618+ def test_single_metric_log_metrics_with_durable_context (capsys , namespace , durable_context ):
1619+ # GIVEN SingleMetric is initialized with a durable context
1620+ metric = SingleMetric (namespace = namespace )
1621+
1622+ @metric .log_metrics (capture_cold_start_metric = True )
1623+ def lambda_handler (evt , ctx ):
1624+ metric .add_metric (name = "TestMetric" , unit = MetricUnit .Count , value = 1 )
1625+
1626+ # WHEN handler is called with durable context
1627+ lambda_handler ({}, durable_context )
1628+ output = capsys .readouterr ().out .strip ().split ("\n " )
1629+
1630+ # THEN cold start metric should use function_name from unwrapped context
1631+ cold_start_output = json .loads (output [0 ])
1632+ assert cold_start_output ["ColdStart" ] == [1.0 ]
1633+ assert cold_start_output ["function_name" ] == "example_fn"
You can’t perform that action at this time.
0 commit comments