Skip to content

Commit 89bcf71

Browse files
adinauerclaude
andcommitted
chore: Synchronize data collection stack
Merge the conflict-resolved cookie policy through the remaining stacked branches. Co-Authored-By: Claude <noreply@anthropic.com>
2 parents b2b8015 + 793f1f6 commit 89bcf71

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)
@@ -79,36 +79,78 @@ class DataCollectionResolverTest {
7979
}
8080

8181
@Test
82-
fun `database query data falls back to sendDefaultPii and override takes precedence`() {
83-
val options = SentryOptions().apply { isSendDefaultPii = true }
82+
fun `database query data uses sendDefaultPii when Data Collection is absent`() {
83+
val options = SentryOptions()
84+
85+
assertThat(options.dataCollectionResolver.isDatabaseQueryData).isFalse()
86+
87+
options.isSendDefaultPii = true
8488

8589
assertThat(options.dataCollectionResolver.isDatabaseQueryData).isTrue()
90+
}
91+
92+
@Test
93+
fun `database query data uses configured Data Collection value`() {
94+
val options = SentryOptions().apply { isSendDefaultPii = true }
8695

8796
options.dataCollection.setDatabaseQueryData(false)
8897

8998
assertThat(options.dataCollectionResolver.isDatabaseQueryData).isFalse()
99+
100+
options.isSendDefaultPii = false
101+
options.dataCollection.setDatabaseQueryData(true)
102+
103+
assertThat(options.dataCollectionResolver.isDatabaseQueryData).isTrue()
90104
}
91105

92106
@Test
93-
fun `GraphQL document falls back to sendDefaultPii and override takes precedence`() {
94-
val options = SentryOptions().apply { isSendDefaultPii = true }
107+
fun `GraphQL document uses sendDefaultPii when Data Collection is absent`() {
108+
val options = SentryOptions()
109+
110+
assertThat(options.dataCollectionResolver.isGraphqlDocument).isFalse()
111+
112+
options.isSendDefaultPii = true
95113

96114
assertThat(options.dataCollectionResolver.isGraphqlDocument).isTrue()
115+
}
116+
117+
@Test
118+
fun `GraphQL document uses configured Data Collection value`() {
119+
val options = SentryOptions().apply { isSendDefaultPii = true }
97120

98121
options.dataCollection.graphql.setDocument(false)
99122

100123
assertThat(options.dataCollectionResolver.isGraphqlDocument).isFalse()
124+
125+
options.isSendDefaultPii = false
126+
options.dataCollection.graphql.setDocument(true)
127+
128+
assertThat(options.dataCollectionResolver.isGraphqlDocument).isTrue()
101129
}
102130

103131
@Test
104-
fun `GraphQL variables fall back to sendDefaultPii and override takes precedence`() {
105-
val options = SentryOptions().apply { isSendDefaultPii = true }
132+
fun `GraphQL variables use sendDefaultPii when Data Collection is absent`() {
133+
val options = SentryOptions()
134+
135+
assertThat(options.dataCollectionResolver.isGraphqlVariables).isFalse()
136+
137+
options.isSendDefaultPii = true
106138

107139
assertThat(options.dataCollectionResolver.isGraphqlVariables).isTrue()
140+
}
141+
142+
@Test
143+
fun `GraphQL variables use configured Data Collection value`() {
144+
val options = SentryOptions().apply { isSendDefaultPii = true }
108145

109146
options.dataCollection.graphql.setVariables(false)
110147

111148
assertThat(options.dataCollectionResolver.isGraphqlVariables).isFalse()
149+
150+
options.isSendDefaultPii = false
151+
options.dataCollection.graphql.setVariables(true)
152+
153+
assertThat(options.dataCollectionResolver.isGraphqlVariables).isTrue()
112154
}
113155

114156
@Test
@@ -221,7 +263,7 @@ class DataCollectionResolverTest {
221263
}
222264

223265
@Test
224-
fun `cookies override takes precedence over sendDefaultPii`() {
266+
fun `cookies use configured Data Collection behavior`() {
225267
val options = SentryOptions().apply { isSendDefaultPii = false }
226268
val behavior = KeyValueCollectionBehavior.allowList("language", "theme")
227269

@@ -239,7 +281,7 @@ class DataCollectionResolverTest {
239281
}
240282

241283
@Test
242-
fun `URL query params override takes precedence`() {
284+
fun `URL query params use configured Data Collection behavior`() {
243285
val options = SentryOptions()
244286
val behavior = KeyValueCollectionBehavior.allowList("language", "theme")
245287

@@ -257,7 +299,7 @@ class DataCollectionResolverTest {
257299
}
258300

259301
@Test
260-
fun `HTTP request headers override takes precedence`() {
302+
fun `HTTP request headers use configured Data Collection behavior`() {
261303
val options = SentryOptions()
262304
val behavior = KeyValueCollectionBehavior.allowList("content-type")
263305

@@ -275,7 +317,7 @@ class DataCollectionResolverTest {
275317
}
276318

277319
@Test
278-
fun `HTTP response headers override takes precedence`() {
320+
fun `HTTP response headers use configured Data Collection behavior`() {
279321
val options = SentryOptions()
280322
val behavior = KeyValueCollectionBehavior.off()
281323

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