Skip to content
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

fix: Stack trace lost when exception is thrown the when using decorator #357

Merged
merged 4 commits into from
Aug 15, 2023

Conversation

hjgraca
Copy link
Contributor

@hjgraca hjgraca commented Jul 22, 2023

Please provide the issue number

Issue number: #353

Summary

When an exception is thrown inside a method which that is decorated with utilities the user should see the full stack trace for that exception.
Currently the stack traces is lost.

Changes

Please provide a summary of what's being changed

MethodAspectHandler interface update so that OnException does not return.
On each utility that implements MethodApstectHandler, we capture the exception with ExceptionDispatchInfo.
[ExceptionDispatchInfo](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.exceptionservices.exceptiondispatchinfo?view=net-7.0&redirectedfrom=MSDN) is used to preserve the stack trace after an Exception is thrown, allowing you to catch that exception, not throwing it immediately (as part of a catch), and to raise such exception on a later point in the future.
Docs on how to Capture exceptions and rethrow later
Added tests that validate the stack trace is being sent to the client

User experience

Please share what the user experience looks like before and after this change

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

…DispatchInfo is used to preserve the stack trace after an Exception is thrown, allows catching that exception, not throwing it immediately (as part of a catch), and to raise such exception on a later point in the future. Add tests
@auto-assign auto-assign bot requested a review from amirkaws July 22, 2023 18:31
@boring-cyborg boring-cyborg bot added the area/common Core Powertools utility label Jul 22, 2023
@auto-assign auto-assign bot requested a review from sliedig July 22, 2023 18:31
@boring-cyborg boring-cyborg bot added area/logging Core logging utility area/metrics Core metrics utility area/tracing Core tracing utility tests labels Jul 22, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 22, 2023
@hjgraca hjgraca changed the title bug: Callstack lost when exception is thrown the when using decorator fix: Callstack lost when exception is thrown the when using decorator Jul 22, 2023
@github-actions github-actions bot added the bug Unexpected, reproducible and unintended software behaviour label Jul 22, 2023
@hjgraca hjgraca changed the title fix: Callstack lost when exception is thrown the when using decorator fix: Stack trace lost when exception is thrown the when using decorator Jul 22, 2023
@hjgraca hjgraca linked an issue Jul 22, 2023 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2023

Codecov Report

Patch coverage: 57.14% and project coverage change: +1.96% 🎉

Comparison is base (902d6a6) 69.52% compared to head (277ff0d) 71.48%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #357      +/-   ##
===========================================
+ Coverage    69.52%   71.48%   +1.96%     
===========================================
  Files           79       79              
  Lines         3491     3496       +5     
===========================================
+ Hits          2427     2499      +72     
+ Misses        1064      997      -67     
Flag Coverage Δ
unittests 71.48% <57.14%> (+1.96%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
...Powertools.Common/Aspects/MethodAspectAttribute.cs 37.93% <25.00%> (+37.93%) ⬆️
...owertools.Logging/Internal/LoggingAspectHandler.cs 76.54% <100.00%> (+3.25%) ⬆️
...owertools.Metrics/Internal/MetricsAspectHandler.cs 78.43% <100.00%> (+2.43%) ⬆️
...owertools.Tracing/Internal/TracingAspectHandler.cs 93.33% <100.00%> (-0.79%) ⬇️

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

# Conflicts:
#	libraries/tests/AWS.Lambda.Powertools.Logging.Tests/AWS.Lambda.Powertools.Logging.Tests.csproj
#	libraries/tests/AWS.Lambda.Powertools.Metrics.Tests/AWS.Lambda.Powertools.Metrics.Tests.csproj
#	libraries/tests/AWS.Lambda.Powertools.Metrics.Tests/MetricsTests.cs
#	libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/AWS.Lambda.Powertools.Tracing.Tests.csproj
#	libraries/tests/AWS.Lambda.Powertools.Tracing.Tests/TracingAttributeTest.cs
@sonarcloud
Copy link

sonarcloud bot commented Aug 14, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Contributor

@amirkaws amirkaws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hjgraca hjgraca merged commit 8ff0dd3 into aws-powertools:develop Aug 15, 2023
7 checks passed
@hjgraca hjgraca deleted the fix-capture-stacktrace branch August 15, 2023 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/common Core Powertools utility area/logging Core logging utility area/metrics Core metrics utility area/tracing Core tracing utility bug Unexpected, reproducible and unintended software behaviour size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [Trace] attribute hides stacktrance
3 participants