From 64ed366d427059e37eb9308641b7d9807a4530db Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Fri, 7 Mar 2025 10:12:07 +0100 Subject: [PATCH 1/2] Add support for setting in-app-includes/in-app-excludes via AndroidManifest.xml --- .../android/core/ManifestMetadataReader.java | 19 ++++++- .../core/ManifestMetadataReaderTest.kt | 50 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) 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 86d9d6aa292..71c6894045e 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 @@ -107,6 +107,10 @@ final class ManifestMetadataReader { static final String IGNORED_ERRORS = "io.sentry.ignored-errors"; + static final String IN_APP_INCLUDES = "io.sentry.in-app-includes"; + + static final String IN_APP_EXCLUDES = "io.sentry.in-app-excludes"; + static final String ENABLE_AUTO_TRACE_ID_GENERATION = "io.sentry.traces.enable-auto-id-generation"; @@ -414,8 +418,21 @@ static void applyMetadata( .setMaskAllImages(readBool(metadata, logger, REPLAYS_MASK_ALL_IMAGES, true)); options.setIgnoredErrors(readList(metadata, logger, IGNORED_ERRORS)); - } + final @Nullable List includes = readList(metadata, logger, IN_APP_INCLUDES); + if (includes != null && !includes.isEmpty()) { + for (final @NotNull String include : includes) { + options.addInAppInclude(include); + } + } + + final @Nullable List excludes = readList(metadata, logger, IN_APP_EXCLUDES); + if (excludes != null && !excludes.isEmpty()) { + for (final @NotNull String exclude : excludes) { + options.addInAppExclude(exclude); + } + } + } options .getLogger() .log(SentryLevel.INFO, "Retrieving configuration from AndroidManifest.xml"); 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 16f51948d40..263c9c5950c 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 @@ -1447,4 +1447,54 @@ class ManifestMetadataReaderTest { // Assert assertEquals(listOf(FilterString("Some error"), FilterString("Another .*")), fixture.options.ignoredErrors) } + + @Test + fun `applyMetadata reads inAppIncludes to options and sets the value if found`() { + // Arrange + val bundle = bundleOf(ManifestMetadataReader.IN_APP_INCLUDES to "com.example.package1,com.example.package2") + val context = fixture.getContext(metaData = bundle) + + // Act + ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) + + // Assert + assertEquals(listOf("com.example.package1", "com.example.package2"), fixture.options.inAppIncludes) + } + + @Test + fun `applyMetadata reads inAppIncludes to options and keeps empty if not found`() { + // Arrange + val context = fixture.getContext() + + // Act + ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) + + // Assert + assertTrue(fixture.options.inAppIncludes.isEmpty()) + } + + @Test + fun `applyMetadata reads inAppExcludes to options and sets the value if found`() { + // Arrange + val bundle = bundleOf(ManifestMetadataReader.IN_APP_EXCLUDES to "com.example.excluded1,com.example.excluded2") + val context = fixture.getContext(metaData = bundle) + + // Act + ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) + + // Assert + assertEquals(listOf("com.example.excluded1", "com.example.excluded2"), fixture.options.inAppExcludes) + } + + @Test + fun `applyMetadata reads inAppExcludes to options and keeps empty if not found`() { + // Arrange + val context = fixture.getContext() + + // Act + ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) + + // Assert + assertTrue(fixture.options.inAppExcludes.isEmpty()) + } } From 52b86da3be18d8dd1ff99d3f3c2735681795542e Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Fri, 7 Mar 2025 10:15:45 +0100 Subject: [PATCH 2/2] Update Changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b1508b4b7d..440881b5940 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Add support for setting in-app-includes/in-app-excludes via AndroidManifest.xml ([#4240](https://github.com/getsentry/sentry-java/pull/4240)) + ### Features - The SDK now automatically propagates the trace-context to the native layer. This allows to connect errors on different layers of the application. ([#4137](https://github.com/getsentry/sentry-java/pull/4137))