Skip to content
Draft
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
2 changes: 2 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -3697,6 +3697,7 @@ public class io/sentry/SentryOptions {
public fun getContextTags ()Ljava/util/List;
public fun getContinuousProfiler ()Lio/sentry/IContinuousProfiler;
public fun getCron ()Lio/sentry/SentryOptions$Cron;
public fun getDataCollection ()Lio/sentry/DataCollection;
public fun getDateProvider ()Lio/sentry/SentryDateProvider;
public fun getDeadlineTimeout ()J
public fun getDebugMetaLoader ()Lio/sentry/internal/debugmeta/IDebugMetaLoader;
Expand Down Expand Up @@ -3845,6 +3846,7 @@ public class io/sentry/SentryOptions {
public fun setConnectionTimeoutMillis (I)V
public fun setContinuousProfiler (Lio/sentry/IContinuousProfiler;)V
public fun setCron (Lio/sentry/SentryOptions$Cron;)V
public fun setDataCollection (Lio/sentry/DataCollection;)V
public fun setDateProvider (Lio/sentry/SentryDateProvider;)V
public fun setDeadlineTimeout (J)V
public fun setDebug (Z)V
Expand Down
21 changes: 21 additions & 0 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ public class SentryOptions {
/** whether to send personal identifiable information along with events */
private boolean sendDefaultPii = false;

private @NotNull DataCollection dataCollection = new DataCollection(false);

/** SSLSocketFactory for self-signed certificate trust * */
private @Nullable SSLSocketFactory sslSocketFactory;

Expand Down Expand Up @@ -1697,6 +1699,25 @@ public void setSendDefaultPii(boolean sendDefaultPii) {
this.sendDefaultPii = sendDefaultPii;
}

/**
* Returns the configuration for data that the SDK collects automatically.
*
* <p>The returned object is always present. Accessing it does not configure data collection, but
* setting one of its options does.
*/
public @NotNull DataCollection getDataCollection() {
return dataCollection;
}

/**
* Replaces the configuration for data that the SDK collects automatically.
*
* <p>Passing an empty {@link DataCollection} opts into the documented data-collection defaults.
*/
public void setDataCollection(final @NotNull DataCollection dataCollection) {
this.dataCollection = dataCollection;
}

/**
* Adds a Scope observer
*
Expand Down
47 changes: 47 additions & 0 deletions sentry/src/test/java/io/sentry/SentryOptionsTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry

import com.google.common.truth.Truth.assertThat
import io.sentry.SentryOptions.RequestSize
import io.sentry.logger.ILoggerBatchProcessorFactory
import io.sentry.util.StringUtils
Expand All @@ -20,6 +21,52 @@ import org.mockito.kotlin.mock
import org.mockito.kotlin.verify

class SentryOptionsTest {
@Test
fun `data collection is always present without being explicitly configured`() {
val options = SentryOptions()

assertThat(options.dataCollection).isNotNull()
assertThat(options.dataCollection.isExplicitlyConfigured()).isFalse()
}

@Test
fun `data collection getter returns the same instance`() {
val options = SentryOptions()

assertThat(options.dataCollection).isSameInstanceAs(options.dataCollection)
assertThat(options.dataCollection.isExplicitlyConfigured()).isFalse()
}

@Test
fun `setting a data collection override marks it explicitly configured`() {
val options = SentryOptions()

options.dataCollection.setUserInfo(false)

assertThat(options.dataCollection.userInfo).isFalse()
assertThat(options.dataCollection.isExplicitlyConfigured()).isTrue()
}

@Test
fun `setting an empty data collection marks it explicitly configured`() {
val options = SentryOptions()

options.dataCollection = DataCollection()

assertThat(options.dataCollection.isExplicitlyConfigured()).isTrue()
}

@Test
fun `setting data collection replaces the default instance`() {
val options = SentryOptions()
val dataCollection = DataCollection().apply { setQueues(false) }

options.dataCollection = dataCollection

assertThat(options.dataCollection).isSameInstanceAs(dataCollection)
assertThat(options.dataCollection.queues).isFalse()
}

@Test
fun `when options is initialized, logger is not null`() {
assertNotNull(SentryOptions().logger)
Expand Down
Loading