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

Update Sentry scope usage #218

Merged
merged 1 commit into from
Aug 29, 2024
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
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
Loading