diff --git a/sentry-jdbc/api/sentry-jdbc.api b/sentry-jdbc/api/sentry-jdbc.api index cff0f37fd2..700cbb2d69 100644 --- a/sentry-jdbc/api/sentry-jdbc.api +++ b/sentry-jdbc/api/sentry-jdbc.api @@ -16,7 +16,7 @@ public final class io/sentry/jdbc/DatabaseUtils$DatabaseDetails { public class io/sentry/jdbc/SentryJdbcEventListener : com/p6spy/engine/event/SimpleJdbcEventListener { public fun ()V - public fun (Lio/sentry/IHub;)V + public fun (Lio/sentry/IScopes;)V public fun onAfterAnyExecute (Lcom/p6spy/engine/common/StatementInformation;JLjava/sql/SQLException;)V public fun onBeforeAnyExecute (Lcom/p6spy/engine/common/StatementInformation;)V } diff --git a/sentry-jdbc/src/main/java/io/sentry/jdbc/SentryJdbcEventListener.java b/sentry-jdbc/src/main/java/io/sentry/jdbc/SentryJdbcEventListener.java index 0346d2d0b9..4cb21188e4 100644 --- a/sentry-jdbc/src/main/java/io/sentry/jdbc/SentryJdbcEventListener.java +++ b/sentry-jdbc/src/main/java/io/sentry/jdbc/SentryJdbcEventListener.java @@ -6,9 +6,9 @@ import com.jakewharton.nopen.annotation.Open; import com.p6spy.engine.common.StatementInformation; import com.p6spy.engine.event.SimpleJdbcEventListener; -import io.sentry.HubAdapter; -import io.sentry.IHub; +import io.sentry.IScopes; import io.sentry.ISpan; +import io.sentry.ScopesAdapter; import io.sentry.SentryIntegrationPackageStorage; import io.sentry.Span; import io.sentry.SpanStatus; @@ -21,24 +21,24 @@ @Open public class SentryJdbcEventListener extends SimpleJdbcEventListener { private static final String TRACE_ORIGIN = "auto.db.jdbc"; - private final @NotNull IHub hub; + private final @NotNull IScopes scopes; private static final @NotNull ThreadLocal CURRENT_SPAN = new ThreadLocal<>(); private volatile @Nullable DatabaseUtils.DatabaseDetails cachedDatabaseDetails = null; private final @NotNull Object databaseDetailsLock = new Object(); - public SentryJdbcEventListener(final @NotNull IHub hub) { - this.hub = Objects.requireNonNull(hub, "hub is required"); + public SentryJdbcEventListener(final @NotNull IScopes scopes) { + this.scopes = Objects.requireNonNull(scopes, "scopes are required"); addPackageAndIntegrationInfo(); } public SentryJdbcEventListener() { - this(HubAdapter.getInstance()); + this(ScopesAdapter.getInstance()); } @Override public void onBeforeAnyExecute(final @NotNull StatementInformation statementInformation) { - final ISpan parent = hub.getSpan(); + final ISpan parent = scopes.getSpan(); if (parent != null && !parent.isNoOp()) { final ISpan span = parent.startChild("db.query", statementInformation.getSql()); CURRENT_SPAN.set(span); diff --git a/sentry-jdbc/src/test/kotlin/io/sentry/jdbc/SentryJdbcEventListenerTest.kt b/sentry-jdbc/src/test/kotlin/io/sentry/jdbc/SentryJdbcEventListenerTest.kt index 78c5d4cf12..00ce03de41 100644 --- a/sentry-jdbc/src/test/kotlin/io/sentry/jdbc/SentryJdbcEventListenerTest.kt +++ b/sentry-jdbc/src/test/kotlin/io/sentry/jdbc/SentryJdbcEventListenerTest.kt @@ -2,7 +2,7 @@ package io.sentry.jdbc import com.p6spy.engine.common.StatementInformation import com.p6spy.engine.spy.P6DataSource -import io.sentry.IHub +import io.sentry.IScopes import io.sentry.SentryOptions import io.sentry.SentryTracer import io.sentry.SpanDataConvention.DB_NAME_KEY @@ -26,7 +26,7 @@ import kotlin.test.assertTrue class SentryJdbcEventListenerTest { class Fixture { - val hub = mock().apply { + val scopes = mock().apply { whenever(options).thenReturn( SentryOptions().apply { sdkVersion = SdkVersion("test", "1.2.3") @@ -37,9 +37,9 @@ class SentryJdbcEventListenerTest { val actualDataSource = JDBCDataSource() fun getSut(withRunningTransaction: Boolean = true, existingRow: Int? = null): DataSource { - tx = SentryTracer(TransactionContext("name", "op"), hub) + tx = SentryTracer(TransactionContext("name", "op"), scopes) if (withRunningTransaction) { - whenever(hub.span).thenReturn(tx) + whenever(scopes.span).thenReturn(tx) } actualDataSource.setURL("jdbc:hsqldb:mem:testdb") @@ -54,7 +54,7 @@ class SentryJdbcEventListenerTest { } } - val sentryQueryExecutionListener = SentryJdbcEventListener(hub) + val sentryQueryExecutionListener = SentryJdbcEventListener(scopes) val p6spyDataSource = P6DataSource(actualDataSource) p6spyDataSource.setJdbcEventListenerFactory { sentryQueryExecutionListener } return p6spyDataSource @@ -131,9 +131,9 @@ class SentryJdbcEventListenerTest { @Test fun `sets SDKVersion Info`() { val sut = fixture.getSut() - assertNotNull(fixture.hub.options.sdkVersion) - assert(fixture.hub.options.sdkVersion!!.integrationSet.contains("JDBC")) - val packageInfo = fixture.hub.options.sdkVersion!!.packageSet.firstOrNull { pkg -> pkg.name == "maven:io.sentry:sentry-jdbc" } + assertNotNull(fixture.scopes.options.sdkVersion) + assert(fixture.scopes.options.sdkVersion!!.integrationSet.contains("JDBC")) + val packageInfo = fixture.scopes.options.sdkVersion!!.packageSet.firstOrNull { pkg -> pkg.name == "maven:io.sentry:sentry-jdbc" } assertNotNull(packageInfo) assert(packageInfo.version == BuildConfig.VERSION_NAME) } diff --git a/sentry-kotlin-extensions/api/sentry-kotlin-extensions.api b/sentry-kotlin-extensions/api/sentry-kotlin-extensions.api index d501240a3a..7e3be67279 100644 --- a/sentry-kotlin-extensions/api/sentry-kotlin-extensions.api +++ b/sentry-kotlin-extensions/api/sentry-kotlin-extensions.api @@ -1,16 +1,16 @@ public final class io/sentry/kotlin/SentryContext : kotlin/coroutines/AbstractCoroutineContextElement, kotlinx/coroutines/CopyableThreadContextElement { public fun ()V - public fun (Lio/sentry/IHub;)V - public synthetic fun (Lio/sentry/IHub;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Lio/sentry/IScopes;)V + public synthetic fun (Lio/sentry/IScopes;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun copyForChild ()Lkotlinx/coroutines/CopyableThreadContextElement; public fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object; public fun get (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext$Element; public fun mergeForChild (Lkotlin/coroutines/CoroutineContext$Element;)Lkotlin/coroutines/CoroutineContext; public fun minusKey (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext; public fun plus (Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext; - public fun restoreThreadContext (Lkotlin/coroutines/CoroutineContext;Lio/sentry/IHub;)V + public fun restoreThreadContext (Lkotlin/coroutines/CoroutineContext;Lio/sentry/IScopes;)V public synthetic fun restoreThreadContext (Lkotlin/coroutines/CoroutineContext;Ljava/lang/Object;)V - public fun updateThreadContext (Lkotlin/coroutines/CoroutineContext;)Lio/sentry/IHub; + public fun updateThreadContext (Lkotlin/coroutines/CoroutineContext;)Lio/sentry/IScopes; public synthetic fun updateThreadContext (Lkotlin/coroutines/CoroutineContext;)Ljava/lang/Object; } diff --git a/sentry-kotlin-extensions/src/main/java/io/sentry/kotlin/SentryContext.kt b/sentry-kotlin-extensions/src/main/java/io/sentry/kotlin/SentryContext.kt index 3cf22a20da..4c814f2805 100644 --- a/sentry-kotlin-extensions/src/main/java/io/sentry/kotlin/SentryContext.kt +++ b/sentry-kotlin-extensions/src/main/java/io/sentry/kotlin/SentryContext.kt @@ -1,6 +1,6 @@ package io.sentry.kotlin -import io.sentry.IHub +import io.sentry.IScopes import io.sentry.Sentry import kotlinx.coroutines.CopyableThreadContextElement import kotlin.coroutines.AbstractCoroutineContextElement @@ -9,26 +9,32 @@ import kotlin.coroutines.CoroutineContext /** * Sentry context element for [CoroutineContext]. */ -public class SentryContext(private val hub: IHub = Sentry.getCurrentHub().clone()) : - CopyableThreadContextElement, AbstractCoroutineContextElement(Key) { +@SuppressWarnings("deprecation") +// TODO fork instead +public class SentryContext(private val scopes: IScopes = Sentry.getCurrentScopes().clone()) : + CopyableThreadContextElement, AbstractCoroutineContextElement(Key) { private companion object Key : CoroutineContext.Key - override fun copyForChild(): CopyableThreadContextElement { - return SentryContext(hub.clone()) + @SuppressWarnings("deprecation") + override fun copyForChild(): CopyableThreadContextElement { + // TODO fork instead + return SentryContext(scopes.clone()) } + @SuppressWarnings("deprecation") override fun mergeForChild(overwritingElement: CoroutineContext.Element): CoroutineContext { - return overwritingElement[Key] ?: SentryContext(hub.clone()) + // TODO fork instead? + return overwritingElement[Key] ?: SentryContext(scopes.clone()) } - override fun updateThreadContext(context: CoroutineContext): IHub { - val oldState = Sentry.getCurrentHub() - Sentry.setCurrentHub(hub) + override fun updateThreadContext(context: CoroutineContext): IScopes { + val oldState = Sentry.getCurrentScopes() + Sentry.setCurrentScopes(scopes) return oldState } - override fun restoreThreadContext(context: CoroutineContext, oldState: IHub) { - Sentry.setCurrentHub(oldState) + override fun restoreThreadContext(context: CoroutineContext, oldState: IScopes) { + Sentry.setCurrentScopes(oldState) } } diff --git a/sentry-kotlin-extensions/src/test/java/io/sentry/kotlin/SentryContextTest.kt b/sentry-kotlin-extensions/src/test/java/io/sentry/kotlin/SentryContextTest.kt index b54ceabc51..578b610267 100644 --- a/sentry-kotlin-extensions/src/test/java/io/sentry/kotlin/SentryContextTest.kt +++ b/sentry-kotlin-extensions/src/test/java/io/sentry/kotlin/SentryContextTest.kt @@ -119,7 +119,7 @@ class SentryContextTest { val c2 = launch( SentryContext( - Sentry.getCurrentHub().clone().also { + Sentry.getCurrentScopes().clone().also { it.setTag("cloned", "clonedValue") } ) @@ -145,7 +145,7 @@ class SentryContextTest { @Test fun `mergeForChild returns copy of initial context if Key not present`() { val initialContextElement = SentryContext( - Sentry.getCurrentHub().clone().also { + Sentry.getCurrentScopes().clone().also { it.setTag("cloned", "clonedValue") } ) @@ -158,7 +158,7 @@ class SentryContextTest { @Test fun `mergeForChild returns passed context`() { val initialContextElement = SentryContext( - Sentry.getCurrentHub().clone().also { + Sentry.getCurrentScopes().clone().also { it.setTag("cloned", "clonedValue") } ) diff --git a/sentry-openfeign/api/sentry-openfeign.api b/sentry-openfeign/api/sentry-openfeign.api index beb15c9e02..4ab65a5ca4 100644 --- a/sentry-openfeign/api/sentry-openfeign.api +++ b/sentry-openfeign/api/sentry-openfeign.api @@ -1,12 +1,12 @@ public final class io/sentry/openfeign/SentryCapability : feign/Capability { public fun ()V - public fun (Lio/sentry/IHub;Lio/sentry/openfeign/SentryFeignClient$BeforeSpanCallback;)V + public fun (Lio/sentry/IScopes;Lio/sentry/openfeign/SentryFeignClient$BeforeSpanCallback;)V public fun (Lio/sentry/openfeign/SentryFeignClient$BeforeSpanCallback;)V public fun enrich (Lfeign/Client;)Lfeign/Client; } public final class io/sentry/openfeign/SentryFeignClient : feign/Client { - public fun (Lfeign/Client;Lio/sentry/IHub;Lio/sentry/openfeign/SentryFeignClient$BeforeSpanCallback;)V + public fun (Lfeign/Client;Lio/sentry/IScopes;Lio/sentry/openfeign/SentryFeignClient$BeforeSpanCallback;)V public fun execute (Lfeign/Request;Lfeign/Request$Options;)Lfeign/Response; } diff --git a/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryCapability.java b/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryCapability.java index b65685c3fd..1ad6b1f274 100644 --- a/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryCapability.java +++ b/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryCapability.java @@ -2,33 +2,34 @@ import feign.Capability; import feign.Client; -import io.sentry.HubAdapter; -import io.sentry.IHub; +import io.sentry.IScopes; +import io.sentry.ScopesAdapter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** Adds Sentry tracing capability to Feign clients. */ public final class SentryCapability implements Capability { - private final @NotNull IHub hub; + private final @NotNull IScopes scopes; private final @Nullable SentryFeignClient.BeforeSpanCallback beforeSpan; public SentryCapability( - final @NotNull IHub hub, final @Nullable SentryFeignClient.BeforeSpanCallback beforeSpan) { - this.hub = hub; + final @NotNull IScopes scopes, + final @Nullable SentryFeignClient.BeforeSpanCallback beforeSpan) { + this.scopes = scopes; this.beforeSpan = beforeSpan; } public SentryCapability(final @Nullable SentryFeignClient.BeforeSpanCallback beforeSpan) { - this(HubAdapter.getInstance(), beforeSpan); + this(ScopesAdapter.getInstance(), beforeSpan); } public SentryCapability() { - this(HubAdapter.getInstance(), null); + this(ScopesAdapter.getInstance(), null); } @Override public @NotNull Client enrich(final @NotNull Client client) { - return new SentryFeignClient(client, hub, beforeSpan); + return new SentryFeignClient(client, scopes, beforeSpan); } } diff --git a/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java b/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java index cb8aa3d9e0..037768c7ad 100644 --- a/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java +++ b/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java @@ -9,7 +9,7 @@ import io.sentry.BaggageHeader; import io.sentry.Breadcrumb; import io.sentry.Hint; -import io.sentry.IHub; +import io.sentry.IScopes; import io.sentry.ISpan; import io.sentry.SpanDataConvention; import io.sentry.SpanStatus; @@ -30,15 +30,15 @@ public final class SentryFeignClient implements Client { private static final String TRACE_ORIGIN = "auto.http.openfeign"; private final @NotNull Client delegate; - private final @NotNull IHub hub; + private final @NotNull IScopes scopes; private final @Nullable BeforeSpanCallback beforeSpan; public SentryFeignClient( final @NotNull Client delegate, - final @NotNull IHub hub, + final @NotNull IScopes scopes, final @Nullable BeforeSpanCallback beforeSpan) { this.delegate = Objects.requireNonNull(delegate, "delegate is required"); - this.hub = Objects.requireNonNull(hub, "hub is required"); + this.scopes = Objects.requireNonNull(scopes, "scopes are required"); this.beforeSpan = beforeSpan; } @@ -47,7 +47,7 @@ public Response execute(final @NotNull Request request, final @NotNull Request.O throws IOException { Response response = null; try { - final ISpan activeSpan = hub.getSpan(); + final ISpan activeSpan = scopes.getSpan(); if (activeSpan == null) { final @NotNull Request modifiedRequest = maybeAddTracingHeaders(request, null); @@ -102,7 +102,7 @@ public Response execute(final @NotNull Request request, final @NotNull Request.O final @Nullable TracingUtils.TracingHeaders tracingHeaders = TracingUtils.traceIfAllowed( - hub, + scopes, request.url(), (requestBaggageHeaders != null ? new ArrayList<>(requestBaggageHeaders) : null), span); @@ -139,7 +139,7 @@ private void addBreadcrumb(final @NotNull Request request, final @Nullable Respo hint.set(OPEN_FEIGN_RESPONSE, response); } - hub.addBreadcrumb(breadcrumb, hint); + scopes.addBreadcrumb(breadcrumb, hint); } static final class RequestWrapper { diff --git a/sentry-openfeign/src/test/kotlin/io/sentry/openfeign/SentryFeignClientTest.kt b/sentry-openfeign/src/test/kotlin/io/sentry/openfeign/SentryFeignClientTest.kt index 65e56ab02b..959b890d46 100644 --- a/sentry-openfeign/src/test/kotlin/io/sentry/openfeign/SentryFeignClientTest.kt +++ b/sentry-openfeign/src/test/kotlin/io/sentry/openfeign/SentryFeignClientTest.kt @@ -7,7 +7,7 @@ import feign.HeaderMap import feign.RequestLine import io.sentry.BaggageHeader import io.sentry.Breadcrumb -import io.sentry.IHub +import io.sentry.IScopes import io.sentry.Scope import io.sentry.ScopeCallback import io.sentry.SentryOptions @@ -37,7 +37,7 @@ import kotlin.test.fail class SentryFeignClientTest { class Fixture { - val hub = mock() + val scopes = mock() val server = MockWebServer() val sentryTracer: SentryTracer val sentryOptions = SentryOptions().apply { @@ -46,9 +46,9 @@ class SentryFeignClientTest { val scope = Scope(sentryOptions) init { - whenever(hub.options).thenReturn(sentryOptions) - doAnswer { (it.arguments[0] as ScopeCallback).run(scope) }.whenever(hub).configureScope(any()) - sentryTracer = SentryTracer(TransactionContext("name", "op"), hub) + whenever(scopes.options).thenReturn(sentryOptions) + doAnswer { (it.arguments[0] as ScopeCallback).run(scope) }.whenever(scopes).configureScope(any()) + sentryTracer = SentryTracer(TransactionContext("name", "op"), scopes) } fun getSut( @@ -59,7 +59,7 @@ class SentryFeignClientTest { beforeSpan: SentryFeignClient.BeforeSpanCallback? = null ): MockApi { if (isSpanActive) { - whenever(hub.span).thenReturn(sentryTracer) + whenever(scopes.span).thenReturn(sentryTracer) } server.enqueue( MockResponse() @@ -70,12 +70,12 @@ class SentryFeignClientTest { return if (!networkError) { Feign.builder() - .addCapability(SentryCapability(hub, beforeSpan)) + .addCapability(SentryCapability(scopes, beforeSpan)) } else { val mockClient = mock() whenever(mockClient.execute(any(), any())).thenThrow(RuntimeException::class.java) Feign.builder() - .client(SentryFeignClient(mockClient, hub, beforeSpan)) + .client(SentryFeignClient(mockClient, scopes, beforeSpan)) }.target(MockApi::class.java, server.url("/").toUrl().toString()) } } @@ -201,7 +201,7 @@ class SentryFeignClientTest { fun `adds breadcrumb when http calls succeeds`() { val sut = fixture.getSut(responseBody = "response body") sut.postWithBody("request-body") - verify(fixture.hub).addBreadcrumb( + verify(fixture.scopes).addBreadcrumb( check { assertEquals("http", it.type) assertEquals(13, it.data["response_body_size"]) @@ -215,7 +215,7 @@ class SentryFeignClientTest { fun `adds breadcrumb when http calls succeeds even though response body is null`() { val sut = fixture.getSut(responseBody = "") sut.postWithBody("request-body") - verify(fixture.hub).addBreadcrumb( + verify(fixture.scopes).addBreadcrumb( check { assertEquals("http", it.type) assertEquals(0, it.data["response_body_size"]) @@ -236,7 +236,7 @@ class SentryFeignClientTest { } catch (e: Exception) { // ignore me } - verify(fixture.hub).addBreadcrumb( + verify(fixture.scopes).addBreadcrumb( check { assertEquals("http", it.type) }, diff --git a/sentry-quartz/api/sentry-quartz.api b/sentry-quartz/api/sentry-quartz.api index ff32280dc5..23fce49e7d 100644 --- a/sentry-quartz/api/sentry-quartz.api +++ b/sentry-quartz/api/sentry-quartz.api @@ -7,7 +7,7 @@ public final class io/sentry/quartz/SentryJobListener : org/quartz/JobListener { public static final field SENTRY_CHECK_IN_ID_KEY Ljava/lang/String; public static final field SENTRY_SLUG_KEY Ljava/lang/String; public fun ()V - public fun (Lio/sentry/IHub;)V + public fun (Lio/sentry/IScopes;)V public fun getName ()Ljava/lang/String; public fun jobExecutionVetoed (Lorg/quartz/JobExecutionContext;)V public fun jobToBeExecuted (Lorg/quartz/JobExecutionContext;)V diff --git a/sentry-quartz/src/main/java/io/sentry/quartz/SentryJobListener.java b/sentry-quartz/src/main/java/io/sentry/quartz/SentryJobListener.java index 28a0e51200..f9c22022cc 100644 --- a/sentry-quartz/src/main/java/io/sentry/quartz/SentryJobListener.java +++ b/sentry-quartz/src/main/java/io/sentry/quartz/SentryJobListener.java @@ -3,8 +3,8 @@ import io.sentry.BuildConfig; import io.sentry.CheckIn; import io.sentry.CheckInStatus; -import io.sentry.HubAdapter; -import io.sentry.IHub; +import io.sentry.IScopes; +import io.sentry.ScopesAdapter; import io.sentry.SentryIntegrationPackageStorage; import io.sentry.SentryLevel; import io.sentry.protocol.SentryId; @@ -24,14 +24,14 @@ public final class SentryJobListener implements JobListener { public static final String SENTRY_CHECK_IN_ID_KEY = "sentry-checkin-id"; public static final String SENTRY_SLUG_KEY = "sentry-slug"; - private final @NotNull IHub hub; + private final @NotNull IScopes scopes; public SentryJobListener() { - this(HubAdapter.getInstance()); + this(ScopesAdapter.getInstance()); } - public SentryJobListener(final @NotNull IHub hub) { - this.hub = Objects.requireNonNull(hub, "hub is required"); + public SentryJobListener(final @NotNull IScopes scopes) { + this.scopes = Objects.requireNonNull(scopes, "scopes are required"); SentryIntegrationPackageStorage.getInstance().addIntegration("Quartz"); SentryIntegrationPackageStorage.getInstance() .addPackage("maven:io.sentry:sentry-quartz", BuildConfig.VERSION_NAME); @@ -49,15 +49,16 @@ public void jobToBeExecuted(final @NotNull JobExecutionContext context) { if (maybeSlug == null) { return; } - hub.pushScope(); - TracingUtils.startNewTrace(hub); + scopes.pushScope(); + TracingUtils.startNewTrace(scopes); final @NotNull String slug = maybeSlug; final @NotNull CheckIn checkIn = new CheckIn(slug, CheckInStatus.IN_PROGRESS); - final @NotNull SentryId checkInId = hub.captureCheckIn(checkIn); + final @NotNull SentryId checkInId = scopes.captureCheckIn(checkIn); context.put(SENTRY_CHECK_IN_ID_KEY, checkInId); context.put(SENTRY_SLUG_KEY, slug); } catch (Throwable t) { - hub.getOptions() + scopes + .getOptions() .getLogger() .log(SentryLevel.ERROR, "Unable to capture check-in in jobToBeExecuted.", t); } @@ -94,14 +95,15 @@ public void jobWasExecuted(JobExecutionContext context, JobExecutionException jo if (slug != null) { final boolean isFailed = jobException != null; final @NotNull CheckInStatus status = isFailed ? CheckInStatus.ERROR : CheckInStatus.OK; - hub.captureCheckIn(new CheckIn(checkInId, slug, status)); + scopes.captureCheckIn(new CheckIn(checkInId, slug, status)); } } catch (Throwable t) { - hub.getOptions() + scopes + .getOptions() .getLogger() .log(SentryLevel.ERROR, "Unable to capture check-in in jobWasExecuted.", t); } finally { - hub.popScope(); + scopes.popScope(); } } } diff --git a/sentry-servlet-jakarta/api/sentry-servlet-jakarta.api b/sentry-servlet-jakarta/api/sentry-servlet-jakarta.api index d0367e5195..a5421e7453 100644 --- a/sentry-servlet-jakarta/api/sentry-servlet-jakarta.api +++ b/sentry-servlet-jakarta/api/sentry-servlet-jakarta.api @@ -10,7 +10,7 @@ public class io/sentry/servlet/jakarta/SentryServletContainerInitializer : jakar public class io/sentry/servlet/jakarta/SentryServletRequestListener : jakarta/servlet/ServletRequestListener { public fun ()V - public fun (Lio/sentry/IHub;)V + public fun (Lio/sentry/IScopes;)V public fun requestDestroyed (Ljakarta/servlet/ServletRequestEvent;)V public fun requestInitialized (Ljakarta/servlet/ServletRequestEvent;)V } diff --git a/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletRequestListener.java b/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletRequestListener.java index e3811157f8..54775386fd 100644 --- a/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletRequestListener.java +++ b/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletRequestListener.java @@ -5,8 +5,8 @@ import com.jakewharton.nopen.annotation.Open; import io.sentry.Breadcrumb; import io.sentry.Hint; -import io.sentry.HubAdapter; -import io.sentry.IHub; +import io.sentry.IScopes; +import io.sentry.ScopesAdapter; import io.sentry.util.Objects; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletRequestEvent; @@ -21,24 +21,24 @@ @Open public class SentryServletRequestListener implements ServletRequestListener { - private final IHub hub; + private final IScopes scopes; - public SentryServletRequestListener(@NotNull IHub hub) { - this.hub = Objects.requireNonNull(hub, "hub is required"); + public SentryServletRequestListener(@NotNull IScopes scopes) { + this.scopes = Objects.requireNonNull(scopes, "scopes are required"); } public SentryServletRequestListener() { - this(HubAdapter.getInstance()); + this(ScopesAdapter.getInstance()); } @Override public void requestDestroyed(@NotNull ServletRequestEvent servletRequestEvent) { - hub.popScope(); + scopes.popScope(); } @Override public void requestInitialized(@NotNull ServletRequestEvent servletRequestEvent) { - hub.pushScope(); + scopes.pushScope(); final ServletRequest servletRequest = servletRequestEvent.getServletRequest(); if (servletRequest instanceof HttpServletRequest) { @@ -47,10 +47,10 @@ public void requestInitialized(@NotNull ServletRequestEvent servletRequestEvent) final Hint hint = new Hint(); hint.set(SERVLET_REQUEST, httpRequest); - hub.addBreadcrumb( + scopes.addBreadcrumb( Breadcrumb.http(httpRequest.getRequestURI(), httpRequest.getMethod()), hint); - hub.configureScope( + scopes.configureScope( scope -> { scope.addEventProcessor(new SentryRequestHttpServletRequestProcessor(httpRequest)); }); diff --git a/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryServletRequestListenerTest.kt b/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryServletRequestListenerTest.kt index b87ea218a2..3be76d1cd2 100644 --- a/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryServletRequestListenerTest.kt +++ b/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryServletRequestListenerTest.kt @@ -1,7 +1,7 @@ package io.sentry.servlet.jakarta import io.sentry.Breadcrumb -import io.sentry.IHub +import io.sentry.IScopes import jakarta.servlet.ServletRequestEvent import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.check @@ -13,9 +13,9 @@ import kotlin.test.assertEquals class SentryServletRequestListenerTest { private class Fixture { - val hub = mock() + val scopes = mock() val listener = - SentryServletRequestListener(hub) + SentryServletRequestListener(scopes) val request = mockRequest( url = "http://localhost:8080/some-uri", method = "POST" @@ -33,14 +33,14 @@ class SentryServletRequestListenerTest { fun `pushes scope when request gets initialized`() { fixture.listener.requestInitialized(fixture.event) - verify(fixture.hub).pushScope() + verify(fixture.scopes).pushScope() } @Test fun `adds breadcrumb when request gets initialized`() { fixture.listener.requestInitialized(fixture.event) - verify(fixture.hub).addBreadcrumb( + verify(fixture.scopes).addBreadcrumb( check { it: Breadcrumb -> assertEquals("/some-uri", it.getData("url")) assertEquals("POST", it.getData("method")) @@ -54,6 +54,6 @@ class SentryServletRequestListenerTest { fun `pops scope when request gets destroyed`() { fixture.listener.requestDestroyed(fixture.event) - verify(fixture.hub).popScope() + verify(fixture.scopes).popScope() } } diff --git a/sentry-servlet/api/sentry-servlet.api b/sentry-servlet/api/sentry-servlet.api index a0a2a1e0d2..fd7aee819b 100644 --- a/sentry-servlet/api/sentry-servlet.api +++ b/sentry-servlet/api/sentry-servlet.api @@ -10,7 +10,7 @@ public class io/sentry/servlet/SentryServletContainerInitializer : javax/servlet public class io/sentry/servlet/SentryServletRequestListener : javax/servlet/ServletRequestListener { public fun ()V - public fun (Lio/sentry/IHub;)V + public fun (Lio/sentry/IScopes;)V public fun requestDestroyed (Ljavax/servlet/ServletRequestEvent;)V public fun requestInitialized (Ljavax/servlet/ServletRequestEvent;)V } diff --git a/sentry-servlet/src/main/java/io/sentry/servlet/SentryServletRequestListener.java b/sentry-servlet/src/main/java/io/sentry/servlet/SentryServletRequestListener.java index 9b981676c4..97c37e1133 100644 --- a/sentry-servlet/src/main/java/io/sentry/servlet/SentryServletRequestListener.java +++ b/sentry-servlet/src/main/java/io/sentry/servlet/SentryServletRequestListener.java @@ -5,8 +5,8 @@ import com.jakewharton.nopen.annotation.Open; import io.sentry.Breadcrumb; import io.sentry.Hint; -import io.sentry.HubAdapter; -import io.sentry.IHub; +import io.sentry.IScopes; +import io.sentry.ScopesAdapter; import io.sentry.util.Objects; import javax.servlet.ServletRequest; import javax.servlet.ServletRequestEvent; @@ -21,24 +21,24 @@ @Open public class SentryServletRequestListener implements ServletRequestListener { - private final IHub hub; + private final IScopes scopes; - public SentryServletRequestListener(@NotNull IHub hub) { - this.hub = Objects.requireNonNull(hub, "hub is required"); + public SentryServletRequestListener(@NotNull IScopes scopes) { + this.scopes = Objects.requireNonNull(scopes, "scopes are required"); } public SentryServletRequestListener() { - this(HubAdapter.getInstance()); + this(ScopesAdapter.getInstance()); } @Override public void requestDestroyed(@NotNull ServletRequestEvent servletRequestEvent) { - hub.popScope(); + scopes.popScope(); } @Override public void requestInitialized(@NotNull ServletRequestEvent servletRequestEvent) { - hub.pushScope(); + scopes.pushScope(); final ServletRequest servletRequest = servletRequestEvent.getServletRequest(); if (servletRequest instanceof HttpServletRequest) { @@ -47,10 +47,10 @@ public void requestInitialized(@NotNull ServletRequestEvent servletRequestEvent) final Hint hint = new Hint(); hint.set(SERVLET_REQUEST, httpRequest); - hub.addBreadcrumb( + scopes.addBreadcrumb( Breadcrumb.http(httpRequest.getRequestURI(), httpRequest.getMethod()), hint); - hub.configureScope( + scopes.configureScope( scope -> { scope.addEventProcessor(new SentryRequestHttpServletRequestProcessor(httpRequest)); }); diff --git a/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryServletRequestListenerTest.kt b/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryServletRequestListenerTest.kt index b94e73f2ef..bfa216f738 100644 --- a/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryServletRequestListenerTest.kt +++ b/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryServletRequestListenerTest.kt @@ -1,7 +1,7 @@ package io.sentry.servlet import io.sentry.Breadcrumb -import io.sentry.IHub +import io.sentry.IScopes import org.assertj.core.api.Assertions.assertThat import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.check @@ -14,8 +14,8 @@ import kotlin.test.Test class SentryServletRequestListenerTest { private class Fixture { - val hub = mock() - val listener = SentryServletRequestListener(hub) + val scopes = mock() + val listener = SentryServletRequestListener(scopes) val request = MockHttpServletRequest() val event = mock() @@ -32,14 +32,14 @@ class SentryServletRequestListenerTest { fun `pushes scope when request gets initialized`() { fixture.listener.requestInitialized(fixture.event) - verify(fixture.hub).pushScope() + verify(fixture.scopes).pushScope() } @Test fun `adds breadcrumb when request gets initialized`() { fixture.listener.requestInitialized(fixture.event) - verify(fixture.hub).addBreadcrumb( + verify(fixture.scopes).addBreadcrumb( check { it: Breadcrumb -> assertThat(it.getData("url")).isEqualTo("http://localhost:8080/some-uri") assertThat(it.getData("method")).isEqualTo("POST") @@ -53,6 +53,6 @@ class SentryServletRequestListenerTest { fun `pops scope when request gets destroyed`() { fixture.listener.requestDestroyed(fixture.event) - verify(fixture.hub).popScope() + verify(fixture.scopes).popScope() } } diff --git a/sentry-test-support/api/sentry-test-support.api b/sentry-test-support/api/sentry-test-support.api index ffce23a516..dd1a4b69d3 100644 --- a/sentry-test-support/api/sentry-test-support.api +++ b/sentry-test-support/api/sentry-test-support.api @@ -32,6 +32,7 @@ public final class io/sentry/test/ImmediateExecutorService : io/sentry/ISentryEx } public final class io/sentry/test/ReflectionKt { + public static final fun collectInterfaceHierarchy (Ljava/lang/Class;)Ljava/util/List; public static final fun containsMethod (Ljava/lang/Class;Ljava/lang/String;Ljava/lang/Class;)Z public static final fun containsMethod (Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Z public static final fun getCtor (Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Constructor; diff --git a/sentry-test-support/src/main/kotlin/io/sentry/test/Reflection.kt b/sentry-test-support/src/main/kotlin/io/sentry/test/Reflection.kt index 690dcc8725..19d11676e1 100644 --- a/sentry-test-support/src/main/kotlin/io/sentry/test/Reflection.kt +++ b/sentry-test-support/src/main/kotlin/io/sentry/test/Reflection.kt @@ -12,16 +12,23 @@ inline fun T.callMethod(name: String, parameterTypes: Class<*> val declaredMethod = try { T::class.java.getDeclaredMethod(name, parameterTypes) } catch (e: NoSuchMethodException) { - T::class.java.interfaces.first { it.containsMethod(name, parameterTypes) }.getDeclaredMethod(name, parameterTypes) + collectInterfaceHierarchy(T::class.java).first { it.containsMethod(name, parameterTypes) }.getDeclaredMethod(name, parameterTypes) } return declaredMethod.invoke(this, value) } +fun collectInterfaceHierarchy(clazz: Class<*>): List> { + if (clazz.interfaces.isEmpty()) { + return listOf(clazz) + } + return clazz.interfaces.flatMap { iface -> collectInterfaceHierarchy(iface) }.also { it.toMutableList().add(clazz) } +} + inline fun T.callMethod(name: String, parameterTypes: Array>, vararg value: Any?): Any? { val declaredMethod = try { T::class.java.getDeclaredMethod(name, *parameterTypes) } catch (e: NoSuchMethodException) { - T::class.java.interfaces.first { it.containsMethod(name, parameterTypes) }.getDeclaredMethod(name, *parameterTypes) + collectInterfaceHierarchy(T::class.java).first { it.containsMethod(name, parameterTypes) }.getDeclaredMethod(name, *parameterTypes) } return declaredMethod.invoke(this, *value) }