-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
268 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
60 changes: 60 additions & 0 deletions
60
sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/ReactorUtils.java
This file contains 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,60 @@ | ||
package io.sentry.spring.jakarta.webflux; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import io.sentry.IHub; | ||
import io.sentry.Sentry; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
import reactor.util.context.Context; | ||
|
||
@ApiStatus.Experimental | ||
public final class ReactorUtils { | ||
|
||
/** | ||
* Writes the Sentry {@link IHub} to the {@link Context} and uses {@link io.micrometer.context.ThreadLocalAccessor} to propagate it. | ||
* | ||
* This requires | ||
* - reactor.core.publisher.Hooks#enableAutomaticContextPropagation() to be enabled | ||
* - having `io.micrometer:context-propagation:1.0.2` or newer as dependency | ||
* - having `io.projectreactor:reactor-core:3.5.3` or newer as dependency | ||
*/ | ||
@ApiStatus.Experimental | ||
public static <T> Mono<T> withSentry(Mono<T> mono) { | ||
final @NotNull IHub oldHub = Sentry.getCurrentHub(); | ||
final @NotNull IHub clonedHub = oldHub.clone(); | ||
|
||
/** | ||
* WARNING: Cannot set the clonedHub as current hub. | ||
* It would be used by others to clone again causing shared hubs and scopes and thus | ||
* leading to issues like unrelated breadcrumbs showing up in events. | ||
*/ | ||
// Sentry.setCurrentHub(clonedHub); | ||
|
||
return Mono.deferContextual(ctx -> mono).contextWrite(Context.of(SentryReactorThreadLocalAccessor.KEY, clonedHub)); | ||
} | ||
|
||
/** | ||
* Writes the Sentry {@link IHub} to the {@link Context} and uses {@link io.micrometer.context.ThreadLocalAccessor} to propagate it. | ||
* | ||
* This requires | ||
* - reactor.core.publisher.Hooks#enableAutomaticContextPropagation() to be enabled | ||
* - having `io.micrometer:context-propagation:1.0.2` or newer as dependency | ||
* - having `io.projectreactor:reactor-core:3.5.3` or newer as dependency | ||
*/ | ||
@ApiStatus.Experimental | ||
public static <T> Flux<T> withSentry(Flux<T> flux) { | ||
final @NotNull IHub oldHub = Sentry.getCurrentHub(); | ||
final @NotNull IHub clonedHub = oldHub.clone(); | ||
|
||
/** | ||
* WARNING: Cannot set the clonedHub as current hub. | ||
* It would be used by others to clone again causing shared hubs and scopes and thus | ||
* leading to issues like unrelated breadcrumbs showing up in events. | ||
*/ | ||
// Sentry.setCurrentHub(clonedHub); | ||
|
||
return Flux.deferContextual(ctx -> flux).contextWrite(Context.of(SentryReactorThreadLocalAccessor.KEY, clonedHub)); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...arta/src/main/java/io/sentry/spring/jakarta/webflux/SentryReactorThreadLocalAccessor.java
This file contains 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,34 @@ | ||
package io.sentry.spring.jakarta.webflux; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import io.micrometer.context.ThreadLocalAccessor; | ||
import io.sentry.IHub; | ||
import io.sentry.NoOpHub; | ||
import io.sentry.Sentry; | ||
|
||
@ApiStatus.Experimental | ||
public final class SentryReactorThreadLocalAccessor implements ThreadLocalAccessor<IHub> { | ||
|
||
public static final String KEY = "sentry-hub"; | ||
|
||
@Override | ||
public Object key() { | ||
return KEY; | ||
} | ||
|
||
@Override | ||
public IHub getValue() { | ||
return Sentry.getCurrentHub(); | ||
} | ||
|
||
@Override | ||
public void setValue(IHub value) { | ||
Sentry.setCurrentHub(value); | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
Sentry.setCurrentHub(NoOpHub.getInstance()); | ||
} | ||
} |
This file contains 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.