Skip to content

Commit 6cdd40e

Browse files
adinauerclaude
andcommitted
chore: Merge data collection base into cookie filtering
Bring the latest data collection behavior into the cookie filtering branch and retain coverage for both cookie and request header filtering. Co-Authored-By: Claude <noreply@anthropic.com>
2 parents a81ffe7 + 86e38ab commit 6cdd40e

4 files changed

Lines changed: 77 additions & 17 deletions

File tree

sentry-apollo-4/src/test/java/io/sentry/apollo4/SentryApollo4BuilderExtensionsClientErrorsTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,23 @@ abstract class SentryApollo4BuilderExtensionsClientErrorsTest(
397397
)
398398
}
399399

400+
@Test
401+
fun `data collection filters request headers`() {
402+
val sut =
403+
fixture.getSut(responseBody = fixture.responseBodyNotOk) {
404+
dataCollection.httpHeaders.request = KeyValueCollectionBehavior.denyList("accept")
405+
}
406+
executeQuery(sut)
407+
408+
verify(fixture.scopes)
409+
.captureEvent(
410+
check {
411+
assertEquals("[Filtered]", it.request!!.headers?.get("Accept"))
412+
},
413+
any<Hint>(),
414+
)
415+
}
416+
400417
@Test
401418
fun `data collection can disable request headers`() {
402419
val sut =

sentry/src/main/java/io/sentry/DataCollection.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
/** Configures data that the SDK collects automatically. */
1111
public final class DataCollection {
1212

13-
private boolean overridden;
13+
// Forces Data Collection to be used even when no individual option has been configured.
14+
private boolean forceDataCollection;
1415
private @Nullable Boolean userInfo;
1516
private @Nullable KeyValueCollectionBehavior cookies;
1617
private @Nullable KeyValueCollectionBehavior urlQueryParams;
@@ -23,8 +24,8 @@ public DataCollection() {
2324
this(true);
2425
}
2526

26-
DataCollection(final boolean overridden) {
27-
this.overridden = overridden;
27+
DataCollection(final boolean forceDataCollection) {
28+
this.forceDataCollection = forceDataCollection;
2829
}
2930

3031
public @Nullable Boolean getUserInfo() {
@@ -82,7 +83,7 @@ public void setDatabaseQueryData(final boolean databaseQueryData) {
8283

8384
@ApiStatus.Internal
8485
boolean isExplicitlyConfigured() {
85-
return overridden
86+
return forceDataCollection
8687
|| userInfo != null
8788
|| cookies != null
8889
|| urlQueryParams != null

sentry/src/test/java/io/sentry/DataCollectionResolverTest.kt

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class DataCollectionResolverTest {
4242
}
4343

4444
@Test
45-
fun `user info override takes precedence over sendDefaultPii`() {
45+
fun `user info uses configured Data Collection value`() {
4646
val options = SentryOptions().apply { isSendDefaultPii = true }
4747

4848
options.dataCollection.setUserInfo(false)
@@ -68,36 +68,78 @@ class DataCollectionResolverTest {
6868
}
6969

7070
@Test
71-
fun `database query data falls back to sendDefaultPii and override takes precedence`() {
72-
val options = SentryOptions().apply { isSendDefaultPii = true }
71+
fun `database query data uses sendDefaultPii when Data Collection is absent`() {
72+
val options = SentryOptions()
73+
74+
assertThat(options.dataCollectionResolver.isDatabaseQueryData).isFalse()
75+
76+
options.isSendDefaultPii = true
7377

7478
assertThat(options.dataCollectionResolver.isDatabaseQueryData).isTrue()
79+
}
80+
81+
@Test
82+
fun `database query data uses configured Data Collection value`() {
83+
val options = SentryOptions().apply { isSendDefaultPii = true }
7584

7685
options.dataCollection.setDatabaseQueryData(false)
7786

7887
assertThat(options.dataCollectionResolver.isDatabaseQueryData).isFalse()
88+
89+
options.isSendDefaultPii = false
90+
options.dataCollection.setDatabaseQueryData(true)
91+
92+
assertThat(options.dataCollectionResolver.isDatabaseQueryData).isTrue()
7993
}
8094

8195
@Test
82-
fun `GraphQL document falls back to sendDefaultPii and override takes precedence`() {
83-
val options = SentryOptions().apply { isSendDefaultPii = true }
96+
fun `GraphQL document uses sendDefaultPii when Data Collection is absent`() {
97+
val options = SentryOptions()
98+
99+
assertThat(options.dataCollectionResolver.isGraphqlDocument).isFalse()
100+
101+
options.isSendDefaultPii = true
84102

85103
assertThat(options.dataCollectionResolver.isGraphqlDocument).isTrue()
104+
}
105+
106+
@Test
107+
fun `GraphQL document uses configured Data Collection value`() {
108+
val options = SentryOptions().apply { isSendDefaultPii = true }
86109

87110
options.dataCollection.graphql.setDocument(false)
88111

89112
assertThat(options.dataCollectionResolver.isGraphqlDocument).isFalse()
113+
114+
options.isSendDefaultPii = false
115+
options.dataCollection.graphql.setDocument(true)
116+
117+
assertThat(options.dataCollectionResolver.isGraphqlDocument).isTrue()
90118
}
91119

92120
@Test
93-
fun `GraphQL variables fall back to sendDefaultPii and override takes precedence`() {
94-
val options = SentryOptions().apply { isSendDefaultPii = true }
121+
fun `GraphQL variables use sendDefaultPii when Data Collection is absent`() {
122+
val options = SentryOptions()
123+
124+
assertThat(options.dataCollectionResolver.isGraphqlVariables).isFalse()
125+
126+
options.isSendDefaultPii = true
95127

96128
assertThat(options.dataCollectionResolver.isGraphqlVariables).isTrue()
129+
}
130+
131+
@Test
132+
fun `GraphQL variables use configured Data Collection value`() {
133+
val options = SentryOptions().apply { isSendDefaultPii = true }
97134

98135
options.dataCollection.graphql.setVariables(false)
99136

100137
assertThat(options.dataCollectionResolver.isGraphqlVariables).isFalse()
138+
139+
options.isSendDefaultPii = false
140+
options.dataCollection.graphql.setVariables(true)
141+
142+
assertThat(options.dataCollectionResolver.isGraphqlVariables).isTrue()
101143
}
102144

103145
@Test
@@ -210,7 +252,7 @@ class DataCollectionResolverTest {
210252
}
211253

212254
@Test
213-
fun `cookies override takes precedence over sendDefaultPii`() {
255+
fun `cookies use configured Data Collection behavior`() {
214256
val options = SentryOptions().apply { isSendDefaultPii = false }
215257
val behavior = KeyValueCollectionBehavior.allowList("language", "theme")
216258

@@ -228,7 +270,7 @@ class DataCollectionResolverTest {
228270
}
229271

230272
@Test
231-
fun `URL query params override takes precedence`() {
273+
fun `URL query params use configured Data Collection behavior`() {
232274
val options = SentryOptions()
233275
val behavior = KeyValueCollectionBehavior.allowList("language", "theme")
234276

@@ -246,7 +288,7 @@ class DataCollectionResolverTest {
246288
}
247289

248290
@Test
249-
fun `HTTP request headers override takes precedence`() {
291+
fun `HTTP request headers use configured Data Collection behavior`() {
250292
val options = SentryOptions()
251293
val behavior = KeyValueCollectionBehavior.allowList("content-type")
252294

@@ -264,7 +306,7 @@ class DataCollectionResolverTest {
264306
}
265307

266308
@Test
267-
fun `HTTP response headers override takes precedence`() {
309+
fun `HTTP response headers use configured Data Collection behavior`() {
268310
val options = SentryOptions()
269311
val behavior = KeyValueCollectionBehavior.off()
270312

sentry/src/test/java/io/sentry/DataCollectionTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import kotlin.test.assertFailsWith
66

77
class DataCollectionTest {
88
@Test
9-
fun `public constructor creates explicit empty configuration`() {
9+
fun `public constructor forces Data Collection for empty configuration`() {
1010
val dataCollection = DataCollection()
1111

1212
assertThat(dataCollection.userInfo).isNull()
@@ -22,7 +22,7 @@ class DataCollectionTest {
2222
}
2323

2424
@Test
25-
fun `SDK-owned configuration starts unconfigured`() {
25+
fun `SDK-owned configuration does not force Data Collection`() {
2626
val dataCollection = DataCollection(false)
2727

2828
assertThat(dataCollection.isExplicitlyConfigured()).isFalse()

0 commit comments

Comments
 (0)