Skip to content

Commit e11f8b1

Browse files
authored
Hubs/Scopes Merge 12 - Replace IHub with IScopes in Spring 6 / Spring Boot 3 integrations (#3309)
* Introduce `IScopes` interface. * Replace `IHub` with `IScopes` in core * Replace `IHub` with `IScopes` in android core * Replace `IHub` with `IScopes` in android integrations * Replace `IHub` with `IScopes` in apollo integrations * Replace `IHub` with `IScopes` in okhttp integration * Replace `IHub` with `IScopes` in graphql integration * Replace `IHub` with `IScopes` in logging integrations * Replace `IHub` with `IScopes` in more integrations * Replace `IHub` with `IScopes` in OTel integration * Replace `IHub` with `IScopes` in Spring 5 / Spring Boot 2 integrations * Replace `IHub` with `IScopes` in Spring 6 / Spring Boot 3 integrations
1 parent 495ed99 commit e11f8b1

File tree

56 files changed

+623
-595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+623
-595
lines changed

sentry-spring-boot-jakarta/api/sentry-spring-boot-jakarta.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class io/sentry/spring/boot/jakarta/SentryProperties$Reactive {
6262

6363
public class io/sentry/spring/boot/jakarta/SentryWebfluxAutoConfiguration {
6464
public fun <init> ()V
65-
public fun sentryWebExceptionHandler (Lio/sentry/IHub;)Lio/sentry/spring/jakarta/webflux/SentryWebExceptionHandler;
65+
public fun sentryWebExceptionHandler (Lio/sentry/IScopes;)Lio/sentry/spring/jakarta/webflux/SentryWebExceptionHandler;
6666
}
6767

6868
public class io/sentry/spring/boot/jakarta/graphql/SentryGraphqlAutoConfiguration {

sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryAutoConfiguration.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import com.jakewharton.nopen.annotation.Open;
44
import graphql.GraphQLError;
55
import io.sentry.EventProcessor;
6-
import io.sentry.HubAdapter;
7-
import io.sentry.IHub;
6+
import io.sentry.IScopes;
87
import io.sentry.ITransportFactory;
98
import io.sentry.Integration;
9+
import io.sentry.ScopesAdapter;
1010
import io.sentry.Sentry;
1111
import io.sentry.SentryIntegrationPackageStorage;
1212
import io.sentry.SentryOptions;
@@ -116,7 +116,7 @@ static class HubConfiguration {
116116
}
117117

118118
@Bean
119-
public @NotNull IHub sentryHub(
119+
public @NotNull IScopes sentryHub(
120120
final @NotNull List<Sentry.OptionsConfiguration<SentryOptions>> optionsConfigurations,
121121
final @NotNull SentryProperties options,
122122
final @NotNull ObjectProvider<GitProperties> gitProperties) {
@@ -139,7 +139,7 @@ static class HubConfiguration {
139139
// here we make sure that only classes that extend throwable are set on this field
140140
options.getIgnoredExceptionsForType().removeIf(it -> !Throwable.class.isAssignableFrom(it));
141141
Sentry.init(options);
142-
return HubAdapter.getInstance();
142+
return ScopesAdapter.getInstance();
143143
}
144144

145145
@Configuration(proxyBeanMethods = false)
@@ -239,19 +239,19 @@ static class SentrySecurityConfiguration {
239239
* HttpServletRequest#getUserPrincipal()}. If Spring Security is auto-configured, its order is
240240
* set to run after Spring Security.
241241
*
242-
* @param hub the Sentry hub
242+
* @param scopes the Sentry scopes
243243
* @param sentryProperties the Sentry properties
244244
* @param sentryUserProvider the user provider
245245
* @return {@link SentryUserFilter} registration bean
246246
*/
247247
@Bean
248248
@ConditionalOnBean(SentryUserProvider.class)
249249
public @NotNull FilterRegistrationBean<SentryUserFilter> sentryUserFilter(
250-
final @NotNull IHub hub,
250+
final @NotNull IScopes scopes,
251251
final @NotNull SentryProperties sentryProperties,
252252
final @NotNull List<SentryUserProvider> sentryUserProvider) {
253253
final FilterRegistrationBean<SentryUserFilter> filter = new FilterRegistrationBean<>();
254-
filter.setFilter(new SentryUserFilter(hub, sentryUserProvider));
254+
filter.setFilter(new SentryUserFilter(scopes, sentryUserProvider));
255255
filter.setOrder(resolveUserFilterOrder(sentryProperties));
256256
return filter;
257257
}
@@ -263,8 +263,8 @@ static class SentrySecurityConfiguration {
263263
}
264264

265265
@Bean
266-
public @NotNull SentryRequestResolver sentryRequestResolver(final @NotNull IHub hub) {
267-
return new SentryRequestResolver(hub);
266+
public @NotNull SentryRequestResolver sentryRequestResolver(final @NotNull IScopes scopes) {
267+
return new SentryRequestResolver(scopes);
268268
}
269269

270270
@Bean
@@ -276,22 +276,23 @@ static class SentrySecurityConfiguration {
276276
@Bean
277277
@ConditionalOnMissingBean(name = "sentrySpringFilter")
278278
public @NotNull FilterRegistrationBean<SentrySpringFilter> sentrySpringFilter(
279-
final @NotNull IHub hub,
279+
final @NotNull IScopes scopes,
280280
final @NotNull SentryRequestResolver requestResolver,
281281
final @NotNull TransactionNameProvider transactionNameProvider) {
282282
FilterRegistrationBean<SentrySpringFilter> filter =
283283
new FilterRegistrationBean<>(
284-
new SentrySpringFilter(hub, requestResolver, transactionNameProvider));
284+
new SentrySpringFilter(scopes, requestResolver, transactionNameProvider));
285285
filter.setOrder(SENTRY_SPRING_FILTER_PRECEDENCE);
286286
return filter;
287287
}
288288

289289
@Bean
290290
@ConditionalOnMissingBean(name = "sentryTracingFilter")
291291
public FilterRegistrationBean<SentryTracingFilter> sentryTracingFilter(
292-
final @NotNull IHub hub, final @NotNull TransactionNameProvider transactionNameProvider) {
292+
final @NotNull IScopes scopes,
293+
final @NotNull TransactionNameProvider transactionNameProvider) {
293294
FilterRegistrationBean<SentryTracingFilter> filter =
294-
new FilterRegistrationBean<>(new SentryTracingFilter(hub, transactionNameProvider));
295+
new FilterRegistrationBean<>(new SentryTracingFilter(scopes, transactionNameProvider));
295296
filter.setOrder(SENTRY_SPRING_FILTER_PRECEDENCE + 1); // must run after SentrySpringFilter
296297
return filter;
297298
}
@@ -300,11 +301,11 @@ public FilterRegistrationBean<SentryTracingFilter> sentryTracingFilter(
300301
@ConditionalOnMissingBean
301302
@ConditionalOnClass(HandlerExceptionResolver.class)
302303
public @NotNull SentryExceptionResolver sentryExceptionResolver(
303-
final @NotNull IHub sentryHub,
304+
final @NotNull IScopes scopes,
304305
final @NotNull TransactionNameProvider transactionNameProvider,
305306
final @NotNull SentryProperties options) {
306307
return new SentryExceptionResolver(
307-
sentryHub, transactionNameProvider, options.getExceptionResolverOrder());
308+
scopes, transactionNameProvider, options.getExceptionResolverOrder());
308309
}
309310
}
310311

@@ -354,8 +355,8 @@ static class SentrySpanPointcutAutoConfiguration {}
354355
@Open
355356
static class SentryPerformanceRestTemplateConfiguration {
356357
@Bean
357-
public SentrySpanRestTemplateCustomizer sentrySpanRestTemplateCustomizer(IHub hub) {
358-
return new SentrySpanRestTemplateCustomizer(hub);
358+
public SentrySpanRestTemplateCustomizer sentrySpanRestTemplateCustomizer(IScopes scopes) {
359+
return new SentrySpanRestTemplateCustomizer(scopes);
359360
}
360361
}
361362

@@ -365,8 +366,8 @@ public SentrySpanRestTemplateCustomizer sentrySpanRestTemplateCustomizer(IHub hu
365366
@Open
366367
static class SentrySpanRestClientConfiguration {
367368
@Bean
368-
public SentrySpanRestClientCustomizer sentrySpanRestClientCustomizer(IHub hub) {
369-
return new SentrySpanRestClientCustomizer(hub);
369+
public SentrySpanRestClientCustomizer sentrySpanRestClientCustomizer(IScopes scopes) {
370+
return new SentrySpanRestClientCustomizer(scopes);
370371
}
371372
}
372373

@@ -376,8 +377,8 @@ public SentrySpanRestClientCustomizer sentrySpanRestClientCustomizer(IHub hub) {
376377
@Open
377378
static class SentryPerformanceWebClientConfiguration {
378379
@Bean
379-
public SentrySpanWebClientCustomizer sentrySpanWebClientCustomizer(IHub hub) {
380-
return new SentrySpanWebClientCustomizer(hub);
380+
public SentrySpanWebClientCustomizer sentrySpanWebClientCustomizer(IScopes scopes) {
381+
return new SentrySpanWebClientCustomizer(scopes);
381382
}
382383
}
383384

sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentrySpanRestClientCustomizer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.sentry.spring.boot.jakarta;
22

33
import com.jakewharton.nopen.annotation.Open;
4-
import io.sentry.IHub;
4+
import io.sentry.IScopes;
55
import io.sentry.spring.jakarta.tracing.SentrySpanClientHttpRequestInterceptor;
66
import org.jetbrains.annotations.NotNull;
77
import org.springframework.boot.web.client.RestClientCustomizer;
@@ -11,8 +11,8 @@
1111
class SentrySpanRestClientCustomizer implements RestClientCustomizer {
1212
private final @NotNull SentrySpanClientHttpRequestInterceptor interceptor;
1313

14-
public SentrySpanRestClientCustomizer(final @NotNull IHub hub) {
15-
this.interceptor = new SentrySpanClientHttpRequestInterceptor(hub, false);
14+
public SentrySpanRestClientCustomizer(final @NotNull IScopes scopes) {
15+
this.interceptor = new SentrySpanClientHttpRequestInterceptor(scopes, false);
1616
}
1717

1818
@Override

sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentrySpanRestTemplateCustomizer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.sentry.spring.boot.jakarta;
22

33
import com.jakewharton.nopen.annotation.Open;
4-
import io.sentry.IHub;
4+
import io.sentry.IScopes;
55
import io.sentry.spring.jakarta.tracing.SentrySpanClientHttpRequestInterceptor;
66
import java.util.ArrayList;
77
import java.util.List;
@@ -14,8 +14,8 @@
1414
class SentrySpanRestTemplateCustomizer implements RestTemplateCustomizer {
1515
private final @NotNull SentrySpanClientHttpRequestInterceptor interceptor;
1616

17-
public SentrySpanRestTemplateCustomizer(final @NotNull IHub hub) {
18-
this.interceptor = new SentrySpanClientHttpRequestInterceptor(hub);
17+
public SentrySpanRestTemplateCustomizer(final @NotNull IScopes scopes) {
18+
this.interceptor = new SentrySpanClientHttpRequestInterceptor(scopes);
1919
}
2020

2121
@Override

sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentrySpanWebClientCustomizer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.sentry.spring.boot.jakarta;
22

33
import com.jakewharton.nopen.annotation.Open;
4-
import io.sentry.IHub;
4+
import io.sentry.IScopes;
55
import io.sentry.spring.jakarta.tracing.SentrySpanClientWebRequestFilter;
66
import org.jetbrains.annotations.NotNull;
77
import org.springframework.boot.web.reactive.function.client.WebClientCustomizer;
@@ -11,8 +11,8 @@
1111
class SentrySpanWebClientCustomizer implements WebClientCustomizer {
1212
private final @NotNull SentrySpanClientWebRequestFilter filter;
1313

14-
public SentrySpanWebClientCustomizer(final @NotNull IHub hub) {
15-
this.filter = new SentrySpanClientWebRequestFilter(hub);
14+
public SentrySpanWebClientCustomizer(final @NotNull IScopes scopes) {
15+
this.filter = new SentrySpanClientWebRequestFilter(scopes);
1616
}
1717

1818
@Override

sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryWebfluxAutoConfiguration.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package io.sentry.spring.boot.jakarta;
22

33
import com.jakewharton.nopen.annotation.Open;
4-
import io.sentry.IHub;
54
import io.sentry.IScope;
5+
import io.sentry.IScopes;
66
import io.sentry.spring.jakarta.webflux.SentryScheduleHook;
77
import io.sentry.spring.jakarta.webflux.SentryWebExceptionHandler;
88
import io.sentry.spring.jakarta.webflux.SentryWebFilter;
@@ -28,7 +28,7 @@
2828
/** Configures Sentry integration for Spring Webflux and Project Reactor. */
2929
@Configuration(proxyBeanMethods = false)
3030
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
31-
@ConditionalOnBean(IHub.class)
31+
@ConditionalOnBean(IScopes.class)
3232
@ConditionalOnClass(Schedulers.class)
3333
@Open
3434
@ApiStatus.Experimental
@@ -44,14 +44,14 @@ static class SentryWebfluxFilterThreadLocalAccessorConfiguration {
4444
* Configures a filter that sets up Sentry {@link IScope} for each request.
4545
*
4646
* <p>Makes use of newer reactor-core and context-propagation library feature
47-
* ThreadLocalAccessor to propagate the Sentry hub.
47+
* ThreadLocalAccessor to propagate the Sentry scopes.
4848
*/
4949
@Bean
5050
@Order(SENTRY_SPRING_FILTER_PRECEDENCE)
5151
public @NotNull SentryWebFilterWithThreadLocalAccessor sentryWebFilterWithContextPropagation(
52-
final @NotNull IHub hub) {
52+
final @NotNull IScopes scopes) {
5353
Hooks.enableAutomaticContextPropagation();
54-
return new SentryWebFilterWithThreadLocalAccessor(hub);
54+
return new SentryWebFilterWithThreadLocalAccessor(scopes);
5555
}
5656
}
5757

@@ -60,7 +60,7 @@ static class SentryWebfluxFilterThreadLocalAccessorConfiguration {
6060
@Open
6161
static class SentryWebfluxFilterConfiguration {
6262

63-
/** Configures hook that sets correct hub on the executing thread. */
63+
/** Configures hook that sets correct scopes on the executing thread. */
6464
@Bean
6565
public @NotNull ApplicationRunner sentryScheduleHookApplicationRunner() {
6666
return args -> {
@@ -71,15 +71,16 @@ static class SentryWebfluxFilterConfiguration {
7171
/** Configures a filter that sets up Sentry {@link IScope} for each request. */
7272
@Bean
7373
@Order(SENTRY_SPRING_FILTER_PRECEDENCE)
74-
public @NotNull SentryWebFilter sentryWebFilter(final @NotNull IHub hub) {
75-
return new SentryWebFilter(hub);
74+
public @NotNull SentryWebFilter sentryWebFilter(final @NotNull IScopes scopes) {
75+
return new SentryWebFilter(scopes);
7676
}
7777
}
7878

7979
/** Configures exception handler that handles unhandled exceptions and sends them to Sentry. */
8080
@Bean
81-
public @NotNull SentryWebExceptionHandler sentryWebExceptionHandler(final @NotNull IHub hub) {
82-
return new SentryWebExceptionHandler(hub);
81+
public @NotNull SentryWebExceptionHandler sentryWebExceptionHandler(
82+
final @NotNull IScopes scopes) {
83+
return new SentryWebExceptionHandler(scopes);
8384
}
8485

8586
static final class SentryLegacyFilterConfigurationCondition extends AnyNestedCondition {

sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import io.sentry.AsyncHttpTransportFactory
55
import io.sentry.Breadcrumb
66
import io.sentry.EventProcessor
77
import io.sentry.Hint
8-
import io.sentry.IHub
8+
import io.sentry.IScopes
99
import io.sentry.ITransportFactory
1010
import io.sentry.Integration
1111
import io.sentry.NoOpTransportFactory
@@ -77,18 +77,18 @@ class SentryAutoConfigurationTest {
7777
.withConfiguration(AutoConfigurations.of(SentryAutoConfiguration::class.java, WebMvcAutoConfiguration::class.java))
7878

7979
@Test
80-
fun `hub is not created when auto-configuration dsn is not set`() {
80+
fun `scopes is not created when auto-configuration dsn is not set`() {
8181
contextRunner
8282
.run {
83-
assertThat(it).doesNotHaveBean(IHub::class.java)
83+
assertThat(it).doesNotHaveBean(IScopes::class.java)
8484
}
8585
}
8686

8787
@Test
88-
fun `hub is created when dsn is provided`() {
88+
fun `scopes is created when dsn is provided`() {
8989
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj")
9090
.run {
91-
assertThat(it).hasSingleBean(IHub::class.java)
91+
assertThat(it).hasSingleBean(IScopes::class.java)
9292
}
9393
}
9494

@@ -961,7 +961,7 @@ class SentryAutoConfigurationTest {
961961
}
962962

963963
class CustomIntegration : Integration {
964-
override fun register(hub: IHub, options: SentryOptions) {}
964+
override fun register(scopes: IScopes, options: SentryOptions) {}
965965
}
966966

967967
@Configuration(proxyBeanMethods = false)

sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentrySpanRestClientCustomizerTest.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package io.sentry.spring.boot.jakarta
22

33
import io.sentry.BaggageHeader
44
import io.sentry.Breadcrumb
5-
import io.sentry.IHub
5+
import io.sentry.IScopes
66
import io.sentry.Scope
77
import io.sentry.ScopeCallback
88
import io.sentry.SentryOptions
@@ -36,18 +36,18 @@ import kotlin.test.assertTrue
3636
class SentrySpanRestClientCustomizerTest {
3737
class Fixture {
3838
val sentryOptions = SentryOptions()
39-
val hub = mock<IHub>()
39+
val scopes = mock<IScopes>()
4040
val restClientBuilder = RestClient.builder()
4141
var mockServer = MockWebServer()
4242
val transaction: SentryTracer
43-
internal val customizer = SentrySpanRestClientCustomizer(hub)
43+
internal val customizer = SentrySpanRestClientCustomizer(scopes)
4444
val url = mockServer.url("/test/123").toString()
4545
val scope = Scope(sentryOptions)
4646

4747
init {
48-
whenever(hub.options).thenReturn(sentryOptions)
49-
doAnswer { (it.arguments[0] as ScopeCallback).run(scope) }.whenever(hub).configureScope(any())
50-
transaction = SentryTracer(TransactionContext("aTransaction", "op", TracesSamplingDecision(true)), hub)
48+
whenever(scopes.options).thenReturn(sentryOptions)
49+
doAnswer { (it.arguments[0] as ScopeCallback).run(scope) }.whenever(scopes).configureScope(any())
50+
transaction = SentryTracer(TransactionContext("aTransaction", "op", TracesSamplingDecision(true)), scopes)
5151
}
5252

5353
fun getSut(
@@ -75,7 +75,7 @@ class SentrySpanRestClientCustomizerTest {
7575
)
7676

7777
if (isTransactionActive) {
78-
whenever(hub.span).thenReturn(transaction)
78+
whenever(scopes.span).thenReturn(transaction)
7979
}
8080

8181
return restClientBuilder.apply {
@@ -247,7 +247,7 @@ class SentrySpanRestClientCustomizerTest {
247247
.body("content")
248248
.retrieve()
249249
.toEntity(String::class.java)
250-
verify(fixture.hub).addBreadcrumb(
250+
verify(fixture.scopes).addBreadcrumb(
251251
check<Breadcrumb> {
252252
assertEquals("http", it.type)
253253
assertEquals(fixture.url, it.data["url"])
@@ -269,7 +269,7 @@ class SentrySpanRestClientCustomizerTest {
269269
.toEntity(String::class.java)
270270
} catch (e: Throwable) {
271271
}
272-
verify(fixture.hub).addBreadcrumb(
272+
verify(fixture.scopes).addBreadcrumb(
273273
check<Breadcrumb> {
274274
assertEquals("http", it.type)
275275
assertEquals(fixture.url, it.data["url"])
@@ -287,7 +287,7 @@ class SentrySpanRestClientCustomizerTest {
287287
.body("content")
288288
.retrieve()
289289
.toEntity(String::class.java)
290-
verify(fixture.hub).addBreadcrumb(
290+
verify(fixture.scopes).addBreadcrumb(
291291
check<Breadcrumb> {
292292
assertEquals("http", it.type)
293293
assertEquals(fixture.url, it.data["url"])
@@ -309,7 +309,7 @@ class SentrySpanRestClientCustomizerTest {
309309
.toEntity(String::class.java)
310310
} catch (e: Throwable) {
311311
}
312-
verify(fixture.hub).addBreadcrumb(
312+
verify(fixture.scopes).addBreadcrumb(
313313
check<Breadcrumb> {
314314
assertEquals("http", it.type)
315315
assertEquals(fixture.url, it.data["url"])

0 commit comments

Comments
 (0)