Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class io/sentry/spring/boot/jakarta/SentryProperties$Reactive {

public class io/sentry/spring/boot/jakarta/SentryWebfluxAutoConfiguration {
public fun <init> ()V
public fun sentryWebExceptionHandler (Lio/sentry/IHub;)Lio/sentry/spring/jakarta/webflux/SentryWebExceptionHandler;
public fun sentryWebExceptionHandler (Lio/sentry/IScopes;)Lio/sentry/spring/jakarta/webflux/SentryWebExceptionHandler;
}

public class io/sentry/spring/boot/jakarta/graphql/SentryGraphqlAutoConfiguration {
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename HubConfiguration in SentryAutoConfiguration?

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.jakewharton.nopen.annotation.Open;
import graphql.GraphQLError;
import io.sentry.EventProcessor;
import io.sentry.HubAdapter;
import io.sentry.IHub;
import io.sentry.IScopes;
import io.sentry.ITransportFactory;
import io.sentry.Integration;
import io.sentry.ScopesAdapter;
import io.sentry.Sentry;
import io.sentry.SentryIntegrationPackageStorage;
import io.sentry.SentryOptions;
Expand Down Expand Up @@ -116,7 +116,7 @@ static class HubConfiguration {
}

@Bean
public @NotNull IHub sentryHub(
public @NotNull IScopes sentryHub(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename this method?

final @NotNull List<Sentry.OptionsConfiguration<SentryOptions>> optionsConfigurations,
final @NotNull SentryProperties options,
final @NotNull ObjectProvider<GitProperties> gitProperties) {
Expand All @@ -139,7 +139,7 @@ static class HubConfiguration {
// here we make sure that only classes that extend throwable are set on this field
options.getIgnoredExceptionsForType().removeIf(it -> !Throwable.class.isAssignableFrom(it));
Sentry.init(options);
return HubAdapter.getInstance();
return ScopesAdapter.getInstance();
}

@Configuration(proxyBeanMethods = false)
Expand Down Expand Up @@ -239,19 +239,19 @@ static class SentrySecurityConfiguration {
* HttpServletRequest#getUserPrincipal()}. If Spring Security is auto-configured, its order is
* set to run after Spring Security.
*
* @param hub the Sentry hub
* @param scopes the Sentry scopes
* @param sentryProperties the Sentry properties
* @param sentryUserProvider the user provider
* @return {@link SentryUserFilter} registration bean
*/
@Bean
@ConditionalOnBean(SentryUserProvider.class)
public @NotNull FilterRegistrationBean<SentryUserFilter> sentryUserFilter(
final @NotNull IHub hub,
final @NotNull IScopes scopes,
final @NotNull SentryProperties sentryProperties,
final @NotNull List<SentryUserProvider> sentryUserProvider) {
final FilterRegistrationBean<SentryUserFilter> filter = new FilterRegistrationBean<>();
filter.setFilter(new SentryUserFilter(hub, sentryUserProvider));
filter.setFilter(new SentryUserFilter(scopes, sentryUserProvider));
filter.setOrder(resolveUserFilterOrder(sentryProperties));
return filter;
}
Expand All @@ -263,8 +263,8 @@ static class SentrySecurityConfiguration {
}

@Bean
public @NotNull SentryRequestResolver sentryRequestResolver(final @NotNull IHub hub) {
return new SentryRequestResolver(hub);
public @NotNull SentryRequestResolver sentryRequestResolver(final @NotNull IScopes scopes) {
return new SentryRequestResolver(scopes);
}

@Bean
Expand All @@ -276,22 +276,23 @@ static class SentrySecurityConfiguration {
@Bean
@ConditionalOnMissingBean(name = "sentrySpringFilter")
public @NotNull FilterRegistrationBean<SentrySpringFilter> sentrySpringFilter(
final @NotNull IHub hub,
final @NotNull IScopes scopes,
final @NotNull SentryRequestResolver requestResolver,
final @NotNull TransactionNameProvider transactionNameProvider) {
FilterRegistrationBean<SentrySpringFilter> filter =
new FilterRegistrationBean<>(
new SentrySpringFilter(hub, requestResolver, transactionNameProvider));
new SentrySpringFilter(scopes, requestResolver, transactionNameProvider));
filter.setOrder(SENTRY_SPRING_FILTER_PRECEDENCE);
return filter;
}

@Bean
@ConditionalOnMissingBean(name = "sentryTracingFilter")
public FilterRegistrationBean<SentryTracingFilter> sentryTracingFilter(
final @NotNull IHub hub, final @NotNull TransactionNameProvider transactionNameProvider) {
final @NotNull IScopes scopes,
final @NotNull TransactionNameProvider transactionNameProvider) {
FilterRegistrationBean<SentryTracingFilter> filter =
new FilterRegistrationBean<>(new SentryTracingFilter(hub, transactionNameProvider));
new FilterRegistrationBean<>(new SentryTracingFilter(scopes, transactionNameProvider));
filter.setOrder(SENTRY_SPRING_FILTER_PRECEDENCE + 1); // must run after SentrySpringFilter
return filter;
}
Expand All @@ -300,11 +301,11 @@ public FilterRegistrationBean<SentryTracingFilter> sentryTracingFilter(
@ConditionalOnMissingBean
@ConditionalOnClass(HandlerExceptionResolver.class)
public @NotNull SentryExceptionResolver sentryExceptionResolver(
final @NotNull IHub sentryHub,
final @NotNull IScopes scopes,
final @NotNull TransactionNameProvider transactionNameProvider,
final @NotNull SentryProperties options) {
return new SentryExceptionResolver(
sentryHub, transactionNameProvider, options.getExceptionResolverOrder());
scopes, transactionNameProvider, options.getExceptionResolverOrder());
}
}

Expand Down Expand Up @@ -354,8 +355,8 @@ static class SentrySpanPointcutAutoConfiguration {}
@Open
static class SentryPerformanceRestTemplateConfiguration {
@Bean
public SentrySpanRestTemplateCustomizer sentrySpanRestTemplateCustomizer(IHub hub) {
return new SentrySpanRestTemplateCustomizer(hub);
public SentrySpanRestTemplateCustomizer sentrySpanRestTemplateCustomizer(IScopes scopes) {
return new SentrySpanRestTemplateCustomizer(scopes);
}
}

Expand All @@ -365,8 +366,8 @@ public SentrySpanRestTemplateCustomizer sentrySpanRestTemplateCustomizer(IHub hu
@Open
static class SentrySpanRestClientConfiguration {
@Bean
public SentrySpanRestClientCustomizer sentrySpanRestClientCustomizer(IHub hub) {
return new SentrySpanRestClientCustomizer(hub);
public SentrySpanRestClientCustomizer sentrySpanRestClientCustomizer(IScopes scopes) {
return new SentrySpanRestClientCustomizer(scopes);
}
}

Expand All @@ -376,8 +377,8 @@ public SentrySpanRestClientCustomizer sentrySpanRestClientCustomizer(IHub hub) {
@Open
static class SentryPerformanceWebClientConfiguration {
@Bean
public SentrySpanWebClientCustomizer sentrySpanWebClientCustomizer(IHub hub) {
return new SentrySpanWebClientCustomizer(hub);
public SentrySpanWebClientCustomizer sentrySpanWebClientCustomizer(IScopes scopes) {
return new SentrySpanWebClientCustomizer(scopes);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.sentry.spring.boot.jakarta;

import com.jakewharton.nopen.annotation.Open;
import io.sentry.IHub;
import io.sentry.IScopes;
import io.sentry.spring.jakarta.tracing.SentrySpanClientHttpRequestInterceptor;
import org.jetbrains.annotations.NotNull;
import org.springframework.boot.web.client.RestClientCustomizer;
Expand All @@ -11,8 +11,8 @@
class SentrySpanRestClientCustomizer implements RestClientCustomizer {
private final @NotNull SentrySpanClientHttpRequestInterceptor interceptor;

public SentrySpanRestClientCustomizer(final @NotNull IHub hub) {
this.interceptor = new SentrySpanClientHttpRequestInterceptor(hub, false);
public SentrySpanRestClientCustomizer(final @NotNull IScopes scopes) {
this.interceptor = new SentrySpanClientHttpRequestInterceptor(scopes, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.sentry.spring.boot.jakarta;

import com.jakewharton.nopen.annotation.Open;
import io.sentry.IHub;
import io.sentry.IScopes;
import io.sentry.spring.jakarta.tracing.SentrySpanClientHttpRequestInterceptor;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -14,8 +14,8 @@
class SentrySpanRestTemplateCustomizer implements RestTemplateCustomizer {
private final @NotNull SentrySpanClientHttpRequestInterceptor interceptor;

public SentrySpanRestTemplateCustomizer(final @NotNull IHub hub) {
this.interceptor = new SentrySpanClientHttpRequestInterceptor(hub);
public SentrySpanRestTemplateCustomizer(final @NotNull IScopes scopes) {
this.interceptor = new SentrySpanClientHttpRequestInterceptor(scopes);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.sentry.spring.boot.jakarta;

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

public SentrySpanWebClientCustomizer(final @NotNull IHub hub) {
this.filter = new SentrySpanClientWebRequestFilter(hub);
public SentrySpanWebClientCustomizer(final @NotNull IScopes scopes) {
this.filter = new SentrySpanClientWebRequestFilter(scopes);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.sentry.spring.boot.jakarta;

import com.jakewharton.nopen.annotation.Open;
import io.sentry.IHub;
import io.sentry.IScope;
import io.sentry.IScopes;
import io.sentry.spring.jakarta.webflux.SentryScheduleHook;
import io.sentry.spring.jakarta.webflux.SentryWebExceptionHandler;
import io.sentry.spring.jakarta.webflux.SentryWebFilter;
Expand All @@ -28,7 +28,7 @@
/** Configures Sentry integration for Spring Webflux and Project Reactor. */
@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@ConditionalOnBean(IHub.class)
@ConditionalOnBean(IScopes.class)
@ConditionalOnClass(Schedulers.class)
@Open
@ApiStatus.Experimental
Expand All @@ -44,14 +44,14 @@ static class SentryWebfluxFilterThreadLocalAccessorConfiguration {
* Configures a filter that sets up Sentry {@link IScope} for each request.
*
* <p>Makes use of newer reactor-core and context-propagation library feature
* ThreadLocalAccessor to propagate the Sentry hub.
* ThreadLocalAccessor to propagate the Sentry scopes.
*/
@Bean
@Order(SENTRY_SPRING_FILTER_PRECEDENCE)
public @NotNull SentryWebFilterWithThreadLocalAccessor sentryWebFilterWithContextPropagation(
final @NotNull IHub hub) {
final @NotNull IScopes scopes) {
Hooks.enableAutomaticContextPropagation();
return new SentryWebFilterWithThreadLocalAccessor(hub);
return new SentryWebFilterWithThreadLocalAccessor(scopes);
}
}

Expand All @@ -60,7 +60,7 @@ static class SentryWebfluxFilterThreadLocalAccessorConfiguration {
@Open
static class SentryWebfluxFilterConfiguration {

/** Configures hook that sets correct hub on the executing thread. */
/** Configures hook that sets correct scopes on the executing thread. */
@Bean
public @NotNull ApplicationRunner sentryScheduleHookApplicationRunner() {
return args -> {
Expand All @@ -71,15 +71,16 @@ static class SentryWebfluxFilterConfiguration {
/** Configures a filter that sets up Sentry {@link IScope} for each request. */
@Bean
@Order(SENTRY_SPRING_FILTER_PRECEDENCE)
public @NotNull SentryWebFilter sentryWebFilter(final @NotNull IHub hub) {
return new SentryWebFilter(hub);
public @NotNull SentryWebFilter sentryWebFilter(final @NotNull IScopes scopes) {
return new SentryWebFilter(scopes);
}
}

/** Configures exception handler that handles unhandled exceptions and sends them to Sentry. */
@Bean
public @NotNull SentryWebExceptionHandler sentryWebExceptionHandler(final @NotNull IHub hub) {
return new SentryWebExceptionHandler(hub);
public @NotNull SentryWebExceptionHandler sentryWebExceptionHandler(
final @NotNull IScopes scopes) {
return new SentryWebExceptionHandler(scopes);
}

static final class SentryLegacyFilterConfigurationCondition extends AnyNestedCondition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.sentry.AsyncHttpTransportFactory
import io.sentry.Breadcrumb
import io.sentry.EventProcessor
import io.sentry.Hint
import io.sentry.IHub
import io.sentry.IScopes
import io.sentry.ITransportFactory
import io.sentry.Integration
import io.sentry.NoOpTransportFactory
Expand Down Expand Up @@ -77,18 +77,18 @@ class SentryAutoConfigurationTest {
.withConfiguration(AutoConfigurations.of(SentryAutoConfiguration::class.java, WebMvcAutoConfiguration::class.java))

@Test
fun `hub is not created when auto-configuration dsn is not set`() {
fun `scopes is not created when auto-configuration dsn is not set`() {
contextRunner
.run {
assertThat(it).doesNotHaveBean(IHub::class.java)
assertThat(it).doesNotHaveBean(IScopes::class.java)
}
}

@Test
fun `hub is created when dsn is provided`() {
fun `scopes is created when dsn is provided`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.run {
assertThat(it).hasSingleBean(IHub::class.java)
assertThat(it).hasSingleBean(IScopes::class.java)
}
}

Expand Down Expand Up @@ -961,7 +961,7 @@ class SentryAutoConfigurationTest {
}

class CustomIntegration : Integration {
override fun register(hub: IHub, options: SentryOptions) {}
override fun register(scopes: IScopes, options: SentryOptions) {}
}

@Configuration(proxyBeanMethods = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.sentry.spring.boot.jakarta

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
Expand Down Expand Up @@ -36,18 +36,18 @@ import kotlin.test.assertTrue
class SentrySpanRestClientCustomizerTest {
class Fixture {
val sentryOptions = SentryOptions()
val hub = mock<IHub>()
val scopes = mock<IScopes>()
val restClientBuilder = RestClient.builder()
var mockServer = MockWebServer()
val transaction: SentryTracer
internal val customizer = SentrySpanRestClientCustomizer(hub)
internal val customizer = SentrySpanRestClientCustomizer(scopes)
val url = mockServer.url("/test/123").toString()
val scope = Scope(sentryOptions)

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

fun getSut(
Expand Down Expand Up @@ -75,7 +75,7 @@ class SentrySpanRestClientCustomizerTest {
)

if (isTransactionActive) {
whenever(hub.span).thenReturn(transaction)
whenever(scopes.span).thenReturn(transaction)
}

return restClientBuilder.apply {
Expand Down Expand Up @@ -247,7 +247,7 @@ class SentrySpanRestClientCustomizerTest {
.body("content")
.retrieve()
.toEntity(String::class.java)
verify(fixture.hub).addBreadcrumb(
verify(fixture.scopes).addBreadcrumb(
check<Breadcrumb> {
assertEquals("http", it.type)
assertEquals(fixture.url, it.data["url"])
Expand All @@ -269,7 +269,7 @@ class SentrySpanRestClientCustomizerTest {
.toEntity(String::class.java)
} catch (e: Throwable) {
}
verify(fixture.hub).addBreadcrumb(
verify(fixture.scopes).addBreadcrumb(
check<Breadcrumb> {
assertEquals("http", it.type)
assertEquals(fixture.url, it.data["url"])
Expand All @@ -287,7 +287,7 @@ class SentrySpanRestClientCustomizerTest {
.body("content")
.retrieve()
.toEntity(String::class.java)
verify(fixture.hub).addBreadcrumb(
verify(fixture.scopes).addBreadcrumb(
check<Breadcrumb> {
assertEquals("http", it.type)
assertEquals(fixture.url, it.data["url"])
Expand All @@ -309,7 +309,7 @@ class SentrySpanRestClientCustomizerTest {
.toEntity(String::class.java)
} catch (e: Throwable) {
}
verify(fixture.hub).addBreadcrumb(
verify(fixture.scopes).addBreadcrumb(
check<Breadcrumb> {
assertEquals("http", it.type)
assertEquals(fixture.url, it.data["url"])
Expand Down
Loading