-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Sentry to Flank Wrapper (#2074)
- Loading branch information
1 parent
5dadae6
commit 9503d08
Showing
4 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/CrashReporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.github.flank.wrapper.internal | ||
|
||
import flank.common.config.isTest | ||
import io.sentry.Sentry | ||
import java.util.UUID | ||
|
||
private const val SESSION_ID = "session.id" | ||
private const val OS_NAME = "os.name" | ||
private const val FLANK_WRAPPER_VERSION = "flank_wrapper.version" | ||
private const val DSN = "https://[email protected]/5855220" | ||
|
||
fun setupCrashReporter() { | ||
if (isTest().not()) { | ||
Sentry.init { options -> | ||
options.dsn = DSN | ||
options.tracesSampleRate = 1.0 | ||
} | ||
|
||
logTags( | ||
SESSION_ID to sessionID, | ||
OS_NAME to osName, | ||
FLANK_WRAPPER_VERSION to flankWrapperVersion, | ||
) | ||
} | ||
} | ||
|
||
private fun logTags(vararg tags: Pair<String, String>) { | ||
tags.forEach { (key, value) -> Sentry.setTag(key, value) } | ||
} | ||
|
||
private val sessionID by lazy { UUID.randomUUID().toString() } | ||
|
||
private val osName: String | ||
get() = System.getProperty("os.name") | ||
|
||
private val flankWrapperVersion by lazy { | ||
(object {}.javaClass.getResource("/version.txt")?.readText() ?: "UNKNOWN") | ||
} | ||
|
||
internal fun Throwable.report() { | ||
Sentry.captureException(this) | ||
} |
15 changes: 9 additions & 6 deletions
15
flank_wrapper/src/main/kotlin/com/github/flank/wrapper/internal/RunFlankOnLatestVersion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package com.github.flank.wrapper.internal | ||
|
||
internal fun runFlankOnLatestVersion(args: Array<out String>) { | ||
if (!compareLatestVersionCheckSumWithCurrent()) { | ||
println("The new Flank version is available. Downloading new version...") | ||
downloadLatestFlankVersion() | ||
println("The new Flank version is ready to use") | ||
} | ||
executeFlank(args) | ||
runCatching { | ||
setupCrashReporter() | ||
if (!compareLatestVersionCheckSumWithCurrent()) { | ||
println("The new Flank version is available. Downloading new version...") | ||
downloadLatestFlankVersion() | ||
println("The new Flank version is ready to use") | ||
} | ||
executeFlank(args) | ||
}.onFailure(Throwable::report) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.1.0 |