Skip to content

Commit 419986b

Browse files
adinauerclaude
andcommitted
feat(spring): Warn for legacy Logs property
Inspect the Spring Environment before SDK initialization and emit tailored migration warnings for explicit sentry.logs.enabled values without binding or applying the obsolete property. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 50dc84e commit 419986b

6 files changed

Lines changed: 267 additions & 3 deletions

File tree

‎sentry-spring-boot-4/src/main/java/io/sentry/spring/boot4/SentryAutoConfiguration.java‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.sentry.ScopesAdapter;
1212
import io.sentry.Sentry;
1313
import io.sentry.SentryIntegrationPackageStorage;
14+
import io.sentry.SentryLevel;
1415
import io.sentry.SentryOptions;
1516
import io.sentry.protocol.SdkVersion;
1617
import io.sentry.quartz.SentryJobListener;
@@ -163,7 +164,8 @@ static class OpenTelemetryNoAgentConfiguration {}
163164
final @NotNull List<Sentry.OptionsConfiguration<SentryOptions>> optionsConfigurations,
164165
final @NotNull SentryProperties options,
165166
final @NotNull ObjectProvider<ISpanFactory> spanFactory,
166-
final @NotNull ObjectProvider<GitProperties> gitProperties) {
167+
final @NotNull ObjectProvider<GitProperties> gitProperties,
168+
final @NotNull Environment environment) {
167169
optionsConfigurations.forEach(
168170
optionsConfiguration -> optionsConfiguration.configure(options));
169171
gitProperties.ifAvailable(
@@ -184,10 +186,36 @@ static class OpenTelemetryNoAgentConfiguration {}
184186
// its technically possible to set non-throwable class to `ignoredExceptionsForType` set
185187
// here we make sure that only classes that extend throwable are set on this field
186188
options.getIgnoredExceptionsForType().removeIf(it -> !Throwable.class.isAssignableFrom(it));
189+
warnForLegacyLogsConfiguration(environment, options);
187190
Sentry.init(options);
188191
return ScopesAdapter.getInstance();
189192
}
190193

194+
private void warnForLegacyLogsConfiguration(
195+
final @NotNull Environment environment, final @NotNull SentryOptions options) {
196+
if (environment.containsProperty("sentry.logs.enabled")) {
197+
final boolean enableLogs =
198+
Boolean.TRUE.equals(environment.getProperty("sentry.logs.enabled", Boolean.class));
199+
if (enableLogs) {
200+
options
201+
.getLogger()
202+
.log(
203+
SentryLevel.WARNING,
204+
"The 'sentry.logs.enabled' property is no longer supported. Manual "
205+
+ "Sentry.logger() calls no longer require it, and automatic logging "
206+
+ "integrations now require their own opt-ins.");
207+
} else {
208+
options
209+
.getLogger()
210+
.log(
211+
SentryLevel.WARNING,
212+
"The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() "
213+
+ "calls. Automatic logging integrations remain disabled unless enabled "
214+
+ "through their own opt-ins.");
215+
}
216+
}
217+
}
218+
191219
@Configuration(proxyBeanMethods = false)
192220
@ConditionalOnClass(MDC.class)
193221
@Open

‎sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import io.sentry.EventProcessor
88
import io.sentry.FilterString
99
import io.sentry.Hint
1010
import io.sentry.IContinuousProfiler
11+
import io.sentry.ILogger
1112
import io.sentry.IProfileConverter
1213
import io.sentry.IScopes
1314
import io.sentry.ITransportFactory
@@ -56,7 +57,9 @@ import org.assertj.core.api.Assertions.assertThat
5657
import org.mockito.internal.util.MockUtil.isMock
5758
import org.mockito.kotlin.any
5859
import org.mockito.kotlin.anyOrNull
60+
import org.mockito.kotlin.eq
5961
import org.mockito.kotlin.mock
62+
import org.mockito.kotlin.never
6063
import org.mockito.kotlin.verify
6164
import org.mockito.kotlin.whenever
6265
import org.quartz.JobExecutionContext
@@ -194,6 +197,56 @@ class SentryAutoConfigurationTest {
194197
}
195198
}
196199

