Skip to content
Open
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 @@ -11,6 +11,7 @@
import io.sentry.ScopesAdapter;
import io.sentry.Sentry;
import io.sentry.SentryIntegrationPackageStorage;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.protocol.SdkVersion;
import io.sentry.quartz.SentryJobListener;
Expand Down Expand Up @@ -163,7 +164,8 @@ static class OpenTelemetryNoAgentConfiguration {}
final @NotNull List<Sentry.OptionsConfiguration<SentryOptions>> optionsConfigurations,
final @NotNull SentryProperties options,
final @NotNull ObjectProvider<ISpanFactory> spanFactory,
final @NotNull ObjectProvider<GitProperties> gitProperties) {
final @NotNull ObjectProvider<GitProperties> gitProperties,
final @NotNull Environment environment) {
optionsConfigurations.forEach(
optionsConfiguration -> optionsConfiguration.configure(options));
gitProperties.ifAvailable(
Expand All @@ -185,9 +187,35 @@ static class OpenTelemetryNoAgentConfiguration {}
// 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);
warnForLegacyLogsConfiguration(environment, options);
return ScopesAdapter.getInstance();
}

private void warnForLegacyLogsConfiguration(
final @NotNull Environment environment, final @NotNull SentryOptions options) {
if (environment.containsProperty("sentry.logs.enabled")) {
final boolean enableLogs =
Boolean.TRUE.equals(environment.getProperty("sentry.logs.enabled", Boolean.class));
if (enableLogs) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"The 'sentry.logs.enabled' property is no longer supported. Manual "
+ "Sentry.logger() calls no longer require it, and automatic logging "
+ "integrations now require their own opt-ins.");
} else {
options
.getLogger()
.log(
SentryLevel.WARNING,
"The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() "
+ "calls. Automatic logging integrations remain disabled unless enabled "
+ "through their own opt-ins.");
}
}
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(MDC.class)
@Open
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.sentry.EventProcessor
import io.sentry.FilterString
import io.sentry.Hint
import io.sentry.IContinuousProfiler
import io.sentry.ILogger
import io.sentry.IProfileConverter
import io.sentry.IScopes
import io.sentry.ITransportFactory
Expand Down Expand Up @@ -57,7 +58,9 @@ import org.assertj.core.api.Assertions.assertThat
import org.mockito.internal.util.MockUtil.isMock
import org.mockito.kotlin.any
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.quartz.JobExecutionContext
Expand Down Expand Up @@ -195,6 +198,56 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `legacy logs property emits no warning when absent`() {
val logger = mock<ILogger>()
dsnEnabledRunner
.withPropertyValues("sentry.debug=true")
.withBean(ILogger::class.java, { logger })
.withUserConfiguration(LoggerConfiguration::class.java)
.run { verify(logger, never()).log(eq(SentryLevel.WARNING), any<String>()) }
}

@Test
fun `legacy logs property true emits migration warning`() {
val logger = mock<ILogger>()
dsnEnabledRunner
.withPropertyValues("sentry.debug=true", "sentry.logs.enabled=true")
.withBean(ILogger::class.java, { logger })
.withUserConfiguration(LoggerConfiguration::class.java)
.run {
verify(logger)
.log(
SentryLevel.WARNING,
"The 'sentry.logs.enabled' property is no longer supported. Manual " +
"Sentry.logger() calls no longer require it, and automatic logging " +
"integrations now require their own opt-ins.",
*emptyArray(),
)
assertThat(it.getBean(SentryProperties::class.java).logging.isEnableLogs).isFalse()
}
}

@Test
fun `legacy logs property false emits migration warning`() {
val logger = mock<ILogger>()
dsnEnabledRunner
.withPropertyValues("sentry.debug=true", "sentry.logs.enabled=false")
.withBean(ILogger::class.java, { logger })
.withUserConfiguration(LoggerConfiguration::class.java)
.run {
verify(logger)
.log(
SentryLevel.WARNING,
"The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() " +
"calls. Automatic logging integrations remain disabled unless enabled through " +
"their own opt-ins.",
*emptyArray(),
)
assertThat(it.getBean(SentryProperties::class.java).logging.isEnableLogs).isFalse()
}
}

