Skip to content

Commit

Permalink
Merge ecf34f2 into 9246ed4
Browse files Browse the repository at this point in the history
  • Loading branch information
markushi authored Jun 22, 2023
2 parents 9246ed4 + ecf34f2 commit 41de78f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import java.io.IOException
class SentryOkHttpInterceptor(
private val hub: IHub = HubAdapter.getInstance(),
private val beforeSpan: BeforeSpanCallback? = null,
private val captureFailedRequests: Boolean = false,
private val captureFailedRequests: Boolean = true,
private val failedRequestStatusCodes: List<HttpStatusCodeRange> = listOf(
HttpStatusCodeRange(HttpStatusCodeRange.DEFAULT_MIN, HttpStatusCodeRange.DEFAULT_MAX)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SentryOkHttpInterceptorTest {
beforeSpan: SentryOkHttpInterceptor.BeforeSpanCallback? = null,
includeMockServerInTracePropagationTargets: Boolean = true,
keepDefaultTracePropagationTargets: Boolean = false,
captureFailedRequests: Boolean = false,
captureFailedRequests: Boolean? = false,
failedRequestTargets: List<String> = listOf(".*"),
failedRequestStatusCodes: List<HttpStatusCodeRange> = listOf(
HttpStatusCodeRange(
Expand Down Expand Up @@ -91,13 +91,22 @@ class SentryOkHttpInterceptorTest {
.setResponseCode(httpStatusCode)
)

val interceptor = SentryOkHttpInterceptor(
hub,
beforeSpan,
captureFailedRequests = captureFailedRequests,
failedRequestTargets = failedRequestTargets,
failedRequestStatusCodes = failedRequestStatusCodes
)
val interceptor = when (captureFailedRequests) {
null -> SentryOkHttpInterceptor(
hub,
beforeSpan,
failedRequestTargets = failedRequestTargets,
failedRequestStatusCodes = failedRequestStatusCodes
)

else -> SentryOkHttpInterceptor(
hub,
beforeSpan,
captureFailedRequests = captureFailedRequests,
failedRequestTargets = failedRequestTargets,
failedRequestStatusCodes = failedRequestStatusCodes
)
}
return OkHttpClient.Builder().addInterceptor(interceptor).build()
}
}
Expand Down Expand Up @@ -349,6 +358,17 @@ class SentryOkHttpInterceptorTest {
}
}

@Test
fun `captures failed requests by default`() {
val sut = fixture.getSut(
httpStatusCode = 500,
captureFailedRequests = null
)
sut.newCall(getRequest()).execute()

verify(fixture.hub).captureEvent(any(), any<Hint>())
}

@Test
fun `captures an event if captureFailedRequests is enabled and within the range`() {
val sut = fixture.getSut(
Expand Down

0 comments on commit 41de78f

Please sign in to comment.