diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java b/sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java index 0a4ed051bf..d94d2aa72a 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java @@ -709,32 +709,40 @@ static void applyMetadata( if (metadata.containsKey(ENABLE_LOGS)) { final boolean enableLogs = readBool(metadata, logger, ENABLE_LOGS, false); if (enableLogs) { - logger.log( - SentryLevel.WARNING, - "The Android manifest option 'io.sentry.logs.enabled' is no longer supported. " - + "Manual Sentry.logger() calls no longer require it, and automatic logging " - + "integrations now require their own opt-ins."); + options + .getFatalLogger() + .log( + SentryLevel.WARNING, + "The Android manifest option 'io.sentry.logs.enabled' is no longer supported. " + + "Manual Sentry.logger() calls no longer require it, and automatic logging " + + "integrations now require their own opt-ins."); } else { - logger.log( - SentryLevel.WARNING, - "The Android manifest option 'io.sentry.logs.enabled' no longer disables manual " - + "Sentry.logger() calls. Automatic logging integrations remain disabled " - + "unless enabled through their own opt-ins."); + options + .getFatalLogger() + .log( + SentryLevel.WARNING, + "The Android manifest option 'io.sentry.logs.enabled' no longer disables manual " + + "Sentry.logger() calls. Automatic logging integrations remain disabled " + + "unless enabled through their own opt-ins."); } } if (metadata.containsKey(ENABLE_METRICS)) { final boolean enableMetrics = readBool(metadata, logger, ENABLE_METRICS, false); if (enableMetrics) { - logger.log( - SentryLevel.WARNING, - "The Android manifest option 'io.sentry.metrics.enabled' is no longer supported. " - + "Manual Sentry.metrics() calls no longer require it."); + options + .getFatalLogger() + .log( + SentryLevel.WARNING, + "The Android manifest option 'io.sentry.metrics.enabled' is no longer supported. " + + "Manual Sentry.metrics() calls no longer require it."); } else { - logger.log( - SentryLevel.WARNING, - "The Android manifest option 'io.sentry.metrics.enabled' no longer disables " - + "manual Sentry.metrics() calls."); + options + .getFatalLogger() + .log( + SentryLevel.WARNING, + "The Android manifest option 'io.sentry.metrics.enabled' no longer disables " + + "manual Sentry.metrics() calls."); } } diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/AndroidOptionsInitializerTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/AndroidOptionsInitializerTest.kt index 224b66bbfb..894ea9dfa4 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/AndroidOptionsInitializerTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/AndroidOptionsInitializerTest.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.res.AssetManager import android.os.Build import android.os.Bundle +import android.util.Log import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import io.sentry.CompositePerformanceCollector @@ -58,6 +59,7 @@ import org.mockito.kotlin.spy import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import org.robolectric.annotation.Config +import org.robolectric.shadows.ShadowLog @RunWith(AndroidJUnit4::class) class AndroidOptionsInitializerTest { @@ -203,6 +205,26 @@ class AndroidOptionsInitializerTest { assertTrue(innerLogger.get(loggerField) is AndroidLogger) } + @Test + fun `legacy manifest warning is visible when debug is disabled`() { + ShadowLog.clear() + + fixture.initSut( + metadata = + Bundle().apply { + putString(ManifestMetadataReader.DSN, "https://key@sentry.io/123") + putBoolean(ManifestMetadataReader.ENABLE_LOGS, true) + }, + hasAppContext = false, + ) + + assertTrue( + ShadowLog.getLogsForTag("Sentry").any { + it.type == Log.ASSERT && it.msg.contains("'io.sentry.logs.enabled' is no longer supported") + } + ) + } + @Test fun `flush timeout is set to Android specific default value`() { fixture.initSut() diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt index e5b2f1fcd0..df361b0de1 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt @@ -32,7 +32,12 @@ import org.mockito.kotlin.verify class ManifestMetadataReaderTest { private class Fixture { val logger = mock() - val options = SentryAndroidOptions().apply { setLogger(this@Fixture.logger) } + val fatalLogger = mock() + val options = + SentryAndroidOptions().apply { + setLogger(this@Fixture.logger) + setFatalLogger(this@Fixture.fatalLogger) + } val buildInfoProvider = mock() fun getContext(metaData: Bundle = Bundle()): Context = @@ -1948,26 +1953,21 @@ class ManifestMetadataReaderTest { @Test fun `applyMetadata does not warn when legacy logs enabled metadata is absent`() { - fixture.options.isDebug = true val context = fixture.getContext() ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) - verify(fixture.logger, never()).log(eq(SentryLevel.WARNING), any()) + verify(fixture.fatalLogger, never()).log(eq(SentryLevel.WARNING), any()) } @Test fun `applyMetadata warns when legacy logs enabled metadata is true`() { - val bundle = - bundleOf( - ManifestMetadataReader.DEBUG to true, - ManifestMetadataReader.ENABLE_LOGS to true, - ) + val bundle = bundleOf(ManifestMetadataReader.ENABLE_LOGS to true) val context = fixture.getContext(metaData = bundle) ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) - verify(fixture.logger) + verify(fixture.fatalLogger) .log( SentryLevel.WARNING, "The Android manifest option 'io.sentry.logs.enabled' is no longer supported. " + @@ -1983,16 +1983,12 @@ class ManifestMetadataReaderTest { fun `applyMetadata warns when legacy logs enabled metadata is false`() { fixture.options.isEnableTimberLogs = true fixture.options.isEnableLogcatLogs = true - val bundle = - bundleOf( - ManifestMetadataReader.DEBUG to true, - ManifestMetadataReader.ENABLE_LOGS to false, - ) + val bundle = bundleOf(ManifestMetadataReader.ENABLE_LOGS to false) val context = fixture.getContext(metaData = bundle) ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) - verify(fixture.logger) + verify(fixture.fatalLogger) .log( SentryLevel.WARNING, "The Android manifest option 'io.sentry.logs.enabled' no longer disables manual " + @@ -2055,21 +2051,16 @@ class ManifestMetadataReaderTest { @Test fun `applyMetadata does not warn when legacy metrics enabled metadata is absent`() { - fixture.options.isDebug = true val context = fixture.getContext() ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) - verify(fixture.logger, never()).log(eq(SentryLevel.WARNING), any()) + verify(fixture.fatalLogger, never()).log(eq(SentryLevel.WARNING), any()) } @Test fun `applyMetadata warns when legacy metrics enabled metadata is true`() { - val bundle = - bundleOf( - ManifestMetadataReader.DEBUG to true, - ManifestMetadataReader.ENABLE_METRICS to true, - ) + val bundle = bundleOf(ManifestMetadataReader.ENABLE_METRICS to true) val context = fixture.getContext(metaData = bundle) val client = createSentryClientMock() @@ -2078,7 +2069,7 @@ class ManifestMetadataReaderTest { val scopes = createTestScopes(fixture.options).also { it.bindClient(client) } scopes.metrics().count("metric name") - verify(fixture.logger) + verify(fixture.fatalLogger) .log( SentryLevel.WARNING, "The Android manifest option 'io.sentry.metrics.enabled' is no longer supported. " + @@ -2090,11 +2081,7 @@ class ManifestMetadataReaderTest { @Test fun `applyMetadata warns when legacy metrics enabled metadata is false`() { - val bundle = - bundleOf( - ManifestMetadataReader.DEBUG to true, - ManifestMetadataReader.ENABLE_METRICS to false, - ) + val bundle = bundleOf(ManifestMetadataReader.ENABLE_METRICS to false) val context = fixture.getContext(metaData = bundle) val client = createSentryClientMock() @@ -2103,7 +2090,7 @@ class ManifestMetadataReaderTest { val scopes = createTestScopes(fixture.options).also { it.bindClient(client) } scopes.metrics().count("metric name") - verify(fixture.logger) + verify(fixture.fatalLogger) .log( SentryLevel.WARNING, "The Android manifest option 'io.sentry.metrics.enabled' no longer disables manual " + diff --git a/sentry-spring-boot-4/src/main/java/io/sentry/spring/boot4/SentryAutoConfiguration.java b/sentry-spring-boot-4/src/main/java/io/sentry/spring/boot4/SentryAutoConfiguration.java index 41726cf60c..fe22237d2a 100644 --- a/sentry-spring-boot-4/src/main/java/io/sentry/spring/boot4/SentryAutoConfiguration.java +++ b/sentry-spring-boot-4/src/main/java/io/sentry/spring/boot4/SentryAutoConfiguration.java @@ -199,7 +199,7 @@ private void warnForLegacyLogsConfiguration( Boolean.TRUE.equals(environment.getProperty("sentry.logs.enabled", Boolean.class)); if (enableLogs) { options - .getLogger() + .getFatalLogger() .log( SentryLevel.WARNING, "The 'sentry.logs.enabled' property is no longer supported. Manual " @@ -207,7 +207,7 @@ private void warnForLegacyLogsConfiguration( + "integrations now require their own opt-ins."); } else { options - .getLogger() + .getFatalLogger() .log( SentryLevel.WARNING, "The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() " @@ -224,14 +224,14 @@ private void warnForLegacyMetricsConfiguration( Boolean.TRUE.equals(environment.getProperty("sentry.metrics.enabled", Boolean.class)); if (enableMetrics) { options - .getLogger() + .getFatalLogger() .log( SentryLevel.WARNING, "The 'sentry.metrics.enabled' property is no longer supported. Manual " + "Sentry.metrics() calls no longer require it."); } else { options - .getLogger() + .getFatalLogger() .log( SentryLevel.WARNING, "The 'sentry.metrics.enabled' property no longer disables manual " diff --git a/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt b/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt index 5aabbdef92..00ee58a5c2 100644 --- a/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt @@ -201,9 +201,8 @@ class SentryAutoConfigurationTest { fun `legacy logs property emits no warning when absent`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger, never()).log(eq(SentryLevel.WARNING), any()) } } @@ -211,9 +210,9 @@ class SentryAutoConfigurationTest { fun `legacy logs property true emits migration warning`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true", "sentry.logs.enabled=true") + .withPropertyValues("sentry.logs.enabled=true") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger) .log( @@ -231,9 +230,9 @@ class SentryAutoConfigurationTest { fun `legacy logs property false emits migration warning`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true", "sentry.logs.enabled=false") + .withPropertyValues("sentry.logs.enabled=false") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger) .log( @@ -251,9 +250,8 @@ class SentryAutoConfigurationTest { fun `legacy metrics property emits no warning when absent`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger, never()).log(eq(SentryLevel.WARNING), any()) } } @@ -261,9 +259,9 @@ class SentryAutoConfigurationTest { fun `legacy metrics property true emits migration warning`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true", "sentry.metrics.enabled=true") + .withPropertyValues("sentry.metrics.enabled=true") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger) .log( @@ -279,9 +277,9 @@ class SentryAutoConfigurationTest { fun `legacy metrics property false emits migration warning`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true", "sentry.metrics.enabled=false") + .withPropertyValues("sentry.metrics.enabled=false") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger) .log( @@ -1384,10 +1382,10 @@ class SentryAutoConfigurationTest { } @Configuration(proxyBeanMethods = false) - open class LoggerConfiguration { + open class FatalLoggerConfiguration { @Bean - open fun loggerConfiguration(logger: ILogger) = - Sentry.OptionsConfiguration { it.setLogger(logger) } + open fun fatalLoggerConfiguration(logger: ILogger) = + Sentry.OptionsConfiguration { it.setFatalLogger(logger) } } @Configuration(proxyBeanMethods = false) diff --git a/sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryAutoConfiguration.java b/sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryAutoConfiguration.java index b215e05c7a..b355fcbdf1 100644 --- a/sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryAutoConfiguration.java +++ b/sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryAutoConfiguration.java @@ -201,7 +201,7 @@ private void warnForLegacyLogsConfiguration( Boolean.TRUE.equals(environment.getProperty("sentry.logs.enabled", Boolean.class)); if (enableLogs) { options - .getLogger() + .getFatalLogger() .log( SentryLevel.WARNING, "The 'sentry.logs.enabled' property is no longer supported. Manual " @@ -209,7 +209,7 @@ private void warnForLegacyLogsConfiguration( + "integrations now require their own opt-ins."); } else { options - .getLogger() + .getFatalLogger() .log( SentryLevel.WARNING, "The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() " @@ -226,14 +226,14 @@ private void warnForLegacyMetricsConfiguration( Boolean.TRUE.equals(environment.getProperty("sentry.metrics.enabled", Boolean.class)); if (enableMetrics) { options - .getLogger() + .getFatalLogger() .log( SentryLevel.WARNING, "The 'sentry.metrics.enabled' property is no longer supported. Manual " + "Sentry.metrics() calls no longer require it."); } else { options - .getLogger() + .getFatalLogger() .log( SentryLevel.WARNING, "The 'sentry.metrics.enabled' property no longer disables manual " diff --git a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt index df99445940..1d8b8817bd 100644 --- a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt @@ -204,9 +204,8 @@ class SentryAutoConfigurationTest { fun `legacy logs property emits no warning when absent`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger, never()).log(eq(SentryLevel.WARNING), any()) } } @@ -214,9 +213,9 @@ class SentryAutoConfigurationTest { fun `legacy logs property true emits migration warning`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true", "sentry.logs.enabled=true") + .withPropertyValues("sentry.logs.enabled=true") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger) .log( @@ -234,9 +233,9 @@ class SentryAutoConfigurationTest { fun `legacy logs property false emits migration warning`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true", "sentry.logs.enabled=false") + .withPropertyValues("sentry.logs.enabled=false") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger) .log( @@ -254,9 +253,8 @@ class SentryAutoConfigurationTest { fun `legacy metrics property emits no warning when absent`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger, never()).log(eq(SentryLevel.WARNING), any()) } } @@ -264,9 +262,9 @@ class SentryAutoConfigurationTest { fun `legacy metrics property true emits migration warning`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true", "sentry.metrics.enabled=true") + .withPropertyValues("sentry.metrics.enabled=true") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger) .log( @@ -282,9 +280,9 @@ class SentryAutoConfigurationTest { fun `legacy metrics property false emits migration warning`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true", "sentry.metrics.enabled=false") + .withPropertyValues("sentry.metrics.enabled=false") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger) .log( @@ -1376,10 +1374,10 @@ class SentryAutoConfigurationTest { } @Configuration(proxyBeanMethods = false) - open class LoggerConfiguration { + open class FatalLoggerConfiguration { @Bean - open fun loggerConfiguration(logger: ILogger) = - Sentry.OptionsConfiguration { it.setLogger(logger) } + open fun fatalLoggerConfiguration(logger: ILogger) = + Sentry.OptionsConfiguration { it.setFatalLogger(logger) } } @Configuration(proxyBeanMethods = false) diff --git a/sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java b/sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java index 37872b02fe..0954a498e3 100644 --- a/sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java +++ b/sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentryAutoConfiguration.java @@ -196,7 +196,7 @@ private void warnForLegacyLogsConfiguration( Boolean.TRUE.equals(environment.getProperty("sentry.logs.enabled", Boolean.class)); if (enableLogs) { options - .getLogger() + .getFatalLogger() .log( SentryLevel.WARNING, "The 'sentry.logs.enabled' property is no longer supported. Manual " @@ -204,7 +204,7 @@ private void warnForLegacyLogsConfiguration( + "integrations now require their own opt-ins."); } else { options - .getLogger() + .getFatalLogger() .log( SentryLevel.WARNING, "The 'sentry.logs.enabled' property no longer disables manual Sentry.logger() " @@ -221,14 +221,14 @@ private void warnForLegacyMetricsConfiguration( Boolean.TRUE.equals(environment.getProperty("sentry.metrics.enabled", Boolean.class)); if (enableMetrics) { options - .getLogger() + .getFatalLogger() .log( SentryLevel.WARNING, "The 'sentry.metrics.enabled' property is no longer supported. Manual " + "Sentry.metrics() calls no longer require it."); } else { options - .getLogger() + .getFatalLogger() .log( SentryLevel.WARNING, "The 'sentry.metrics.enabled' property no longer disables manual " diff --git a/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt b/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt index 2315a616d2..39185e581f 100644 --- a/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt @@ -202,9 +202,8 @@ class SentryAutoConfigurationTest { fun `legacy logs property emits no warning when absent`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger, never()).log(eq(SentryLevel.WARNING), any()) } } @@ -212,9 +211,9 @@ class SentryAutoConfigurationTest { fun `legacy logs property true emits migration warning`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true", "sentry.logs.enabled=true") + .withPropertyValues("sentry.logs.enabled=true") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger) .log( @@ -232,9 +231,9 @@ class SentryAutoConfigurationTest { fun `legacy logs property false emits migration warning`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true", "sentry.logs.enabled=false") + .withPropertyValues("sentry.logs.enabled=false") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger) .log( @@ -252,9 +251,8 @@ class SentryAutoConfigurationTest { fun `legacy metrics property emits no warning when absent`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger, never()).log(eq(SentryLevel.WARNING), any()) } } @@ -262,9 +260,9 @@ class SentryAutoConfigurationTest { fun `legacy metrics property true emits migration warning`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true", "sentry.metrics.enabled=true") + .withPropertyValues("sentry.metrics.enabled=true") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger) .log( @@ -280,9 +278,9 @@ class SentryAutoConfigurationTest { fun `legacy metrics property false emits migration warning`() { val logger = mock() dsnEnabledRunner - .withPropertyValues("sentry.debug=true", "sentry.metrics.enabled=false") + .withPropertyValues("sentry.metrics.enabled=false") .withBean(ILogger::class.java, { logger }) - .withUserConfiguration(LoggerConfiguration::class.java) + .withUserConfiguration(FatalLoggerConfiguration::class.java) .run { verify(logger) .log( @@ -1309,10 +1307,10 @@ class SentryAutoConfigurationTest { } @Configuration(proxyBeanMethods = false) - open class LoggerConfiguration { + open class FatalLoggerConfiguration { @Bean - open fun loggerConfiguration(logger: ILogger) = - Sentry.OptionsConfiguration { it.setLogger(logger) } + open fun fatalLoggerConfiguration(logger: ILogger) = + Sentry.OptionsConfiguration { it.setFatalLogger(logger) } } @Configuration(proxyBeanMethods = false) diff --git a/sentry/src/main/java/io/sentry/Sentry.java b/sentry/src/main/java/io/sentry/Sentry.java index 266aa39e79..b429465ea9 100644 --- a/sentry/src/main/java/io/sentry/Sentry.java +++ b/sentry/src/main/java/io/sentry/Sentry.java @@ -306,6 +306,7 @@ private static void init(final @NotNull SentryOptions options, final boolean glo + options.getClass().getName()); } + initFatalLogger(options); if (!preInitConfigurations(options)) { return; } @@ -317,7 +318,6 @@ private static void init(final @NotNull SentryOptions options, final boolean glo .getLogger() .log(SentryLevel.INFO, "GlobalHubMode: '%s'", String.valueOf(globalHubModeToUse)); Sentry.globalHubMode = globalHubModeToUse; - initFatalLogger(options); final boolean shouldInit = InitUtil.shouldInit(globalScope.getOptions(), options, isEnabled()); if (shouldInit) { diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index 33948ead53..f33fd78f98 100644 --- a/sentry/src/main/java/io/sentry/SentryOptions.java +++ b/sentry/src/main/java/io/sentry/SentryOptions.java @@ -3735,13 +3735,13 @@ public void merge(final @NotNull ExternalOptions options) { if (options.isEnableLogs() != null) { if (options.isEnableLogs()) { - logger.log( + fatalLogger.log( SentryLevel.WARNING, "The 'logs.enabled' option is no longer supported. Manual Sentry.logger() calls no " + "longer require it, and automatic logging integrations now require their own " + "opt-ins."); } else { - logger.log( + fatalLogger.log( SentryLevel.WARNING, "The 'logs.enabled' option no longer disables manual Sentry.logger() calls. Automatic " + "logging integrations remain disabled unless enabled through their own opt-ins."); @@ -3750,12 +3750,12 @@ public void merge(final @NotNull ExternalOptions options) { if (options.isEnableMetrics() != null) { if (options.isEnableMetrics()) { - logger.log( + fatalLogger.log( SentryLevel.WARNING, "The 'metrics.enabled' option is no longer supported. Manual Sentry.metrics() calls no " + "longer require it."); } else { - logger.log( + fatalLogger.log( SentryLevel.WARNING, "The 'metrics.enabled' option no longer disables manual Sentry.metrics() calls."); } diff --git a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt index 398a1de11b..2d94c4fad1 100644 --- a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt +++ b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt @@ -501,30 +501,22 @@ class SentryOptionsTest { @Test fun `merging options does not warn when legacy logs configuration is absent`() { - val logger = mock() - val options = - SentryOptions().also { - it.isDebug = true - it.setLogger(logger) - } + val fatalLogger = mock() + val options = SentryOptions().also { it.setFatalLogger(fatalLogger) } options.merge(ExternalOptions()) - verify(logger, never()).log(eq(SentryLevel.WARNING), any()) + verify(fatalLogger, never()).log(eq(SentryLevel.WARNING), any()) } @Test - fun `merging options warns when legacy logs configuration is true`() { - val logger = mock() - val options = - SentryOptions().also { - it.isDebug = true - it.setLogger(logger) - } + fun `merging options warns through fatal logger when legacy logs configuration is true`() { + val fatalLogger = mock() + val options = SentryOptions().also { it.setFatalLogger(fatalLogger) } options.merge(ExternalOptions().apply { isEnableLogs = true }) - verify(logger) + verify(fatalLogger) .log( SentryLevel.WARNING, "The 'logs.enabled' option is no longer supported. Manual Sentry.logger() calls no " + @@ -535,17 +527,13 @@ class SentryOptionsTest { } @Test - fun `merging options warns when legacy logs configuration is false`() { - val logger = mock() - val options = - SentryOptions().also { - it.isDebug = true - it.setLogger(logger) - } + fun `merging options warns through fatal logger when legacy logs configuration is false`() { + val fatalLogger = mock() + val options = SentryOptions().also { it.setFatalLogger(fatalLogger) } options.merge(ExternalOptions().apply { isEnableLogs = false }) - verify(logger) + verify(fatalLogger) .log( SentryLevel.WARNING, "The 'logs.enabled' option no longer disables manual Sentry.logger() calls. Automatic " + @@ -567,30 +555,22 @@ class SentryOptionsTest { @Test fun `merging options does not warn when legacy metrics configuration is absent`() { - val logger = mock() - val options = - SentryOptions().also { - it.isDebug = true - it.setLogger(logger) - } + val fatalLogger = mock() + val options = SentryOptions().also { it.setFatalLogger(fatalLogger) } options.merge(ExternalOptions()) - verify(logger, never()).log(eq(SentryLevel.WARNING), any()) + verify(fatalLogger, never()).log(eq(SentryLevel.WARNING), any()) } @Test - fun `merging options warns when legacy metrics configuration is true`() { - val logger = mock() - val options = - SentryOptions().also { - it.isDebug = true - it.setLogger(logger) - } + fun `merging options warns through fatal logger when legacy metrics configuration is true`() { + val fatalLogger = mock() + val options = SentryOptions().also { it.setFatalLogger(fatalLogger) } options.merge(ExternalOptions().apply { isEnableMetrics = true }) - verify(logger) + verify(fatalLogger) .log( SentryLevel.WARNING, "The 'metrics.enabled' option is no longer supported. Manual Sentry.metrics() calls no " + @@ -601,17 +581,13 @@ class SentryOptionsTest { } @Test - fun `merging options warns when legacy metrics configuration is false`() { - val logger = mock() - val options = - SentryOptions().also { - it.isDebug = true - it.setLogger(logger) - } + fun `merging options warns through fatal logger when legacy metrics configuration is false`() { + val fatalLogger = mock() + val options = SentryOptions().also { it.setFatalLogger(fatalLogger) } options.merge(ExternalOptions().apply { isEnableMetrics = false }) - verify(logger) + verify(fatalLogger) .log( SentryLevel.WARNING, "The 'metrics.enabled' option no longer disables manual Sentry.metrics() calls.", diff --git a/sentry/src/test/java/io/sentry/SentryTest.kt b/sentry/src/test/java/io/sentry/SentryTest.kt index 98cda8e9d8..680d846ecc 100644 --- a/sentry/src/test/java/io/sentry/SentryTest.kt +++ b/sentry/src/test/java/io/sentry/SentryTest.kt @@ -24,9 +24,11 @@ import io.sentry.test.injectForField import io.sentry.util.PlatformTestManipulator import io.sentry.util.thread.IThreadChecker import io.sentry.util.thread.ThreadChecker +import java.io.ByteArrayOutputStream import java.io.Closeable import java.io.File import java.io.FileReader +import java.io.PrintStream import java.nio.file.Files import java.util.Properties import java.util.concurrent.CompletableFuture @@ -299,10 +301,38 @@ class SentryTest { initForTest { it.isEnableExternalConfiguration = true } assertTrue(ScopesAdapter.getInstance().isEnabled) } finally { + System.clearProperty("sentry.properties.file") temporaryFolder.delete() } } + @Test + fun `external legacy configuration warning is visible when debug is disabled`() { + val file = tmpDir.newFile("sentry.properties") + file.writeText("dsn=$dsn\nlogs.enabled=true") + System.setProperty("sentry.properties.file", file.absolutePath) + val originalOut = System.out + val output = ByteArrayOutputStream() + System.setOut(PrintStream(output)) + + try { + initForTest { it.isEnableExternalConfiguration = true } + } finally { + System.setOut(originalOut) + System.clearProperty("sentry.properties.file") + } + + assertTrue( + output + .toString() + .contains( + "WARNING: The 'logs.enabled' option is no longer supported. Manual Sentry.logger() " + + "calls no longer require it, and automatic logging integrations now require their " + + "own opt-ins." + ) + ) + } + @Test fun `initializes Sentry with enabled=false, thus disabling Sentry even if dsn is set`() { initForTest {