Conversation
LinQingYuu
left a comment
There was a problem hiding this comment.
也许可以考虑有选择性的上报
像一些 IOException 还有 HTTP 请求超时其实没有上报的必要,报这个纯粹在浪费钱
b545c25 to
fe7aa62
Compare
| options.AutoSessionTracking = true; | ||
| options.Release = release; | ||
| options.Environment = environment; | ||
| options.SetBeforeSend(@event => |
There was a problem hiding this comment.
@event.Exception 可能为 null(message/event 类型、或异常在 @event.Exceptions 列表里),这段逻辑可能根本过滤不到你想过滤的 timeout。
仅通过 Level == Debug 丢弃也未必等同于你想要的策略:你在 ReportException 里会把 Info/Warning 也送过去;但 LogService 现在对“任何带 Exception 的日志”都会调用上报,因此 Sentry 可能被 Warning/Info 异常大量污染。
|
对了,我觉得我有必要再解释一下昨天那个回复: 我就说这么多 |
|
@sourcery-ai review |
Reviewer's Guide集成 Sentry 作为遥测后端,将异常上报接入日志管线,在启用遥测且配置了 将日志中的异常上报到 Sentry 遥测的时序图sequenceDiagram
participant Caller
participant LogService
participant TelemetryService
participant SentrySdk
Caller->>LogService: Log(level, message, module, ex)
LogService->>LogService: _OnWrapperLog(level, msg, module, ex)
LogService->>LogService: Compose formatted log line
alt Exception_present
LogService->>TelemetryService: ReportException(ex, plainMessage, level)
TelemetryService->>TelemetryService: Create SentryEvent(ex)
TelemetryService->>TelemetryService: Map LogLevel to SentryLevel
TelemetryService->>TelemetryService: Attach message to SentryEvent
TelemetryService->>SentrySdk: CaptureEvent(sentryEvent)
end
LogService->>LogService: _LogAction(level, actionLevel, formatted, plain, ex)
LogService-->>Caller: Log completed
通过 Sentry 在启动时上报遥测环境的时序图sequenceDiagram
participant App
participant TelemetryService
participant SentrySdk
App->>TelemetryService: _StartAsync()
TelemetryService->>TelemetryService: Check Config.System.Telemetry
alt Telemetry_enabled
TelemetryService->>TelemetryService: _InitSentry()
TelemetryService->>SentrySdk: Init(options)
TelemetryService->>TelemetryService: Collect TelemetryDeviceEnvironment
TelemetryService->>TelemetryService: _ReportDeviceEnvironment(telemetry)
TelemetryService->>SentrySdk: ConfigureScope(scope)
TelemetryService->>SentrySdk: CaptureMessage("设备环境调查")
else Telemetry_disabled
TelemetryService-->>App: Return without telemetry
end
App->>TelemetryService: _StopAsync() on shutdown
TelemetryService->>SentrySdk: Close()
更新后的 TelemetryService 和 LogService 遥测集成类图classDiagram
class TelemetryService {
<<sealed>>
+_InitSentry() void
+ReportException(ex Exception, plain string, level LogLevel?) void
+_ReportDeviceEnvironment(content TelemetryDeviceEnvironment) void
+_StartAsync() Task
+_StopAsync() void
}
class TelemetryDeviceEnvironment {
+LauncherVersion string
+LauncherId string
+OsVersion string
+OsArchitecture string
+MemorySize string
+NatType string
+NatFilterBehaviour string
+Ipv6Status string
+HasUsedOfficialPcl bool
+HasUsedHmcl bool
+HasUsedBakaXL bool
}
class LogService {
+StartAsync() Task
+StopAsync() Task
+OnLog(item LifecycleLogItem) void
-_LogAction(reportLevel LogLevel, level ActionLevel, formatted string, plain string, ex Exception?) void
-_OnWrapperLog(level LogLevel, msg string, module string, ex Exception?) void
}
class LifecycleLogItem {
+Level LogLevel
+ActionLevel ActionLevel
+Message string
+Exception Exception?
+ComposeMessage() string
}
class LogLevel {
+Fatal
+Error
+Warning
+Info
+Debug
+Trace
+PrintName() string
+DefaultActionLevel() ActionLevel
}
class ActionLevel {
+TraceLog
+InfoLog
+WarningLog
+ErrorLog
}
LogService --> TelemetryService : uses ReportException
LogService --> LifecycleLogItem : consumes
LifecycleLogItem --> LogLevel : has
LifecycleLogItem --> ActionLevel : has
TelemetryService --> TelemetryDeviceEnvironment : reports
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your Experience前往你的 dashboard 可进行以下操作:
Getting HelpOriginal review guide in EnglishReviewer's GuideIntegrates Sentry as the telemetry backend, wiring exception reporting into the logging pipeline and using Sentry to capture both runtime errors and device environment data when telemetry is enabled and SENTRY_DSN is configured. Sequence diagram for logging exceptions reported to Sentry telemetrysequenceDiagram
participant Caller
participant LogService
participant TelemetryService
participant SentrySdk
Caller->>LogService: Log(level, message, module, ex)
LogService->>LogService: _OnWrapperLog(level, msg, module, ex)
LogService->>LogService: Compose formatted log line
alt Exception_present
LogService->>TelemetryService: ReportException(ex, plainMessage, level)
TelemetryService->>TelemetryService: Create SentryEvent(ex)
TelemetryService->>TelemetryService: Map LogLevel to SentryLevel
TelemetryService->>TelemetryService: Attach message to SentryEvent
TelemetryService->>SentrySdk: CaptureEvent(sentryEvent)
end
LogService->>LogService: _LogAction(level, actionLevel, formatted, plain, ex)
LogService-->>Caller: Log completed
Sequence diagram for startup telemetry environment reporting via SentrysequenceDiagram
participant App
participant TelemetryService
participant SentrySdk
App->>TelemetryService: _StartAsync()
TelemetryService->>TelemetryService: Check Config.System.Telemetry
alt Telemetry_enabled
TelemetryService->>TelemetryService: _InitSentry()
TelemetryService->>SentrySdk: Init(options)
TelemetryService->>TelemetryService: Collect TelemetryDeviceEnvironment
TelemetryService->>TelemetryService: _ReportDeviceEnvironment(telemetry)
TelemetryService->>SentrySdk: ConfigureScope(scope)
TelemetryService->>SentrySdk: CaptureMessage("设备环境调查")
else Telemetry_disabled
TelemetryService-->>App: Return without telemetry
end
App->>TelemetryService: _StopAsync() on shutdown
TelemetryService->>SentrySdk: Close()
Class diagram for updated TelemetryService and LogService telemetry integrationclassDiagram
class TelemetryService {
<<sealed>>
+_InitSentry() void
+ReportException(ex Exception, plain string, level LogLevel?) void
+_ReportDeviceEnvironment(content TelemetryDeviceEnvironment) void
+_StartAsync() Task
+_StopAsync() void
}
class TelemetryDeviceEnvironment {
+LauncherVersion string
+LauncherId string
+OsVersion string
+OsArchitecture string
+MemorySize string
+NatType string
+NatFilterBehaviour string
+Ipv6Status string
+HasUsedOfficialPcl bool
+HasUsedHmcl bool
+HasUsedBakaXL bool
}
class LogService {
+StartAsync() Task
+StopAsync() Task
+OnLog(item LifecycleLogItem) void
-_LogAction(reportLevel LogLevel, level ActionLevel, formatted string, plain string, ex Exception?) void
-_OnWrapperLog(level LogLevel, msg string, module string, ex Exception?) void
}
class LifecycleLogItem {
+Level LogLevel
+ActionLevel ActionLevel
+Message string
+Exception Exception?
+ComposeMessage() string
}
class LogLevel {
+Fatal
+Error
+Warning
+Info
+Debug
+Trace
+PrintName() string
+DefaultActionLevel() ActionLevel
}
class ActionLevel {
+TraceLog
+InfoLog
+WarningLog
+ErrorLog
}
LogService --> TelemetryService : uses ReportException
LogService --> LifecycleLogItem : consumes
LifecycleLogItem --> LogLevel : has
LifecycleLogItem --> ActionLevel : has
TelemetryService --> TelemetryDeviceEnvironment : reports
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我在这里给出了一些整体性的反馈:
- 现在每个带有异常的日志条目都会调用
TelemetryService.ReportException,但它有可能在_InitSentry之前(或者在遥测被禁用时)被调用,这可能导致 Sentry 行为异常或抛出错误;建议在遥测关闭 / Sentry 尚未初始化时直接短路返回,以确保在所有配置下日志记录都是安全的。 _InitSentry当前假设SentrySdk.Init一定会成功;将初始化过程包在 try/catch 中并记录失败日志,可以避免 Sentry 配置/网络问题影响应用程序启动。
给 AI 助手的提示
请根据本次代码审查中的评论进行修改:
## 整体评论
- 现在每个带有异常的日志条目都会调用 `TelemetryService.ReportException`,但它有可能在 `_InitSentry` 之前(或者在遥测被禁用时)被调用,这可能导致 Sentry 行为异常或抛出错误;建议在遥测关闭 / Sentry 尚未初始化时直接短路返回,以确保在所有配置下日志记录都是安全的。
- `_InitSentry` 当前假设 `SentrySdk.Init` 一定会成功;将初始化过程包在 try/catch 中并记录失败日志,可以避免 Sentry 配置/网络问题影响应用程序启动。帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的审查。
Original comment in English
Hey - I've left some high level feedback:
TelemetryService.ReportExceptionis now invoked for every log entry with an exception, but it can be called before_InitSentry(or when telemetry is disabled), which may cause Sentry to misbehave or throw; consider short‑circuiting when telemetry is off / Sentry is not initialized so logging remains safe in all configurations._InitSentrycurrently assumesSentrySdk.Initalways succeeds; wrapping the initialization in a try/catch and logging failures would prevent Sentry configuration/network issues from impacting application startup.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- `TelemetryService.ReportException` is now invoked for every log entry with an exception, but it can be called before `_InitSentry` (or when telemetry is disabled), which may cause Sentry to misbehave or throw; consider short‑circuiting when telemetry is off / Sentry is not initialized so logging remains safe in all configurations.
- `_InitSentry` currently assumes `SentrySdk.Init` always succeeds; wrapping the initialization in a try/catch and logging failures would prevent Sentry configuration/network issues from impacting application startup.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| // 错误上报 | ||
| public static void ReportException(Exception ex, string plain, LogLevel? level = null) |
There was a problem hiding this comment.
此方法直接假设 SentrySdk 已初始化完毕,若未初始化时调用则会导致问题
若调用时未初始化,可考虑在 telemetry 启用的情况下记录信息并等待初始化后上报,否则直接丢弃
There was a problem hiding this comment.
Sentry SDK 对这种情况的默认行为就是静默丢弃,不会上报也不会抛出异常。
There was a problem hiding this comment.
不不不,我说的导致问题就是它可能直接忽略不上报,这不符合预期
预期行为应为初始化阶段(running 前)崩掉也会上报,因为我们很多 issue 都是初始化阶段崩掉的
There was a problem hiding this comment.
初始化之前就崩掉的话,遥测服务根本来不及初始化程序就退出了。
如果不改变遥测服务初始化的顺序,即便尝试实现一个队列缓存也没有任何作用,因为它们还没等到遥测服务初始化就因为强制退出被清掉了。
|
先这样吧,再出问题再说,但是你是不是没给 CI 加 secret |
本 PR 对遥测服务与日志服务进行了改动,使用 Sentry 收集启动器上报的环境信息与错误。
在启用遥测后,Sentry 将会自动收集程序启动后出现的错误与环境信息,并将其上报至服务器。程序自行收集的环境信息也会被一并包含在收集到的错误内上报。
需要添加一个新的环境变量:
SENTRY_DSN用于配置 Sentry SDK 使用的后端。在不配置SENTRY_DSN或未勾选启用遥测数据收集设置项的情况下,遥测服务不会上报任何数据。遥测服务现在具有一个新的方法:
ReportException(ex),用于在需要的地方进行调用以上报启动器错误供开发者调查、复现与修复。参见:
Note
这个 PR 和目前所使用的 Sentry 实例配置可能还不是很完善,如果有任何建议欢迎提出,也欢迎直接向
feat/sentry-telemetry分支提交你的更改。Sentry 实例的访问权限请各位开发联系 @Big-Cake-jpg 提供邮箱获取注册邮件。
Summary by Sourcery
集成基于 Sentry 的遥测,用于错误和环境报告,并将其接入现有的日志和遥测生命周期。
新功能:
SENTRY_DSN驱动的 Sentry SDK 初始化,以启用远程错误和遥测上报。TelemetryService.ReportExceptionAPI,并将其挂接到日志管道中,以便将已记录的异常发送到 Sentry。增强:
Original summary in English
Summary by Sourcery
Integrate Sentry-based telemetry for error and environment reporting and wire it into the existing logging and telemetry lifecycle.
New Features:
Enhancements: