Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Allow disabling sending of client reports via Android Manifest and external options #2007

Merged
merged 2 commits into from
Apr 26, 2022
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

* Fix: Allow disabling sending of client reports via Android Manifest and external options (#2007)

## 6.0.0-alpha.6

* Feat: Add sentry-servlet-jakarta module (#1987)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ final class ManifestMetadataReader {
static final String PROGUARD_UUID = "io.sentry.proguard-uuid";

static final String ATTACH_SCREENSHOT = "io.sentry.attach-screenshot";
static final String CLIENT_REPORTS_ENABLE = "io.sentry.send-client-reports";

/** ManifestMetadataReader ctor */
private ManifestMetadataReader() {}
Expand Down Expand Up @@ -201,6 +202,9 @@ static void applyMetadata(
options.setAttachScreenshot(
readBool(metadata, logger, ATTACH_SCREENSHOT, options.isAttachScreenshot()));

options.setSendClientReports(
readBool(metadata, logger, CLIENT_REPORTS_ENABLE, options.isSendClientReports()));

if (options.getTracesSampleRate() == null) {
final Double tracesSampleRate = readDouble(metadata, logger, TRACES_SAMPLE_RATE);
if (tracesSampleRate != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,29 @@ class ManifestMetadataReaderTest {
// Assert
assertFalse(fixture.options.isAttachScreenshot)
}

@Test
fun `applyMetadata reads send client reports to options`() {
// Arrange
val bundle = bundleOf(ManifestMetadataReader.CLIENT_REPORTS_ENABLE to false)
val context = fixture.getContext(metaData = bundle)

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options)

// Assert
assertFalse(fixture.options.isSendClientReports)
}

@Test
fun `applyMetadata reads send client reports and keep default value if not found`() {
// Arrange
val context = fixture.getContext()

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options)

// Assert
assertTrue(fixture.options.isSendClientReports)
}
}
2 changes: 2 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public final class io/sentry/ExternalOptions {
public fun getProguardUuid ()Ljava/lang/String;
public fun getProxy ()Lio/sentry/SentryOptions$Proxy;
public fun getRelease ()Ljava/lang/String;
public fun getSendClientReports ()Ljava/lang/Boolean;
public fun getServerName ()Ljava/lang/String;
public fun getTags ()Ljava/util/Map;
public fun getTracesSampleRate ()Ljava/lang/Double;
Expand All @@ -176,6 +177,7 @@ public final class io/sentry/ExternalOptions {
public fun setProguardUuid (Ljava/lang/String;)V
public fun setProxy (Lio/sentry/SentryOptions$Proxy;)V
public fun setRelease (Ljava/lang/String;)V
public fun setSendClientReports (Ljava/lang/Boolean;)V
public fun setServerName (Ljava/lang/String;)V
public fun setTag (Ljava/lang/String;Ljava/lang/String;)V
public fun setTracesSampleRate (Ljava/lang/Double;)V
Expand Down
10 changes: 10 additions & 0 deletions sentry/src/main/java/io/sentry/ExternalOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public final class ExternalOptions {
private final @NotNull Set<Class<? extends Throwable>> ignoredExceptionsForType =
new CopyOnWriteArraySet<>();
private @Nullable Boolean printUncaughtStackTrace;
private @Nullable Boolean sendClientReports;

@SuppressWarnings("unchecked")
public static @NotNull ExternalOptions from(
Expand All @@ -54,6 +55,7 @@ public final class ExternalOptions {
options.setTracesSampleRate(propertiesProvider.getDoubleProperty("traces-sample-rate"));
options.setDebug(propertiesProvider.getBooleanProperty("debug"));
options.setEnableDeduplication(propertiesProvider.getBooleanProperty("enable-deduplication"));
options.setSendClientReports(propertiesProvider.getBooleanProperty("send-client-reports"));
final String maxRequestBodySize = propertiesProvider.getProperty("max-request-body-size");
if (maxRequestBodySize != null) {
options.setMaxRequestBodySize(
Expand Down Expand Up @@ -263,4 +265,12 @@ public void setTag(final @NotNull String key, final @NotNull String value) {
public void setPrintUncaughtStackTrace(final @Nullable Boolean printUncaughtStackTrace) {
this.printUncaughtStackTrace = printUncaughtStackTrace;
}

public @Nullable Boolean getSendClientReports() {
return sendClientReports;
}

public void setSendClientReports(final @Nullable Boolean sendClientReports) {
this.sendClientReports = sendClientReports;
}
}
3 changes: 3 additions & 0 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,9 @@ void merge(final @NotNull ExternalOptions options) {
if (options.getEnableDeduplication() != null) {
setEnableDeduplication(options.getEnableDeduplication());
}
if (options.getSendClientReports() != null) {
setSendClientReports(options.getSendClientReports());
}
final Map<String, String> tags = new HashMap<>(options.getTags());
for (final Map.Entry<String, String> tag : tags.entrySet()) {
this.tags.put(tag.getKey(), tag.getValue());
Expand Down
9 changes: 9 additions & 0 deletions sentry/src/test/java/io/sentry/ExternalOptionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ class ExternalOptionsTest {
}
}

@Test
fun `creates options with sendClientReports using external properties`() {
withPropertiesFile("send-client-reports=false") {
assertNotNull(it.sendClientReports) {
assertFalse(it)
}
}
}

@Test
fun `creates options with maxRequestBodySize using external properties`() {
withPropertiesFile("max-request-body-size=small") {
Expand Down