-
-
Notifications
You must be signed in to change notification settings - Fork 465
Refactor ReactorUtils into its own sentry-reactor module
#4155
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ee9f422
Refactor `ReactorUtils` into its own `sentry-reactor` module
lcian d2bb9a3
comment out failing tests
lcian a4abdf4
add dependency to sentry-samples-spring-boot-webflux-jakarta
lcian 79bcd82
fixes (#4160)
adinauer add77aa
update
lcian c6cb568
Merge branch 'main' into lcian/ref/reactor-as-module
lcian 1e21862
update
lcian ab6bcef
update
lcian f3f2e7f
changelog
lcian 3039283
update
lcian 5b33ba5
readme
lcian 739c6c9
Update README.md
lcian b6ed560
Merge branch 'main' into lcian/ref/reactor-as-module
lcian 88eefe7
Update CHANGELOG.md
lcian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # sentry-reactor | ||
|
|
||
| This module provides a set of utilities to use Sentry with [Reactor](https://projectreactor.io/). | ||
|
|
||
| ## Setup | ||
|
|
||
| Please refer to the documentation on how to set up our [Java SDK](https://docs.sentry.io/platforms/java/), | ||
| or our [Spring](https://docs.sentry.io/platforms/java/guides/spring/) | ||
| or [Spring Boot](https://docs.sentry.io/platforms/java/guides/spring-boot/) integrations if you're using Spring WebFlux. | ||
|
|
||
| If you're using our Spring Boot SDK with Spring Boot (`sentry-spring-boot` or `sentry-spring-boot-jakarta`), this module will be available and used under the hood to automatically instrument WebFlux. | ||
| If you're using our Spring SDK (`sentry-spring` or `sentry-spring-jakarta`), you need to configure WebFlux as we do in [SentryWebFluxAutoConfiguration](https://github.com/getsentry/sentry-java/blob/a5098280b52aec28c71c150e286b5c937767634d/sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryWebfluxAutoConfiguration.java) for Spring Boot. | ||
|
|
||
| Otherwise, read on to find out how to set up and use the integration. | ||
|
|
||
| Add the latest version of `io.sentry.reactor` as a dependency. | ||
| Make sure you're using `io.micrometer:context-propagation:1.0.2` or later, and `io.projectreactor:reactor-core:3.5.3` or later. | ||
|
|
||
| Then, enable automatic context propagation: | ||
| ```java | ||
| import reactor.core.publisher.Hooks; | ||
| // ... | ||
| Hooks.enableAutomaticContextPropagation(); | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| You can use the utilities provided by this module to wrap `Mono` and `Flux` objects to enable correct errors, breadcrumbs and tracing in your application. | ||
|
|
||
| For normal use cases, you should wrap your operations on `Mono` or `Flux` objects using the `withSentry` function. | ||
| This will fork the *current scopes* and use them throughout the stream's execution context. | ||
|
|
||
| For example: | ||
| ```java | ||
| 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 `withSentryForkedRoots` to fork the root scopes or `withSentryScopes` to wrap the operation in arbitrary scopes. | ||
|
|
||
| For more information on scopes and scope forking, please consult our [scopes documentation](https://docs.sentry.io/platforms/java/enriching-events/scopes). | ||
|
|
||
| Examples of usage of this module (with Spring WebFlux) are provided in | ||
| [sentry-samples-spring-boot-webflux](https://github.com/getsentry/sentry-java/tree/main/sentry-samples/sentry-samples-spring-boot-webflux) | ||
| and | ||
| [sentry-samples-spring-boot-webflux-jakarta](https://github.com/getsentry/sentry-java/tree/main/sentry-samples/sentry-samples-spring-boot-webflux-jakarta) | ||
| . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| public final class io/sentry/reactor/BuildConfig { | ||
| public static final field SENTRY_REACTOR_SDK_NAME Ljava/lang/String; | ||
| public static final field VERSION_NAME Ljava/lang/String; | ||
| } | ||
|
|
||
| public final class io/sentry/reactor/SentryReactorThreadLocalAccessor : io/micrometer/context/ThreadLocalAccessor { | ||
| public static final field KEY Ljava/lang/String; | ||
| public fun <init> ()V | ||
| public fun getValue ()Lio/sentry/IScopes; | ||
| public synthetic fun getValue ()Ljava/lang/Object; | ||
| public fun key ()Ljava/lang/Object; | ||
| public fun reset ()V | ||
| public fun setValue (Lio/sentry/IScopes;)V | ||
| public synthetic fun setValue (Ljava/lang/Object;)V | ||
| } | ||
|
|
||
| public class io/sentry/reactor/SentryReactorUtils { | ||
| public fun <init> ()V | ||
| public static fun withSentry (Lreactor/core/publisher/Flux;)Lreactor/core/publisher/Flux; | ||
| public static fun withSentry (Lreactor/core/publisher/Mono;)Lreactor/core/publisher/Mono; | ||
| public static fun withSentryForkedRoots (Lreactor/core/publisher/Flux;)Lreactor/core/publisher/Flux; | ||
| public static fun withSentryForkedRoots (Lreactor/core/publisher/Mono;)Lreactor/core/publisher/Mono; | ||
| public static fun withSentryScopes (Lreactor/core/publisher/Flux;Lio/sentry/IScopes;)Lreactor/core/publisher/Flux; | ||
| public static fun withSentryScopes (Lreactor/core/publisher/Mono;Lio/sentry/IScopes;)Lreactor/core/publisher/Mono; | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import net.ltgt.gradle.errorprone.errorprone | ||
| import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
|
||
| plugins { | ||
| `java-library` | ||
| kotlin("jvm") | ||
| jacoco | ||
| id(Config.QualityPlugins.errorProne) | ||
| id(Config.QualityPlugins.gradleVersions) | ||
| id(Config.BuildPlugins.buildConfig) version Config.BuildPlugins.buildConfigVersion | ||
| } | ||
|
|
||
| configure<JavaPluginExtension> { | ||
| sourceCompatibility = JavaVersion.VERSION_17 | ||
| targetCompatibility = JavaVersion.VERSION_17 | ||
| } | ||
|
|
||
| tasks.withType<KotlinCompile>().configureEach { | ||
| kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString() | ||
| kotlinOptions.languageVersion = Config.kotlinCompatibleLanguageVersion | ||
| } | ||
|
|
||
| dependencies { | ||
| api(projects.sentry) | ||
| compileOnly(Config.Libs.reactorCore) | ||
| compileOnly(Config.Libs.contextPropagation) | ||
|
|
||
| compileOnly(Config.CompileOnly.nopen) | ||
| errorprone(Config.CompileOnly.nopenChecker) | ||
| errorprone(Config.CompileOnly.errorprone) | ||
| errorprone(Config.CompileOnly.errorProneNullAway) | ||
| compileOnly(Config.CompileOnly.jetbrainsAnnotations) | ||
|
|
||
| // tests | ||
| testImplementation(projects.sentryTestSupport) | ||
| testImplementation(kotlin(Config.kotlinStdLib)) | ||
| testImplementation(Config.TestLibs.kotlinTestJunit) | ||
| testImplementation(Config.TestLibs.mockitoKotlin) | ||
|
|
||
| testImplementation(Config.Libs.reactorCore) | ||
| testImplementation(Config.Libs.contextPropagation) | ||
|
|
||
| testImplementation(platform("org.junit:junit-bom:5.10.0")) | ||
| testImplementation("org.junit.jupiter:junit-jupiter") | ||
| } | ||
|
|
||
| configure<SourceSetContainer> { | ||
| test { | ||
| java.srcDir("src/test/java") | ||
| } | ||
| } | ||
|
|
||
| jacoco { | ||
| toolVersion = Config.QualityPlugins.Jacoco.version | ||
| } | ||
|
|
||
| tasks.jacocoTestReport { | ||
| reports { | ||
| xml.required.set(true) | ||
| html.required.set(false) | ||
| } | ||
| } | ||
|
|
||
| tasks { | ||
| jacocoTestCoverageVerification { | ||
| violationRules { | ||
| rule { limit { minimum = Config.QualityPlugins.Jacoco.minimumCoverage } } | ||
| } | ||
| } | ||
| check { | ||
| dependsOn(jacocoTestCoverageVerification) | ||
| dependsOn(jacocoTestReport) | ||
| } | ||
| } | ||
|
|
||
| buildConfig { | ||
| useJavaOutput() | ||
| packageName("io.sentry.reactor") | ||
| buildConfigField("String", "SENTRY_REACTOR_SDK_NAME", "\"${Config.Sentry.SENTRY_REACTOR_SDK_NAME}\"") | ||
| buildConfigField("String", "VERSION_NAME", "\"${project.version}\"") | ||
| } | ||
|
|
||
| val generateBuildConfig by tasks | ||
| tasks.withType<JavaCompile>().configureEach { | ||
| dependsOn(generateBuildConfig) | ||
| options.errorprone { | ||
| check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR) | ||
| option("NullAway:AnnotatedPackages", "io.sentry") | ||
| } | ||
| } | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } |
4 changes: 1 addition & 3 deletions
4
...lux/SentryReactorThreadLocalAccessor.java → ...tor/SentryReactorThreadLocalAccessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
.../spring/jakarta/webflux/ReactorUtils.java → ...io/sentry/reactor/SentryReactorUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ry-reactor/src/main/resources/META-INF/services/io.micrometer.context.ThreadLocalAccessor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| io.sentry.reactor.SentryReactorThreadLocalAccessor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.