Skip to content

Commit bbfee21

Browse files
committed
feat(Sentry): Add addIntegration method
1 parent 0e7f46b commit bbfee21

5 files changed

Lines changed: 23 additions & 2 deletions

File tree

buildSrc/src/main/kotlin/commons.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ repositories {
1818

1919
dependencies {
2020
"implementation"(kotlin("stdlib-jdk8"))
21-
"implementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
2221
}
2322

2423
tasks.withType<KotlinCompile>().configureEach {

inspector-api/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
plugins {
33
`bintray-publish`
44
}
5+
6+
dependencies {
7+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
8+
}

inspector-api/src/main/kotlin/report/ReportEnvironment.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ public interface ReportEnvironment {
44

55
public companion object {
66
public val EMPTY: ReportEnvironment = object : ReportEnvironment {
7+
override val appName: String = ""
78
override val appVersion: String = ""
89
override val reporterId: String = ""
910
override val fields: Map<String, ReportField> = emptyMap()
1011
override val isInspectorEnabled: Boolean = false
1112
}
1213
}
1314

15+
/**
16+
* Name of app that uses Inspector.
17+
*/
18+
public val appName: String
19+
1420
/**
1521
* Version of app that uses Inspector.
1622
*/

inspector-bukkit/src/main/kotlin/report/BukkitEnvironment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class BukkitEnvironment internal constructor(
2525

2626
public val inspector: Inspector = Inspector(plugin, properties.configName)
2727

28+
override val appName: String = plugin.description.name
2829
override val appVersion: String = plugin.description.version
2930
override val reporterId: String = inspector.serverId.toString()
3031

inspector-sentry-reporter/src/main/kotlin/SentryReporter.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ru.endlesscode.inspector.report
22

3+
import io.sentry.Integration
34
import io.sentry.Sentry
45
import io.sentry.SentryEvent
56
import io.sentry.protocol.Message
@@ -10,6 +11,7 @@ import io.sentry.protocol.User
1011
*/
1112
public class SentryReporter private constructor(
1213
dsn: String,
14+
integrations: List<Integration>,
1315
override val focus: ReporterFocus,
1416
private val fields: Set<ReportField>,
1517
) : Reporter {
@@ -21,9 +23,10 @@ public class SentryReporter private constructor(
2123
init {
2224
Sentry.init { options ->
2325
options.dsn = dsn
24-
options.release = focus.environment.appVersion
26+
options.release = "${focus.environment.appName}@${focus.environment.appVersion}"
2527
options.addInAppInclude(focus.focusedPackage)
2628
options.enableUncaughtExceptionHandler = false
29+
integrations.forEach(options::addIntegration)
2730
}
2831

2932
Sentry.configureScope { scope ->
@@ -63,6 +66,7 @@ public class SentryReporter private constructor(
6366
public class Builder : Reporter.Builder() {
6467

6568
private var dsn: String = ""
69+
private val integrations = mutableListOf<Integration>()
6670

6771
/**
6872
* Set Sentry [dsn].
@@ -101,6 +105,12 @@ public class SentryReporter private constructor(
101105
return setDsn(dsn)
102106
}
103107

108+
/** Adds given [integration] to Sentry. */
109+
public fun addIntegration(integration: Integration): Builder {
110+
this.integrations.add(integration)
111+
return this
112+
}
113+
104114
/**
105115
* Build configured [SentryReporter].
106116
*/
@@ -111,6 +121,7 @@ public class SentryReporter private constructor(
111121

112122
return SentryReporter(
113123
dsn = dsn,
124+
integrations = integrations,
114125
focus = focus,
115126
fields = fields
116127
)

0 commit comments

Comments
 (0)