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

Clone hub from main hub for every WebFlux request #2567

Conversation

adinauer
Copy link
Member

@adinauer adinauer commented Feb 24, 2023

#skip-changelog
(modified changelog entry for this chain of PRs instead of having a separate one)

📜 Description

Clone hub from main hub for every WebFlux request

💡 Motivation and Context

If we just use whatever hub is there on the thread, we could leak between requests.

💚 How did you test it?

manually using debugger

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@adinauer adinauer marked this pull request as draft February 24, 2023 10:53
@adinauer adinauer changed the base branch from main to feat/use-thread-local-accessor-for-webclient February 24, 2023 10:54
@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2023

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against c88609d

@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2023

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 336.57 ms 451.40 ms 114.83 ms
Size 1.73 MiB 2.34 MiB 626.30 KiB

Previous results on branch: feat/reactor-with-sentry-continue-or-fresh

Startup times

Revision Plain With Sentry Diff
b19c118 417.94 ms 478.42 ms 60.48 ms
a864e2f 353.66 ms 392.94 ms 39.28 ms
b300cf4 371.66 ms 401.00 ms 29.34 ms
a98c90a 293.96 ms 333.90 ms 39.94 ms
b548154 328.82 ms 405.74 ms 76.92 ms
098ff45 273.73 ms 363.61 ms 89.88 ms

App size

Revision Plain With Sentry Diff
b19c118 1.73 MiB 2.34 MiB 626.30 KiB
a864e2f 1.73 MiB 2.34 MiB 626.31 KiB
b300cf4 1.73 MiB 2.34 MiB 626.31 KiB
a98c90a 1.73 MiB 2.34 MiB 626.31 KiB
b548154 1.73 MiB 2.34 MiB 626.30 KiB
098ff45 1.73 MiB 2.34 MiB 626.30 KiB

@codecov
Copy link

codecov bot commented Feb 24, 2023

Codecov Report

Patch coverage: 40.00% and project coverage change: +0.06 🎉

Comparison is base (bd5f90e) 80.35% compared to head (1947daf) 80.41%.

❗ Current head 1947daf differs from pull request most recent head c88609d. Consider uploading reports for the commit c88609d to get more accurate results

Additional details and impacted files
@@                                Coverage Diff                                 @@
##             feat/use-thread-local-accessor-for-webclient    #2567      +/-   ##
==================================================================================
+ Coverage                                           80.35%   80.41%   +0.06%     
- Complexity                                           4011     4020       +9     
==================================================================================
  Files                                                 332      332              
  Lines                                               15148    15155       +7     
  Branches                                             1979     1979              
==================================================================================
+ Hits                                                12172    12187      +15     
+ Misses                                               2197     2189       -8     
  Partials                                              779      779              
Impacted Files Coverage Δ
...ebflux/SentryWebFilterWithThreadLocalAccessor.java 0.00% <0.00%> (ø)
sentry/src/main/java/io/sentry/Sentry.java 55.78% <0.00%> (-0.30%) ⬇️
...io/sentry/spring/jakarta/webflux/ReactorUtils.java 61.53% <50.00%> (+61.53%) ⬆️
...arta/webflux/SentryReactorThreadLocalAccessor.java 100.00% <0.00%> (+100.00%) ⬆️

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

*/
@ApiStatus.Internal
@ApiStatus.Experimental
public static @NotNull IHub getNewHub() {
Copy link
Member

Choose a reason for hiding this comment

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

maybe naming it something like cloneMainHub or mainHubClone is better? Because getNewHub is not self-descriptive (e.g. from the first look it's not clear what's the diff between getCurrentHub and getNewHub)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, didn't like the name either. cloneMainHub sounds good to me.

@stefanosiano
Copy link
Member

I think it’s fine. My only thought would be if we should skip cloning on global hub mode?

@adinauer adinauer marked this pull request as ready for review February 28, 2023 07:21
Copy link
Member

@cleptric cleptric left a comment

Choose a reason for hiding this comment

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

LGTM, maybe call it withSentryMain/GlobalHub

@ApiStatus.Internal
@ApiStatus.Experimental
public static @NotNull IHub getNewHub() {
return mainHub.clone();
Copy link
Member Author

Choose a reason for hiding this comment

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

The idea was to get a fresh hub cloned from the main hub to not risk leaking data from one request into another. Any static interaction with Sentry on a thread that isn't being wrapped by the whole ThreadLocalAccessor thing could possibly write to another requests hub.

Copy link
Member Author

Choose a reason for hiding this comment

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

*/
@ApiStatus.Internal
@ApiStatus.Experimental
public static @NotNull IHub getNewHub() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, didn't like the name either. cloneMainHub sounds good to me.

* - having `io.projectreactor:reactor-core:3.5.3+` (provided by Spring Boot 3.0.3+)
*/
@ApiStatus.Experimental
public static <T> Mono<T> withFreshSentry(final @NotNull Mono<T> mono) {
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO find better name

@adinauer adinauer merged commit d3f277b into feat/use-thread-local-accessor-for-webclient Mar 1, 2023
@adinauer adinauer deleted the feat/reactor-with-sentry-continue-or-fresh branch March 1, 2023 05:03
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