Skip to content

Commit 0d69665

Browse files
authored
Merge pull request #5803 from getsentry/feat/data-collection-incoming-response-body
feat(apollo): [Data Collection 7] Apply incoming response body policy
2 parents 34b69d0 + 13f738d commit 0d69665

4 files changed

Lines changed: 46 additions & 2 deletions

File tree

‎sentry-apollo-3/src/main/java/io/sentry/apollo3/SentryApollo3HttpInterceptor.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ constructor(
394394
response.body?.buffer?.size?.ifHasValidLength { contentLength ->
395395
bodySize = contentLength
396396
}
397-
data = body
397+
if (scopes.options.dataCollectionResolver.isIncomingResponseBody) {
398+
data = body
399+
}
398400
}
399401

400402
fingerprints.add(response.statusCode.toString())

‎sentry-apollo-3/src/test/java/io/sentry/apollo3/SentryApollo3InterceptorClientErrors.kt‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,26 @@ class SentryApollo3InterceptorClientErrors {
360360
)
361361
}
362362

363+
@Test
364+
fun `data collection can disable incoming response body`() {
365+
val sut =
366+
fixture.getSut(responseBody = fixture.responseBodyNotOk) {
367+
dataCollection.httpBodies = emptySet()
368+
}
369+
executeQuery(sut)
370+
371+
verify(fixture.scopes)
372+
.captureEvent(
373+
check {
374+
val response = it.contexts.response!!
375+
assertEquals(200, response.statusCode)
376+
assertEquals(200, response.bodySize)
377+
assertNull(response.data)
378+
},
379+
any<Hint>(),
380+
)
381+
}
382+
363383
@Test
364384
fun `capture errors with more response context if sendDefaultPii is enabled`() {
365385
val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, sendDefaultPii = true)

‎sentry-apollo-4/src/main/java/io/sentry/apollo4/SentryApollo4HttpInterceptor.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,9 @@ constructor(
393393
response.body?.buffer?.size?.ifHasValidLength { contentLength ->
394394
bodySize = contentLength
395395
}
396-
data = body
396+
if (scopes.options.dataCollectionResolver.isIncomingResponseBody) {
397+
data = body
398+
}
397399
}
398400

399401
fingerprints.add(response.statusCode.toString())

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,26 @@ abstract class SentryApollo4BuilderExtensionsClientErrorsTest(
373373
)
374374
}
375375

376+
@Test
377+
fun `data collection can disable incoming response body`() {
378+
val sut =
379+
fixture.getSut(responseBody = fixture.responseBodyNotOk) {
380+
dataCollection.httpBodies = emptySet()
381+
}
382+
executeQuery(sut)
383+
384+
verify(fixture.scopes)
385+
.captureEvent(
386+
check {
387+
val response = it.contexts.response!!
388+
assertEquals(200, response.statusCode)
389+
assertEquals(200, response.bodySize)
390+
assertNull(response.data)
391+
},
392+
any<Hint>(),
393+
)
394+
}
395+
376396
@Test
377397
fun `capture errors with more response context if sendDefaultPii is enabled`() {
378398
val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, sendDefaultPii = true)

0 commit comments

Comments
 (0)