Skip to content

Commit 5859cb5

Browse files
committed
Test the base provider using Single Metric class
1 parent f5640d2 commit 5859cb5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/functional/metrics/required_dependencies/test_metrics_cloudwatch_emf.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
SchemaValidationError,
2020
single_metric,
2121
)
22+
from aws_lambda_powertools.metrics.base import SingleMetric
2223
from 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"

0 commit comments

Comments
 (0)