Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to register multiple OptionsConfiguration beans. #1093

Merged
merged 3 commits into from
Dec 4, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Enhancement: Resolve in-app-includes and in-app-excludes parameters from the external configuration
* Enhancement: Make InAppIncludesResolver public (#1084)
* Ref: Change "op" to "operation" in @SentrySpan and @SentryTransaction
* Enhancement: Add the ability to register multiple OptionsConfiguration beans (#1093)
Copy link
Member

Choose a reason for hiding this comment

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

L: can we just call it feat: like in the other repos at Sentry?
Enhancement takes up a lot of space of the changelog

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feature is something different than enhancement AFAIK. Perhaps "enc"?

* Fix: Append DebugImage list if event already has it

# 4.0.0-alpha.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public final class io/sentry/spring/boot/BuildConfig {

public class io/sentry/spring/boot/InAppIncludesResolver : org/springframework/context/ApplicationContextAware {
public fun <init> ()V
public fun resolveInAppIncludes ()Ljava/util/List;
public fun setApplicationContext (Lorg/springframework/context/ApplicationContext;)V
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class InAppIncludesResolver implements ApplicationContextAware {
private @Nullable ApplicationContext applicationContext;

@Nullable
List<String> resolveInAppIncludes() {
public List<String> resolveInAppIncludes() {
if (applicationContext != null) {
Map<String, Object> beansWithAnnotation =
applicationContext.getBeansWithAnnotation(SpringBootConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.client.RestTemplate;

@Configuration
Expand All @@ -57,8 +58,9 @@ public class SentryAutoConfiguration {
static class HubConfiguration {

@Bean
@ConditionalOnMissingBean
public @NotNull Sentry.OptionsConfiguration<SentryOptions> optionsOptionsConfiguration(
@ConditionalOnMissingBean(name = "sentryOptionsConfiguration")
@Order(Ordered.HIGHEST_PRECEDENCE)
public @NotNull Sentry.OptionsConfiguration<SentryOptions> sentryOptionsConfiguration(
final @NotNull ObjectProvider<SentryOptions.BeforeSendCallback> beforeSendCallback,
final @NotNull ObjectProvider<SentryOptions.BeforeBreadcrumbCallback>
beforeBreadcrumbCallback,
Expand Down Expand Up @@ -92,10 +94,11 @@ static class HubConfiguration {

@Bean
public @NotNull IHub sentryHub(
final @NotNull Sentry.OptionsConfiguration<SentryOptions> optionsConfiguration,
final @NotNull List<Sentry.OptionsConfiguration<SentryOptions>> optionsConfigurations,
final @NotNull SentryProperties options,
final @NotNull ObjectProvider<GitProperties> gitProperties) {
optionsConfiguration.configure(options);
optionsConfigurations.forEach(
optionsConfiguration -> optionsConfiguration.configure(options));
gitProperties.ifAvailable(
git -> {
if (options.getRelease() == null && options.isUseGitCommitIdAsRelease()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,42 @@ class SentryAutoConfigurationTest {
}

@Test
fun `OptionsConfiguration is created if custom one is not provided`() {
fun `OptionsConfiguration is created if custom one with name "sentryOptionsConfiguration" is not provided`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.run {
assertThat(it).hasSingleBean(Sentry.OptionsConfiguration::class.java)
}
}

@Test
fun `OptionsConfiguration is not created if custom one is provided`() {
fun `OptionsConfiguration with name "sentryOptionsConfiguration" is created if another one with different name is provided`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.withUserConfiguration(CustomOptionsConfigurationConfiguration::class.java)
.run {
assertThat(it).getBeans(Sentry.OptionsConfiguration::class.java).hasSize(2)
assertThat(it).getBean("sentryOptionsConfiguration")
.isNotNull()
.isInstanceOf(Sentry.OptionsConfiguration::class.java)
assertThat(it).getBean("customOptionsConfiguration")
.isNotNull()
.isInstanceOf(Sentry.OptionsConfiguration::class.java)
}
}

@Test
fun `"sentryOptionsConfiguration" bean is configured before custom OptionsConfiguration`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.withUserConfiguration(CustomOptionsConfigurationConfiguration::class.java)
.run {
val options = it.getBean(SentryOptions::class.java)
assertThat(options.beforeSend).isNull()
}
}

@Test
fun `OptionsConfiguration is not created if custom one with name "sentryOptionsConfiguration" is provided`() {
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj")
.withUserConfiguration(OverridingOptionsConfigurationConfiguration::class.java)
.run {
assertThat(it).hasSingleBean(Sentry.OptionsConfiguration::class.java)
assertThat(it.getBean(Sentry.OptionsConfiguration::class.java, "customOptionsConfiguration")).isNotNull
Expand Down Expand Up @@ -432,6 +457,18 @@ class SentryAutoConfigurationTest {

@Bean
open fun customOptionsConfiguration() = Sentry.OptionsConfiguration<SentryOptions> {
it.setBeforeSend(null)
}

@Bean
open fun beforeSendCallback() = CustomBeforeSendCallback()
}

@Configuration(proxyBeanMethods = false)
open class OverridingOptionsConfigurationConfiguration {

@Bean
open fun sentryOptionsConfiguration() = Sentry.OptionsConfiguration<SentryOptions> {
}
}

Expand Down