200+
@Test
201+
fun `legacy logs property emits no warning when absent`() {
202+
val logger = mock<ILogger>()
203+
dsnEnabledRunner
204+
.withPropertyValues("sentry.debug=true")
205+
.withBean(ILogger::class.java, { logger })
206+
.withUserConfiguration(LoggerConfiguration::class.java)
207+
.run { verify(logger, never()).log(eq(SentryLevel.WARNING), any<String>()) }
208+
}
209+
210+
@Test
211+
fun `legacy logs property true emits migration warning`() {
212+
val logger = mock<ILogger>()
213+
dsnEnabledRunner
214+
.withPropertyValues("sentry.debug=true", "sentry.logs.enabled=true")
215+
.withBean(ILogger::class.java, { logger })
216+
.withUserConfiguration(LoggerConfiguration::class.java)
217+
.run {
218+
verify(logger)
219+
.log(
220+
SentryLevel.WARNING,
221+
"The 'sentry.logs.enabled' property is no longer supported. Manual " +
222+
"Sentry.logger() calls no longer require it, and automatic logging " +
223+
"integrations now require their own opt-ins.",
224+
*emptyArray(),
225+
)
226+
assertThat(it.getBean(SentryProperties::class.java).logging.isEnableLogs).isFalse()
227+
}
228+
}
229+
230+
@Test
231+
fun `legacy logs property false emits migration warning`() {
232+
val logger = mock<ILogger>()
233+
dsnEnabledRunner
234+
.withPropertyValues("sentry.debug=true", "sentry.logs.enabled=false")
235+
.withBean(ILogger::class.java, { logger })
236+
.withUserConfiguration(LoggerConfiguration::class.java)
237+
.run {
238+
verify(logger)
239+
.log(
240+
SentryLevel.WARNING,
241+
"The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() " +
242+
"calls. Automatic logging integrations remain disabled unless enabled through " +
243+
"their own opt-ins.",
244+
*emptyArray(),
245+
)
246+
assertThat(it.getBean(SentryProperties::class.java).logging.isEnableLogs).isFalse()
247+
}
248+
}
249+
197250
@Test
198251
fun `properties are applied to SentryOptions`() {
199252
contextRunner
@@ -1284,6 +1337,13 @@ class SentryAutoConfigurationTest {
12841337
@Bean open fun sentryTransport() = transport
12851338
}
12861339

1340+
@Configuration(proxyBeanMethods = false)
1341+
open class LoggerConfiguration {
1342+
@Bean
1343+
open fun loggerConfiguration(logger: ILogger) =
1344+
Sentry.OptionsConfiguration<SentryOptions> { it.setLogger(logger) }
1345+
}
1346+
12871347
@Configuration(proxyBeanMethods = false)
12881348
open class NoOpTransportConfiguration {
12891349

‎sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryAutoConfiguration.java‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.sentry.ScopesAdapter;
1212
import io.sentry.Sentry;
1313
import io.sentry.SentryIntegrationPackageStorage;
14+
import io.sentry.SentryLevel;
1415
import io.sentry.SentryOptions;
1516
import io.sentry.protocol.SdkVersion;
1617
import io.sentry.quartz.SentryJobListener;
@@ -165,7 +166,8 @@ static class OpenTelemetryNoAgentConfiguration {}
165166
final @NotNull List<Sentry.OptionsConfiguration<SentryOptions>> optionsConfigurations,
166167
final @NotNull SentryProperties options,
167168
final @NotNull ObjectProvider<ISpanFactory> spanFactory,
168-
final @NotNull ObjectProvider<GitProperties> gitProperties) {
169+
final @NotNull ObjectProvider<GitProperties> gitProperties,
170+
final @NotNull Environment environment) {
169171
optionsConfigurations.forEach(
170172
optionsConfiguration -> optionsConfiguration.configure(options));
171173
gitProperties.ifAvailable(
@@ -186,10 +188,36 @@ static class OpenTelemetryNoAgentConfiguration {}
186188
// its technically possible to set non-throwable class to `ignoredExceptionsForType` set
187189
// here we make sure that only classes that extend throwable are set on this field
188190
options.getIgnoredExceptionsForType().removeIf(it -> !Throwable.class.isAssignableFrom(it));
191+
warnForLegacyLogsConfiguration(environment, options);
189192
Sentry.init(options);
190193
return ScopesAdapter.getInstance();
191194
}
192195

196+
private void warnForLegacyLogsConfiguration(
197+
final @NotNull Environment environment, final @NotNull SentryOptions options) {
198+
if (environment.containsProperty("sentry.logs.enabled")) {
199+
final boolean enableLogs =
200+
Boolean.TRUE.equals(environment.getProperty("sentry.logs.enabled", Boolean.class));
201+
if (enableLogs) {
202+
options
203+
.getLogger()
204+
.log(
205+
SentryLevel.WARNING,
206+
"The 'sentry.logs.enabled' property is no longer supported. Manual "
207+
+ "Sentry.logger() calls no longer require it, and automatic logging "
208+
+ "integrations now require their own opt-ins.");
209+
} else {
210+
options
211+
.getLogger()
212+
.log(
213+
SentryLevel.WARNING,
214+
"The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() "
215+
+ "calls. Automatic logging integrations remain disabled unless enabled "
216+
+ "through their own opt-ins.");
217+
}
218+
}
219+
}
220+
193221
@Configuration(proxyBeanMethods = false)
194222
@ConditionalOnClass(MDC.class)
195223
@Open

‎sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import io.sentry.EventProcessor
99
import io.sentry.FilterString
1010
import io.sentry.Hint
1111
import io.sentry.IContinuousProfiler
12+
import io.sentry.ILogger
1213
import io.sentry.IProfileConverter
1314
import io.sentry.IScopes
1415
import io.sentry.ITransportFactory
@@ -59,7 +60,9 @@ import org.assertj.core.api.Assertions.assertThat
5960
import org.mockito.internal.util.MockUtil.isMock
6061
import org.mockito.kotlin.any
6162
import org.mockito.kotlin.anyOrNull
63+
import org.mockito.kotlin.eq
6264
import org.mockito.kotlin.mock
65+
import org.mockito.kotlin.never
6366
import org.mockito.kotlin.verify
6467
import org.mockito.kotlin.whenever
6568
import org.quartz.JobExecutionContext
@@ -197,6 +200,56 @@ class SentryAutoConfigurationTest {
197200
}
198201
}
199202

203+
@Test
204+
fun `legacy logs property emits no warning when absent`() {
205+
val logger = mock<ILogger>()
206+
dsnEnabledRunner
207+
.withPropertyValues("sentry.debug=true")
208+
.withBean(ILogger::class.java, { logger })
209+
.withUserConfiguration(LoggerConfiguration::class.java)
210+
.run { verify(logger, never()).log(eq(SentryLevel.WARNING), any<String>()) }
211+
}
212+
213+
@Test
214+
fun `legacy logs property true emits migration warning`() {
215+
val logger = mock<ILogger>()
216+
dsnEnabledRunner
217+
.withPropertyValues("sentry.debug=true", "sentry.logs.enabled=true")
218+
.withBean(ILogger::class.java, { logger })
219+
.withUserConfiguration(LoggerConfiguration::class.java)
220+
.run {
221+
verify(logger)
222+
.log(
223+
SentryLevel.WARNING,
224+
"The 'sentry.logs.enabled' property is no longer supported. Manual " +
225+
"Sentry.logger() calls no longer require it, and automatic logging " +
226+
"integrations now require their own opt-ins.",
227+
*emptyArray(),
228+
)
229+
assertThat(it.getBean(SentryProperties::class.java).logging.isEnableLogs).isFalse()
230+
}
231+
}
232+
233+
@Test
234+
fun `legacy logs property false emits migration warning`() {
235+
val logger = mock<ILogger>()
236+
dsnEnabledRunner
237+
.withPropertyValues("sentry.debug=true", "sentry.logs.enabled=false")
238+
.withBean(ILogger::class.java, { logger })
239+
.withUserConfiguration(LoggerConfiguration::class.java)
240+
.run {
241+
verify(logger)
242+
.log(
243+
SentryLevel.WARNING,
244+
"The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() " +
245+
"calls. Automatic logging integrations remain disabled unless enabled through " +
246+
"their own opt-ins.",
247+
*emptyArray(),
248+
)
249+
assertThat(it.getBean(SentryProperties::class.java).logging.isEnableLogs).isFalse()
250+
}
251+
}
252+
200253
@Test
201254
fun `properties are applied to SentryOptions`() {
202255
contextRunner
@@ -1276,6 +1329,13 @@ class SentryAutoConfigurationTest {
12761329
@Bean open fun sentryTransport() = transport
12771330
}
12781331

1332+
@Configuration(proxyBeanMethods = false)
1333+
open class LoggerConfiguration {
1334+
@Bean
1335+
open fun loggerConfiguration(logger: ILogger) =
1336+
Sentry.OptionsConfiguration<SentryOptions> { it.setLogger(logger) }
1337+
}
1338+
12791339
@Configuration(proxyBeanMethods = false)
12801340
open class NoOpTransportConfiguration {
12811341

‎sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.sentry.ScopesAdapter;
1111
import io.sentry.Sentry;
1212
import io.sentry.SentryIntegrationPackageStorage;
13+
import io.sentry.SentryLevel;
1314
import io.sentry.SentryOptions;
1415
import io.sentry.protocol.SdkVersion;
1516
import io.sentry.quartz.SentryJobListener;
@@ -160,7 +161,8 @@ static class OpenTelemetryNoAgentConfiguration {}
160161
final @NotNull List<Sentry.OptionsConfiguration<SentryOptions>> optionsConfigurations,
161162
final @NotNull SentryProperties options,
162163
final @NotNull ObjectProvider<ISpanFactory> spanFactory,
163-
final @NotNull ObjectProvider<GitProperties> gitProperties) {
164+
final @NotNull ObjectProvider<GitProperties> gitProperties,
165+
final @NotNull Environment environment) {
164166
optionsConfigurations.forEach(
165167
optionsConfiguration -> optionsConfiguration.configure(options));
166168
gitProperties.ifAvailable(
@@ -181,10 +183,36 @@ static class OpenTelemetryNoAgentConfiguration {}
181183
// its technically possible to set non-throwable class to `ignoredExceptionsForType` set
182184
// here we make sure that only classes that extend throwable are set on this field
183185
options.getIgnoredExceptionsForType().removeIf(it -> !Throwable.class.isAssignableFrom(it));
186+
warnForLegacyLogsConfiguration(environment, options);
184187
Sentry.init(options);
185188
return ScopesAdapter.getInstance();
186189
}
187190

191+
private void warnForLegacyLogsConfiguration(
192+
final @NotNull Environment environment, final @NotNull SentryOptions options) {
193+
if (environment.containsProperty("sentry.logs.enabled")) {
194+
final boolean enableLogs =
195+
Boolean.TRUE.equals(environment.getProperty("sentry.logs.enabled", Boolean.class));
196+
if (enableLogs) {
197+
options
198+
.getLogger()
199+
.log(
200+
SentryLevel.WARNING,
201+
"The 'sentry.logs.enabled' property is no longer supported. Manual "
202+
+ "Sentry.logger() calls no longer require it, and automatic logging "
203+
+ "integrations now require their own opt-ins.");
204+
} else {
205+
options
206+
.getLogger()
207+
.log(
208+
SentryLevel.WARNING,
209+
"The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() "
210+
+ "calls. Automatic logging integrations remain disabled unless enabled "
211+
+ "through their own opt-ins.");
212+
}
213+
}
214+
}
215+
188216
@Configuration(proxyBeanMethods = false)
189217
@ConditionalOnClass(MDC.class)
190218
@Open

0 commit comments

Comments
 (0)