@Test
fun `properties are applied to SentryOptions`() {
contextRunner
Expand Down Expand Up @@ -1316,6 +1369,13 @@ class SentryAutoConfigurationTest {
@Bean open fun sentryTransport() = transport
}

@Configuration(proxyBeanMethods = false)
open class LoggerConfiguration {
@Bean
open fun loggerConfiguration(logger: ILogger) =
Sentry.OptionsConfiguration<SentryOptions> { it.setLogger(logger) }
}

@Configuration(proxyBeanMethods = false)
open class NoOpTransportConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.sentry.ScopesAdapter;
import io.sentry.Sentry;
import io.sentry.SentryIntegrationPackageStorage;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.protocol.SdkVersion;
import io.sentry.quartz.SentryJobListener;
Expand Down Expand Up @@ -165,7 +166,8 @@ static class OpenTelemetryNoAgentConfiguration {}
final @NotNull List<Sentry.OptionsConfiguration<SentryOptions>> optionsConfigurations,
final @NotNull SentryProperties options,
final @NotNull ObjectProvider<ISpanFactory> spanFactory,
final @NotNull ObjectProvider<GitProperties> gitProperties) {
final @NotNull ObjectProvider<GitProperties> gitProperties,
final @NotNull Environment environment) {
optionsConfigurations.forEach(
optionsConfiguration -> optionsConfiguration.configure(options));
gitProperties.ifAvailable(
Expand All @@ -187,9 +189,35 @@ static class OpenTelemetryNoAgentConfiguration {}
// 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);
warnForLegacyLogsConfiguration(environment, options);
return ScopesAdapter.getInstance();
}

private void warnForLegacyLogsConfiguration(
final @NotNull Environment environment, final @NotNull SentryOptions options) {
if (environment.containsProperty("sentry.logs.enabled")) {
final boolean enableLogs =
Boolean.TRUE.equals(environment.getProperty("sentry.logs.enabled", Boolean.class));
if (enableLogs) {
Comment thread
sentry[bot] marked this conversation as resolved.
options
.getLogger()
.log(
SentryLevel.WARNING,
"The 'sentry.logs.enabled' property is no longer supported. Manual "
+ "Sentry.logger() calls no longer require it, and automatic logging "
+ "integrations now require their own opt-ins.");
} else {
options
.getLogger()
.log(
SentryLevel.WARNING,
"The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() "
+ "calls. Automatic logging integrations remain disabled unless enabled "
+ "through their own opt-ins.");
}
}
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(MDC.class)
@Open
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.sentry.EventProcessor
import io.sentry.FilterString
import io.sentry.Hint
import io.sentry.IContinuousProfiler
import io.sentry.ILogger
import io.sentry.IProfileConverter
import io.sentry.IScopes
import io.sentry.ITransportFactory
Expand Down Expand Up @@ -60,7 +61,9 @@ import org.assertj.core.api.Assertions.assertThat
import org.mockito.internal.util.MockUtil.isMock
import org.mockito.kotlin.any
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.quartz.JobExecutionContext
Expand Down Expand Up @@ -198,6 +201,56 @@ class SentryAutoConfigurationTest {
}
}

@Test
fun `legacy logs property emits no warning when absent`() {
val logger = mock<ILogger>()
dsnEnabledRunner
.withPropertyValues("sentry.debug=true")
.withBean(ILogger::class.java, { logger })
.withUserConfiguration(LoggerConfiguration::class.java)
.run { verify(logger, never()).log(eq(SentryLevel.WARNING), any<String>()) }
}

@Test
fun `legacy logs property true emits migration warning`() {
val logger = mock<ILogger>()
dsnEnabledRunner
.withPropertyValues("sentry.debug=true", "sentry.logs.enabled=true")
.withBean(ILogger::class.java, { logger })
.withUserConfiguration(LoggerConfiguration::class.java)
.run {
verify(logger)
.log(
SentryLevel.WARNING,
"The 'sentry.logs.enabled' property is no longer supported. Manual " +
"Sentry.logger() calls no longer require it, and automatic logging " +
"integrations now require their own opt-ins.",
*emptyArray(),
)
assertThat(it.getBean(SentryProperties::class.java).logging.isEnableLogs).isFalse()
}
}

@Test
fun `legacy logs property false emits migration warning`() {
val logger = mock<ILogger>()
dsnEnabledRunner
.withPropertyValues("sentry.debug=true", "sentry.logs.enabled=false")
.withBean(ILogger::class.java, { logger })
.withUserConfiguration(LoggerConfiguration::class.java)
.run {
verify(logger)
.log(
SentryLevel.WARNING,
"The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() " +
"calls. Automatic logging integrations remain disabled unless enabled through " +
"their own opt-ins.",
*emptyArray(),
)
assertThat(it.getBean(SentryProperties::class.java).logging.isEnableLogs).isFalse()
}
}

@Test
fun `properties are applied to SentryOptions`() {
contextRunner
Expand Down Expand Up @@ -1308,6 +1361,13 @@ class SentryAutoConfigurationTest {
@Bean open fun sentryTransport() = transport
}

@Configuration(proxyBeanMethods = false)
open class LoggerConfiguration {
@Bean
open fun loggerConfiguration(logger: ILogger) =
Sentry.OptionsConfiguration<SentryOptions> { it.setLogger(logger) }
}

@Configuration(proxyBeanMethods = false)
open class NoOpTransportConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.sentry.ScopesAdapter;
import io.sentry.Sentry;
import io.sentry.SentryIntegrationPackageStorage;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.protocol.SdkVersion;
import io.sentry.quartz.SentryJobListener;
Expand Down Expand Up @@ -160,7 +161,8 @@ static class OpenTelemetryNoAgentConfiguration {}
final @NotNull List<Sentry.OptionsConfiguration<SentryOptions>> optionsConfigurations,
final @NotNull SentryProperties options,
final @NotNull ObjectProvider<ISpanFactory> spanFactory,
final @NotNull ObjectProvider<GitProperties> gitProperties) {
final @NotNull ObjectProvider<GitProperties> gitProperties,
final @NotNull Environment environment) {
optionsConfigurations.forEach(
optionsConfiguration -> optionsConfiguration.configure(options));
gitProperties.ifAvailable(
Expand All @@ -182,9 +184,35 @@ static class OpenTelemetryNoAgentConfiguration {}
// 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);
warnForLegacyLogsConfiguration(environment, options);
return ScopesAdapter.getInstance();
}

private void warnForLegacyLogsConfiguration(
final @NotNull Environment environment, final @NotNull SentryOptions options) {
if (environment.containsProperty("sentry.logs.enabled")) {
final boolean enableLogs =
Boolean.TRUE.equals(environment.getProperty("sentry.logs.enabled", Boolean.class));
if (enableLogs) {
options
.getLogger()
.log(
SentryLevel.WARNING,
"The 'sentry.logs.enabled' property is no longer supported. Manual "
+ "Sentry.logger() calls no longer require it, and automatic logging "
+ "integrations now require their own opt-ins.");
} else {
options
.getLogger()
.log(
SentryLevel.WARNING,
"The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() "
+ "calls. Automatic logging integrations remain disabled unless enabled "
+ "through their own opt-ins.");
}
}
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(MDC.class)
@Open
Expand Down
Loading
Loading