Skip to content

Commit e6aafed

Browse files
authored
Merge pull request #2 from EndlessCodeGroup/feature/update-sentry
Update Sentry to 4.0.0-beta.1
2 parents 13fad82 + f1bd1de commit e6aafed

18 files changed

Lines changed: 135 additions & 187 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 {

buildSrc/src/main/kotlin/dependencies.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@file:Suppress("ClassName")
22

3-
const val sentry = "io.sentry:sentry:1.7.29"
3+
const val sentry = "io.sentry:sentry:4.0.0-beta.1"
44

55
object fuel {
66
private const val group = "com.github.kittinunf.fuel"

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/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
}
1010

1111
bukkit {
12-
version = "1.16.4"
12+
apiVersion = "1.16.4"
1313

1414
meta {
1515
name.set("Inspector")

inspector-bukkit/src/main/kotlin/InspectorPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class InspectorPlugin : JavaPlugin() {
1414
logger.severe("")
1515
logger.severe("What to do?")
1616
logger.severe(" Please report about it to author of the plugin, that requires Inspector.")
17-
logger.severe(" He must bundle it to the plugin or you can use Inspector v0.6.0.")
17+
logger.severe(" He should bundle it to the plugin.")
1818
logger.severe("")
1919

2020
throw AuthorNagException("Aggrh!!! Throwing an exception is only one possible way to disable plugin in onLoad()")

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: 46 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,97 @@
11
package ru.endlesscode.inspector.report
22

3-
import io.sentry.DefaultSentryClientFactory
4-
import io.sentry.DefaultSentryClientFactory.IN_APP_FRAMES_OPTION
5-
import io.sentry.DefaultSentryClientFactory.UNCAUGHT_HANDLER_ENABLED_OPTION
3+
import io.sentry.Integration
64
import io.sentry.Sentry
7-
import io.sentry.SentryClientFactory
8-
import io.sentry.connection.EventSendCallback
9-
import io.sentry.event.Event
10-
import io.sentry.event.EventBuilder
11-
import io.sentry.event.UserBuilder
12-
import io.sentry.event.interfaces.ExceptionInterface
13-
import java.util.*
5+
import io.sentry.SentryEvent
6+
import io.sentry.protocol.Message
7+
import io.sentry.protocol.User
148

159
/**
1610
* Reporter that sends reports to Sentry.
1711
*/
1812
public class SentryReporter private constructor(
1913
dsn: String,
20-
factory: SentryClientFactory,
14+
integrations: List<Integration>,
2115
override val focus: ReporterFocus,
2216
private val fields: Set<ReportField>,
2317
) : Reporter {
2418

2519
override var enabled: Boolean = true
2620

27-
private val sentry = Sentry.init(dsn, factory)
28-
2921
private val handlers = CompoundReportHandler()
30-
private val pendingExceptions = mutableMapOf<UUID, ExceptionData>()
3122

3223
init {
33-
sentry.addEventSendCallback(object : EventSendCallback {
34-
override fun onSuccess(event: Event) {
35-
val reportedException = removePendingException(event.id)
36-
if (reportedException != null) {
37-
handlers.onSuccess(event.message, reportedException)
38-
}
39-
}
24+
Sentry.init { options ->
25+
options.dsn = dsn
26+
options.release = "${focus.environment.appName}@${focus.environment.appVersion}"
27+
options.addInAppInclude(focus.focusedPackage)
28+
options.enableUncaughtExceptionHandler = false
29+
integrations.forEach(options::addIntegration)
30+
}
4031

41-
override fun onFailure(event: Event, exception: Exception) {
42-
val isErrorReport = removePendingException(event.id) != null
43-
if (isErrorReport) {
44-
handlers.onError(exception)
45-
}
32+
Sentry.configureScope { scope ->
33+
scope.user = User().apply {
34+
id = focus.environment.reporterId
4635
}
47-
})
48-
49-
sentry.release = focus.environment.appVersion
50-
sentry.context.user = UserBuilder()
51-
.setId(focus.environment.reporterId)
52-
.build()
36+
}
5337
}
5438

5539
override fun addHandler(handler: ReportHandler) {
5640
handlers.addHandler(handler)
5741
}
5842

5943
override fun report(message: String, exception: Exception, async: Boolean) {
60-
val exceptionData = ExceptionData(exception)
61-
handlers.beforeReport(message, exceptionData)
62-
63-
val eventBuilder = EventBuilder()
64-
.withMessage(message)
65-
.withSentryInterface(ExceptionInterface(exception))
66-
.apply {
67-
fields.asSequence()
68-
.filter(ReportField::show)
69-
.forEach { withExtra(it.name, it.value) }
70-
}
44+
val sentryMessage = Message().apply {
45+
formatted = message
46+
}
7147

72-
sentry.sendEvent(eventBuilder)
73-
addPendingException(sentry.context.lastEventId, exceptionData)
74-
}
48+
val event = SentryEvent(exception).apply {
49+
setMessage(sentryMessage)
50+
fields.asSequence()
51+
.filter(ReportField::show)
52+
.forEach { setExtra(it.name, it.value) }
53+
}
54+
Sentry.captureEvent(event)
7555

76-
private fun addPendingException(id: UUID, exception: ExceptionData) {
77-
pendingExceptions[id] = exception
56+
// We can't track errors on error sending. So we just assume that report was sent successfully.
57+
val exceptionData = ExceptionData(exception)
58+
handlers.onSuccess(message, exceptionData)
7859
}
7960

80-
private fun removePendingException(id: UUID): ExceptionData? = pendingExceptions.remove(id)
81-
8261
/**
8362
* Builder that should be used to build [SentryReporter].
8463
*
8564
* You should specify DSN with one of [setDataSourceName] methods.
8665
*/
8766
public class Builder : Reporter.Builder() {
8867

89-
private var clientFactory: SentryClientFactory? = null
9068
private var dsn: String = ""
91-
private var options: Map<String, String> = emptyMap()
69+
private val integrations = mutableListOf<Integration>()
9270

9371
/**
94-
* Set [SentryClientFactory], that will be used to create SentryClient.
72+
* Set Sentry [dsn].
73+
* See: [Setting the DSN](https://docs.sentry.io/clients/java/config/#setting-the-dsn)
9574
*/
96-
public fun setClientFactory(clientFactory: SentryClientFactory): Builder {
97-
this.clientFactory = clientFactory
75+
public fun setDsn(dsn: String): Builder {
76+
this.dsn = dsn
9877
return this
9978
}
10079

101-
/**
102-
* Set Sentry [dsn] with one string.
103-
* See: https://docs.sentry.io/clients/java/config/#setting-the-dsn
104-
*/
80+
@Deprecated("Use setDsn", ReplaceWith("setDsn(dsn)"))
10581
public fun setDataSourceName(dsn: String): Builder {
106-
this.dsn = dsn
107-
return this
82+
return setDsn(dsn)
10883
}
10984

110-
/**
111-
* Set Sentry [dsn] built from separated parts.
112-
* See: https://docs.sentry.io/clients/java/config/#setting-the-dsn
113-
*/
11485
@JvmOverloads
86+
@Deprecated("Use setDsn")
11587
public fun setDataSourceName(
11688
publicKey: String,
11789
projectId: String,
11890
protocol: String = "https",
11991
host: String = "sentry.io",
12092
port: String = "",
121-
options: Map<String, String> = emptyMap(),
12293
): Builder {
123-
this.dsn = buildString {
94+
val dsn = buildString {
12495
append(protocol)
12596
append("://")
12697
append(publicKey)
@@ -131,8 +102,12 @@ public class SentryReporter private constructor(
131102
append(projectId)
132103
}
133104

134-
this.options = options
105+
return setDsn(dsn)
106+
}
135107

108+
/** Adds given [integration] to Sentry. */
109+
public fun addIntegration(integration: Integration): Builder {
110+
this.integrations.add(integration)
136111
return this
137112
}
138113

@@ -141,21 +116,12 @@ public class SentryReporter private constructor(
141116
*/
142117
override fun build(): Reporter {
143118
require(dsn.isNotBlank()) {
144-
"You should specify DSN with method `setDataSourceName(...)` and it shouldn't be blank."
119+
"You should specify DSN with method `setDsn(...)` and it shouldn't be blank."
145120
}
146121

147-
val options = mutableMapOf(
148-
IN_APP_FRAMES_OPTION to focus.focusedPackage,
149-
UNCAUGHT_HANDLER_ENABLED_OPTION to "false"
150-
)
151-
options.putAll(this.options)
152-
153-
val optionsString = options.asSequence()
154-
.joinToString(prefix = "?", separator = "&") { (key, value) -> "$key=$value" }
155-
156122
return SentryReporter(
157-
dsn = "$dsn$optionsString",
158-
factory = clientFactory ?: DefaultSentryClientFactory(),
123+
dsn = dsn,
124+
integrations = integrations,
159125
focus = focus,
160126
fields = fields
161127
)

samples/hello-maven/src/main/java/com/example/myplugin/Myplugin.java renamed to samples/hello-maven/src/main/java/com/example/myplugin/MyPlugin.java

File renamed without changes.

samples/sentry-reporter/build.gradle

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
plugins {
2-
id 'ru.endlesscode.bukkitgradle' version '0.8.2'
3-
id 'com.github.johnrengelman.shadow' version '5.2.0'
2+
id 'ru.endlesscode.bukkitgradle' version '0.9.2'
3+
id 'com.github.johnrengelman.shadow' version '6.1.0'
44
}
55

6-
group = "com.example"
6+
group = "com.example.myplugin"
77
description = "My Bukkit plugin with Sentry Reporter"
88
version = "0.1-SNAPSHOT"
99

1010
// Read more about BukkitGradle: https://github.com/EndlessCodeGroup/BukkitGradle
1111
bukkit {
12-
version = "1.15.1"
12+
apiVersion = "1.16.4"
1313

1414
meta {
15-
name = "MyPlugin"
16-
url = "http://www.example.com"
17-
authors = ["osipxd"]
15+
name.set("MyPlugin")
16+
url.set("http://www.example.com")
17+
authors.set(["osipxd"])
1818
}
1919

20-
run {
20+
server {
2121
core = "spigot"
2222
eula = true
2323
}
@@ -37,13 +37,13 @@ shadowJar {
3737
}
3838
tasks.assemble.dependsOn tasks.shadowJar
3939

40-
ext.inspectorVerson = "0.9"
40+
def inspectorVersion = "0.10.0"
4141

4242
dependencies {
43-
compileOnly(bukkit()) { transitive = false }
44-
implementation("ru.endlesscode.inspector:inspector-bukkit:$inspectorVerson")
45-
implementation("ru.endlesscode.inspector:inspector-sentry-reporter:$inspectorVerson")
46-
implementation("ru.endlesscode.inspector:sentry-bukkit:$inspectorVerson")
43+
compileOnly(spigotApi()) { transitive = false }
44+
implementation("ru.endlesscode.inspector:inspector-bukkit:$inspectorVersion")
45+
implementation("ru.endlesscode.inspector:inspector-sentry-reporter:$inspectorVersion")
46+
implementation("ru.endlesscode.inspector:sentry-bukkit:$inspectorVersion")
4747
}
4848

4949
repositories {

0 commit comments

Comments
 (0)