Batch startup events

This commit is contained in:
Brahim Hadriche committed 2026-10-13 19:36:32 -04:00
1 parent 37c61d8ba7
commit 029582817f
2 files changed
+18 -15

No files matched your search

@@ -1,19 +1,17 @@
#const DEBUG_THROW_ON_UNKNOWN_EXIT_CODE = true
import "pkg:/components/Telemetry/Sentry.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/Types.bs"
function ReportLastExitCrash() as void
function CreateLastExitCrashEvent() as dynamic
scene = m.top.getScene()
if scene = invalid or not scene.hasField("lastExitInfo")
return
return invalid
end if
lastExitInfo = scene.lastExitInfo
scene.lastExitInfo = invalid
if not IsAssociativeArray(lastExitInfo)
return
return invalid
end if
crashExitCodes = {
@@ -63,7 +61,7 @@ function ReportLastExitCrash() as void
#end if
if crashExitCodes[exitCode] = false
return
return invalid
end if
message = `[FATAL][LastExit] App crashed: ${exitCode}`
@@ -71,7 +69,7 @@ function ReportLastExitCrash() as void
message += `\n${key}: ${ToString(lastExitInfo[key])}`
end for
Sentry.SendEvents([{
return {
level: "fatal"
message: message
timestamp: ValidString(lastExitInfo.timestamp)
@@ -80,5 +78,5 @@ function ReportLastExitCrash() as void
dist: m.dist
tags: m.tags
userId: m.userId
}])
}
end function
@@ -53,9 +53,6 @@ function TelemetryLoop() as void
m.top.observeField("LogError", msgPort)
m.top.observeField("LogEvent", msgPort)
ReportSessionStart()
ReportLastExitCrash()
#if SUPPORTS_BATCHING
debouceMs = 2000
debounceCountLimit = 20
@@ -63,8 +60,11 @@ function TelemetryLoop() as void
debounceTimer = CreateObject("roTimeSpan")
#end if
retryAfter = 0
retryAfterTimer = CreateObject("roTimeSpan")
retryAfter = Sentry.SendEvents(CreateLaunchEvents())
if retryAfter > 0
retryAfterTimer.Mark()
end if
levelMap = {
"LogInfo": "info"
@@ -160,8 +160,8 @@ function TelemetryLoop() as void
end while
end function
function ReportSessionStart() as void
Sentry.SendEvents([{
function CreateLaunchEvents() as object
events = [{
level: "info"
message: "[SESSION] start"
fingerprint: ["session start"]
@@ -169,7 +169,12 @@ function ReportSessionStart() as void
dist: m.dist
tags: m.tags
userId: m.userId
}])
}]
lastExitCrashEvent = CreateLastExitCrashEvent()
if lastExitCrashEvent <> invalid
events.Push(lastExitCrashEvent)
end if
return events
end function
function GetTags() as object