From e18e7a807c808c98b9726bdec139b19b35a9539d Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Fri, 28 Aug 2020 22:10:22 +0200 Subject: [PATCH 1/3] Bind directly to SentryOptions in Logback integration. --- .../io/sentry/logback/SentryAppender.java | 91 +++---------------- .../io/sentry/logback/SentryAppenderTest.kt | 23 +++-- .../src/main/resources/logback.xml | 6 +- 3 files changed, 31 insertions(+), 89 deletions(-) diff --git a/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java b/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java index 46c532094..5063a60bc 100644 --- a/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java +++ b/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java @@ -11,7 +11,8 @@ import io.sentry.core.SentryOptions; import io.sentry.core.protocol.Message; import io.sentry.core.protocol.SdkVersion; - +import io.sentry.core.transport.ITransport; +import io.sentry.core.util.CollectionUtils; import java.util.Arrays; import java.util.Collections; import java.util.Date; @@ -20,48 +21,22 @@ import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; - -import io.sentry.core.transport.ITransport; -import io.sentry.core.util.CollectionUtils; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** Appender for logback in charge of sending the logged events to a Sentry server. */ public final class SentryAppender extends UnsynchronizedAppenderBase { - private @Nullable String dsn; - private @Nullable String environment; - private @Nullable Integer maxBreadcrumbs; - private @Nullable Integer shutdownTimeoutMillis; - private @Nullable Integer flushTimeoutMillis; - private @Nullable Integer readTimeoutMillis; - private @Nullable Double sampleRate; - private @Nullable Boolean bypassSecurity; - private @Nullable Boolean debug; - private @Nullable Boolean attachThreads; - private @Nullable Boolean attachStacktrace; + private @Nullable SentryOptions options; private @Nullable ITransport transport; @Override public void start() { - if (dsn != null) { - Sentry.init( - options -> { - options.setDsn(dsn); - Optional.ofNullable(maxBreadcrumbs).ifPresent(options::setMaxBreadcrumbs); - Optional.ofNullable(environment).ifPresent(options::setEnvironment); - Optional.ofNullable(shutdownTimeoutMillis).ifPresent(options::setShutdownTimeout); - Optional.ofNullable(flushTimeoutMillis).ifPresent(options::setFlushTimeoutMillis); - Optional.ofNullable(readTimeoutMillis).ifPresent(options::setReadTimeoutMillis); - Optional.ofNullable(sampleRate).ifPresent(options::setSampleRate); - Optional.ofNullable(bypassSecurity).ifPresent(options::setBypassSecurity); - Optional.ofNullable(debug).ifPresent(options::setDebug); - Optional.ofNullable(attachThreads).ifPresent(options::setAttachThreads); - Optional.ofNullable(attachStacktrace).ifPresent(options::setAttachStacktrace); - options.setSentryClientName(BuildConfig.SENTRY_LOGBACK_SDK_NAME); - options.setSdkVersion(createSdkVersion(options)); - Optional.ofNullable(transport).ifPresent(options::setTransport); - }); + if (options != null && options.getDsn() != null) { + options.setSentryClientName(BuildConfig.SENTRY_LOGBACK_SDK_NAME); + options.setSdkVersion(createSdkVersion(options)); + Optional.ofNullable(transport).ifPresent(options::setTransport); + Sentry.init(options); } super.start(); } @@ -79,7 +54,8 @@ protected void append(@NotNull ILoggingEvent eventObject) { */ @SuppressWarnings("JdkObsolete") final @NotNull SentryEvent createEvent(@NotNull ILoggingEvent loggingEvent) { - final SentryEvent event = new SentryEvent(DateUtils.getDateTime(new Date(loggingEvent.getTimeStamp()))); + final SentryEvent event = + new SentryEvent(DateUtils.getDateTime(new Date(loggingEvent.getTimeStamp()))); final Message message = new Message(); message.setMessage(loggingEvent.getMessage()); message.setFormatted(loggingEvent.getFormattedMessage()); @@ -97,7 +73,8 @@ protected void append(@NotNull ILoggingEvent eventObject) { event.setExtra("thread_name", loggingEvent.getThreadName()); } - final Map mdcProperties = CollectionUtils.shallowCopy(loggingEvent.getMDCPropertyMap()); + final Map mdcProperties = + CollectionUtils.shallowCopy(loggingEvent.getMDCPropertyMap()); if (!mdcProperties.isEmpty()) { event.getContexts().put("MDC", mdcProperties); } @@ -149,48 +126,8 @@ protected void append(@NotNull ILoggingEvent eventObject) { return sdkVersion; } - public void setDsn(@Nullable String dsn) { - this.dsn = dsn; - } - - public void setEnvironment(@Nullable String environment) { - this.environment = environment; - } - - public void setMaxBreadcrumbs(@Nullable Integer maxBreadcrumbs) { - this.maxBreadcrumbs = maxBreadcrumbs; - } - - public void setShutdownTimeoutMillis(@Nullable Integer shutdownTimeoutMillis) { - this.shutdownTimeoutMillis = shutdownTimeoutMillis; - } - - public void setFlushTimeoutMillis(@Nullable Integer flushTimeoutMillis) { - this.flushTimeoutMillis = flushTimeoutMillis; - } - - public void setReadTimeoutMillis(@Nullable Integer readTimeoutMillis) { - this.readTimeoutMillis = readTimeoutMillis; - } - - public void setSampleRate(@Nullable Double sampleRate) { - this.sampleRate = sampleRate; - } - - public void setBypassSecurity(@Nullable Boolean bypassSecurity) { - this.bypassSecurity = bypassSecurity; - } - - public void setDebug(@Nullable Boolean debug) { - this.debug = debug; - } - - public void setAttachThreads(@Nullable Boolean attachThreads) { - this.attachThreads = attachThreads; - } - - public void setAttachStacktrace(@Nullable Boolean attachStacktrace) { - this.attachStacktrace = attachStacktrace; + public void setOptions(SentryOptions options) { + this.options = options; } @ApiStatus.Internal diff --git a/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt b/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt index d54c4472a..262e4b3d9 100644 --- a/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt +++ b/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt @@ -9,22 +9,23 @@ import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever import io.sentry.core.SentryEvent import io.sentry.core.SentryLevel +import io.sentry.core.SentryOptions import io.sentry.core.transport.ITransport import io.sentry.core.transport.TransportResult -import org.awaitility.kotlin.await -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertNotNull -import org.slf4j.Logger -import org.slf4j.LoggerFactory -import org.slf4j.MDC import java.time.Instant import java.time.LocalDateTime import java.time.ZoneId import kotlin.test.AfterTest import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertFalse +import kotlin.test.assertNotNull import kotlin.test.assertTrue +import org.awaitility.kotlin.await +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.slf4j.MDC class SentryAppenderTest { private class Fixture { @@ -36,7 +37,9 @@ class SentryAppenderTest { whenever(transport.send(any())).thenReturn(TransportResult.success()) val appender = SentryAppender() - appender.setDsn("http://key@localhost/proj") + val options = SentryOptions() + options.dsn = "http://key@localhost/proj" + appender.setOptions(options) appender.context = loggerContext appender.setTransport(transport) @@ -204,8 +207,8 @@ class SentryAppenderTest { assertEquals(BuildConfig.VERSION_NAME, it.sdk.version) assertNotNull(it.sdk.packages) assertTrue(it.sdk.packages!!.any { pkg -> - "maven:sentry-logback" == pkg.name - && BuildConfig.VERSION_NAME == pkg.version + "maven:sentry-logback" == pkg.name && + BuildConfig.VERSION_NAME == pkg.version }) }) } diff --git a/sentry-samples/sentry-samples-logback/src/main/resources/logback.xml b/sentry-samples/sentry-samples-logback/src/main/resources/logback.xml index 2d10daa78..e0004e806 100644 --- a/sentry-samples/sentry-samples-logback/src/main/resources/logback.xml +++ b/sentry-samples/sentry-samples-logback/src/main/resources/logback.xml @@ -7,8 +7,10 @@ - - https://f7f320d5c3a54709be7b28e0f2ca7081@sentry.io/1808954 + + + https://f7f320d5c3a54709be7b28e0f2ca7081@sentry.io/1808954 + From dfa5a6675cbc572897da0cd7032f87699900d831 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Fri, 28 Aug 2020 22:24:42 +0200 Subject: [PATCH 2/3] Bind directly to SentryOptions in Spring integration. --- .../java/io/sentry/core/SentryOptions.java | 6 +- .../spring/boot/SentryAutoConfiguration.java | 16 +- .../sentry/spring/boot/SentryProperties.java | 283 +----------------- .../boot/SentryAutoConfigurationTest.kt | 2 +- 4 files changed, 10 insertions(+), 297 deletions(-) diff --git a/sentry-core/src/main/java/io/sentry/core/SentryOptions.java b/sentry-core/src/main/java/io/sentry/core/SentryOptions.java index c3246f8d3..101a5f49c 100644 --- a/sentry-core/src/main/java/io/sentry/core/SentryOptions.java +++ b/sentry-core/src/main/java/io/sentry/core/SentryOptions.java @@ -48,7 +48,7 @@ public class SentryOptions { * background queue and this queue is given a certain amount to drain pending events Default is * 2000 = 2s */ - private long shutdownTimeoutMillis = 2000; // 2s + private long shutdownTimeout = 2000; // 2s /** * Controls how many seconds to wait before flushing down. Sentry SDKs cache events from a @@ -369,7 +369,7 @@ public void setEnableNdk(boolean enableNdk) { * @return the timeout in Millis */ public long getShutdownTimeout() { - return shutdownTimeoutMillis; + return shutdownTimeout; } /** @@ -378,7 +378,7 @@ public long getShutdownTimeout() { * @param shutdownTimeoutMillis the shutdown timeout in millis */ public void setShutdownTimeout(long shutdownTimeoutMillis) { - this.shutdownTimeoutMillis = shutdownTimeoutMillis; + this.shutdownTimeout = shutdownTimeoutMillis; } /** diff --git a/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java b/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java index 57820d14b..e0a1e4c0d 100644 --- a/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java +++ b/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java @@ -55,27 +55,21 @@ static class HubConfiguration { } @Bean - public @NotNull SentryOptions sentryOptions( + public @NotNull IHub sentryHub( final @NotNull Sentry.OptionsConfiguration optionsConfiguration, - final @NotNull SentryProperties properties, + final @NotNull SentryProperties options, final @NotNull ObjectProvider gitProperties) { - final SentryOptions options = new SentryOptions(); optionsConfiguration.configure(options); gitProperties.ifAvailable( git -> { - if (properties.isUseGitCommitIdAsRelease()) { + if (options.getRelease() == null && options.isUseGitCommitIdAsRelease()) { options.setRelease(git.getCommitId()); } }); - properties.applyTo(options); + options.setSentryClientName(BuildConfig.SENTRY_SPRING_BOOT_SDK_NAME); options.setSdkVersion(createSdkVersion(options)); - return options; - } - - @Bean - public @NotNull IHub sentryHub(final @NotNull SentryOptions sentryOptions) { - Sentry.init(sentryOptions); + Sentry.init(options); return HubAdapter.getInstance(); } diff --git a/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryProperties.java b/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryProperties.java index 947d750ec..09b6cf9b5 100644 --- a/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryProperties.java +++ b/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryProperties.java @@ -1,133 +1,20 @@ package io.sentry.spring.boot; import com.jakewharton.nopen.annotation.Open; -import io.sentry.core.SentryLevel; import io.sentry.core.SentryOptions; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; import org.springframework.boot.context.properties.ConfigurationProperties; /** Configuration for Sentry integration. */ @ConfigurationProperties("sentry") @Open -public class SentryProperties { +public class SentryProperties extends SentryOptions { /** Whether Sentry integration should be enabled. */ private boolean enabled = true; - /** - * The DSN tells the SDK where to send the events to. If this value is not provided, the SDK will - * just not send any events. - */ - private String dsn = ""; - - /** - * Controls how many seconds to wait before shutting down. Sentry SDKs send events from a - * background queue and this queue is given a certain amount to drain pending events. - */ - private Long shutdownTimeoutMillis; - - /** - * Controls how many seconds to wait before flushing down. Sentry SDKs cache events from a - * background queue and this queue is given a certain amount to drain pending events. - */ - private Long flushTimeoutMillis; - - /** Read timeout in milliseconds. */ - private Integer readTimeoutMillis; - - /** Whether to ignore TLS errors. */ - private Boolean bypassSecurity; - - /** - * Turns debug mode on or off. If debug is enabled SDK will attempt to print out useful debugging - * information if something goes wrong. Default is disabled. - */ - private Boolean debug; - - /** minimum LogLevel to be used if debug is enabled */ - private SentryLevel diagnosticLevel = SentryLevel.DEBUG; - - /** This variable controls the total amount of breadcrumbs that should be captured. */ - private Integer maxBreadcrumbs; - - /** Sets the release. SDK will try to automatically configure a release out of the box */ - private String release; - - /** - * Sets the environment. This string is freeform and not set by default. A release can be - * associated with more than one environment to separate them in the UI Think staging vs prod or - * similar. - */ - private String environment; - - /** - * Configures the sample rate as a percentage of events to be sent in the range of 0.0 to 1.0. if - * 1.0 is set it means that 100% of events are sent. If set to 0.1 only 10% of events will be - * sent. Events are picked randomly. - */ - private Double sampleRate; - - /** - * A list of string prefixes of module names that do not belong to the app, but rather third-party - * packages. Modules considered not to be part of the app will be hidden from stack traces by - * default. - */ - private List inAppExcludes = new ArrayList<>(); - - /** - * A list of string prefixes of module names that belong to the app. This option takes precedence - * over inAppExcludes. - */ - private List inAppIncludes = new ArrayList<>(); - - /** Sets the distribution. Think about it together with release and environment */ - private String dist; - - /** When enabled, threads are automatically attached to all logged events. */ - private Boolean attachThreads; - - /** - * When enabled, stack traces are automatically attached to all threads logged. Stack traces are - * always attached to exceptions but when this is set stack traces are also sent with threads - */ - private Boolean attachStacktrace; - - /** The server name used in the Sentry messages. */ - private String serverName; - /** Weather to use Git commit id as a release. */ private boolean useGitCommitIdAsRelease = true; - /** - * Applies configuration from this instance to the {@link SentryOptions} instance. - * - * @param options the instance of {@link SentryOptions} to apply the configuration to - */ - public void applyTo(SentryOptions options) { - options.setDsn(this.getDsn()); - Optional.ofNullable(maxBreadcrumbs).ifPresent(options::setMaxBreadcrumbs); - Optional.ofNullable(environment).ifPresent(options::setEnvironment); - Optional.ofNullable(shutdownTimeoutMillis).ifPresent(options::setShutdownTimeout); - Optional.ofNullable(flushTimeoutMillis).ifPresent(options::setFlushTimeoutMillis); - Optional.ofNullable(readTimeoutMillis).ifPresent(options::setReadTimeoutMillis); - Optional.ofNullable(sampleRate).ifPresent(options::setSampleRate); - Optional.ofNullable(bypassSecurity).ifPresent(options::setBypassSecurity); - Optional.ofNullable(debug).ifPresent(options::setDebug); - Optional.ofNullable(attachThreads).ifPresent(options::setAttachThreads); - Optional.ofNullable(attachStacktrace).ifPresent(options::setAttachStacktrace); - Optional.ofNullable(diagnosticLevel).ifPresent(options::setDiagnosticLevel); - Optional.ofNullable(dist).ifPresent(options::setDist); - Optional.ofNullable(release).ifPresent(options::setRelease); - Optional.ofNullable(sampleRate).ifPresent(options::setSampleRate); - Optional.ofNullable(serverName).ifPresent(options::setServerName); - Optional.ofNullable(inAppExcludes) - .ifPresent(excludes -> excludes.forEach(options::addInAppExclude)); - Optional.ofNullable(inAppIncludes) - .ifPresent(includes -> includes.forEach(options::addInAppInclude)); - } - public boolean isEnabled() { return enabled; } @@ -136,174 +23,6 @@ public void setEnabled(boolean enabled) { this.enabled = enabled; } - public String getDsn() { - return dsn; - } - - public void setDsn(String dsn) { - this.dsn = dsn; - } - - public long getShutdownTimeoutMillis() { - return shutdownTimeoutMillis; - } - - public void setShutdownTimeoutMillis(long shutdownTimeoutMillis) { - this.shutdownTimeoutMillis = shutdownTimeoutMillis; - } - - public boolean isDebug() { - return debug; - } - - public void setDebug(boolean debug) { - this.debug = debug; - } - - public SentryLevel getDiagnosticLevel() { - return diagnosticLevel; - } - - public void setDiagnosticLevel(SentryLevel diagnosticLevel) { - this.diagnosticLevel = diagnosticLevel; - } - - public int getMaxBreadcrumbs() { - return maxBreadcrumbs; - } - - public void setMaxBreadcrumbs(int maxBreadcrumbs) { - this.maxBreadcrumbs = maxBreadcrumbs; - } - - public String getRelease() { - return release; - } - - public void setRelease(String release) { - this.release = release; - } - - public String getEnvironment() { - return environment; - } - - public void setEnvironment(String environment) { - this.environment = environment; - } - - public Double getSampleRate() { - return sampleRate; - } - - public void setSampleRate(Double sampleRate) { - this.sampleRate = sampleRate; - } - - public List getInAppExcludes() { - return inAppExcludes; - } - - public void setInAppExcludes(List inAppExcludes) { - this.inAppExcludes = inAppExcludes; - } - - public List getInAppIncludes() { - return inAppIncludes; - } - - public void setInAppIncludes(List inAppIncludes) { - this.inAppIncludes = inAppIncludes; - } - - public String getDist() { - return dist; - } - - public void setDist(String dist) { - this.dist = dist; - } - - public boolean isAttachThreads() { - return attachThreads; - } - - public void setAttachThreads(boolean attachThreads) { - this.attachThreads = attachThreads; - } - - public boolean isAttachStacktrace() { - return attachStacktrace; - } - - public void setAttachStacktrace(boolean attachStacktrace) { - this.attachStacktrace = attachStacktrace; - } - - public String getServerName() { - return serverName; - } - - public void setServerName(String serverName) { - this.serverName = serverName; - } - - public void setShutdownTimeoutMillis(Long shutdownTimeoutMillis) { - this.shutdownTimeoutMillis = shutdownTimeoutMillis; - } - - public Long getFlushTimeoutMillis() { - return flushTimeoutMillis; - } - - public void setFlushTimeoutMillis(Long flushTimeoutMillis) { - this.flushTimeoutMillis = flushTimeoutMillis; - } - - public Integer getReadTimeoutMillis() { - return readTimeoutMillis; - } - - public void setReadTimeoutMillis(Integer readTimeoutMillis) { - this.readTimeoutMillis = readTimeoutMillis; - } - - public Boolean getBypassSecurity() { - return bypassSecurity; - } - - public void setBypassSecurity(Boolean bypassSecurity) { - this.bypassSecurity = bypassSecurity; - } - - public Boolean getDebug() { - return debug; - } - - public void setDebug(Boolean debug) { - this.debug = debug; - } - - public void setMaxBreadcrumbs(Integer maxBreadcrumbs) { - this.maxBreadcrumbs = maxBreadcrumbs; - } - - public Boolean getAttachThreads() { - return attachThreads; - } - - public void setAttachThreads(Boolean attachThreads) { - this.attachThreads = attachThreads; - } - - public Boolean getAttachStacktrace() { - return attachStacktrace; - } - - public void setAttachStacktrace(Boolean attachStacktrace) { - this.attachStacktrace = attachStacktrace; - } - public boolean isUseGitCommitIdAsRelease() { return useGitCommitIdAsRelease; } diff --git a/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt b/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt index cef98d47a..4645742b0 100644 --- a/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt @@ -87,7 +87,7 @@ class SentryAutoConfigurationTest { contextRunner.withPropertyValues( "sentry.dsn=http://key@localhost/proj", "sentry.read-timeout-millis=10", - "sentry.shutdown-timeout-millis=20", + "sentry.shutdown-timeout=20", "sentry.flush-timeout-millis=30", "sentry.bypass-security=true", "sentry.debug=true", From 647c265400f8a69f137c6821786f11f0b62f3c2a Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Fri, 28 Aug 2020 22:43:29 +0200 Subject: [PATCH 3/3] Remove "enabled" property from SentryProperties. --- .../spring/boot/SentryAutoConfiguration.java | 4 +--- .../sentry/spring/boot/SentryProperties.java | 11 --------- .../boot/SentryAutoConfigurationTest.kt | 24 ++----------------- 3 files changed, 3 insertions(+), 36 deletions(-) diff --git a/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java b/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java index e0a1e4c0d..ffda4a04a 100644 --- a/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java +++ b/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java @@ -23,13 +23,12 @@ import org.springframework.core.Ordered; @Configuration -@ConditionalOnProperty(name = "sentry.enabled", havingValue = "true", matchIfMissing = true) +@ConditionalOnProperty(name = "sentry.dsn") @Open public class SentryAutoConfiguration { /** Registers general purpose Sentry related beans. */ @Configuration - @ConditionalOnProperty("sentry.dsn") @EnableConfigurationProperties(SentryProperties.class) @Open static class HubConfiguration { @@ -76,7 +75,6 @@ static class HubConfiguration { /** Registers beans specific to Spring MVC. */ @Configuration @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) - @ConditionalOnProperty("sentry.dsn") @Open static class SentryWebMvcConfiguration { diff --git a/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryProperties.java b/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryProperties.java index 09b6cf9b5..18cb6f4ee 100644 --- a/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryProperties.java +++ b/sentry-spring-boot-starter/src/main/java/io/sentry/spring/boot/SentryProperties.java @@ -9,20 +9,9 @@ @Open public class SentryProperties extends SentryOptions { - /** Whether Sentry integration should be enabled. */ - private boolean enabled = true; - /** Weather to use Git commit id as a release. */ private boolean useGitCommitIdAsRelease = true; - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - public boolean isUseGitCommitIdAsRelease() { return useGitCommitIdAsRelease; } diff --git a/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt b/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt index 4645742b0..43571670a 100644 --- a/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt @@ -21,7 +21,6 @@ import org.springframework.boot.autoconfigure.AutoConfigurations import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration import org.springframework.boot.info.GitProperties import org.springframework.boot.test.context.runner.ApplicationContextRunner -import org.springframework.boot.test.context.runner.WebApplicationContextRunner import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -29,25 +28,14 @@ class SentryAutoConfigurationTest { private val contextRunner = ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(SentryAutoConfiguration::class.java, WebMvcAutoConfiguration::class.java)) - private val webContextRunner = WebApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(SentryAutoConfiguration::class.java)) - @Test - fun `hub is not created when auto-configuration is disabled`() { - contextRunner.withPropertyValues("sentry.enabled=false", "sentry.dsn=http://key@localhost/proj") + fun `hub is not created when auto-configuration dsn is not set`() { + contextRunner .run { assertThat(it).doesNotHaveBean(IHub::class.java) } } - @Test - fun `hub is created when auto-configuration is enabled`() { - contextRunner.withPropertyValues("sentry.enabled=true", "sentry.dsn=http://key@localhost/proj") - .run { - assertThat(it).hasSingleBean(IHub::class.java) - } - } - @Test fun `hub is created when dsn is provided`() { contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj") @@ -56,14 +44,6 @@ class SentryAutoConfigurationTest { } } - @Test - fun `hub is not created when dsn is provided but sentry is disabled`() { - contextRunner.withPropertyValues("sentry.enabled=false", "sentry.dsn=http://key@localhost/proj") - .run { - assertThat(it).doesNotHaveBean(IHub::class.java) - } - } - @Test fun `OptionsConfiguration is created if custom one is not provided`() { contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj")