Skip to content

feat: 转发 log 到 Sentry Structured Logs(含凭据脱敏)#72

Merged
wnzzer merged 2 commits into
mainfrom
feat/sentry-logs
May 29, 2026
Merged

feat: 转发 log 到 Sentry Structured Logs(含凭据脱敏)#72
wnzzer merged 2 commits into
mainfrom
feat/sentry-logs

Conversation

@wnzzer
Copy link
Copy Markdown
Owner

@wnzzer wnzzer commented May 29, 2026

Summary

  • 开启 sentry 的 log + logs feature;用 SentryLogger::with_dest(env_logger) 包住控制台 logger,把所有 log 记录在打印到控制台的同时转发为 Sentry Structured LogsLogFilter::Log,全级别含 info)。
  • 仅在错误上报开启时启用(复用 errorReportingEnabled:release 默认关 / debug 开),关闭时行为同从前(只走控制台)。
  • 安全脱敏ClientOptions.before_send_log = scrub_log,对日志正文 bodyredact_pii;扩展 redact_pii 字段名表,新增覆盖 LCU 命令行的 *-auth-token--remoting-auth-token / --riotclient-auth-token)及 password / secret / authorization / access_token,避免会话令牌 / puuid / 召唤师名随 info 日志外传。

Test plan

  • cargo check 通过(sentry 0.42 log/logs feature 编译)
  • cargo fmt --check + cargo clippy --all-targets --all-features -Dwarnings 通过
  • cargo test:observability 9 passed,含新增 should_redact_lcu_auth_tokens
  • 端到端投递:受国服网络限制(DSN 指向 ingest.us.sentry.io,代码已注明常不可达),实际送达 Sentry Logs 需在可达网络/代理下验证

注意

  • 错误日志(log::error!)现作为 Log(level=error)进入 Sentry Logs,而非 Issues 事件;真实 panic 仍经 panic 集成进 Issues。

开启 sentry 的 log/logs feature,用 SentryLogger 包住 env_logger:所有 log
记录在打印控制台的同时转发为 Sentry Structured Logs(全级别 → Log),仅在错误
上报开启时生效(复用 errorReportingEnabled,release 默认关 / debug 开)。

安全:日志正文经 before_send_log(scrub_log) 脱敏后再发;扩展 redact_pii 覆盖
LCU 命令行里的 *-auth-token 及 password/secret/authorization/access_token,
避免 LCU 会话令牌、puuid、召唤师名随 info 级日志外传。
Copilot AI review requested due to automatic review settings May 29, 2026 16:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds forwarding of Rust log records to Sentry Structured Logs when error reporting is enabled, while extending observability redaction to reduce the risk of sending LCU/session identifiers and player PII.

Changes:

  • Enables Sentry log/logs features and adds before_send_log redaction.
  • Wraps the console logger with SentryLogger when reporting is enabled.
  • Expands PII/credential redaction tests for LCU auth token command-line arguments.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
lol-record-analysis-tauri/src-tauri/src/observability.rs Enables Sentry Logs and adds log-body scrubbing plus expanded credential redaction.
lol-record-analysis-tauri/src-tauri/src/main.rs Installs either plain console logging or Sentry-forwarding logging based on reporting settings.
lol-record-analysis-tauri/src-tauri/Cargo.toml Enables Sentry logging-related crate features.
lol-record-analysis-tauri/src-tauri/Cargo.lock Adds the resolved sentry-log dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

static PII_PARAM_RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(
r#"(?i)("?\b(?:game_?name|tag_?line|summoner_?name|display_?name|riot_?id|puuid|account|name)"?\s*[:=]\s*"?)([^"&,\s}\])]+)"#,
r#"(?i)("?\b(?:game_?name|tag_?line|summoner_?name|display_?name|riot_?id|puuid|account|name|auth_?token|access_?token|token|password|secret|authorization)"?\s*[:=]\s*"?)([^"&,\s}\])]+)"#,
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复(525f44f):从通用 PII 正则移除 authorization,新增 AUTH_HEADER_RE,值类允许空格,把 "Scheme token"(Bearer/Basic )整体脱敏,不再只洗 scheme 漏 token。补了 Bearer 与 LCU Basic 两个测试。

Copilot review(#72):原 PII_PARAM_RE 的值类遇空格即停,对 "Authorization: Bearer xxx"
只会把 Bearer 换成 <redacted> 而漏掉 token。改为:从通用正则移除 authorization,
新增 AUTH_HEADER_RE(值类允许空格)把 scheme+token 整体脱敏;补 Bearer/Basic 测试。
@wnzzer wnzzer merged commit 78eea2a into main May 29, 2026
3 checks passed
@wnzzer wnzzer deleted the feat/sentry-logs branch May 29, 2026 17:17
@wnzzer wnzzer restored the feat/sentry-logs branch May 29, 2026 17:17
@wnzzer wnzzer deleted the feat/sentry-logs branch May 30, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants