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: set correct transaction status for unhandled exceptions in SentryTracingFilter. #1406

Merged
merged 7 commits into from Apr 19, 2021

Conversation

maciejwalkowiak
Copy link
Contributor

📜 Description

Fix: set correct transaction status for unhandled exceptions in SentryTracingFilter.

💡 Motivation and Context

For exceptions that have not been handled with @ControllerAdvice or @ExceptionHandler, the response#status in SentryTracingFilter is equal to 200, which results in setting SpanStatus.OK on transaction.

With this change, we handle also the case when the exception is not handled and set correct status code.

💚 How did you test it?

Unit tests.

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the docs if needed
  • No breaking changes

@maciejwalkowiak maciejwalkowiak marked this pull request as ready for review April 14, 2021 14:52
@@ -67,16 +67,22 @@ protected void doFilterInternal(
final ITransaction transaction = startTransaction(httpRequest, sentryTraceHeader);
try {
filterChain.doFilter(httpRequest, httpResponse);
} catch (Exception e) {
// exceptions that are not handled by Spring
transaction.setStatus(SpanStatus.INTERNAL_ERROR);
Copy link
Contributor

Choose a reason for hiding this comment

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

should we transaction.setThrowable(e) and throw e;?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no need to setThrowable as the exception is captured while transaction is active - SentryClient sets the span context on the event.

@codecov-io
Copy link

Codecov Report

Merging #1406 (f97cdb9) into main (b40c474) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head f97cdb9 differs from pull request most recent head 42fe6b0. Consider uploading reports for the commit 42fe6b0 to get more accurate results
Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1406      +/-   ##
============================================
+ Coverage     75.76%   75.77%   +0.01%     
- Complexity     1864     1865       +1     
============================================
  Files           185      185              
  Lines          6383     6387       +4     
  Branches        636      637       +1     
============================================
+ Hits           4836     4840       +4     
  Misses         1258     1258              
  Partials        289      289              
Impacted Files Coverage Δ Complexity Δ
.../io/sentry/spring/tracing/SentryTracingFilter.java 76.31% <100.00%> (+2.78%) 6.00 <0.00> (+1.00)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b40c474...42fe6b0. Read the comment docs.

Copy link
Contributor

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

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

LGTM

@maciejwalkowiak maciejwalkowiak merged commit e905c4b into main Apr 19, 2021
@maciejwalkowiak maciejwalkowiak deleted the fix-sentry-tracing-filter branch April 19, 2021 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants