Reactor Integration
Learn how to capture errors, breadcrumbs and traces for your reactive applications.
Sentry's Reactor integration provides a set of utilities to use Sentry with Reactor.
Using the utilities ensures that your errors and traces are always enriched with the correct context and breadcrumbs. Due to how Reactor works under the hood, if you don't use this integration, you might run into issues such as unrelated breadcrumbs appearing in the events that are sent to Sentry within the context of Reactive Streams.
If you're using Spring Boot WebFlux, you just need to install our Spring Boot SDK and the Reactor integration will be automatically configured and enabled under the hood.
Otherwise, read on to learn how to install and use the Sentry Reactor integration.
To install use:
implementation 'io.sentry:sentry-reactor:8.3.0'
For other dependency managers, check out the central Maven repository.
Make sure your dependencies include io.micrometer:context-propagation
version 1.0.2
or later, and io.projectreactor:reactor-core
version 3.5.3
or later, as those are required for the integration to work.
Enable automatic context propagation:
import reactor.core.publisher.Hooks;
// ...
Hooks.enableAutomaticContextPropagation();
Wrap your Mono
and Flux
objects using the SentryReactorUtils.withSentry
function to enable correct capturing of errors, breadcrumbs and traces in the context of your Reactive Streams. This will execute your publisher in the context of forked current scopes, which should be the default for most use cases.
For example:
import reactor.core.publisher.Mono;
import io.sentry.Sentry;
import io.sentry.ISpan;
import io.sentry.ITransaction;
import io.sentry.TransactionOptions;
TransactionOptions txOptions = new TransactionOptions();
txOptions.setBindToScope(true);
ITransaction tx = Sentry.startTransaction("Transaction", "op", txOptions);
ISpan child = tx.startChild("Outside Mono", "op")
Sentry.captureMessage("Message outside Mono")
child.finish()
String result = SentryReactorUtils.withSentry(
Mono.just("hello")
.map({ (it) ->
ISpan span = Sentry.getCurrentScopes().transaction.startChild("Inside Mono", "map");
Sentry.captureMessage("Message inside Mono");
span.finish();
return it;
})
).block();
System.out.println(result);
tx.finish();
For more complex use cases, you can also use SentryReactorUtils.withSentryForkedRoots
to fork the root scopes or SentryReactorUtils.withSentryScopes
to wrap the operation in arbitrary scopes.
For more information on scopes and scope forking, please consult our scopes documentation.
You can also consult our GitHub repository for practical examples on how to use our Reactor integration with Spring WebFlux with Spring Boot 2 and Spring Boot 3.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").