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
4 changes: 2 additions & 2 deletions sentry-spring-boot/api/sentry-spring-boot.api
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class io/sentry/spring/boot/SentryProperties$Logging {
public class io/sentry/spring/boot/SentryWebfluxAutoConfiguration {
public fun <init> ()V
public fun sentryScheduleHookApplicationRunner ()Lorg/springframework/boot/ApplicationRunner;
public fun sentryWebExceptionHandler (Lio/sentry/IHub;)Lio/sentry/spring/webflux/SentryWebExceptionHandler;
public fun sentryWebFilter (Lio/sentry/IHub;)Lio/sentry/spring/webflux/SentryWebFilter;
public fun sentryWebExceptionHandler (Lio/sentry/IScopes;)Lio/sentry/spring/webflux/SentryWebExceptionHandler;
public fun sentryWebFilter (Lio/sentry/IScopes;)Lio/sentry/spring/webflux/SentryWebFilter;
}

public class io/sentry/spring/boot/graphql/SentryGraphqlAutoConfiguration {
Expand Down
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 @@ -114,7 +114,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 @@ -137,7 +137,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 @@ -237,19 +237,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 @@ -261,8 +261,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 @@ -274,22 +274,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 @@ -298,11 +299,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 @@ -348,8 +349,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 @@ -359,8 +360,8 @@ public SentrySpanRestTemplateCustomizer sentrySpanRestTemplateCustomizer(IHub hu
@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;

import com.jakewharton.nopen.annotation.Open;
import io.sentry.IHub;
import io.sentry.IScopes;
import io.sentry.spring.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;

import com.jakewharton.nopen.annotation.Open;
import io.sentry.IHub;
import io.sentry.IScopes;
import io.sentry.spring.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;

import com.jakewharton.nopen.annotation.Open;
import io.sentry.IHub;
import io.sentry.IScope;
import io.sentry.IScopes;
import io.sentry.spring.webflux.SentryScheduleHook;
import io.sentry.spring.webflux.SentryWebExceptionHandler;
import io.sentry.spring.webflux.SentryWebFilter;
Expand All @@ -21,14 +21,14 @@
/** 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
public class SentryWebfluxAutoConfiguration {
private static final int SENTRY_SPRING_FILTER_PRECEDENCE = Ordered.HIGHEST_PRECEDENCE;

/** 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 @@ -39,13 +39,14 @@ public class SentryWebfluxAutoConfiguration {
/** 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);
}
}
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 @@ -76,18 +76,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 @@ -943,7 +943,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

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 @@ -37,23 +37,23 @@ import kotlin.test.assertTrue
class SentrySpanRestTemplateCustomizerTest {
class Fixture {
val sentryOptions = SentryOptions()
val hub = mock<IHub>()
val scopes = mock<IScopes>()
val restTemplate = RestTemplateBuilder()
.setConnectTimeout(Duration.ofSeconds(2))
.setReadTimeout(Duration.ofSeconds(2))
.build()
var mockServer = MockWebServer()
val transaction: SentryTracer
internal val customizer = SentrySpanRestTemplateCustomizer(hub)
internal val customizer = SentrySpanRestTemplateCustomizer(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(
whenever(scopes.options).thenReturn(sentryOptions)
doAnswer { (it.arguments[0] as ScopeCallback).run(scope) }.whenever(scopes).configureScope(
any()
)
transaction = SentryTracer(TransactionContext("aTransaction", "op", TracesSamplingDecision(true)), hub)
transaction = SentryTracer(TransactionContext("aTransaction", "op", TracesSamplingDecision(true)), scopes)
}

fun getSut(isTransactionActive: Boolean, status: HttpStatus = HttpStatus.OK, socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN, includeMockServerInTracingOrigins: Boolean = true): RestTemplate {
Expand All @@ -76,7 +76,7 @@ class SentrySpanRestTemplateCustomizerTest {
)

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

return restTemplate
Expand Down Expand Up @@ -211,7 +211,7 @@ class SentrySpanRestTemplateCustomizerTest {
@Test
fun `when transaction is active adds breadcrumb when http calls succeeds`() {
fixture.getSut(isTransactionActive = true).postForObject(fixture.url, "content", 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 @@ -229,7 +229,7 @@ class SentrySpanRestTemplateCustomizerTest {
fixture.getSut(isTransactionActive = true, status = HttpStatus.INTERNAL_SERVER_ERROR).getForObject(fixture.url, 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 @@ -242,7 +242,7 @@ class SentrySpanRestTemplateCustomizerTest {
@Test
fun `when transaction is not active adds breadcrumb when http calls succeeds`() {
fixture.getSut(isTransactionActive = false).postForObject(fixture.url, "content", 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 @@ -260,7 +260,7 @@ class SentrySpanRestTemplateCustomizerTest {
fixture.getSut(isTransactionActive = false, status = HttpStatus.INTERNAL_SERVER_ERROR).getForObject(fixture.url, 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