Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Oct 12, 2022
1 parent 2284f88 commit 6268a19
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import java.io.IOException
class SentryOkHttpInterceptor(
private val hub: IHub = HubAdapter.getInstance(),
private val beforeSpan: BeforeSpanCallback? = null,
// TODO: should this be under the options or here? also define the names
// should this be under the options or here? also define the names
private val captureFailedRequests: Boolean = false,
private val failedRequestStatusCode: List<HttpStatusCodeRange> = listOf(HttpStatusCodeRange(500, 599)),
private val failedRequestStatusCode: List<HttpStatusCodeRange> = listOf(
HttpStatusCodeRange(HttpStatusCodeRange.DEFAULT_MIN, HttpStatusCodeRange.DEFAULT_MAX)),
private val failedRequestsTargets: List<String> = listOf(".*")
) : Interceptor {

Expand Down Expand Up @@ -141,22 +142,25 @@ class SentryOkHttpInterceptor(
requestUrl = requestUrl.replace("#$urlFragment", "")
}

if (!captureFailedRequests || !PropagationTargetsUtils.contain(failedRequestsTargets, requestUrl) || !containsStatusCode(response.code)) {
if (!captureFailedRequests ||
!PropagationTargetsUtils.contain(failedRequestsTargets, requestUrl) ||
!containsStatusCode(response.code)) {
return
}

val mechanism = Mechanism().apply {
type = "SentryOkHttpInterceptor"
}
val exception = SentryHttpClientException("Event was captured because the request status code was ${response.code}")
val exception = SentryHttpClientException(
"Event was captured because the request status code was ${response.code}")
val mechanismException = ExceptionMechanismException(mechanism, exception, Thread.currentThread(), true)
val event = SentryEvent(mechanismException)

val hint = Hint()
hint.set("request", request)
hint.set("response", response)

// TODO: remove after fields indexed
// remove after fields indexed
// val tags = mutableMapOf<String, String>()
// tags["status_code"] = response.code.toString()
// tags["url"] = requestUrl
Expand All @@ -173,7 +177,7 @@ class SentryOkHttpInterceptor(
fragment = urlFragment

request.body?.contentLength().ifHasValidLength {
// TODO: should be mapped in relay and added to the protocol, right now
// should be mapped in relay and added to the protocol, right now
// relay isn't retaining unmapped fields
unknownRequestFields["body_size"] = it
}
Expand Down
2 changes: 2 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ public final class io/sentry/Hint {
}

public final class io/sentry/HttpStatusCodeRange {
public static final field DEFAULT_MAX I
public static final field DEFAULT_MIN I
public fun <init> (I)V
public fun <init> (II)V
public fun isInRange (I)Z
Expand Down
3 changes: 3 additions & 0 deletions sentry/src/main/java/io/sentry/HttpStatusCodeRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* <p>Example for a single status code 400 500
*/
public final class HttpStatusCodeRange {
public static final int DEFAULT_MIN = 500;
public static final int DEFAULT_MAX = 599;

private final int min;
private final int max;

Expand Down

0 comments on commit 6268a19

Please sign in to comment.