diff --git a/sentry-spring-jakarta/api/sentry-spring-jakarta.api b/sentry-spring-jakarta/api/sentry-spring-jakarta.api index 13eb6033f9..156ab1aaee 100644 --- a/sentry-spring-jakarta/api/sentry-spring-jakarta.api +++ b/sentry-spring-jakarta/api/sentry-spring-jakarta.api @@ -282,10 +282,10 @@ public final class io/sentry/spring/jakarta/webflux/ReactorUtils { public fun ()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 withSentryHub (Lreactor/core/publisher/Flux;Lio/sentry/IScopes;)Lreactor/core/publisher/Flux; - public static fun withSentryHub (Lreactor/core/publisher/Mono;Lio/sentry/IScopes;)Lreactor/core/publisher/Mono; - public static fun withSentryNewMainHubClone (Lreactor/core/publisher/Flux;)Lreactor/core/publisher/Flux; - public static fun withSentryNewMainHubClone (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; } public final class io/sentry/spring/jakarta/webflux/SentryReactorThreadLocalAccessor : io/micrometer/context/ThreadLocalAccessor { diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentrySpringFilter.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentrySpringFilter.java index be06d3d253..2e3561a982 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentrySpringFilter.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentrySpringFilter.java @@ -9,6 +9,7 @@ import io.sentry.EventProcessor; import io.sentry.Hint; import io.sentry.IScopes; +import io.sentry.ISentryLifecycleToken; import io.sentry.ScopesAdapter; import io.sentry.SentryEvent; import io.sentry.SentryLevel; @@ -60,7 +61,7 @@ protected void doFilterInternal( if (scopes.isEnabled()) { // request may qualify for caching request body, if so resolve cached request final HttpServletRequest request = resolveHttpServletRequest(servletRequest); - scopes.pushScope(); + final @NotNull ISentryLifecycleToken lifecycleToken = scopes.pushIsolationScope(); try { final Hint hint = new Hint(); hint.set(SPRING_REQUEST_FILTER_REQUEST, servletRequest); @@ -70,7 +71,7 @@ protected void doFilterInternal( configureScope(request); filterChain.doFilter(request, response); } finally { - scopes.popScope(); + lifecycleToken.close(); } } else { filterChain.doFilter(servletRequest, response); diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryTaskDecorator.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryTaskDecorator.java index c99abf3e21..943a7cc5ff 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryTaskDecorator.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryTaskDecorator.java @@ -1,6 +1,7 @@ package io.sentry.spring.jakarta; import io.sentry.IScopes; +import io.sentry.ISentryLifecycleToken; import io.sentry.Sentry; import java.util.concurrent.Callable; import org.jetbrains.annotations.NotNull; @@ -14,18 +15,13 @@ */ public final class SentryTaskDecorator implements TaskDecorator { @Override - @SuppressWarnings("deprecation") + // TODO should there also be a SentryIsolatedTaskDecorator or similar that uses forkedScopes()? public @NotNull Runnable decorate(final @NotNull Runnable runnable) { - // TODO fork - final IScopes newHub = Sentry.getCurrentScopes().clone(); + final IScopes newScopes = Sentry.getCurrentScopes().forkedCurrentScope("spring.taskDecorator"); return () -> { - final IScopes oldState = Sentry.getCurrentScopes(); - Sentry.setCurrentScopes(newHub); - try { + try (final @NotNull ISentryLifecycleToken ignored = newScopes.makeCurrent()) { runnable.run(); - } finally { - Sentry.setCurrentScopes(oldState); } }; } diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/tracing/SentryTransactionAdvice.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/tracing/SentryTransactionAdvice.java index f04b3dd7a6..da781afcd8 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/tracing/SentryTransactionAdvice.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/tracing/SentryTransactionAdvice.java @@ -2,6 +2,7 @@ import com.jakewharton.nopen.annotation.Open; import io.sentry.IScopes; +import io.sentry.ISentryLifecycleToken; import io.sentry.ITransaction; import io.sentry.ScopesAdapter; import io.sentry.SpanStatus; @@ -68,7 +69,7 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl } else { operation = "bean"; } - scopes.pushScope(); + final @NotNull ISentryLifecycleToken lifecycleToken = scopes.pushIsolationScope(); final TransactionOptions transactionOptions = new TransactionOptions(); transactionOptions.setBindToScope(true); final ITransaction transaction = @@ -86,7 +87,7 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl throw e; } finally { transaction.finish(); - scopes.popScope(); + lifecycleToken.close(); } } } diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/AbstractSentryWebFilter.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/AbstractSentryWebFilter.java index 3321874dd8..5995728785 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/AbstractSentryWebFilter.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/AbstractSentryWebFilter.java @@ -68,10 +68,6 @@ protected void doFinally( if (transaction != null) { finishTransaction(serverWebExchange, transaction); } - if (requestHub.isEnabled()) { - // TODO close lifecycle token instead of popscope - requestHub.popScope(); - } Sentry.setCurrentScopes(NoOpScopes.getInstance()); } @@ -79,8 +75,6 @@ protected void doFirst( final @NotNull ServerWebExchange serverWebExchange, final @NotNull IScopes requestHub) { if (requestHub.isEnabled()) { serverWebExchange.getAttributes().put(SENTRY_SCOPES_KEY, requestHub); - // TODO fork instead - requestHub.pushScope(); final ServerHttpRequest request = serverWebExchange.getRequest(); final ServerHttpResponse response = serverWebExchange.getResponse(); diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/ReactorUtils.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/ReactorUtils.java index 41dd2e4bc0..9755ea0932 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/ReactorUtils.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/ReactorUtils.java @@ -10,6 +10,8 @@ // TODO deprecate and replace with "withSentryScopes" etc. @ApiStatus.Experimental +// TODO do we keep old methods around and deprecate them? +// TODO do we need to offer isolated variants? public final class ReactorUtils { /** @@ -20,27 +22,23 @@ public final class ReactorUtils { * enabled - having `io.micrometer:context-propagation:1.0.2+` (provided by Spring Boot 3.0.3+) - * having `io.projectreactor:reactor-core:3.5.3+` (provided by Spring Boot 3.0.3+) */ - @ApiStatus.Experimental - @SuppressWarnings("deprecation") public static Mono withSentry(final @NotNull Mono mono) { - final @NotNull IScopes oldHub = Sentry.getCurrentScopes(); - // TODO fork - final @NotNull IScopes clonedHub = oldHub.clone(); - return withSentryHub(mono, clonedHub); + final @NotNull IScopes oldScopes = Sentry.getCurrentScopes(); + final @NotNull IScopes forkedScopes = oldScopes.forkedCurrentScope("reactor.withSentry"); + return withSentryScopes(mono, forkedScopes); } /** - * Writes a new Sentry {@link IScopes} cloned from the main hub to the {@link Context} and uses + * Writes a new Sentry {@link IScopes} cloned from the main scopes 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+` (provided by Spring Boot 3.0.3+) - * having `io.projectreactor:reactor-core:3.5.3+` (provided by Spring Boot 3.0.3+) */ - @ApiStatus.Experimental - public static Mono withSentryNewMainHubClone(final @NotNull Mono mono) { - final @NotNull IScopes hub = Sentry.cloneMainHub(); - return withSentryHub(mono, hub); + public static Mono withSentryForkedRoots(final @NotNull Mono mono) { + final @NotNull IScopes scopes = Sentry.forkedRootScopes("reactor"); + return withSentryScopes(mono, scopes); } /** @@ -51,17 +49,16 @@ public static Mono withSentryNewMainHubClone(final @NotNull Mono mono) * enabled - having `io.micrometer:context-propagation:1.0.2+` (provided by Spring Boot 3.0.3+) - * having `io.projectreactor:reactor-core:3.5.3+` (provided by Spring Boot 3.0.3+) */ - @ApiStatus.Experimental - public static Mono withSentryHub(final @NotNull Mono mono, final @NotNull IScopes hub) { + public static Mono withSentryScopes( + final @NotNull Mono mono, final @NotNull IScopes scopes) { /** - * WARNING: Cannot set the hub as current. 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. + * WARNING: Cannot set the scopes as current. It would be used by others to clone again causing + * shared scopes and thus leading to issues like unrelated breadcrumbs showing up in events. */ - // Sentry.setCurrentHub(clonedHub); + // Sentry.setCurrentScopes(forkedScopes); return Mono.deferContextual(ctx -> mono) - .contextWrite(Context.of(SentryReactorThreadLocalAccessor.KEY, hub)); + .contextWrite(Context.of(SentryReactorThreadLocalAccessor.KEY, scopes)); } /** @@ -72,28 +69,24 @@ public static Mono withSentryHub(final @NotNull Mono mono, final @NotN * enabled - having `io.micrometer:context-propagation:1.0.2+` (provided by Spring Boot 3.0.3+) - * having `io.projectreactor:reactor-core:3.5.3+` (provided by Spring Boot 3.0.3+) */ - @ApiStatus.Experimental - @SuppressWarnings("deprecation") public static Flux withSentry(final @NotNull Flux flux) { - final @NotNull IScopes oldHub = Sentry.getCurrentScopes(); - // TODO fork - final @NotNull IScopes clonedHub = oldHub.clone(); + final @NotNull IScopes oldScopes = Sentry.getCurrentScopes(); + final @NotNull IScopes forkedScopes = oldScopes.forkedCurrentScope("reactor.withSentry"); - return withSentryHub(flux, clonedHub); + return withSentryScopes(flux, forkedScopes); } /** - * Writes a new Sentry {@link IScopes} cloned from the main hub to the {@link Context} and uses + * Writes a new Sentry {@link IScopes} cloned from the main scopes 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+` (provided by Spring Boot 3.0.3+) - * having `io.projectreactor:reactor-core:3.5.3+` (provided by Spring Boot 3.0.3+) */ - @ApiStatus.Experimental - public static Flux withSentryNewMainHubClone(final @NotNull Flux flux) { - final @NotNull IScopes hub = Sentry.cloneMainHub(); - return withSentryHub(flux, hub); + public static Flux withSentryForkedRoots(final @NotNull Flux flux) { + final @NotNull IScopes scopes = Sentry.forkedRootScopes("reactor"); + return withSentryScopes(flux, scopes); } /** @@ -104,16 +97,15 @@ public static Flux withSentryNewMainHubClone(final @NotNull Flux flux) * enabled - having `io.micrometer:context-propagation:1.0.2+` (provided by Spring Boot 3.0.3+) - * having `io.projectreactor:reactor-core:3.5.3+` (provided by Spring Boot 3.0.3+) */ - @ApiStatus.Experimental - public static Flux withSentryHub(final @NotNull Flux flux, final @NotNull IScopes hub) { + public static Flux withSentryScopes( + final @NotNull Flux flux, final @NotNull IScopes scopes) { /** - * WARNING: Cannot set the hub as current. 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. + * WARNING: Cannot set the scopes as current. It would be used by others to clone again causing + * shared scopes and thus leading to issues like unrelated breadcrumbs showing up in events. */ - // Sentry.setCurrentHub(clonedHub); + // Sentry.setCurrentScopes(forkedScopes); return Flux.deferContextual(ctx -> flux) - .contextWrite(Context.of(SentryReactorThreadLocalAccessor.KEY, hub)); + .contextWrite(Context.of(SentryReactorThreadLocalAccessor.KEY, scopes)); } } diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryScheduleHook.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryScheduleHook.java index 882a0b268a..21b35bc60b 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryScheduleHook.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryScheduleHook.java @@ -1,6 +1,7 @@ package io.sentry.spring.jakarta.webflux; import io.sentry.IScopes; +import io.sentry.ISentryLifecycleToken; import io.sentry.Sentry; import java.util.function.Function; import org.jetbrains.annotations.ApiStatus; @@ -8,23 +9,18 @@ /** * Hook meant to used with {@link reactor.core.scheduler.Schedulers#onScheduleHook(String, - * Function)} to configure Reactor to copy correct hub into the operating thread. + * Function)} to configure Reactor to copy correct scopes into the operating thread. */ @ApiStatus.Experimental public final class SentryScheduleHook implements Function { @Override @SuppressWarnings("deprecation") public Runnable apply(final @NotNull Runnable runnable) { - // TODO fork instead - final IScopes newHub = Sentry.getCurrentScopes().clone(); + final IScopes newScopes = Sentry.getCurrentScopes().forkedCurrentScope("spring.scheduleHook"); return () -> { - final IScopes oldState = Sentry.getCurrentScopes(); - Sentry.setCurrentScopes(newHub); - try { + try (final @NotNull ISentryLifecycleToken ignored = newScopes.makeCurrent()) { runnable.run(); - } finally { - Sentry.setCurrentScopes(oldState); } }; } diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryWebExceptionHandler.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryWebExceptionHandler.java index 40b0ed4e87..15c73ab625 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryWebExceptionHandler.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryWebExceptionHandler.java @@ -40,7 +40,7 @@ public SentryWebExceptionHandler(final @NotNull IScopes scopes) { serverWebExchange.getAttributeOrDefault(SentryWebFilter.SENTRY_SCOPES_KEY, null); final @NotNull IScopes scopesToUse = requestScopes != null ? requestScopes : scopes; - return ReactorUtils.withSentryHub( + return ReactorUtils.withSentryScopes( Mono.just(ex) .map( it -> { diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryWebFilter.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryWebFilter.java index dab985eecf..0a6b767ec4 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryWebFilter.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryWebFilter.java @@ -28,7 +28,7 @@ public SentryWebFilter(final @NotNull IScopes scopes) { public Mono filter( final @NotNull ServerWebExchange serverWebExchange, final @NotNull WebFilterChain webFilterChain) { - @NotNull IScopes requestScopes = Sentry.cloneMainHub(); + @NotNull IScopes requestScopes = Sentry.forkedRootScopes("request.webflux"); final ServerHttpRequest request = serverWebExchange.getRequest(); final @Nullable ITransaction transaction = maybeStartTransaction(requestScopes, request); if (transaction != null) { diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryWebFilterWithThreadLocalAccessor.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryWebFilterWithThreadLocalAccessor.java index e760ef8f3e..c38e322731 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryWebFilterWithThreadLocalAccessor.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryWebFilterWithThreadLocalAccessor.java @@ -26,7 +26,7 @@ public Mono filter( final @NotNull ServerWebExchange serverWebExchange, final @NotNull WebFilterChain webFilterChain) { final @NotNull TransactionContainer transactionContainer = new TransactionContainer(); - return ReactorUtils.withSentryNewMainHubClone( + return ReactorUtils.withSentryForkedRoots( webFilterChain .filter(serverWebExchange) .doFinally( diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentrySpringFilterTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentrySpringFilterTest.kt index b6bce77a0b..ac394deb31 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentrySpringFilterTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentrySpringFilterTest.kt @@ -3,6 +3,7 @@ package io.sentry.spring.jakarta import io.sentry.Breadcrumb import io.sentry.IScope import io.sentry.IScopes +import io.sentry.ISentryLifecycleToken import io.sentry.Scope import io.sentry.ScopeCallback import io.sentry.SentryOptions @@ -39,6 +40,7 @@ class SentrySpringFilterTest { private class Fixture { val scopes = mock() val response = MockHttpServletResponse() + val lifecycleToken = mock() val chain = mock() lateinit var scope: IScope lateinit var request: HttpServletRequest @@ -47,6 +49,7 @@ class SentrySpringFilterTest { scope = Scope(options) whenever(scopes.options).thenReturn(options) whenever(scopes.isEnabled).thenReturn(true) + whenever(scopes.pushIsolationScope()).thenReturn(lifecycleToken) doAnswer { (it.arguments[0] as ScopeCallback).run(scope) }.whenever(scopes).configureScope(any()) this.request = request ?: MockHttpServletRequest().apply { @@ -64,7 +67,7 @@ class SentrySpringFilterTest { val listener = fixture.getSut() listener.doFilter(fixture.request, fixture.response, fixture.chain) - verify(fixture.scopes).pushScope() + verify(fixture.scopes).pushIsolationScope() } @Test @@ -87,7 +90,7 @@ class SentrySpringFilterTest { val listener = fixture.getSut() listener.doFilter(fixture.request, fixture.response, fixture.chain) - verify(fixture.scopes).popScope() + verify(fixture.lifecycleToken).close() } @Test @@ -99,7 +102,7 @@ class SentrySpringFilterTest { listener.doFilter(fixture.request, fixture.response, fixture.chain) fail() } catch (e: Exception) { - verify(fixture.scopes).popScope() + verify(fixture.lifecycleToken).close() } } diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryTaskDecoratorTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryTaskDecoratorTest.kt index e5f8704b49..d44e64f78d 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryTaskDecoratorTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryTaskDecoratorTest.kt @@ -25,35 +25,35 @@ class SentryTaskDecoratorTest { } @Test - fun `hub is reset to its state within the thread after decoration is done`() { + fun `scopes is reset to its state within the thread after decoration is done`() { Sentry.init { it.dsn = dsn } val sut = SentryTaskDecorator() - val mainHub = Sentry.getCurrentScopes() - val threadedHub = Sentry.getCurrentScopes().clone() + val mainScopes = Sentry.getCurrentScopes() + val threadedScopes = Sentry.getCurrentScopes().forkedCurrentScope("test") executor.submit { - Sentry.setCurrentScopes(threadedHub) + Sentry.setCurrentScopes(threadedScopes) }.get() - assertEquals(mainHub, Sentry.getCurrentScopes()) + assertEquals(mainScopes, Sentry.getCurrentScopes()) val callableFuture = executor.submit( sut.decorate { - assertNotEquals(mainHub, Sentry.getCurrentScopes()) - assertNotEquals(threadedHub, Sentry.getCurrentScopes()) + assertNotEquals(mainScopes, Sentry.getCurrentScopes()) + assertNotEquals(threadedScopes, Sentry.getCurrentScopes()) } ) callableFuture.get() executor.submit { - assertNotEquals(mainHub, Sentry.getCurrentScopes()) - assertEquals(threadedHub, Sentry.getCurrentScopes()) + assertNotEquals(mainScopes, Sentry.getCurrentScopes()) + assertEquals(threadedScopes, Sentry.getCurrentScopes()) }.get() } } diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/tracing/SentryTransactionAdviceTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/tracing/SentryTransactionAdviceTest.kt index 390b4d8241..b0f83782e0 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/tracing/SentryTransactionAdviceTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/tracing/SentryTransactionAdviceTest.kt @@ -1,6 +1,7 @@ package io.sentry.spring.jakarta.tracing import io.sentry.IScopes +import io.sentry.ISentryLifecycleToken import io.sentry.Sentry import io.sentry.SentryOptions import io.sentry.SentryTracer @@ -46,6 +47,8 @@ class SentryTransactionAdviceTest { @Autowired lateinit var scopes: IScopes + val lifecycleToken = mock() + @BeforeTest fun setup() { reset(scopes) @@ -55,6 +58,7 @@ class SentryTransactionAdviceTest { dsn = "https://key@sentry.io/proj" } ) + whenever(scopes.pushIsolationScope()).thenReturn(lifecycleToken) } @Test @@ -141,13 +145,13 @@ class SentryTransactionAdviceTest { @Test fun `pushes the scope when advice starts`() { classAnnotatedSampleService.hello() - verify(scopes).pushScope() + verify(scopes).pushIsolationScope() } @Test fun `pops the scope when advice finishes`() { classAnnotatedSampleService.hello() - verify(scopes).popScope() + verify(lifecycleToken).close() } @Configuration diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/ReactorUtilsTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/ReactorUtilsTest.kt index 9c851cde11..f3bd5d2653 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/ReactorUtilsTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/ReactorUtilsTest.kt @@ -1,9 +1,9 @@ package io.sentry.spring.jakarta.webflux -import io.sentry.IHub 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 @@ -31,88 +31,88 @@ class ReactorUtilsTest { } @Test - fun `propagates hub inside mono`() { - val hubToUse = mock() - var hubInside: IScopes? = null - val mono = ReactorUtils.withSentryHub( + fun `propagates scopes inside mono`() { + val scopesToUse = mock() + var scopesInside: IScopes? = null + val mono = ReactorUtils.withSentryScopes( Mono.just("hello") .publishOn(Schedulers.boundedElastic()) .map { it -> - hubInside = Sentry.getCurrentScopes() + scopesInside = Sentry.getCurrentScopes() it }, - hubToUse + scopesToUse ) assertEquals("hello", mono.block()) - assertSame(hubToUse, hubInside) + assertSame(scopesToUse, scopesInside) } @Test - fun `propagates hub inside flux`() { - val hubToUse = mock() - var hubInside: IScopes? = null - val flux = ReactorUtils.withSentryHub( + fun `propagates scopes inside flux`() { + val scopesToUse = mock() + var scopesInside: IScopes? = null + val flux = ReactorUtils.withSentryScopes( Flux.just("hello") .publishOn(Schedulers.boundedElastic()) .map { it -> - hubInside = Sentry.getCurrentScopes() + scopesInside = Sentry.getCurrentScopes() it }, - hubToUse + scopesToUse ) assertEquals("hello", flux.blockFirst()) - assertSame(hubToUse, hubInside) + assertSame(scopesToUse, scopesInside) } @Test - fun `without reactive utils hub is not propagated to mono`() { - val hubToUse = mock() - var hubInside: IScopes? = null + fun `without reactive utils scopes is not propagated to mono`() { + val scopesToUse = mock() + var scopesInside: IScopes? = null val mono = Mono.just("hello") .publishOn(Schedulers.boundedElastic()) .map { it -> - hubInside = Sentry.getCurrentScopes() + scopesInside = Sentry.getCurrentScopes() it } assertEquals("hello", mono.block()) - assertNotSame(hubToUse, hubInside) + assertNotSame(scopesToUse, scopesInside) } @Test - fun `without reactive utils hub is not propagated to flux`() { - val hubToUse = mock() - var hubInside: IScopes? = null + fun `without reactive utils scopes is not propagated to flux`() { + val scopesToUse = mock() + var scopesInside: IScopes? = null val flux = Flux.just("hello") .publishOn(Schedulers.boundedElastic()) .map { it -> - hubInside = Sentry.getCurrentScopes() + scopesInside = Sentry.getCurrentScopes() it } assertEquals("hello", flux.blockFirst()) - assertNotSame(hubToUse, hubInside) + assertNotSame(scopesToUse, scopesInside) } @Test - fun `clones hub for mono`() { + fun `clones scopes for mono`() { val mockScopes = mock() - whenever(mockScopes.clone()).thenReturn(mock()) + whenever(mockScopes.forkedCurrentScope(any())).thenReturn(mock()) Sentry.setCurrentScopes(mockScopes) ReactorUtils.withSentry(Mono.just("hello")).block() - verify(mockScopes).clone() + verify(mockScopes).forkedCurrentScope(any()) } @Test - fun `clones hub for flux`() { + fun `clones scopes for flux`() { val mockScopes = mock() - whenever(mockScopes.clone()).thenReturn(mock()) + whenever(mockScopes.forkedCurrentScope(any())).thenReturn(mock()) Sentry.setCurrentScopes(mockScopes) ReactorUtils.withSentry(Flux.just("hello")).blockFirst() - verify(mockScopes).clone() + verify(mockScopes).forkedCurrentScope(any()) } } diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryScheduleHookTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryScheduleHookTest.kt index 5403caa7e0..4b540da1aa 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryScheduleHookTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryScheduleHookTest.kt @@ -26,35 +26,35 @@ class SentryScheduleHookTest { } @Test - fun `hub is reset to its state within the thread after hook is done`() { + fun `scopes is reset to its state within the thread after hook is done`() { Sentry.init { it.dsn = dsn } val sut = SentryScheduleHook() - val mainHub = Sentry.getCurrentScopes() - val threadedHub = Sentry.getCurrentScopes().clone() + val mainScopes = Sentry.getCurrentScopes() + val threadedScopes = Sentry.getCurrentScopes().forkedCurrentScope("test") executor.submit { - Sentry.setCurrentScopes(threadedHub) + Sentry.setCurrentScopes(threadedScopes) }.get() - assertEquals(mainHub, Sentry.getCurrentScopes()) + assertEquals(mainScopes, Sentry.getCurrentScopes()) val callableFuture = executor.submit( sut.apply { - assertNotEquals(mainHub, Sentry.getCurrentScopes()) - assertNotEquals(threadedHub, Sentry.getCurrentScopes()) + assertNotEquals(mainScopes, Sentry.getCurrentScopes()) + assertNotEquals(threadedScopes, Sentry.getCurrentScopes()) } ) callableFuture.get() executor.submit { - assertNotEquals(mainHub, Sentry.getCurrentScopes()) - assertEquals(threadedHub, Sentry.getCurrentScopes()) + assertNotEquals(mainScopes, Sentry.getCurrentScopes()) + assertEquals(threadedScopes, Sentry.getCurrentScopes()) }.get() } } diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryWebFluxTracingFilterTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryWebFluxTracingFilterTest.kt index ddbbe75817..44f4925c2d 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryWebFluxTracingFilterTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryWebFluxTracingFilterTest.kt @@ -89,7 +89,7 @@ class SentryWebFluxTracingFilterTest { fun withMockScopes(closure: () -> Unit) = Mockito.mockStatic(Sentry::class.java).use { it.`when` { Sentry.getCurrentHub() }.thenReturn(HubScopesWrapper(fixture.scopes)) it.`when` { Sentry.getCurrentScopes() }.thenReturn(fixture.scopes) - it.`when` { Sentry.cloneMainHub() }.thenReturn(fixture.scopes) + it.`when` { Sentry.forkedRootScopes(any()) }.thenReturn(fixture.scopes) closure.invoke() } @@ -210,7 +210,7 @@ class SentryWebFluxTracingFilterTest { verify(fixture.chain).filter(fixture.exchange) - verify(fixture.scopes, times(3)).isEnabled + verify(fixture.scopes, times(2)).isEnabled verifyNoMoreInteractions(fixture.scopes) } } @@ -249,13 +249,11 @@ class SentryWebFluxTracingFilterTest { verify(fixture.chain).filter(fixture.exchange) - verify(fixture.scopes, times(3)).isEnabled + verify(fixture.scopes, times(2)).isEnabled verify(fixture.scopes, times(2)).options verify(fixture.scopes).continueTrace(anyOrNull(), anyOrNull()) - verify(fixture.scopes).pushScope() // TODO don't verify(fixture.scopes).addBreadcrumb(any(), any()) verify(fixture.scopes).configureScope(any()) - verify(fixture.scopes).popScope() // TODO don't verifyNoMoreInteractions(fixture.scopes) } } diff --git a/sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java b/sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java index 7695545f04..252a07910c 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java +++ b/sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java @@ -9,6 +9,7 @@ import io.sentry.EventProcessor; import io.sentry.Hint; import io.sentry.IScopes; +import io.sentry.ISentryLifecycleToken; import io.sentry.ScopesAdapter; import io.sentry.SentryEvent; import io.sentry.SentryLevel; @@ -60,7 +61,7 @@ protected void doFilterInternal( if (scopes.isEnabled()) { // request may qualify for caching request body, if so resolve cached request final HttpServletRequest request = resolveHttpServletRequest(servletRequest); - scopes.pushScope(); + final @NotNull ISentryLifecycleToken lifecycleToken = scopes.pushIsolationScope(); try { final Hint hint = new Hint(); hint.set(SPRING_REQUEST_FILTER_REQUEST, servletRequest); @@ -70,7 +71,7 @@ protected void doFilterInternal( configureScope(request); filterChain.doFilter(request, response); } finally { - scopes.popScope(); + lifecycleToken.close(); } } else { filterChain.doFilter(servletRequest, response); diff --git a/sentry-spring/src/main/java/io/sentry/spring/SentryTaskDecorator.java b/sentry-spring/src/main/java/io/sentry/spring/SentryTaskDecorator.java index 88d205a57e..761038ece0 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/SentryTaskDecorator.java +++ b/sentry-spring/src/main/java/io/sentry/spring/SentryTaskDecorator.java @@ -1,6 +1,7 @@ package io.sentry.spring; import io.sentry.IScopes; +import io.sentry.ISentryLifecycleToken; import io.sentry.Sentry; import java.util.concurrent.Callable; import org.jetbrains.annotations.NotNull; @@ -14,18 +15,13 @@ */ public final class SentryTaskDecorator implements TaskDecorator { @Override - @SuppressWarnings("deprecation") + // TODO should there also be a SentryIsolatedTaskDecorator or similar that uses forkedScopes()? public @NotNull Runnable decorate(final @NotNull Runnable runnable) { - // TODO fork instead - final IScopes newHub = Sentry.getCurrentScopes().clone(); + final IScopes newHub = Sentry.getCurrentScopes().forkedCurrentScope("spring.taskDecorator"); return () -> { - final IScopes oldState = Sentry.getCurrentScopes(); - Sentry.setCurrentScopes(newHub); - try { + try (final @NotNull ISentryLifecycleToken ignored = newHub.makeCurrent()) { runnable.run(); - } finally { - Sentry.setCurrentScopes(oldState); } }; } diff --git a/sentry-spring/src/main/java/io/sentry/spring/tracing/SentryTransactionAdvice.java b/sentry-spring/src/main/java/io/sentry/spring/tracing/SentryTransactionAdvice.java index 8f4f5bbdfc..a885510fcd 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/tracing/SentryTransactionAdvice.java +++ b/sentry-spring/src/main/java/io/sentry/spring/tracing/SentryTransactionAdvice.java @@ -2,6 +2,7 @@ import com.jakewharton.nopen.annotation.Open; import io.sentry.IScopes; +import io.sentry.ISentryLifecycleToken; import io.sentry.ITransaction; import io.sentry.ScopesAdapter; import io.sentry.SpanStatus; @@ -67,7 +68,7 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl } else { operation = "bean"; } - scopes.pushScope(); + final @NotNull ISentryLifecycleToken lifecycleToken = scopes.pushIsolationScope(); final TransactionOptions transactionOptions = new TransactionOptions(); transactionOptions.setBindToScope(true); final ITransaction transaction = @@ -85,7 +86,7 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl throw e; } finally { transaction.finish(); - scopes.popScope(); + lifecycleToken.close(); } } } diff --git a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryScheduleHook.java b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryScheduleHook.java index 20f494168d..4f8312835a 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryScheduleHook.java +++ b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryScheduleHook.java @@ -1,6 +1,7 @@ package io.sentry.spring.webflux; import io.sentry.IScopes; +import io.sentry.ISentryLifecycleToken; import io.sentry.Sentry; import java.util.function.Function; import org.jetbrains.annotations.ApiStatus; @@ -8,23 +9,18 @@ /** * Hook meant to used with {@link reactor.core.scheduler.Schedulers#onScheduleHook(String, - * Function)} to configure Reactor to copy correct hub into the operating thread. + * Function)} to configure Reactor to copy correct scopes into the operating thread. */ @ApiStatus.Experimental public final class SentryScheduleHook implements Function { @Override @SuppressWarnings("deprecation") public Runnable apply(final @NotNull Runnable runnable) { - // TODO fork instead - final IScopes newHub = Sentry.getCurrentScopes().clone(); + final IScopes newScopes = Sentry.getCurrentScopes().forkedCurrentScope("spring.scheduleHook"); return () -> { - final IScopes oldState = Sentry.getCurrentScopes(); - Sentry.setCurrentScopes(newHub); - try { + try (final @NotNull ISentryLifecycleToken ignored = newScopes.makeCurrent()) { runnable.run(); - } finally { - Sentry.setCurrentScopes(oldState); } }; } diff --git a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebFilter.java b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebFilter.java index 4d39e092bc..10e80ebe8b 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebFilter.java +++ b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebFilter.java @@ -50,7 +50,7 @@ public SentryWebFilter(final @NotNull IScopes scopes) { public Mono filter( final @NotNull ServerWebExchange serverWebExchange, final @NotNull WebFilterChain webFilterChain) { - @NotNull IScopes requestHub = Sentry.cloneMainHub(); + @NotNull IScopes requestHub = Sentry.forkedRootScopes("request.webflux"); // TODO do not push / pop, use fork instead if (!requestHub.isEnabled()) { return webFilterChain.filter(serverWebExchange); @@ -81,8 +81,6 @@ isTracingEnabled && shouldTraceRequest(requestHub, request) if (transaction != null) { finishTransaction(serverWebExchange, transaction); } - requestHub.popScope(); // TODO don't - // TODO token based cleanup instead? Sentry.setCurrentScopes(NoOpScopes.getInstance()); }) .doOnError( @@ -96,7 +94,6 @@ isTracingEnabled && shouldTraceRequest(requestHub, request) () -> { serverWebExchange.getAttributes().put(SENTRY_SCOPES_KEY, requestHub); Sentry.setCurrentScopes(requestHub); - requestHub.pushScope(); // TODO don't final ServerHttpResponse response = serverWebExchange.getResponse(); final Hint hint = new Hint(); diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/SentrySpringFilterTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/SentrySpringFilterTest.kt index c6ac952531..6037e253c8 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/SentrySpringFilterTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/SentrySpringFilterTest.kt @@ -3,6 +3,7 @@ package io.sentry.spring import io.sentry.Breadcrumb import io.sentry.IScope import io.sentry.IScopes +import io.sentry.ISentryLifecycleToken import io.sentry.Scope import io.sentry.ScopeCallback import io.sentry.SentryOptions @@ -39,6 +40,7 @@ class SentrySpringFilterTest { private class Fixture { val scopes = mock() val response = MockHttpServletResponse() + val lifecycleToken = mock() val chain = mock() lateinit var scope: IScope lateinit var request: HttpServletRequest @@ -47,6 +49,7 @@ class SentrySpringFilterTest { scope = Scope(options) whenever(scopes.options).thenReturn(options) whenever(scopes.isEnabled).thenReturn(true) + whenever(scopes.pushIsolationScope()).thenReturn(lifecycleToken) doAnswer { (it.arguments[0] as ScopeCallback).run(scope) }.whenever(scopes).configureScope(any()) this.request = request ?: MockHttpServletRequest().apply { @@ -64,7 +67,7 @@ class SentrySpringFilterTest { val listener = fixture.getSut() listener.doFilter(fixture.request, fixture.response, fixture.chain) - verify(fixture.scopes).pushScope() + verify(fixture.scopes).pushIsolationScope() } @Test @@ -87,7 +90,7 @@ class SentrySpringFilterTest { val listener = fixture.getSut() listener.doFilter(fixture.request, fixture.response, fixture.chain) - verify(fixture.scopes).popScope() + verify(fixture.lifecycleToken).close() } @Test @@ -99,7 +102,7 @@ class SentrySpringFilterTest { listener.doFilter(fixture.request, fixture.response, fixture.chain) fail() } catch (e: Exception) { - verify(fixture.scopes).popScope() + verify(fixture.lifecycleToken).close() } } diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/SentryTaskDecoratorTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/SentryTaskDecoratorTest.kt index 3f34ab9d9d..4bbce919eb 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/SentryTaskDecoratorTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/SentryTaskDecoratorTest.kt @@ -25,35 +25,35 @@ class SentryTaskDecoratorTest { } @Test - fun `hub is reset to its state within the thread after decoration is done`() { + fun `scopes is reset to its state within the thread after decoration is done`() { Sentry.init { it.dsn = dsn } val sut = SentryTaskDecorator() - val mainHub = Sentry.getCurrentScopes() - val threadedHub = Sentry.getCurrentScopes().clone() + val mainScopes = Sentry.getCurrentScopes() + val threadedScopes = Sentry.getCurrentScopes().forkedCurrentScope("test") executor.submit { - Sentry.setCurrentScopes(threadedHub) + Sentry.setCurrentScopes(threadedScopes) }.get() - assertEquals(mainHub, Sentry.getCurrentScopes()) + assertEquals(mainScopes, Sentry.getCurrentScopes()) val callableFuture = executor.submit( sut.decorate { - assertNotEquals(mainHub, Sentry.getCurrentScopes()) - assertNotEquals(threadedHub, Sentry.getCurrentScopes()) + assertNotEquals(mainScopes, Sentry.getCurrentScopes()) + assertNotEquals(threadedScopes, Sentry.getCurrentScopes()) } ) callableFuture.get() executor.submit { - assertNotEquals(mainHub, Sentry.getCurrentScopes()) - assertEquals(threadedHub, Sentry.getCurrentScopes()) + assertNotEquals(mainScopes, Sentry.getCurrentScopes()) + assertEquals(threadedScopes, Sentry.getCurrentScopes()) }.get() } } diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/tracing/SentryTransactionAdviceTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/tracing/SentryTransactionAdviceTest.kt index f53acde8aa..8a3d8ee46c 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/tracing/SentryTransactionAdviceTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/tracing/SentryTransactionAdviceTest.kt @@ -1,6 +1,7 @@ package io.sentry.spring.tracing import io.sentry.IScopes +import io.sentry.ISentryLifecycleToken import io.sentry.Sentry import io.sentry.SentryOptions import io.sentry.SentryTracer @@ -46,6 +47,8 @@ class SentryTransactionAdviceTest { @Autowired lateinit var scopes: IScopes + val lifecycleToken = mock() + @BeforeTest fun setup() { reset(scopes) @@ -55,6 +58,7 @@ class SentryTransactionAdviceTest { dsn = "https://key@sentry.io/proj" } ) + whenever(scopes.pushIsolationScope()).thenReturn(lifecycleToken) } @Test @@ -141,13 +145,13 @@ class SentryTransactionAdviceTest { @Test fun `pushes the scope when advice starts`() { classAnnotatedSampleService.hello() - verify(scopes).pushScope() + verify(scopes).pushIsolationScope() } @Test fun `pops the scope when advice finishes`() { classAnnotatedSampleService.hello() - verify(scopes).popScope() + verify(lifecycleToken).close() } @Configuration diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryScheduleHookTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryScheduleHookTest.kt index 7a8b2993f9..88c33c3695 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryScheduleHookTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryScheduleHookTest.kt @@ -26,35 +26,35 @@ class SentryScheduleHookTest { } @Test - fun `hub is reset to its state within the thread after hook is done`() { + fun `scopes is reset to its state within the thread after hook is done`() { Sentry.init { it.dsn = dsn } val sut = SentryScheduleHook() - val mainHub = Sentry.getCurrentScopes() - val threadedHub = Sentry.getCurrentScopes().clone() + val mainScopes = Sentry.getCurrentScopes() + val threadedScopes = Sentry.getCurrentScopes().forkedCurrentScope("test") executor.submit { - Sentry.setCurrentHub(threadedHub) + Sentry.setCurrentScopes(threadedScopes) }.get() - assertEquals(mainHub, Sentry.getCurrentScopes()) + assertEquals(mainScopes, Sentry.getCurrentScopes()) val callableFuture = executor.submit( sut.apply { - assertNotEquals(mainHub, Sentry.getCurrentScopes()) - assertNotEquals(threadedHub, Sentry.getCurrentScopes()) + assertNotEquals(mainScopes, Sentry.getCurrentScopes()) + assertNotEquals(threadedScopes, Sentry.getCurrentScopes()) } ) callableFuture.get() executor.submit { - assertNotEquals(mainHub, Sentry.getCurrentScopes()) - assertEquals(threadedHub, Sentry.getCurrentScopes()) + assertNotEquals(mainScopes, Sentry.getCurrentScopes()) + assertEquals(threadedScopes, Sentry.getCurrentScopes()) }.get() } } diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryWebFluxTracingFilterTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryWebFluxTracingFilterTest.kt index 1a31dcaa10..ff527abd7d 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryWebFluxTracingFilterTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryWebFluxTracingFilterTest.kt @@ -89,7 +89,7 @@ class SentryWebFluxTracingFilterTest { fun withMockScopes(closure: () -> Unit) = Mockito.mockStatic(Sentry::class.java).use { it.`when` { Sentry.getCurrentHub() }.thenReturn(HubScopesWrapper(fixture.scopes)) it.`when` { Sentry.getCurrentScopes() }.thenReturn(fixture.scopes) - it.`when` { Sentry.cloneMainHub() }.thenReturn(fixture.scopes) + it.`when` { Sentry.forkedRootScopes(any()) }.thenReturn(fixture.scopes) closure.invoke() } @@ -253,10 +253,8 @@ class SentryWebFluxTracingFilterTest { verify(fixture.scopes).isEnabled verify(fixture.scopes, times(2)).options verify(fixture.scopes).continueTrace(anyOrNull(), anyOrNull()) - verify(fixture.scopes).pushScope() // TODO don't verify(fixture.scopes).addBreadcrumb(any(), any()) verify(fixture.scopes).configureScope(any()) - verify(fixture.scopes).popScope() // TODO don't verifyNoMoreInteractions(fixture.scopes) } }