Skip to content

Commit a337d9e

Browse files
adinauerclaude
andcommitted
feat(core): Expose Data Collection options
Add an always-present DataCollection object to SentryOptions while preserving an unconfigured state for the legacy bridge. Expose public getter and setter APIs and cover explicit-empty and nested override behavior. Refs #5666 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c4ea3db commit a337d9e

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

‎sentry/api/sentry.api‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,6 +3697,7 @@ public class io/sentry/SentryOptions {
36973697
public fun getContextTags ()Ljava/util/List;
36983698
public fun getContinuousProfiler ()Lio/sentry/IContinuousProfiler;
36993699
public fun getCron ()Lio/sentry/SentryOptions$Cron;
3700+
public fun getDataCollection ()Lio/sentry/DataCollection;
37003701
public fun getDateProvider ()Lio/sentry/SentryDateProvider;
37013702
public fun getDeadlineTimeout ()J
37023703
public fun getDebugMetaLoader ()Lio/sentry/internal/debugmeta/IDebugMetaLoader;
@@ -3845,6 +3846,7 @@ public class io/sentry/SentryOptions {
38453846
public fun setConnectionTimeoutMillis (I)V
38463847
public fun setContinuousProfiler (Lio/sentry/IContinuousProfiler;)V
38473848
public fun setCron (Lio/sentry/SentryOptions$Cron;)V
3849+
public fun setDataCollection (Lio/sentry/DataCollection;)V
38483850
public fun setDateProvider (Lio/sentry/SentryDateProvider;)V
38493851
public fun setDeadlineTimeout (J)V
38503852
public fun setDebug (Z)V

‎sentry/src/main/java/io/sentry/SentryOptions.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ public class SentryOptions {
338338
/** whether to send personal identifiable information along with events */
339339
private boolean sendDefaultPii = false;
340340

341+
private @NotNull DataCollection dataCollection = new DataCollection(false);
342+
341343
/** SSLSocketFactory for self-signed certificate trust * */
342344
private @Nullable SSLSocketFactory sslSocketFactory;
343345

@@ -1697,6 +1699,25 @@ public void setSendDefaultPii(boolean sendDefaultPii) {
16971699
this.sendDefaultPii = sendDefaultPii;
16981700
}
16991701

1702+
/**
1703+
* Returns the configuration for data that the SDK collects automatically.
1704+
*
1705+
* <p>The returned object is always present. Accessing it does not configure data collection, but
1706+
* setting one of its options does.
1707+
*/
1708+
public @NotNull DataCollection getDataCollection() {
1709+
return dataCollection;
1710+
}
1711+
1712+
/**
1713+
* Replaces the configuration for data that the SDK collects automatically.
1714+
*
1715+
* <p>Passing an empty {@link DataCollection} opts into the documented data-collection defaults.
1716+
*/
1717+
public void setDataCollection(final @NotNull DataCollection dataCollection) {
1718+
this.dataCollection = dataCollection;
1719+
}
1720+
17001721
/**
17011722
* Adds a Scope observer
17021723
*

‎sentry/src/test/java/io/sentry/SentryOptionsTest.kt‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry
22

3+
import com.google.common.truth.Truth.assertThat
34
import io.sentry.SentryOptions.RequestSize
45
import io.sentry.logger.ILoggerBatchProcessorFactory
56
import io.sentry.util.StringUtils
@@ -20,6 +21,52 @@ import org.mockito.kotlin.mock
2021
import org.mockito.kotlin.verify
2122

2223
class SentryOptionsTest {
24+
@Test
25+
fun `data collection is always present without being explicitly configured`() {
26+
val options = SentryOptions()
27+
28+
assertThat(options.dataCollection).isNotNull()
29+
assertThat(options.dataCollection.isExplicitlyConfigured()).isFalse()
30+
}
31+
32+
@Test
33+
fun `data collection getter returns the same instance`() {
34+
val options = SentryOptions()
35+
36+
assertThat(options.dataCollection).isSameInstanceAs(options.dataCollection)
37+
assertThat(options.dataCollection.isExplicitlyConfigured()).isFalse()
38+
}
39+
40+
@Test
41+
fun `setting a data collection override marks it explicitly configured`() {
42+
val options = SentryOptions()
43+
44+
options.dataCollection.setUserInfo(false)
45+
46+
assertThat(options.dataCollection.userInfo).isFalse()
47+
assertThat(options.dataCollection.isExplicitlyConfigured()).isTrue()
48+
}
49+
50+
@Test
51+
fun `setting an empty data collection marks it explicitly configured`() {
52+
val options = SentryOptions()
53+
54+
options.dataCollection = DataCollection()
55+
56+
assertThat(options.dataCollection.isExplicitlyConfigured()).isTrue()
57+
}
58+
59+
@Test
60+
fun `setting data collection replaces the default instance`() {
61+
val options = SentryOptions()
62+
val dataCollection = DataCollection().apply { setQueues(false) }
63+
64+
options.dataCollection = dataCollection
65+
66+
assertThat(options.dataCollection).isSameInstanceAs(dataCollection)
67+
assertThat(options.dataCollection.queues).isFalse()
68+
}
69+
2370
@Test
2471
fun `when options is initialized, logger is not null`() {
2572
assertNotNull(SentryOptions().logger)

0 commit comments

Comments
 (0)