You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current example has a python syntax error of ',' or ')' expected
Code snippet
fromaws_lambda_powertoolsimportMetricsfromaws_lambda_powertools.metricsimportMetricUnitfromcollectionsimportnamedtupleimportjsondefcapture_metrics_output_multiple_emf_objects(capsys):
return [json.loads(line.strip()) forlineincapsys.readouterr().out.split("\n") ifline]
deftest_log_metrics(capsys):
# GIVEN Metrics is initializedmetrics=Metrics(namespace="ServerlessAirline")
# WHEN log_metrics is used with capture_cold_start_metric@metrics.log_metrics(capture_cold_start_metric=True)deflambda_handler(evt, ctx):
metrics.add_metric(name="SuccessfulBooking", unit=MetricUnit.Count, value=1)
metrics.add_dimension(name="environment", value="prod")
# log_metrics uses function_name property from context to add as a dimension for cold start metricLambdaContext=namedtuple("LambdaContext", "function_name")
lambda_handler({}, LambdaContext("example_fn")
cold_start_blob, custom_metrics_blob=capture_metrics_output_multiple_emf_objects(capsys)
# THEN ColdStart metric and function_name dimension should be logged# in a separate EMF blob than the application metricsassertcold_start_blob["ColdStart"] == [1.0]
assertcold_start_blob["function_name"] =="example_fn"assert"SuccessfulBooking"incustom_metrics_blob# as per previous example
importjsonfromcollectionsimportnamedtuplefromaws_lambda_powertoolsimportMetricsfromaws_lambda_powertools.metricsimportMetricUnitdefcapture_metrics_output_multiple_emf_objects(capsys):
return [json.loads(line.strip()) forlineincapsys.readouterr().out.split("\n") ifline]
deftest_log_metrics(capsys):
# GIVEN Metrics is initializedmetrics=Metrics(namespace="ServerlessAirline")
# WHEN log_metrics is used with capture_cold_start_metric@metrics.log_metrics(capture_cold_start_metric=True)deflambda_handler(evt, ctx):
metrics.add_metric(name="SuccessfulBooking", unit=MetricUnit.Count, value=1)
metrics.add_dimension(name="environment", value="prod")
# log_metrics uses function_name property from context to add as a dimension for cold start metricLambdaContext=namedtuple("LambdaContext", "function_name")
lambda_handler({}, LambdaContext("example_fn"))
cold_start_blob, custom_metrics_blob=capture_metrics_output_multiple_emf_objects(capsys)
# THEN ColdStart metric and function_name dimension should be logged# in a separate EMF blob than the application metricsassertcold_start_blob["ColdStart"] == [1.0]
assertcold_start_blob["function_name"] =="example_fn"assert"SuccessfulBooking"incustom_metrics_blob# as per previous example
michaelbrewer
changed the title
Bug: Assert multiple EMF blobs with pytest has invalid python syntax
Bug: Metrics, Assert multiple EMF blobs with pytest has invalid python syntax
May 18, 2022
michaelbrewer
changed the title
Bug: Metrics, Assert multiple EMF blobs with pytest has invalid python syntax
Bug: Metrics - Assert multiple EMF blobs with pytest has invalid python syntax
May 18, 2022
sthulb
changed the title
Bug: Metrics - Assert multiple EMF blobs with pytest has invalid python syntax
Docs: Metrics - Assert multiple EMF blobs with pytest has invalid python syntax
May 18, 2022
Expected Behaviour
Metrics - Assert multiple EMF blobs with pytest example should be valid python syntax
Current Behaviour
Current example has a python syntax error of
',' or ')' expected
Code snippet
Possible Solution
Fix the python syntax, like in PR #1122, deployed at https://gyft.github.io/aws-lambda-powertools-python/latest/core/metrics/#functional-testing
Steps to Reproduce
Assert multiple EMF blobs with pytest
AWS Lambda Powertools for Python version
latest
AWS Lambda function runtime
3.9
Packaging format used
PyPi
Debugging logs
The text was updated successfully, but these errors were encountered: