sunnyone
sunnyone

Reputation: 1530

Debugging a Spring WebFlux / Reactor application with IntelliJ IDEA

I'm creating an Spring WebFlux / Reactor application with IntelliJ IDEA. The debugger of IDEA shows many useless lines like MonoDefer, MonoFlatMap, etc. Is there a way to trace the stacks easily?

intellij-debug-traces

Upvotes: 9

Views: 9903

Answers (1)

Simon Baslé
Simon Baslé

Reputation: 28301

In an asynchronous world, unfortunately stack traces lose a lot of their meaning. Here you see a stack that shows the operators making up the whole of the reactive chain (including the ones the Spring Framework uses on top of those you defined in your controller). The only problem is it shows where the chain was triggered (or "subscribed"), because the execution is lazy and that's the only path visible at runtime...

For errors and stack traces proper, there is a .checkpoint() operator that you can use explicitly in a chain in order to capture information about the "assembly" (where the chain of operators is declared in your code), to provide a bit more context. It is then shown as part of the exception stack straces, as a suppressed exception.

It was also a bit too difficult for us to use the new async debugger feature of IntelliJ because the execution model doesn't provide a fixed pair of "scheduling site vs execution site": the Scheduler abstraction used to switch threads in the middle of a sequence by operators like publishOn and subscribeOn implies arbitrary "execution sites" (an arbitrary ExecutorService, a roll-your-own-thread-pool, a Thread, ...).

I encourage you to read up on stack traces and debugging in the official reference documentation at http://projectreactor.io/docs/core/release/reference/#debugging

Upvotes: 7

Related Questions