opencode接入
更新时间:2026-08-07
接入流程
步骤1:获取接入点与 Token
- 接入点:
http://apm-collector.bj.baidubce.com - Authentication:
UFSpMM***lnFrVBqtPDK
步骤2. 安装 opencode
1.1 推荐:通过 Homebrew Tap 安装
Bash
1brew install anomalyco/tap/opencode
安装完验证:
Bash
1opencode --version
2# 期望输出类似: 1.17.13
3which opencode
4# 期望: /opt/homebrew/bin/opencode (M-chip) 或 /usr/local/bin/opencode (Intel)
1.2 备选:官方安装脚本
如果 brew 不方便:
Bash
1# 直接从 opencode.ai 拉取安装
2curl -fsSL https://opencode.ai/install | bash
⚠️ 注意:这个脚本会从 GitHub API 拉取最新版本号,若你的公网出口 IP 被 GitHub API 匿名限流会失败(Failed to fetch version information)。这种情况优先用 brew,或者:
Bash
1# 指定版本号跳过 GitHub API 探测
2curl -fsSL https://opencode.ai/install | bash -s -- --version 1.17.13
步骤3. 安装 OTel 上报插件
opencode 本身不带 OTLP 上报能力,需要装社区插件 @devtheops/opencode-plugin-otel。
2.1 配置插件
编辑 / 新建 ~/.config/opencode/opencode.json:
JSON
1{
2 "$schema": "https://opencode.ai/config.json",
3 "plugin": ["@devtheops/opencode-plugin-otel"]
4}
2.2 安装插件包
Bash
1mkdir -p ~/.config/opencode
2cd ~/.config/opencode
3npm install @devtheops/opencode-plugin-otel --save
装完检查:
Bash
1ls ~/.config/opencode/node_modules/@devtheops/opencode-plugin-otel/dist/
2# 期望能看到 index.js 等文件
不要用
opencode plugin @devtheops/opencode-plugin-otel这个自带命令:实测它会声称"Installed"但不会真的把包放进node_modules(可能是 opencode 本身的 bug),一定要用npm install --save。
步骤4. 配置上报参数
编辑 ~/.zshrc(bash 用户改 ~/.bashrc),在文件末尾追加:
Bash
1# --- opencode OpenTelemetry 上报配置 ---
2export OPENCODE_ENABLE_TELEMETRY=1
3export OPENCODE_OTLP_ENDPOINT="http://<apm-collector-host>"
4export OPENCODE_OTLP_PROTOCOL="http/protobuf"
5export OPENCODE_OTLP_HEADERS="Authentication=<你的 APM Token>"
6export OPENCODE_RESOURCE_ATTRIBUTES="service.name=<你的英文名>"
7export OPENCODE_DISABLE_LOGS=1 //禁用log上报
8# --- end ---
步骤5. 验证opencode
JSON
1opencode run "say ok"
步骤6. 验证数据
然后到 云监控BCM->LLM应用性能监控 搜索 service.name = <你设置的应用名> 查看 Trace 数据。由于数据的处理存在一定延时,如果接入后在控制台没有查询到应用,请等待 30 秒左右。
评价此篇文章
