Skip to content

Commit 7074d0b

Browse files
authored
Add support for setting in-app-includes/in-app-excludes via AndroidManifest.xml (#4240)
* Add support for setting in-app-includes/in-app-excludes via AndroidManifest.xml * Update Changelog
1 parent ff09dc4 commit 7074d0b

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Add support for setting in-app-includes/in-app-excludes via AndroidManifest.xml ([#4240](https://github.com/getsentry/sentry-java/pull/4240))
8+
39
### Features
410

511
- 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))

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ final class ManifestMetadataReader {
107107

108108
static final String IGNORED_ERRORS = "io.sentry.ignored-errors";
109109

110+
static final String IN_APP_INCLUDES = "io.sentry.in-app-includes";
111+
112+
static final String IN_APP_EXCLUDES = "io.sentry.in-app-excludes";
113+
110114
static final String ENABLE_AUTO_TRACE_ID_GENERATION =
111115
"io.sentry.traces.enable-auto-id-generation";
112116

@@ -414,8 +418,21 @@ static void applyMetadata(
414418
.setMaskAllImages(readBool(metadata, logger, REPLAYS_MASK_ALL_IMAGES, true));
415419

416420
options.setIgnoredErrors(readList(metadata, logger, IGNORED_ERRORS));
417-
}
418421

422+
final @Nullable List<String> includes = readList(metadata, logger, IN_APP_INCLUDES);
423+
if (includes != null && !includes.isEmpty()) {
424+
for (final @NotNull String include : includes) {
425+
options.addInAppInclude(include);
426+
}
427+
}
428+
429+
final @Nullable List<String> excludes = readList(metadata, logger, IN_APP_EXCLUDES);
430+
if (excludes != null && !excludes.isEmpty()) {
431+
for (final @NotNull String exclude : excludes) {
432+
options.addInAppExclude(exclude);
433+
}
434+
}
435+
}
419436
options
420437
.getLogger()
421438
.log(SentryLevel.INFO, "Retrieving configuration from AndroidManifest.xml");

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,4 +1447,54 @@ class ManifestMetadataReaderTest {
14471447
// Assert
14481448
assertEquals(listOf(FilterString("Some error"), FilterString("Another .*")), fixture.options.ignoredErrors)
14491449
}
1450+
1451+
@Test
1452+
fun `applyMetadata reads inAppIncludes to options and sets the value if found`() {
1453+
// Arrange
1454+
val bundle = bundleOf(ManifestMetadataReader.IN_APP_INCLUDES to "com.example.package1,com.example.package2")
1455+
val context = fixture.getContext(metaData = bundle)
1456+
1457+
// Act
1458+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
1459+
1460+
// Assert
1461+
assertEquals(listOf("com.example.package1", "com.example.package2"), fixture.options.inAppIncludes)
1462+
}
1463+
1464+
@Test
1465+
fun `applyMetadata reads inAppIncludes to options and keeps empty if not found`() {
1466+
// Arrange
1467+
val context = fixture.getContext()
1468+
1469+
// Act
1470+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
1471+
1472+
// Assert
1473+
assertTrue(fixture.options.inAppIncludes.isEmpty())
1474+
}
1475+
1476+
@Test
1477+
fun `applyMetadata reads inAppExcludes to options and sets the value if found`() {
1478+
// Arrange
1479+
val bundle = bundleOf(ManifestMetadataReader.IN_APP_EXCLUDES to "com.example.excluded1,com.example.excluded2")
1480+
val context = fixture.getContext(metaData = bundle)
1481+
1482+
// Act
1483+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
1484+
1485+
// Assert
1486+
assertEquals(listOf("com.example.excluded1", "com.example.excluded2"), fixture.options.inAppExcludes)
1487+
}
1488+
1489+
@Test
1490+
fun `applyMetadata reads inAppExcludes to options and keeps empty if not found`() {
1491+
// Arrange
1492+
val context = fixture.getContext()
1493+
1494+
// Act
1495+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
1496+
1497+
// Assert
1498+
assertTrue(fixture.options.inAppExcludes.isEmpty())
1499+
}
14501500
}

0 commit comments

Comments
 (0)