Posted in

How to enable debug mode in Project Reactor?

Hey folks, let’s cut to the chase – if you’re working with Project Reactor, you’ve definitely been there: staring at a broken flux/mono stack trace, and it’s all just onError from some random operator with zero clue where it actually blew up. No line numbers, no context, just a vague message that’s about as helpful as a dead smartphone in a blackout. Reactor

As a Reactor vendor, we’ve seen this so many times that we built our whole platform around solving exactly this problem for teams that can’t afford to waste hours debugging reactive streams. So today, I’m gonna walk you through how to actually turn on debug mode in Project Reactor like a pro – no jargon overload, just stuff that works when you’re knee-deep in a production incident. First off, let’s get one thing straight: “debug mode” isn’t a single toggle. Reactor has a whole ecosystem of tools, and you gotta use the right ones for the job, not just hit a random switch and hope for the best.

Let’s start with the basics. The first and most common mistake we see devs make is just trying to slap Hooks.onOperatorDebug() somewhere in their app. Don’t do that unless you know what you’re getting into. Sure, it’s simple – you call that method, and Reactor starts stacking assembly metadata into each signal. But here’s the catch: that stuff is only retained for the life of the stream. If your app has tons of short-lived Fluxes, you’re gonna leak memory. Not cool, especially when you’re running on Kubernetes and every resource counts. Also, by default, onOperatorDebug() only gives you the assembly trace for operators that had an error. That’s good, but what if you need to check a normal stream’s flow?

So let’s talk about the real tools, starting with the built-in ones that come with every Reactor release. First up: reactor.debug.mode property. If you’re using Spring Boot, this is super easy – just add -Dreactor.debug.mode=advanced to your JVM args, or set reactor.debug.mode=advanced in your application.properties. Wait, what’s the difference between simple and advanced mode? Let’s break it down: simple mode just adds operator assembly traces to error signals. advanced? It adds even more context – like the actual source line number where the operator was declared, and even the surrounding code lines if the compiler’s setup right. But heads up: advanced mode adds a tiny bit of overhead, like 5-10% in our benchmarks, so we usually suggest turning it on only for staging or debug builds, not prod. Unless you’re fine-tuning, but even then, most production teams stick to simple mode because it’s light and gets the job done.

Now, if you’re not on Spring Boot (we’ve got customers using raw Spring Boot, plain Java, even Quarkus and Micronaut), here’s how to do it manually: either call Hooks.onOperatorDebug() at app startup, but only if you guard it properly. Wait, guard it how? Because if you call it multiple times, you’ll overwrite hooks and cause weird, hard-to-reproduce bugs. So wrap it in a check: if (System.getProperty("reactor.debug.mode") != null) Hooks.onOperatorDebug(); That way, it only runs when you actually set the property. Also, make sure this runs before you declare any Reactive Streams. If you call it after creating your first Flux, you won’t get assembly traces for that stream. Trust me, we’ve seen teams do this – waste an hour thinking debug mode is broken just because they placed the hook in the wrong spot.

But wait, there’s a newer tool in Reactor 3.5+ that’s way better than Hooks.onOperatorDebug(): DebugListener. Oh right, this is a game-changer for teams that need more control. The old onOperatorDebug() was a global toggle, which meant every stream got debug info. What if you only want debug info for specific parts of your app? Like, your user-service flux is broken, but your payment-service flux is working fine – you don’t need debug info for payments, that’s just extra noise. With DebugListener, you can attach debug context only to the operators you care about. For example:

Flux.just("data")
    .transformDeferred(Operators.debugMode())
    .map(data -> processData(data));

Wait, no, better example: if you have a custom operator, you can inject debug hooks selectively. Or, if you want to enable debug mode for a specific Flux, you can use Flux.doOnEach() with a debug listener, but actually, the Operators.enableOnAssembly() method (wait, no, that’s AssemblyUtils) – yeah, AssemblyUtils.enableOnAssembly() lets you wrap individual streams. That’s perfect for prod, because you don’t have global overhead, and you only get debug info where you need it. As a vendor, we love this because it’s flexible – you can turn debug on for a single endpoint, roll it back when you’re done, no side effects.

Now, let’s talk about the hacks that actually work when stack traces are garbage. Like, when you get a stack trace that just says reactor.core.Exceptions$ReactiveException: java.lang.NullPointerException with no line numbers. That’s where DebugUtils.addAssumption() or wait, no – the reactor.debug.assembly.trace flag? Wait, no, another one: Reactor has this thing called “traceback”, which is the full assembly stack. If you set -Dreactor.traceback=true, Reactor will log the full path of how a stream was assembled, not just where the error happened. This is especially useful if your stack is coming from a nested operator. For example, if you have a Flux that calls another Flux, and the error is in the nested one, the traceback will show you the exact line in the parent Flux that called it. We had a customer last week who spent 3 hours trying to figure out why their flatMap was throwing NPE, and all they had was a generic error – adding -Dreactor.traceback=true fixed it in 2 minutes.

But here’s the thing: even with all these tools, most devs miss one huge step: bytecode instrumentation. Wait, that’s not as scary as it sounds. Reactor has a bytecode inspector that can add debug info at compile time, or via a Java agent. The Java agent is super easy to use – just add -javaagent:reactor-tools-agent.jar to your JVM args. What does that do? It instruments Reactor’s bytecode to inject assembly traces without you having to call any hooks. No more forgetting to add Hooks calls, no more global leaks, no more selective vs global mess. This is our go-to method for all our enterprise customers. Because the agent works transparently – it doesn’t change your code, just adds the debug context you need. And the best part? You can enable it only for specific packages, so you don’t get debug info for third-party Reactor libraries, which cleans up your stack traces.

