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

feat: Add Sentry to Flank Wrapper #2074

Merged
merged 1 commit into from
Jul 9, 2021
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
16 changes: 15 additions & 1 deletion flank_wrapper/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.nio.file.Paths

plugins {
application
Expand All @@ -22,7 +23,7 @@ shadowJar.apply {
}
}
// <breaking change>.<feature added>.<fix/minor change>
version = "1.0.0"
version = "1.1.0"
group = "com.github.flank"

repositories {
Expand Down Expand Up @@ -75,6 +76,7 @@ publishing {

dependencies {
implementation(project(":common"))
implementation(Dependencies.SENTRY)
implementation(Dependencies.Fuel.CORE)
testImplementation(Dependencies.JUNIT)
testImplementation(Dependencies.TRUTH)
Expand Down Expand Up @@ -128,5 +130,17 @@ val prepareJar by tasks.registering(Copy::class) {
into("$projectDir")
}

val setWrapperVersion by tasks.registering {
doLast {
Paths.get(projectDir.absolutePath, "src", "main", "resources", "version.txt")
.toFile()
.apply { createNewFile() }
.writeText(version.toString())
}
}

tasks.processResources {
dependsOn(setWrapperVersion)
}

tasks["lintKotlin"].dependsOn(checkIfVersionUpdated)
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)
}
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)
}
1 change: 1 addition & 0 deletions flank_wrapper/src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.1.0