Skip to content

Commit fcb8040

Browse files
adinauerclaude
andcommitted
feat(android): Warn for legacy Logs metadata
Detect explicit io.sentry.logs.enabled Android manifest metadata and emit tailored migration warnings without changing the integration-local Logs options. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2121c08 commit fcb8040

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,23 @@ static void applyMetadata(
706706
}
707707
}
708708

709+
if (metadata.containsKey(ENABLE_LOGS)) {
710+
final boolean enableLogs = readBool(metadata, logger, ENABLE_LOGS, false);
711+
if (enableLogs) {
712+
logger.log(
713+
SentryLevel.WARNING,
714+
"The Android manifest option 'io.sentry.logs.enabled' is no longer supported. "
715+
+ "Manual Sentry.logger() calls no longer require it, and automatic logging "
716+
+ "integrations now require their own opt-ins.");
717+
} else {
718+
logger.log(
719+
SentryLevel.WARNING,
720+
"The Android manifest option 'io.sentry.logs.enabled' no longer disables manual "
721+
+ "Sentry.logger() calls. Automatic logging integrations remain disabled "
722+
+ "unless enabled through their own opt-ins.");
723+
}
724+
}
725+
709726
options.setEnableTimberLogs(
710727
readBool(metadata, logger, ENABLE_TIMBER_LOGS, options.isEnableTimberLogs()));
711728

sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import org.mockito.kotlin.verify
2929
class ManifestMetadataReaderTest {
3030
private class Fixture {
3131
val logger = mock<ILogger>()
32-
val options = SentryAndroidOptions().apply { setLogger(logger) }
32+
val options = SentryAndroidOptions().apply { setLogger(this@Fixture.logger) }
3333
val buildInfoProvider = mock<BuildInfoProvider>()
3434

3535
fun getContext(metaData: Bundle = Bundle()): Context =
@@ -1943,6 +1943,64 @@ class ManifestMetadataReaderTest {
19431943
assertTrue(fixture.options.inAppExcludes.isEmpty())
19441944
}
19451945

1946+
@Test
1947+
fun `applyMetadata does not warn when legacy logs enabled metadata is absent`() {
1948+
fixture.options.isDebug = true
1949+
val context = fixture.getContext()
1950+
1951+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
1952+
1953+
verify(fixture.logger, never()).log(eq(SentryLevel.WARNING), any<String>())
1954+
}
1955+
1956+
@Test
1957+
fun `applyMetadata warns when legacy logs enabled metadata is true`() {
1958+
val bundle =
1959+
bundleOf(
1960+
ManifestMetadataReader.DEBUG to true,
1961+
ManifestMetadataReader.ENABLE_LOGS to true,
1962+
)
1963+
val context = fixture.getContext(metaData = bundle)
1964+
1965+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
1966+
1967+
verify(fixture.logger)
1968+
.log(
1969+
SentryLevel.WARNING,
1970+
"The Android manifest option 'io.sentry.logs.enabled' is no longer supported. " +
1971+
"Manual Sentry.logger() calls no longer require it, and automatic logging " +
1972+
"integrations now require their own opt-ins.",
1973+
*emptyArray(),
1974+
)
1975+
assertThat(fixture.options.isEnableTimberLogs).isFalse()
1976+
assertThat(fixture.options.isEnableLogcatLogs).isFalse()
1977+
}
1978+
1979+
@Test
1980+
fun `applyMetadata warns when legacy logs enabled metadata is false`() {
1981+
fixture.options.isEnableTimberLogs = true
1982+
fixture.options.isEnableLogcatLogs = true
1983+
val bundle =
1984+
bundleOf(
1985+
ManifestMetadataReader.DEBUG to true,
1986+
ManifestMetadataReader.ENABLE_LOGS to false,
1987+
)
1988+
val context = fixture.getContext(metaData = bundle)
1989+
1990+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
1991+
1992+
verify(fixture.logger)
1993+
.log(
1994+
SentryLevel.WARNING,
1995+
"The Android manifest option 'io.sentry.logs.enabled' no longer disables manual " +
1996+
"Sentry.logger() calls. Automatic logging integrations remain disabled unless " +
1997+
"enabled through their own opt-ins.",
1998+
*emptyArray(),
1999+
)
2000+
assertThat(fixture.options.isEnableTimberLogs).isTrue()
2001+
assertThat(fixture.options.isEnableLogcatLogs).isTrue()
2002+
}
2003+
19462004
@Test
19472005
fun `applyMetadata keeps Timber logs disabled if not found`() {
19482006
val context = fixture.getContext()

0 commit comments

Comments
 (0)