feat: improve error handling for log_metrics decorator#71
feat: improve error handling for log_metrics decorator#71heitorlessa merged 8 commits intodevelopfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #71 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 15 16 +1
Lines 508 516 +8
Branches 48 49 +1
=========================================
+ Hits 508 516 +8
Continue to review full report at Codecov.
|
|
I'm trying to think of an actual customer scenario where this would be common to have no validation by default - Could you share one or two use cases where you wouldn't have a metric if you want to use Metrics? I thought about scenarios where metric value would be 0, but even then it's a data point rather than missing data point. |
|
That’s fair enough - I thought you were also adding metrics on unhappy path
(my expectation).
I’m happy with the change - On my phone now, only change I’d request is to
use “raise_on...” rather than “raise_for...”
…On Mon, 8 Jun 2020 at 17:37, Tom McCarthy ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In aws_lambda_powertools/metrics/metrics.py
<#71 (comment)>
:
> @@ -122,10 +131,13 @@ def decorate(event, context):
if capture_cold_start_metric:
self.__add_cold_start_metric(context=context)
finally:
- metrics = self.serialize_metric_set()
- self.clear_metrics()
- logger.debug("Publishing metrics", {"metrics": metrics})
- print(json.dumps(metrics))
+ if not raise_for_empty_metrics and not self.metric_set:
I added it to the decorator rather than base because I think the behavior
should be different for the decorator. If I'm explicitly making a call to
serialize metrics when their are none, throwing an exception is fine and I
can handle it myself.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#71 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZPQBAEJCOB6HNJILPIPETRVUHVFANCNFSM4NYPVZBQ>
.
|
add raise_on_empty_metrics param to partial func call revert mistake in change to test for exception propagation
Done! |
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
Signed-off-by: heitorlessa <lessa@amazon.co.uk>
* develop: (31 commits) docs: fix contrast on highlighted code text (#73) feat: improve error handling for log_metrics decorator (#71) chore(deps): bump graphql-playground-html from 1.6.19 to 1.6.25 in /docs feat: add high level imports (#70) fix: correct env var name for publish to pypi test (#69) chore: version bump (#68) feat: add capture_cold_start_metric for log_metrics (#67) chore(deps): bump websocket-extensions from 0.1.3 to 0.1.4 in /docs (#66) feat: automate publishing to pypi (#58) feat: add pre-commit hooks (#64) improv: include example tests in `make tests` (#63) chore: rename Makefile target docs-dev to docs-local (#65) improv: better namespace/dimension handling for Metrics (#62) docs: build on master only chore: correct docstring for log_metrics chore: fix typo in metrics doc chore: Correct test comment chore: remove unused import chore: formatting feat: update Metrics interface to resemble tracer & logger: use "service" as its namespace. ...
* feat: dont throw exception by default from log_metrics if no metrics are emitted * docs: update details for change to error handling * chore: rename parameter for clarity * fix: correct bug in exception handling from previous commits add raise_on_empty_metrics param to partial func call revert mistake in change to test for exception propagation * improv: change log debug statement to warning when no metrics are present * docs: add note on suppressing warning for empty metric set * improv: add warning for manual serialization Signed-off-by: heitorlessa <lessa@amazon.co.uk> * improv: whitespace and warning supress as info Signed-off-by: heitorlessa <lessa@amazon.co.uk> Co-authored-by: heitorlessa <lessa@amazon.co.uk>
…tools-python into develop * 'develop' of https://github.com/awslabs/aws-lambda-powertools-python: (104 commits) feat: add metrics metadata (#81) chore: cleanup tests (#79) chore: remove deprecated code before GA (#78) docs: customize contributing guide (#77) chore: move blockquotes as hidden comments chore: update CHANGELOG chore: bump version to 0.11.0 (#76) chore: version bump 0.10.1 fix: default dimension creation now happens when metrics are serialized instead of on metrics constructor (#74) fix: default dimension creation now happens when metrics are serialized instead of on metrics constructor (#74) docs: fix contrast on highlighted code text (#73) feat: improve error handling for log_metrics decorator (#71) chore(deps): bump graphql-playground-html from 1.6.19 to 1.6.25 in /docs feat: add high level imports (#70) fix: correct env var name for publish to pypi test (#69) chore: version bump (#68) feat: add capture_cold_start_metric for log_metrics (#67) chore(deps): bump websocket-extensions from 0.1.3 to 0.1.4 in /docs (#66) feat: automate publishing to pypi (#58) feat: add pre-commit hooks (#64) ...
Issue #, if available:
Description of changes:
Breaking change checklist
RFC issue #:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.