Skip to content

Commit 50dc84e

Browse files
adinauerclaude
andcommitted
feat(core): Warn for legacy Logs configuration
Keep parsing the nullable logs.enabled external option and emit tailored migration warnings for explicit true and false values without changing manual Logs capture. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fcb8040 commit 50dc84e

3 files changed

Lines changed: 99 additions & 0 deletions

File tree

‎sentry/src/main/java/io/sentry/SentryOptions.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3733,6 +3733,21 @@ public void merge(final @NotNull ExternalOptions options) {
37333733
}
37343734
}
37353735

3736+
if (options.isEnableLogs() != null) {
3737+
if (options.isEnableLogs()) {
3738+
logger.log(
3739+
SentryLevel.WARNING,
3740+
"The 'logs.enabled' option is no longer supported. Manual Sentry.logger() calls no "
3741+
+ "longer require it, and automatic logging integrations now require their own "
3742+
+ "opt-ins.");
3743+
} else {
3744+
logger.log(
3745+
SentryLevel.WARNING,
3746+
"The 'logs.enabled' option no longer disables manual Sentry.logger() calls. Automatic "
3747+
+ "logging integrations remain disabled unless enabled through their own opt-ins.");
3748+
}
3749+
}
3750+
37363751
if (options.isEnableMetrics() != null) {
37373752
getMetrics().setEnabled(options.isEnableMetrics());
37383753
}

‎sentry/src/test/java/io/sentry/ExternalOptionsTest.kt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,18 @@ class ExternalOptionsTest {
437437
withPropertiesFile("logs.enabled=true") { options -> assertTrue(options.isEnableLogs == true) }
438438
}
439439

440+
@Test
441+
fun `creates options with enableLogs set to false`() {
442+
withPropertiesFile("logs.enabled=false") { options ->
443+
assertTrue(options.isEnableLogs == false)
444+
}
445+
}
446+
447+
@Test
448+
fun `creates options with enableLogs set to null when not set`() {
449+
withPropertiesFile { assertNull(it.isEnableLogs) }
450+
}
451+
440452
@Test
441453
fun `creates options with enableMetrics set to true`() {
442454
withPropertiesFile("metrics.enabled=true") { options ->

‎sentry/src/test/java/io/sentry/SentryOptionsTest.kt‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package io.sentry
22

33
import io.sentry.SentryOptions.RequestSize
44
import io.sentry.logger.ILoggerBatchProcessorFactory
5+
import io.sentry.logger.LoggerApi
6+
import io.sentry.test.createSentryClientMock
7+
import io.sentry.test.createTestScopes
58
import io.sentry.util.StringUtils
69
import java.io.File
710
import java.net.Proxy
@@ -15,8 +18,11 @@ import kotlin.test.assertNotNull
1518
import kotlin.test.assertNull
1619
import kotlin.test.assertSame
1720
import kotlin.test.assertTrue
21+
import org.mockito.kotlin.any
22+
import org.mockito.kotlin.anyOrNull
1823
import org.mockito.kotlin.eq
1924
import org.mockito.kotlin.mock
25+
import org.mockito.kotlin.never
2026
import org.mockito.kotlin.verify
2127

2228
class SentryOptionsTest {
@@ -501,6 +507,72 @@ class SentryOptionsTest {
501507
assertTrue(options.metrics.isEnabled)
502508
}
503509

510+
@Test
511+
fun `merging options does not warn when legacy logs configuration is absent`() {
512+
val logger = mock<ILogger>()
513+
val options =
514+
SentryOptions().also {
515+
it.isDebug = true
516+
it.setLogger(logger)
517+
}
518+
519+
options.merge(ExternalOptions())
520+
521+
verify(logger, never()).log(eq(SentryLevel.WARNING), any<String>())
522+
}
523+
524+
@Test
525+
fun `merging options warns when legacy logs configuration is true`() {
526+
val logger = mock<ILogger>()
527+
val options =
528+
SentryOptions().also {
529+
it.isDebug = true
530+
it.setLogger(logger)
531+
}
532+
533+
options.merge(ExternalOptions().apply { isEnableLogs = true })
534+
535+
verify(logger)
536+
.log(
537+
SentryLevel.WARNING,
538+
"The 'logs.enabled' option is no longer supported. Manual Sentry.logger() calls no " +
539+
"longer require it, and automatic logging integrations now require their own opt-ins.",
540+
*emptyArray(),
541+
)
542+
assertLegacyLogsConfigurationDoesNotDisableCapture(options)
543+
}
544+
545+
@Test
546+
fun `merging options warns when legacy logs configuration is false`() {
547+
val logger = mock<ILogger>()
548+
val options =
549+
SentryOptions().also {
550+
it.isDebug = true
551+
it.setLogger(logger)
552+
}
553+
554+
options.merge(ExternalOptions().apply { isEnableLogs = false })
555+
556+
verify(logger)
557+
.log(
558+
SentryLevel.WARNING,
559+
"The 'logs.enabled' option no longer disables manual Sentry.logger() calls. Automatic " +
560+
"logging integrations remain disabled unless enabled through their own opt-ins.",
561+
*emptyArray(),
562+
)
563+
assertLegacyLogsConfigurationDoesNotDisableCapture(options)
564+
}
565+
566+
private fun assertLegacyLogsConfigurationDoesNotDisableCapture(options: SentryOptions) {
567+
options.dsn = "https://key@sentry.io/proj"
568+
val client = createSentryClientMock()
569+
val scopes = createTestScopes(options).apply { bindClient(client) }
570+
571+
LoggerApi(scopes).info("test log")
572+
573+
verify(client).captureLog(any(), anyOrNull())
574+
}
575+
504576
@Test
505577
fun `merging options merges and overwrites existing tag values`() {
506578
val externalOptions = ExternalOptions()

0 commit comments

Comments
 (0)