# OpenTelemetry、用量指标与反馈

> 配置 OTel 导出、理解事件与指标，并分别管理匿名统计和反馈收集。

- 网址：https://funcoding.ai/agents/codex/configuration/telemetry/
- 核实日期：2026-10-18（命令、配置和价格以官方文档为准）
- 官方来源：[Codex 官方文档：Advanced Configuration](https://learn.chatgpt.com/docs/config-file/config-advanced)

---
OpenTelemetry 导出默认关闭，可用于观察请求、stream、审批和工具结果。它与发往 OpenAI 的匿名用量/健康统计、用户主动反馈是三套独立控制。

## 启用和检查 OTel

```toml
[otel]
environment = "staging"
exporter = "none"
log_user_prompt = false
```

environment 默认 dev。exporter=none 时记录事件但不向 collector 发送。需要导出时按官方支持的 otlp-http 或 otlp-grpc 配置 endpoint、headers 与协议；示例地址需替换为真实 collector，不能仅改字符串就假定采集已工作。

导出器异步批处理，并在关闭时 flush。先执行一个短任务，确认 collector 收到预期 conversation id、CLI version、model 和环境标签，再部署到更多客户端。

## 事件与指标

代表性日志事件包括 codex.conversation_starts、codex.api_request、codex.sse_event、codex.websocket_request、codex.user_prompt、codex.tool_decision 和 codex.tool_result。Prompt 内容默认脱敏，工具结果可能有输出片段，应按实际载荷检查采集范围。

OTel metrics pipeline 启用后，包含 API/stream/tool 的计数与耗时 histogram，例如 codex.api_request.duration_ms 和 codex.tool.call.duration_ms。日志事件和指标可能使用不同名称，不要仅靠近似字符串关联。

## 匿名统计与用户反馈

```toml
[analytics]
enabled = false

[feedback]
enabled = false
```

analytics 开关关闭 Codex CLI 的匿名用量/健康统计，同时关闭 CLI 里自定义的 OTLP metrics 导出器；OTel 日志和 trace 导出不受影响。feedback=false 禁止反馈提交，/feedback 显示禁用信息；它不等于关闭 OTel。

## 输出与治理

hide_agent_reasoning=true 可抑制 reasoning 事件输出，适合减少 CI 日志噪声。日志展示配置不能替代数据采集政策。企业审核还应对照[Analytics 与 Compliance](https://funcoding.ai/agents/codex/administration/governance/)的范围，验证实际动作是否被所选来源覆盖。