Now, let’s cover the mistakes that will make debug mode useless, because we’ve seen every single one. First, don’t use debug mode in production unless you really have to. Even though the overhead is low, it’s still extra processing, and if you have a busy prod app, every millisecond counts. We always tell our customers to use our monitoring tools (shameless plug, but it’s true) to catch anomalies before they need debug mode, but when they do, use the agent in staging first to test it, then roll it to prod for the shortest time possible. Second, don’t forget to compile with debug symbols. If you’re using Maven, make sure <debug>true</debug> is in your compiler plugin config. If you’re using Gradle, debug { debuggable true } in build types. Without debug symbols, even advanced mode won’t give you line numbers – just class names and method names. Third, don’t mix old Reactor versions with new tools. If you’re on Reactor 3.4, DebugListener doesn’t exist, so you have to use Hooks or the older agent. Make sure you’re on the latest stable Reactor version – most of the bugs we fix in our platform are from devs running outdated Reactor with broken debug tools.

Wait, let’s test this with an example. Suppose you have a simple Flux that’s broken:

Flux.just(1, 2, 0)
    .map(i -> 10 / i)
    .subscribe(System.out::println);

If you run this normally, you’ll get:

Exception in thread "main" java.lang.ArithmeticException: / by zero
	at com.example.MyApp.lambda$main$0(MyApp.java:10)
	...

Wait, that’s actually okay here, but if your stream is nested:

Flux.range(1, 10)
    .flatMap(i -> Flux.just(i, 0).map(j -> i / j))
    .subscribe(System.out::println);

Now run that with -Dreactor.debug.mode=simple: you’ll get an extra line in the stack trace:

Assembly trace from producer [FluxMap] :
	...
	at reactor.core.publisher.FluxMap.subscribe(FluxMap.java:...)

That tells you the operator that was assembled, which is the map inside the flatMap. Without debug mode, you’d never know which map threw the error, because the stack would only show the inner lambda.

Another example: using the Java agent. If you add -javaagent:reactor-tools-agent.jar and run the same nested stream, your stack trace will have the full assembly path: where the flatMap was declared, where the inner Flux.just was declared, all the way down to the line where the error happened. That’s the stuff you need when you’re tracing a complex stream with 10+ operators.

Now, let’s talk about when to use which tool, because that’s the confusion we see most. If you’re a solo dev working on a small app, just use -Dreactor.debug.mode=simple – it’s easy, no setup, works right away. If you’re on Spring Boot, use the property, no need to mess with JVM args (well, you still can, but Spring Boot abstracts it). If you’re an enterprise team with microservices, use the Java agent – it’s scalable, works across all your services, no code changes, easy to turn on/off per service. If you just need debug info for one specific stream, use AssemblyUtils.enableOnAssembly() or DebugListener – it’s selective, no global overhead, perfect for testing a new feature without cluttering all your logs.

Wait, also, don’t forget about Reactor’s debug context. You can actually attach custom debug info to signals, like request IDs, user IDs, whatever. If you use Mono.subscriberContext() to add context, and then use Hooks.onOperatorDebug() or the agent, that context will show up in the debug traces. That’s super useful for tracing errors across multiple services in a reactive ecosystem. For example, if you have a stream that goes from user-service to payment-service to order-service, adding the request ID to the subscriber context will let you find exactly which part of the flow failed, even across service boundaries.

Now, let’s get real – a lot of devs hate debug mode because of noisy logs. We get it. When you turn on debug mode, you might see a bunch of extra lines in your logs, but that’s why we built our Reactor monitoring tool (yeah, the vendor part) that filters out the noise and only shows you the relevant debug info. So you don’t have to sift through hundreds of lines to find the operator that threw an error. If you’re tired of scrolling through stack traces for hours, our tool does that filtering automatically, and integrates seamlessly with all the debug modes we talked about.

But even if you don’t use our tool, you can still clean up logs. Use Logger to filter Reactor’s debug logs. Reactor uses SLF4J, so you can set logger.reactor.level=ERROR in your logging config, and only see debug traces when there’s an error. That way, you get the debug info you need when something breaks, but not when everything’s working fine. That’s a simple trick we learned early on – no more 100MB debug logs from a working app.

Let’s wrap this up with a quick checklist so you don’t forget anything:

  1. Pick your tool based on your use case: solo dev = reactor.debug.mode property; microservices = Reactor agent; selective streams = AssemblyUtils / DebugListener.
  2. Always compile with debug symbols – no exceptions.
  3. Test debug mode in staging first, never run full advanced mode in prod for long.
  4. Filter Reactor logs to avoid noise – set Reactor’s log level to ERROR normally.
  5. For complex cross-service flows, add subscriber context to track requests.

And before you go, if you’re struggling with Reactor debug mode and wasting time on broken streams, we can help. Our team works with teams just like yours to fine-tune Reactor debug setup, optimize reactive flow performance, and eliminate those impossible-to-trace errors. Reach out to us to start a conversation, no pressure, just solving your reactive headaches.

Lab Ultrasonic Extraction Machine Now, for references:

  1. Project Reactor Official Documentation – Debug Mode
  2. Reactor Tools Agent GitHub Repository
  3. Spring Boot Reactor Configuration Guide
  4. Reactor Core GitHub Repository – Hooks and DebugListener Sources

Anyang Gaokang Medical Co., Ltd.
Anyang Gaokang Medical Co., Ltd. is one of the leading reactor manufacturers and suppliers in China. We warmly welcome you to buy high-grade reactor made in China here from our factory. All products are with high quality and competitive price.
Address: No.20, Guangming Road, Wenfeng District, Anyang, Henan, China
E-mail: Info@gaokangmedical-lab.com
WebSite: https://www.gaokbio.com/