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
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,18 @@ constructor(
request.body?.let {
bodySize = it.contentLength

val buffer = Buffer()

try {
it.writeTo(buffer)
data = GraphqlUtils.filterRequestBody(buffer.readUtf8(), scopes.options)
} catch (e: Throwable) {
scopes.options.logger.log(SentryLevel.ERROR, "Error reading the request body.", e)
// continue because the response body alone can already give some insights
} finally {
buffer.close()
if (scopes.options.dataCollectionResolver.isOutgoingRequestBody) {
val buffer = Buffer()

try {
it.writeTo(buffer)
data = GraphqlUtils.filterRequestBody(buffer.readUtf8(), scopes.options)
} catch (e: Throwable) {
scopes.options.logger.log(SentryLevel.ERROR, "Error reading the request body.", e)
// continue because the response body alone can already give some insights
} finally {
buffer.close()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.apollographql.apollo3.api.http.HttpRequest
import com.apollographql.apollo3.api.http.HttpResponse
import com.apollographql.apollo3.exception.ApolloException
import io.sentry.Hint
import io.sentry.HttpBodyType
import io.sentry.IScopes
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.SentryOptions
Expand Down Expand Up @@ -268,6 +269,24 @@ class SentryApollo3InterceptorClientErrors {
)
}

@Test
fun `data collection can disable outgoing request body`() {
val sut =
fixture.getSut(responseBody = fixture.responseBodyNotOk) {
dataCollection.httpBodies = setOf(HttpBodyType.INCOMING_RESPONSE)
}
executeQuery(sut)

verify(fixture.scopes)
.captureEvent(
check {
assertEquals(193L, it.request!!.bodySize)
assertNull(it.request!!.data)
},
any<Hint>(),
)
}

@Test
fun `data collection can disable the GraphQL document independently`() {
val sut =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,18 @@ constructor(
request.body?.let {
bodySize = it.contentLength

val buffer = Buffer()

try {
it.writeTo(buffer)
data = GraphqlUtils.filterRequestBody(buffer.readUtf8(), scopes.options)
} catch (e: Throwable) {
scopes.options.logger.log(SentryLevel.ERROR, "Error reading the request body.", e)
// continue because the response body alone can already give some insights
} finally {
buffer.close()
if (scopes.options.dataCollectionResolver.isOutgoingRequestBody) {
val buffer = Buffer()

try {
it.writeTo(buffer)
data = GraphqlUtils.filterRequestBody(buffer.readUtf8(), scopes.options)
} catch (e: Throwable) {
scopes.options.logger.log(SentryLevel.ERROR, "Error reading the request body.", e)
// continue because the response body alone can already give some insights
} finally {
buffer.close()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.apollographql.apollo.api.http.HttpRequest
import com.apollographql.apollo.api.http.HttpResponse
import com.apollographql.apollo.exception.ApolloException
import io.sentry.Hint
import io.sentry.HttpBodyType
import io.sentry.IScopes
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.SentryOptions
Expand Down Expand Up @@ -282,6 +283,24 @@ abstract class SentryApollo4BuilderExtensionsClientErrorsTest(
)
}

@Test
fun `data collection can disable outgoing request body`() {
val sut =
fixture.getSut(responseBody = fixture.responseBodyNotOk) {
dataCollection.httpBodies = setOf(HttpBodyType.INCOMING_RESPONSE)
}
executeQuery(sut)

verify(fixture.scopes)
.captureEvent(
check {
assertEquals(193L, it.request!!.bodySize)
assertNull(it.request!!.data)
},
any<Hint>(),
)
}

@Test
fun `data collection can disable the GraphQL document independently`() {
val sut =
Expand Down
Loading