fix(bugcollect): flush 时修正初始化前暂存事件的 appKey
SDK 通过 ContentProvider 异步初始化(sdkScope.launch),若应用层在 initialized=true 设置前调用 captureError,事件以 appKey="pending" 存入 pendingErrors。后续 flushPendingErrors 将其原样推送给 LogQueue, 服务端找不到对应应用而丢弃,导致上报丢失。 修复:flush 时检测 appKey=="pending" 并替换为真实值(appKey、userId、 release、buildId),确保早期捕获的错误能正常上报。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
584aba22b1
当前提交
7169e66ee9
@ -205,7 +205,11 @@ object BugCollect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 将 SDK 未就绪时暂存的错误事件 flush 到队列。 */
|
/** 将 SDK 未就绪时暂存的错误事件 flush 到队列。
|
||||||
|
*
|
||||||
|
* 早于 SDK 初始化完成前调用 captureError 时,事件以 appKey="pending"、userId="unknown"
|
||||||
|
* 占位存入 pendingErrors。flush 时用真实值替换,避免服务端因找不到应用而丢弃事件。
|
||||||
|
*/
|
||||||
private fun flushPendingErrors() {
|
private fun flushPendingErrors() {
|
||||||
val events = synchronized(pendingErrorsLock) {
|
val events = synchronized(pendingErrorsLock) {
|
||||||
if (pendingErrors.isEmpty()) return
|
if (pendingErrors.isEmpty()) return
|
||||||
@ -213,7 +217,20 @@ object BugCollect {
|
|||||||
pendingErrors.clear()
|
pendingErrors.clear()
|
||||||
list
|
list
|
||||||
}
|
}
|
||||||
events.forEach { queue().push(it) }
|
val realAppKey = if (XuqmSDK.isInitialized()) XuqmSDK.appKey else return
|
||||||
|
val realUserId = XuqmSDK.getUserId() ?: XuqmSDK.deviceId
|
||||||
|
events.forEach { event ->
|
||||||
|
val fixed = if (event.appKey == "pending") {
|
||||||
|
event.copy(
|
||||||
|
appKey = realAppKey,
|
||||||
|
userId = realUserId,
|
||||||
|
user = IssueEvent.UserInfo(id = realUserId),
|
||||||
|
release = appVersion(),
|
||||||
|
buildId = buildId(),
|
||||||
|
)
|
||||||
|
} else event
|
||||||
|
queue().push(fixed)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 上传上次崩溃落盘的文件(远端配置就绪后由 BugCollectInitProvider 自动调用)。 */
|
/** 上传上次崩溃落盘的文件(远端配置就绪后由 BugCollectInitProvider 自动调用)。 */
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户