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 @@ -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.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ import org.mockito.kotlin.verify
class ManifestMetadataReaderTest {
private class Fixture {
val logger = mock<ILogger>()
val options = SentryAndroidOptions().apply { setLogger(this@Fixture.logger) }
val fatalLogger = mock<ILogger>()
val options =
SentryAndroidOptions().apply {
setLogger(this@Fixture.logger)
setFatalLogger(this@Fixture.fatalLogger)
}
val buildInfoProvider = mock<BuildInfoProvider>()

fun getContext(metaData: Bundle = Bundle()): Context =
Expand Down Expand Up @@ -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<String>())
verify(fixture.fatalLogger, never()).log(eq(SentryLevel.WARNING), any<String>())
}

@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. " +
Expand All @@ -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 " +
Expand Down Expand Up @@ -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<String>())
verify(fixture.fatalLogger, never()).log(eq(SentryLevel.WARNING), any<String>())
}

@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()

Expand All @@ -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. " +
Expand All @@ -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()

Expand All @@ -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 " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ 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 "
+ "Sentry.logger() calls no longer require it, and automatic logging "
+ "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() "
Expand All @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,18 @@ class SentryAutoConfigurationTest {
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)
.withUserConfiguration(FatalLoggerConfiguration::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")
.withPropertyValues("sentry.logs.enabled=true")
.withBean(ILogger::class.java, { logger })
.withUserConfiguration(LoggerConfiguration::class.java)
.withUserConfiguration(FatalLoggerConfiguration::class.java)
.run {
verify(logger)
.log(
Expand All @@ -231,9 +230,9 @@ class SentryAutoConfigurationTest {
fun `legacy logs property false emits migration warning`() {
val logger = mock<ILogger>()
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(
Expand All @@ -251,19 +250,18 @@ class SentryAutoConfigurationTest {
fun `legacy metrics property emits no warning when absent`() {
val logger = mock<ILogger>()
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<String>()) }
}

@Test
fun `legacy metrics property true emits migration warning`() {
val logger = mock<ILogger>()
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(
Expand All @@ -279,9 +277,9 @@ class SentryAutoConfigurationTest {
fun `legacy metrics property false emits migration warning`() {
val logger = mock<ILogger>()
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(
Expand Down Expand Up @@ -1384,10 +1382,10 @@ class SentryAutoConfigurationTest {
}

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

@Configuration(proxyBeanMethods = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ 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 "
+ "Sentry.logger() calls no longer require it, and automatic logging "
+ "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() "
Expand All @@ -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 "
Expand Down
Loading
Loading