Skip to content

Commit 2083fbd

Browse files
committed
feat(sentry): Add fields to any sentry events
1 parent e6aafed commit 2083fbd

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public class SentryReporter private constructor(
2727
options.addInAppInclude(focus.focusedPackage)
2828
options.enableUncaughtExceptionHandler = false
2929
integrations.forEach(options::addIntegration)
30+
options.addEventProcessor { event, _ ->
31+
fields.asSequence()
32+
.filter(ReportField::show)
33+
.forEach { event.setExtra(it.name, it.value) }
34+
event
35+
}
3036
}
3137

3238
Sentry.configureScope { scope ->
@@ -41,20 +47,17 @@ public class SentryReporter private constructor(
4147
}
4248

4349
override fun report(message: String, exception: Exception, async: Boolean) {
44-
val sentryMessage = Message().apply {
45-
formatted = message
46-
}
50+
val exceptionData = ExceptionData(exception)
51+
handlers.beforeReport(message, exceptionData)
4752

4853
val event = SentryEvent(exception).apply {
49-
setMessage(sentryMessage)
50-
fields.asSequence()
51-
.filter(ReportField::show)
52-
.forEach { setExtra(it.name, it.value) }
54+
setMessage(Message().apply {
55+
formatted = message
56+
})
5357
}
5458
Sentry.captureEvent(event)
5559

5660
// We can't track errors on error sending. So we just assume that report was sent successfully.
57-
val exceptionData = ExceptionData(exception)
5861
handlers.onSuccess(message, exceptionData)
5962
}
6063

sentry-bukkit/src/main/kotlin/SentryBukkitIntegration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class SentryBukkitIntegration(private val plugin: Plugin) : Integration {
2525
options.sdkVersion?.addIntegration("bukkit")
2626
options.serverName = plugin.server.knownName
2727
options.setTag("minecraft", plugin.server.minecraftVersion)
28-
options.setBeforeSend { event, _ ->
28+
options.addEventProcessor { event, _ ->
2929
event.contexts.putAll(getContexts())
3030
event
3131
}

0 commit comments

Comments
 (0)