Skip to content

Reactor module fixes #4160

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 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry-reactor/api/sentry-reactor.api
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public final class io/sentry/reactor/SentryReactorThreadLocalAccessor : io/micro
public synthetic fun setValue (Ljava/lang/Object;)V
}

public final class io/sentry/reactor/SentryReactorUtils {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import io.sentry.IScopes;
import io.sentry.NoOpScopes;
import io.sentry.Sentry;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Experimental
public final class SentryReactorThreadLocalAccessor implements ThreadLocalAccessor<IScopes> {

public static final String KEY = "sentry-scopes";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package io.sentry.reactor;

import com.jakewharton.nopen.annotation.Open;
import io.sentry.IScopes;
import io.sentry.Sentry;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.context.Context;

@ApiStatus.Experimental
public final class SentryReactorUtils {
@Open
public class SentryReactorUtils {

/**
* Writes the current Sentry {@link IScopes} to the {@link Context} and uses {@link
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.sentry.reactor

import io.micrometer.context.ContextRegistry
import io.sentry.IScopes
import io.sentry.NoOpScopes
import io.sentry.Sentry
import org.mockito.kotlin.any
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import reactor.core.publisher.Flux
import reactor.core.publisher.Hooks
import reactor.core.publisher.Mono
Expand All @@ -14,61 +16,56 @@ import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotSame
// import org.mockito.kotlin.any
// import org.mockito.kotlin.verify
// import org.mockito.kotlin.whenever
// import kotlin.test.assertSame
import kotlin.test.assertSame

class SentryReactorUtilsTest {

@BeforeTest
fun setup() {
println("setUp")
ContextRegistry.getInstance().registerThreadLocalAccessor(SentryReactorThreadLocalAccessor())
Hooks.enableAutomaticContextPropagation()
Sentry.init("https://key@sentry.io/proj")
}

@AfterTest
fun teardown() {
println("teardown")
Sentry.setCurrentScopes(NoOpScopes.getInstance())
}

// @Test
// fun `propagates scopes inside mono`() {
// val scopesToUse = mock<IScopes>()
// var scopesInside: IScopes? = null
// val mono = SentryReactorUtils.withSentryScopes(
// Mono.just("hello")
// .publishOn(Schedulers.boundedElastic())
// .map { it ->
// scopesInside = Sentry.getCurrentScopes()
// it
// },
// scopesToUse
// )

// assertEquals("hello", mono.block())
// assertSame(scopesToUse, scopesInside)
// }

// @Test
// fun `propagates scopes inside flux`() {
// val scopesToUse = mock<IScopes>()
// var scopesInside: IScopes? = null
// val flux = SentryReactorUtils.withSentryScopes(
// Flux.just("hello")
// .publishOn(Schedulers.boundedElastic())
// .map { it ->
// scopesInside = Sentry.getCurrentScopes()
// it
// },
// scopesToUse
// )

// assertEquals("hello", flux.blockFirst())
// assertSame(scopesToUse, scopesInside)
// }
@Test
fun `propagates scopes inside mono`() {
val scopesToUse = mock<IScopes>()
var scopesInside: IScopes? = null
val mono = SentryReactorUtils.withSentryScopes(
Mono.just("hello")
.publishOn(Schedulers.boundedElastic())
.map { it ->
scopesInside = Sentry.getCurrentScopes()
it
},
scopesToUse
)

assertEquals("hello", mono.block())
assertSame(scopesToUse, scopesInside)
}

@Test
fun `propagates scopes inside flux`() {
val scopesToUse = mock<IScopes>()
var scopesInside: IScopes? = null
val flux = SentryReactorUtils.withSentryScopes(
Flux.just("hello")
.publishOn(Schedulers.boundedElastic())
.map { it ->
scopesInside = Sentry.getCurrentScopes()
it
},
scopesToUse
)

assertEquals("hello", flux.blockFirst())
assertSame(scopesToUse, scopesInside)
}

@Test
fun `without reactive utils scopes is not propagated to mono`() {
Expand Down Expand Up @@ -100,23 +97,23 @@ class SentryReactorUtilsTest {
assertNotSame(scopesToUse, scopesInside)
}

// @Test
// fun `clones scopes for mono`() {
// val mockScopes = mock<IScopes>()
// whenever(mockScopes.forkedCurrentScope(any())).thenReturn(mock<IScopes>())
// Sentry.setCurrentScopes(mockScopes)
// SentryReactorUtils.withSentry(Mono.just("hello")).block()

// verify(mockScopes).forkedCurrentScope(any())
// }

// @Test
// fun `clones scopes for flux`() {
// val mockScopes = mock<IScopes>()
// whenever(mockScopes.forkedCurrentScope(any())).thenReturn(mock<IScopes>())
// Sentry.setCurrentScopes(mockScopes)
// SentryReactorUtils.withSentry(Flux.just("hello")).blockFirst()

// verify(mockScopes).forkedCurrentScope(any())
// }
@Test
fun `clones scopes for mono`() {
val mockScopes = mock<IScopes>()
whenever(mockScopes.forkedCurrentScope(any())).thenReturn(mock<IScopes>())
Sentry.setCurrentScopes(mockScopes)
SentryReactorUtils.withSentry(Mono.just("hello")).block()

verify(mockScopes).forkedCurrentScope(any())
}

@Test
fun `clones scopes for flux`() {
val mockScopes = mock<IScopes>()
whenever(mockScopes.forkedCurrentScope(any())).thenReturn(mock<IScopes>())
Sentry.setCurrentScopes(mockScopes)
SentryReactorUtils.withSentry(Flux.just("hello")).blockFirst()

verify(mockScopes).forkedCurrentScope(any())
}
}
4 changes: 4 additions & 0 deletions sentry-spring-jakarta/api/sentry-spring-jakarta.api
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,7 @@ public final class io/sentry/spring/jakarta/webflux/SentryWebFilterWithThreadLoc
public fun filter (Lorg/springframework/web/server/ServerWebExchange;Lorg/springframework/web/server/WebFilterChain;)Lreactor/core/publisher/Mono;
}

public final class io/sentry/spring/jakarta/webflux/reactor/ReactorUtils : io/sentry/reactor/SentryReactorUtils {
public fun <init> ()V
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.sentry.spring.jakarta.webflux.reactor;

import io.sentry.reactor.SentryReactorUtils;

/**
* @deprecated Please use {@link SentryReactorUtils} directly.
*/
@Deprecated
public final class ReactorUtils extends SentryReactorUtils {}
Loading