Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture failed HTTP requests by default #2794

Merged
merged 3 commits into from
Jul 7, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- Add debouncing mechanism and before-capture callbacks for screenshots and view hierarchies ([#2773](https://github.com/getsentry/sentry-java/pull/2773))
- Capture failed HTTP requests by default ([#2794](https://github.com/getsentry/sentry-java/pull/2794))

### Fixes

Expand Down
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