-
Notifications
You must be signed in to change notification settings - Fork 429
@tracer.capture_lambda_handler does not support functions that return generator expressions #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This should be fixed, version 1.2.0 is released which adds support for generators (including context managers). Please give it a try and either close the issue or let us know here if any issues persist. |
@cakepietoast thanks i will try it out and close this issue if this no longer has issues. |
@cakepietoast this is working better now, but i now have an issue with the context manager.
Example output: {
"errorMessage": "read of closed file",
"errorType": "ValueError",
"stackTrace": [
" File \"/var/task/aws_lambda_powertools/tracing/tracer.py\", line 267, in decorate\n response = lambda_handler(event, context)\n",
" File \"/var/task/tmp.py\", line 58, in lambda_handler\n result = fp.read().decode(\"UTF-8\") # ValueError(read of closed file)\n"
]
} |
@cakepietoast @heitorlessa - i have a potential patch for this. |
Changes: * capture_method should yield from within the "with" statement * Add missing test cases Closes #112
@cakepietoast @heitorlessa - this PR might resolve this: #124 |
Changes: * capture_method should yield from within the "with" statement * Add missing test cases Closes #112
Thanks for spotting this @michaelbrewer! Your PR looks good to me, I'll get a patch version out soon with your changes. |
1.3.1 is published with your changes, please let us know if this issue can be closed. |
Changes: * capture_method should yield from within the "with" statement * Add missing test cases Closes #112
Awesome @cakepietoast i will retest |
Issue is now revolved and passes my test cases. |
* fix(ssm): Make decrypt an explicit option * chore: declare as self * fix: update get_parameter and get_parameters Changes: ssm.py - get_parameters - pass through the **sdk_options and merge in the recursive and decrypt params ssm.py - get_parameter - add explicit option for decrypt * chore: fix typos and type hinting * tests: verify that the default kwargs are set - `decrypt` should be false by default - `recursive` should be true by default * fix(capture_method): should yield inside with (#124) Changes: * capture_method should yield from within the "with" statement * Add missing test cases Closes #112 * chore: version bump to 1.3.1 * refactor: reduce get_multiple complexity Changes: - base.py - update get_multiple to reduce the overall complexity - base.py - `_has_not_expired` returns whether a key exists and has not expired - base.py - `transform_value` add `raise_on_transform_error` and default to True - test_utilities_parameters.py - Add a direct test of transform_value * refactor: revert to a regular for each Changes: * Add type hint to `values` as it can change later on in transform * Use a slightly faster and easier to read for each over dict comprehension Co-authored-by: Tom McCarthy <[email protected]>
I have an async lambda listening to S3 bucket notifications and i wanted to track the performance of downloading a large json file. Original this was a regular function that worked but later when refactoring it to yield the file pointer it failed when deployed. Nothing was found during unit testing.
What were you trying to accomplish?
Add a
@tracer.capture_method
to a function thatyields
a result.Expected Behavior
Either fail the same way during testing when
POWERTOOLS_TRACE_DISABLED='true'
or support generator expressionCurrent Behavior
Either results in a
RuntimeError("generator didn't yield")
or aTask timed out
Possible Solution
Detect and support generator expression, or have a better emulation during testing which returns an error when a return
returns a generator expression.
Steps to Reproduce (for bugs)
yield_without_capture
returns the expected valueyield_with_capture
returns aRuntimeError("generator didn't yield")
boto_yield_without_capture
returns the expected valueboto_yield_with_capture
returns a"Task timed out after 900.01 seconds"
Environment
The text was updated successfully, but these errors were encountered: