Skip to content

Commit

Permalink
Merge pull request #2100 from Infomaniak/add-api-code-to-call-breadcrumb
Browse files Browse the repository at this point in the history
Add api response code to api call sentry breadcrumb
  • Loading branch information
LunarX authored Nov 14, 2024
2 parents cb02c6d + 2a51c42 commit 5534666
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ class UrlTraceInterceptor : Interceptor {
var request = chain.request()

val requestContextId = UUID.randomUUID().toString()
SentryDebug.addUrlBreadcrumb(request.url.toString(), requestContextId)

request.newBuilder().apply {
header("x-infomaniak-request-context-id", requestContextId)
request = build()
}

return chain.proceed(request)
val response = runCatching {
chain.proceed(request)
}.onFailure {
SentryDebug.addUrlBreadcrumb(request.url.toString(), requestContextId, null)
throw it
}.getOrThrow()

SentryDebug.addUrlBreadcrumb(request.url.toString(), requestContextId, response.code)

return response
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/infomaniak/mail/utils/SentryDebug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ object SentryDebug {
previousDestinationName = newDestinationName
}

fun addUrlBreadcrumb(url: String, requestContextId: String) {
fun addUrlBreadcrumb(url: String, requestContextId: String, responseCode: Int?) {
addInfoBreadcrumb(
category = "API",
data = mapOf(
"url" to url,
"requestContextId" to requestContextId,
"responseCode" to responseCode.toString(),
),
)
}
Expand Down

0 comments on commit 5534666

Please sign in to comment.