Skip to content

Commit

Permalink
Add support for setting in-app-includes/in-app-excludes via AndroidMa…
Browse files Browse the repository at this point in the history
…nifest.xml
  • Loading branch information
markushi committed Mar 7, 2025
1 parent ff09dc4 commit 64ed366
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<String> includes = readList(metadata, logger, IN_APP_INCLUDES);
if (includes != null && !includes.isEmpty()) {
for (final @NotNull String include : includes) {
options.addInAppInclude(include);
}
}

final @Nullable List<String> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

0 comments on commit 64ed366

Please sign in to comment.