Skip to content

refactor: extract telemetry into separate module with enable/disable toggle#130

Merged
qorzj merged 3 commits into
lessweb:mainfrom
Lellansin:dev/extract-telemetry
May 29, 2026
Merged

refactor: extract telemetry into separate module with enable/disable toggle#130
qorzj merged 3 commits into
lessweb:mainfrom
Lellansin:dev/extract-telemetry

Conversation

@Lellansin
Copy link
Copy Markdown
Contributor

变更内容

  • 创建 src/common/telemetry.ts,将 telemetry 上报逻辑从 session.ts 中拆分为独立模块
  • 新增 telemetryEnabled 配置项,支持通过 settings.json 或环境变量控制匿名使用数据上报的开关(默认 true,opt-out)
  • DeepcodingSettings / ResolvedDeepcodingSettings / CreateOpenAIClient 类型中补入 telemetryEnabled 字段
  • 配置解析优先级:系统环境变量 > 项目 env > 项目 settings > 用户 env > 用户 settings > 默认 true
  • session.tsreportNewPrompt() 从 20 行内联代码缩减为 3 行委托调用

背景

当前 telemetry 上报逻辑硬编码在 session.ts 中(URL、超时、请求体),且没有关闭开关。用户无法选择是否参与匿名使用数据上报。

本次改动:

  • 将上报逻辑提取为独立、可测试的模块
  • 提供 telemetryEnabled 开关,用户可随时关闭
  • 上报仅包含匿名机器标识,不涉及对话内容、代码或 API 密钥

关闭方式

// settings.json
{ "telemetryEnabled": false }
# 环境变量
DEEPCODE_TELEMETRY_ENABLED=0 deepcode

文件变更

文件 说明
src/common/telemetry.ts 新增 — 独立 telemetry 模块,导出 reportNewPrompt()
src/settings.ts +12 行 — 类型定义 + 解析链
src/common/openai-client.ts +4 行 — 三处 return 透传 telemetryEnabled
src/tools/executor.ts +1 行 — CreateOpenAIClient 类型补字段
src/session.ts -21/+3 行 — 删除内联代码,委托调用
docs/configuration.md +12 行 — 中文文档
docs/configuration_en.md +12 行 — 英文文档

验证

  • npm run check(typecheck + lint + format)✅
  • npm test(366 tests, 0 fail)✅
  • codex review --base origin/main ✅ — no discrete regression or correctness issue

Lellansin added 3 commits May 28, 2026 22:59
…toggle

- Create src/common/telemetry.ts — standalone reportNewPrompt() with
  configurable enabled flag
- Add telemetryEnabled to settings types and resolution chain
  (DeepcodingSettings, ResolvedDeepcodingSettings, CreateOpenAIClient)
- Resolution priority: system env > project env > project settings >
  user env > user settings > default true (opt-out)
- Configurable via settings.json ("telemetryEnabled": false) or env
  (DEEPCODE_TELEMETRY_ENABLED=0)
- Reduce session.ts by ~20 lines, delegating to shared module
- src/tests/telemetry.test.ts: 6 tests covering enabled flag, missing
  machineId, correct fetch params, error swallowing, custom timeout
- src/tests/settings-and-notify.test.ts: 3 new tests + extended
  precedence test verifying telemetryEnabled resolution chain
@qorzj qorzj merged commit ee82fb1 into lessweb:main May 29, 2026
9 checks passed
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