Skip to content

Commit

Permalink
Update Sentry scope usage
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Aug 29, 2024
1 parent 88ac818 commit 455f45a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ data class AppVersion(
return isMinimalVersionValid(minimalAcceptedVersionNumbers) &&
currentVersionNumbers.compareVersionTo(minimalAcceptedVersionNumbers) < 0
}.getOrElse { exception ->
Sentry.withScope { scope ->
Sentry.captureException(exception) { scope ->
scope.level = SentryLevel.ERROR
scope.setExtra("Version from API", minimalAcceptedVersion)
scope.setExtra("Current Version", currentVersion)
Sentry.captureException(exception)
}

return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.google.common.util.concurrent.ListenableFuture
import com.infomaniak.lib.core.utils.SentryLog
import com.infomaniak.lib.stores.updatemanagers.WorkerUpdateManager
import io.sentry.Sentry
import io.sentry.SentryLevel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -79,9 +78,8 @@ class AppUpdateScheduler(
updateManager.installDownloadedUpdate(
onInstallSuccess = { completer.setResult(Result.success()) },
onInstallFailure = { exception ->
Sentry.withScope {scope ->
Sentry.captureMessage("AppUpdate throwed an exception") { scope ->
scope.setTag("message", exception.message ?: "Unknown error")
Sentry.captureMessage("AppUpdate throwed an exception", SentryLevel.INFO)
}
completer.setResult(Result.failure())
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,20 @@ class AccessTokenUsageInterceptor(
return@runBlocking
}

if (previousApiCall != null
&& currentApiCall.accessToken == previousApiCall.accessToken
&& currentApiCall.date < previousApiCall.date + ONE_YEAR
if (previousApiCall != null &&
currentApiCall.accessToken == previousApiCall.accessToken &&
currentApiCall.date < previousApiCall.date + ONE_YEAR
) {
Sentry.withScope { scope ->
scope.level = SentryLevel.FATAL

Sentry.captureMessage(
"Got disconnected due to non-working access token but it's not been a year yet",
SentryLevel.FATAL,
) { scope ->
scope.setExtra("Last known api call date epoch", previousApiCall.date.toString())
scope.setExtra("Last known api call token", formatAccessTokenForSentry(previousApiCall.accessToken))
scope.setExtra("Last known api call response code", previousApiCall.responseCode.toString())

scope.setExtra("Current api call date epoch", currentApiCall.date.toString())
scope.setExtra("Current api call token", formatAccessTokenForSentry(currentApiCall.accessToken))

Sentry.captureMessage("Got disconnected due to non-working access token but it's not been a year yet")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,16 @@ fun Context.getFileNameAndSize(uri: Uri): Pair<String, Long>? {

fileName to fileSize
} else {
Sentry.withScope { scope ->
Sentry.captureMessage("$this has empty cursor") { scope ->
scope.setExtra("available columns", cursor.columnNames.joinToString { it })
Sentry.captureMessage("$this has empty cursor")
}
null
}
}
}.getOrElse { exception ->
uri.path?.substringBeforeLast("/")?.let { providerName ->
Sentry.withScope { scope ->
Sentry.captureException(exception) { scope ->
scope.setExtra("uri", providerName)
Sentry.captureException(exception)
}
}
null
Expand Down

0 comments on commit 455f45a

Please sign in to comment.