-
-
Notifications
You must be signed in to change notification settings - Fork 444
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
Improve versatility of exception resolver component for Spring with more flexible API for consumers. #2577
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, I just added one comment. 🚀
return event; | ||
} | ||
|
||
protected Hint createHint( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be annotated with @NotNull
(same for createEvent
). This way anyone overriding the methods in Kotlin will see the right Nullability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will do. I guess this one should actually be @Nullable
given that the signature of the hub is:
SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hint hint);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution. As @markushi suggested, can you please use org.jetbrains.annotations.NotNull
and org.jetbrains.annotations.Nullable
.
And may I also ask you to duplicate your changes and the test into the sentry-spring-jakarta
module which supports Spring Boot 3 / Spring 6 🙏 ?
Refactor `SentryExceptionResolver` to improve its API in order to allow easier behavior tweaking by Spring Boot integration module consumers.
Include pull request id in the changelog record. Co-authored-by: Alexander Dinauer <[email protected]>
Similarly to Spring Boot 2 module, refactor `SentryExceptionResolver` in Jakarta package to improve its API in order to allow easier behavior tweaking by Spring Boot integration module consumers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @detouched! LGTM 🚀
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2577 +/- ##
============================================
+ Coverage 80.42% 80.43% +0.01%
- Complexity 4024 4028 +4
============================================
Files 333 333
Lines 15181 15189 +8
Branches 1979 1979
============================================
+ Hits 12210 12218 +8
Misses 2192 2192
Partials 779 779
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@@ -17,7 +23,6 @@ | |||
- This is still considered experimental. Once we have enough feedback we may turn this on by default. | |||
- Checkout the sample here: https://github.com/getsentry/sentry-java/tree/main/sentry-samples/sentry-samples-spring-boot-webflux-jakarta | |||
- A new hub is now cloned from the main hub for every request | |||
- Improve versatility of exception resolver component for Spring with more flexible API for consumers. ([#2577](https://github.com/getsentry/sentry-java/pull/2577)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, my bad while merging the change from the upstream, sorry.
Thanks for fixing it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, happens to us as well 😅
📜 Description
Refactor
SentryExceptionResolver
to improve its API: extract Sentry event and hint creation fromresolveException
method into protected methods to allow easier and more flexible override of any of these pieces by the consumers of the Spring integration module.💡 Motivation and Context
A very common scenario for the apps I work on is to return the Sentry ID in the
ModelAndView
back to the client who faced a problem so that they could then reach out to me providing that ID which makes it significantly quicker and easier to locate the relevant report and hence trace down the root cause.The existing implementation of
SentryExceptionResolver
didn't care about the Sentry ID returned fromIHub.captureEvent(event, hint)
and didn't provide a simple way to override this behavior. This change allows a subclass to override just the right bit of code and reuse event an hint creation methods in order to implement the aforementioned scenario. Similarly, it allows to override event and/or hint creation logic without requiring to modify the capture call to theIHub
.💚 How did you test it?
The
SentryExceptionResolver
didn't have any unit tests at all. I added the tests for the existing logic (verifying the shape of the event and the hint passed to theIHub
), and for the introduced refactoring (ensuring that an override of event and hint creation methods is applied correctly).📝 Checklist
sendDefaultPII
is enabled.🔮 Next steps
None.