﻿---
title: "otel 只写用户 config；header 里的环境变量不会展开"
summary: "项目 .codex 里的 otel 会被忽略。metrics_exporter 默认 statsig。OTLP/HTTP 要写带 /v1/logs 的完整路径。"
category: config
level: advanced
surfaces: [cli]
tags: ["otel", "遥测", "config.toml"]
canonical: /tips/otel-user-config/
---

# otel 只写用户 config；header 里的环境变量不会展开

项目 .codex 里的 otel 会被忽略。metrics_exporter 默认 statsig。OTLP/HTTP 要写带 /v1/logs 的完整路径。

遥测路由是机器本地键，必须放 `~/.codex/config.toml`。写进仓库 `.codex/config.toml` 会被忽略。

```toml
[otel]
environment = "dev"
log_user_prompt = false
metrics_exporter = "none"

[otel.exporter.otlp-http]
endpoint = "http://127.0.0.1:4318/v1/logs"
protocol = "binary"

[otel.trace_exporter.otlp-http]
endpoint = "http://127.0.0.1:4318/v1/traces"
protocol = "binary"
```

`exporter` 管日志，`trace_exporter` 管追踪，`metrics_exporter` 管指标，三套独立。不写 metrics 时官方默认是 `statsig`，不想外发就把这项设成 `none` 或改成你的 collector。

OTLP/HTTP 的 `endpoint` 要带信号路径（`/v1/logs`、`/v1/traces`、`/v1/metrics`），CLI 不会自动拼接。`log_user_prompt = true` 会把原文提示送进日志，默认关着。

`headers` 是静态字符串。写成 `Bearer ${OTLP_TOKEN}` 会把美元括号原样发出去，不是环境变量插值。令牌用 collector 侧的本地配置，或本机固定头，不要指望 TOML 替你展开。

一次性覆盖：

```bash
codex -c otel.metrics_exporter=none
```


## 来源

- [OpenAI · Configuration reference](https://developers.openai.com/codex/config-reference)
- [openai/codex#14465](https://github.com/openai/codex/issues/14465)
