agentprof 默认每次 analyze 都要重新 parse JSONL —— 单 session 还好,跨 30 天几百个 session 就开始肉眼可见地慢。hybrid storage 让 cache 自动接管(dev 默认开),db 子命令族把 sessions 显式持久化到 store,ingest-otlp 让 Claude Code / Codex 的 OTel SDK 直接 push session 进来 —— file-based 之外的第二条数据进入路径。
grep 单文件升级到 SQLite + Prometheus push gateway —— 不再每次扫一遍 JSONL,不再要求 agent 必须先写 events.jsonl 才能被分析;Claude Code 跑着就把 spans 推进来,agentprof 在另一边实时聚合。
3 种数据流模式 — 一眼对照
同一份 session 数据,可以从三条路径进入 agentprof。不是互斥的 —— 大多数用户 cache 默认开 + 偶尔升级到 store + 团队场景上 OTLP。
| 模式 | 数据流 | 命令 |
|---|---|---|
| Cache(默认) | Adapter → SQLite cache(XDG_CACHE_HOME)→ analyze 走 cache | agentprof analyze(隐式 cache 启用) |
| Store(显式持久化) | Adapter → SQLite store(XDG_DATA_HOME) | agentprof db init --storage-path ~/.local/share/agentprof/store.sqlite |
| OTLP push | Claude Code / Codex OTel SDK → gRPC :4317 or HTTP :4318 → agentprof-storage | agentprof ingest-otlp --bind 127.0.0.1:4317 |
👇 三张卡片展开 db 子命令家族 / hybrid 概念(含流程图)/ OTLP 接入:① 为什么 · ② agentprof 怎么做 · ③ 其他选择。
1 agentprof db {init,ingest,stats,prune,vacuum,export} — SQLite 存储管理 点击展开
analyze 慢 —— 30 天窗口里 200 个 session、每个 JSONL 几 MB,重 parse 就是「每次跑都要等几秒」。需要一个持久化层把 parse 结果固化,下次跨 session 查询直接走 SQLite index,毫秒级响应。agentprof db 是 6 个子命令的家族:
init—— 在指定路径建空 store(schema migration 自动跑)ingest—— 批量把 adapter 输出的 sessions 写进 storestats—— 看 store 当前大小 / session 数 / 最早最晚时间prune --since 30d—— 按时间窗口删除老 session(释放空间)vacuum—— SQLiteVACUUM整理碎片export—— 把 store 内容导出成 JSONL(迁移 / 备份)
init。--no-cache)—— 每次重 parse,适合「跑完即弃」的一次性诊断;或者「怀疑 cache 损坏」想强制重读 source-of-truth 的场景。生产 / 长期 trend 场景几乎总是要 store。2 hybrid cache vs store — XDG path + ownership + 何时升级 点击展开
--storage-path)。两者 schema 完全相同,从 cache 升级到 store 不需要数据迁移:重新 analyze --storage-mode store 即可,旧 cache 文件可保留也可删。agentprof db init --storage-path ~/.local/share/agentprof/store.sqlite
agentprof analyze --storage-mode store # 后续命令显式带 --storage-mode store
也可以写进 ~/.config/agentprof/config.toml 一劳永逸:
[storage] mode = "store" path = "~/.local/share/agentprof/store.sqlite"
Cache:$XDG_CACHE_HOME/agentprof/cache.sqlite(默认 ~/.cache/agentprof/,OS 可以随时清,agentprof 容忍丢)Store:$XDG_DATA_HOME/agentprof/store.sqlite(默认 ~/.local/share/agentprof/,用户拥有,agentprof 不主动动)。OTLP receiver 写当前 mode 对应的单一 storage,由
--storage-mode / --storage-path 决定,默认 cache。3 agentprof ingest-otlp — Claude Code / Codex OTel SDK 接入 点击展开
# gRPC(默认,性能最好) agentprof ingest-otlp --bind 127.0.0.1:4317 \ --storage-path ~/.local/share/agentprof/store.sqlite # HTTP/protobuf(防火墙穿透更友好) agentprof ingest-otlp --bind 127.0.0.1:4318 --protocol http \ --storage-path ~/.local/share/agentprof/store.sqlite # 想加 bearer auth(生产建议) agentprof ingest-otlp --bind 0.0.0.0:4317 \ --auth-token-file ~/.config/agentprof/otlp-bearer.txt \ --tls-cert ./server.pem --tls-key ./server.key需要编译时开
otlp feature(拉 workspace dep tonic + prost + axum)。full 默认含。# Bash / zsh(gRPC 默认) export OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4317 export OTEL_EXPORTER_OTLP_PROTOCOL=grpc export OTEL_SERVICE_NAME=claude-code # 可选:bearer auth export OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer $(cat ~/.config/agentprof/otlp-bearer.txt)" # 之后跑 agent,spans 自动 push 到 agentprof claude code "your task"
⚠️ Claude Code 当前 v1.x 通过 OTEL_* 环境变量配 OTLP。如果你跑的是自家 agent / 用了 OTel collector 链路(agent → collector → agentprof),collector 端把 agentprof 作为 exporter:
# otel-collector-config.yaml
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
exporters:
otlp/agentprof:
endpoint: 127.0.0.1:4317
tls:
insecure: true
service:
pipelines:
traces:
receivers: [otlp]
exporters: [otlp/agentprof]session.id 256-byte 上限(防 path injection)。
# 验证 receiver 在线 curl -v http://127.0.0.1:4318/v1/traces -X POST # 期望 415 (no protobuf body) # 看进了多少 session agentprof db stats --storage-path ~/.local/share/agentprof/store.sqlite # 看实时 receiver 日志 RUST_LOG=agentprof_storage::otlp=debug agentprof ingest-otlp ...
典型工作流:从 cache 升级到 store + OTLP
三步走,对应上面三张卡片:
# 1. dev 阶段 — 啥都不做,cache 自动开 agentprof analyze agentprof list --since 7d # 2. 想长期保留 / 跨机器同步 — 显式 store agentprof db init --storage-path ~/.local/share/agentprof/store.sqlite agentprof db ingest --since 30d agentprof db stats # 3. 接 Claude Code / Codex 实时数据 — OTLP receiver agentprof ingest-otlp --bind 127.0.0.1:4317 \ --storage-path ~/.local/share/agentprof/store.sqlite # (另一边 Claude Code 配 OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4317)
结语:用法章节完结
这是「用法」章节的最后一节(6/6)。学完之后你已经能用 agentprof 覆盖:单 session 分析(analyze)、跨 session 聚合(list / aggregate)、浏览器看板(serve)、持久化 + OTLP 接入(本节)。
接下来是 Wiki 章节(8 节),面向想深入原理 + 给项目贡献代码的中阶 / 开发者读者:火焰图算法、ROI 公式、tokenizer 选型、adapter 协议、SQLite schema、OTLP 防御、TUI 渲染、xtask 工具链 —— 每节对应一篇 ADR + 一组 source 链接。
📂 相关源码:
agentprof-storage/db.rs
Db
📂 相关源码:
agentprof-storage/query.rs
query_sessions_since
📂 相关源码:
agentprof-storage/otlp/mod.rs
otlp