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

Spring Boot (Webflux): many unrelated http breadcrumbs are recorded with events #1790

Open
4 tasks done
sergey-volkov-lm opened this issue Nov 2, 2021 · 5 comments
Open
4 tasks done
Labels
Platform: Java ThreadLocalHubProblem Issues caused by Hub being ThreadLocal and no or no easy way to clone the hub Type: Bug Something isn't working WebFlux
Projects

Comments

@sergey-volkov-lm
Copy link

Platform:

  • Spring Boot (Webflux server & WebClient) -> 2.5.5

IDE:

  • IntelliJ -> 2021.2

Build system:

  • Maven -> 3.6.3-jdk-11

Platform installed with:

  • Maven Central

The version of the SDK:
5.2.4


I have the following issue:

Many (tens or even ~hundred) unrelated http breadcrumbs recorded with events. These breadcrumbs are:

  • Incoming server http requests (to actuator endpoints, for example)
  • Outgoing http client requests to external services, but they are old and/or unrelated to original incoming server request

Steps to reproduce:

  • Use spring-boot webflux server application
  • Use sentry-spring-boot-starter
  • Use actual sentry server (probably won't work with NoOpHub)
  • Start app locally
  • Put some load on application
    • I used 50 threads in jmeter accessing actuator health, info and prometheus endpoints without delays
    • prometheus worked better
  • Make some meaningful requests which should cause some kind of error which should be sent to sentry
  • Observe events on sentry server or via debugging SentryClient (less effective)

Actual result:
Screenshot from actual server-running instance
sentry webflux bug

Expected result:
Only a couple of related http breadcrumbs are present

Personal thoughts
Both SentryWebFilter & SentrySpanClientWebRequestFilter use HubAdapter, which uses static Sentry.getCurrentHub() method, which returns ThreadLocal instance of Hub.

It seems like this mechanism may not work correctly with reactive application, which serves requests on a small number of threads, and they are switched frequently.

As far as I know, there is a way of storing arbitrary request-related data in webflux:

  • org.springframework.web.server.ServerWebExchange.getAttributes()
  • org.springframework.web.reactive.function.client.ClientRequest.attributes()
@marandaneto
Copy link
Contributor

cc @maciejwalkowiak

@maciejwalkowiak maciejwalkowiak added Type: Bug Something isn't working and removed Status: Untriaged labels Nov 12, 2021
@marandaneto marandaneto added this to To do in kanban via automation Nov 12, 2021
@marandaneto marandaneto moved this from To do to In progress in kanban Dec 1, 2021
@hu-chia
Copy link

hu-chia commented Mar 5, 2022

Based on ThreadLocal, this issue seems unsolvable.

@adinauer adinauer added the ThreadLocalHubProblem Issues caused by Hub being ThreadLocal and no or no easy way to clone the hub label Feb 7, 2023
@adinauer
Copy link
Member

adinauer commented Mar 2, 2023

We have just released 6.15.0 of the Java SDK. If you're on Spring Boot 3.0.3+ you can give ThreadLocalAccessor a try.

Here's a copy of the changelog so you know what's required:
Implement ThreadLocalAccessor for propagating Sentry hub with reactor / WebFlux (#2570)

We've also fixed a bug for the WebFlux integration (#2580) in this release for older versions of Spring Boot and when not using context-propagation. In case you give it a try it would be great if you could give us feedback 🙏 .

@adinauer
Copy link
Member

adinauer commented May 9, 2023

Closing this now as it should be resolved (see comment above), feel free to reopen if you run into the problem again.

@adinauer adinauer closed this as completed May 9, 2023
kanban automation moved this from In progress to Done May 9, 2023
@adinauer adinauer removed their assignment Apr 11, 2024
@adinauer
Copy link
Member

This is still an issue for our Spring Boot 2 integration.

We could take another stab at it by trying to use reactor.core.CoreSubscriber and Hooks.onEachOperator as described here. Needs testing whether this is has a lot of impact on performance.

Putting this in the backlog but can't say when we'll get to it.

@adinauer adinauer reopened this Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Java ThreadLocalHubProblem Issues caused by Hub being ThreadLocal and no or no easy way to clone the hub Type: Bug Something isn't working WebFlux
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants