aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/TelemetryProvider.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-13 17:42:27 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-13 17:42:27 +0100
commitc4e4985b8b96ed156851c6be6d4a8d5e110c3040 (patch)
tree4dc7d19ccff486a9f612738db7ea196beffb38d1 /src/main/kotlin/moe/nea/ledger/TelemetryProvider.kt
parent4e986409ad65aa5c11baf7e8571b78b89ec260a4 (diff)
downloadLocalTransactionLedger-c4e4985b8b96ed156851c6be6d4a8d5e110c3040.tar.gz
LocalTransactionLedger-c4e4985b8b96ed156851c6be6d4a8d5e110c3040.tar.bz2
LocalTransactionLedger-c4e4985b8b96ed156851c6be6d4a8d5e110c3040.zip
Add error reporting framework
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/TelemetryProvider.kt')
-rw-r--r--src/main/kotlin/moe/nea/ledger/TelemetryProvider.kt66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/TelemetryProvider.kt b/src/main/kotlin/moe/nea/ledger/TelemetryProvider.kt
new file mode 100644
index 0000000..04f3fd2
--- /dev/null
+++ b/src/main/kotlin/moe/nea/ledger/TelemetryProvider.kt
@@ -0,0 +1,66 @@
+package moe.nea.ledger
+
+import com.google.gson.JsonArray
+import com.google.gson.JsonElement
+import com.google.gson.JsonObject
+import moe.nea.ledger.gen.BuildConfig
+import moe.nea.ledger.utils.DI
+import moe.nea.ledger.utils.DIProvider
+import moe.nea.ledger.utils.telemetry.CommonKeys
+import moe.nea.ledger.utils.telemetry.ContextValue
+import moe.nea.ledger.utils.telemetry.EventRecorder
+import moe.nea.ledger.utils.telemetry.JsonElementContext
+import moe.nea.ledger.utils.telemetry.LoggingEventRecorder
+import moe.nea.ledger.utils.telemetry.Span
+import net.minecraft.client.Minecraft
+import net.minecraft.util.Session
+import net.minecraftforge.fml.common.Loader
+
+object TelemetryProvider {
+ fun injectTo(di: DI) {
+ di.register(
+ EventRecorder::class.java,
+ if (DevUtil.isDevEnv) DIProvider.singeleton(LoggingEventRecorder(Ledger.logger, true))
+ else DIProvider.singeleton(
+ LoggingEventRecorder(Ledger.logger, false)) // TODO: replace with upload to server
+ )
+ }
+
+ val USER = "minecraft_user"
+ val MINECRAFT_VERSION = "minecraft_version"
+ val MODS = "mods"
+
+ class MinecraftUser(val session: Session) : ContextValue {
+ override fun serialize(): JsonElement {
+ val obj = JsonObject()
+ obj.addProperty("uuid", session.playerID)
+ obj.addProperty("name", session.username)
+ return obj
+ }
+ }
+
+ fun setupDefaultSpan() {
+ val sp = Span.current()
+ sp.add(USER, MinecraftUser(Minecraft.getMinecraft().session))
+ sp.add(MINECRAFT_VERSION, ContextValue.compound(
+ "static" to "1.8.9",
+ "rt" to Minecraft.getMinecraft().version,
+ ))
+ val mods = JsonArray()
+ Loader.instance().activeModList.map {
+ val obj = JsonObject()
+ obj.addProperty("id", it.modId)
+ obj.addProperty("version", it.version)
+ obj.addProperty("displayVersion", it.displayVersion)
+ obj
+ }.forEach(mods::add)
+ sp.add(MODS, JsonElementContext(mods))
+ sp.add(CommonKeys.VERSION, ContextValue.string(BuildConfig.FULL_VERSION))
+ sp.add(CommonKeys.COMMIT_VERSION, ContextValue.string(BuildConfig.GIT_COMMIT))
+ }
+
+ fun setupFor(di: DI) {
+ injectTo(di)
+ setupDefaultSpan()
+ }
+} \ No newline at end of file