Skip to content

Commit

Permalink
feat: Add Sentry to Flank Wrapper (#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotradamczyk5 authored Jul 9, 2021
1 parent 5dadae6 commit 9503d08
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
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

0 comments on commit 9503d08

Please sign in to comment.