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

Experimental Spring Webflux integration #1529

Merged
merged 17 commits into from
Jun 30, 2021
Merged

Experimental Spring Webflux integration #1529

merged 17 commits into from
Jun 30, 2021

Conversation

maciejwalkowiak
Copy link
Contributor

@maciejwalkowiak maciejwalkowiak commented Jun 11, 2021

📜 Description

Experimental Integration for Spring Webflux with Project Reactor.

💡 Motivation and Context

Support reactive Spring stack. #640

💚 How did you test it?

Integration tests.

📝 Checklist

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

🔮 Next steps

  • add reactive Spring Security integration for obtaining current user (depending on effort needed, can be added in a separate PR)
  • update reference docs

@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2021

Codecov Report

Merging #1529 (cb062b3) into main (2e0461e) will decrease coverage by 0.01%.
The diff coverage is 75.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1529      +/-   ##
============================================
- Coverage     76.03%   76.02%   -0.02%     
- Complexity     1955     1974      +19     
============================================
  Files           192      198       +6     
  Lines          6765     6837      +72     
  Branches        675      680       +5     
============================================
+ Hits           5144     5198      +54     
- Misses         1294     1306      +12     
- Partials        327      333       +6     
Impacted Files Coverage Δ
...java/io/sentry/spring/SentryExceptionResolver.java 100.00% <ø> (ø)
...a/io/sentry/spring/webflux/SentryScheduleHook.java 12.50% <12.50%> (ø)
...sentry/spring/webflux/TransactionNameProvider.java 50.00% <50.00%> (ø)
...ry/spring/boot/SentryWebfluxAutoConfiguration.java 66.66% <66.66%> (ø)
...o/sentry/spring/webflux/SentryRequestResolver.java 76.19% <76.19%> (ø)
...ntry/spring/webflux/SentryWebExceptionHandler.java 92.85% <92.85%> (ø)
...java/io/sentry/spring/webflux/SentryWebFilter.java 100.00% <100.00%> (ø)
... and 3 more

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 2e0461e...cb062b3. Read the comment docs.

@maciejwalkowiak maciejwalkowiak changed the title Spring Webflux integration Experimental Spring Webflux integration Jun 14, 2021
@maciejwalkowiak maciejwalkowiak marked this pull request as ready for review June 14, 2021 07:47
CHANGELOG.md Outdated Show resolved Hide resolved
mechanism.setType("SentryWebExceptionHandler");
mechanism.setHandled(false);
final Throwable throwable =
new ExceptionMechanismException(mechanism, ex, Thread.currentThread());
Copy link
Contributor

Choose a reason for hiding this comment

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

more like a question, is SentryWebExceptionHandler always executed in the calling thread? otherwise marking the current thread will be wrong due to the usage of Thread.currentThread().

Asking because of #1524 (comment)
in coroutines, the handler can get called in different threads

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think there is a guarantee that its executed on the same thread. thread is a required property - what should be set there other than currentThread in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

the side effect is that the exception.setThreadId will contain the id of the current thread, which could display the wrong stack trace in the sentry issues page if SentryOptions#attachThreads is enabled (all threads reported).
I'm wondering if we should make ExceptionMechanismException#getThread nullable, and add a new ctor to ExceptionMechanismException and just don't set the threadId if not available.

@bruno-garcia ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

If we include Thread stack traces + Exception stack trace, the UI will display the Exception stack trace on the threads list (and ignore the Thread one) by matching its ID. So if we don't send an ID this could be broken.

Since this is asynchronous, the "thread" is less relevant here in terms of "This thread has done all the work up to this point". But it's OK to be "this thread did the work at the time of capture" which is what this is represented here.

So I think keeping as Thread.currentThread() is fine here and arguably a better approach than making it nullable given how Sentry works.

Copy link
Contributor

Choose a reason for hiding this comment

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

yep I am just afraid that the thread id may be wrong, and we'd be hiding the stack trace of that thread since it's going to be showing the exception stack trace, I don't know if it's a big problem though.

@marandaneto
Copy link
Contributor

add new package entry to https://github.com/getsentry/sentry-java/blob/main/.craft.yml
new packages also require sentry-release-registry eg getsentry/sentry-release-registry#52

@bruno-garcia
Copy link
Member

add new package entry to https://github.com/getsentry/sentry-java/blob/main/.craft.yml
new packages also require sentry-release-registry eg getsentry/sentry-release-registry#52

Instructions for the release registry are on the repo README (it's just a make sync-all-links after you add 1 JSON file and the links are created for you

@maciejwalkowiak
Copy link
Contributor Author

@marandaneto only the sample is a new package and as far as I can see we don't have other samples configured in craft.

@marandaneto
Copy link
Contributor

@marandaneto only the sample is a new package and as far as I can see we don't have other samples configured in craft.

oh, true, I thought it was a new package but indeed, its the sample, all good, thanks!

@marandaneto
Copy link
Contributor

I believe this closes #999

CodeQL is unhappy

CHANGELOG.md Outdated Show resolved Hide resolved
maciejwalkowiak and others added 2 commits June 24, 2021 17:36
Co-authored-by: Manoel Aranda Neto <5731772+marandaneto@users.noreply.github.com>
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

@marandaneto
Copy link
Contributor

@maciejwalkowiak please open up the docs for it

@marandaneto
Copy link
Contributor

@maciejwalkowiak please open up the docs for it

getsentry/sentry-docs#3816

@pkgonan
Copy link

pkgonan commented Jun 30, 2021

Hi. when is the release date of this PR?

@maciejwalkowiak maciejwalkowiak merged commit 36411c2 into main Jun 30, 2021
@maciejwalkowiak maciejwalkowiak deleted the sentry-reactor branch June 30, 2021 17:31
@maciejwalkowiak
Copy link
Contributor Author

@pkgonan we don't have a release schedule, but we release very often: https://github.com/getsentry/sentry-java/releases

I recommend watching this repo for releases and trying out next beta.

@pkgonan
Copy link

pkgonan commented Jul 1, 2021

@maciejwalkowiak Thank you.
Is this feature support to spring boot webflux with kotlin coroutine ? (suspend fun and Flow operator)


/** Handles unhandled exceptions in Spring WebFlux integration. */
@Order(
-2) // the DefaultErrorWebExceptionHandler provided by Spring Boot for error handling is ordered

Choose a reason for hiding this comment

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

Maybe use existing property for order tuning? sentry.exception-resolver-order. But, for some reason, it has default value 1 for MVC handler.

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

6 participants