Repository navigation
feat(otel): attribute Claude usage to the account that sent each request for 0.12.0 - #48
Merged
Merged
Conversation
Token usage still comes from the collector's JSONL reads. The new OTLP/HTTP JSON endpoint records only the account identity of each request, and the ledger rewrites matching usage facts in both arrival orders unless the collector marked the account as model-mapped. The ledger gains request_accounts in a new schema revision. Derived stores stay on the baseline revision so they remain readable by previous releases. Co-Authored-By: Claude Code <noreply@anthropic.com>
Extra profiles read their own CLAUDE_CONFIG_DIR for account, plan and quota data without joining the default login timeline. Usage metadata now records whether the account came from a model mapping or the timeline, and an upgrade marker re-sends facts already pushed so the server can apply request-level OTEL attribution. Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Fastify raises FST_ERR_CTP_BODY_TOO_LARGE before the route handler, and the shared error handler answered 500. OTLP exporters retry 5xx indefinitely, so map the limit error to 413 for both ingest routes. Co-Authored-By: Claude Code <noreply@anthropic.com>
A shell that exports CLAUDE_CONFIG_DIR for the account being registered made that directory look like the default, so the command rejected the intended profile. Compare with ~/.claude instead; registering the collector's own custom default is harmless because the account is then skipped as a duplicate. Co-Authored-By: Claude Code <noreply@anthropic.com>
The ledger moves to the new head while report, lifetime and view-cache databases stay on the baseline, so the smoke check must assert each expected pair instead of one shared revision. Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
生产验收:候选镜像已在 NAS 上线(升级前停服并备份账本,迁移到 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
一台 Mac 上用多个 Claude 订阅账户时,默认账户用
~/.claude,其他账户用各自的CLAUDE_CONFIG_DIR登录,会话目录projects软链接到一处,以便跨账户恢复会话。会话 JSONL 每行没有账户字段,采集器只能按「默认目录当前登录的账户」时间线归属,额外账户的用量会被记到默认账户名下。额外账户的套餐和额度也没有来源。结果
POST /api/otel/v1/logs,用采集器的写入密钥鉴权,接收 Claude Code 的 OpenTelemetry 日志(OTLP/HTTP JSON,可 gzip)。只保存claude_code.api_request中的请求 ID、账户、组织、会话、模型和请求时间,提示词等其他属性即使发来也不保存。request_id把同一请求的用量归到 OTEL 给出的账户,用量先到或映射先到都能对上。归属优先级是「模型映射 > OTEL > 登录时间线」,采集器推送的用量新增metadata.attribution来标明来源,模型映射的不会被覆盖。账户不存在时补一个占位账户,采集器推来的资料优先。claude-profiles,登记额外账户的配置目录,读取各自的账户、套餐(凭据两轮确认,默认账户的 meta 键名不变)、.claude.json额度和状态栏额度。额外账户不进入默认账户的登录时间线。otel-headers,供 Claude Code 的otelHeadersHelper调用,写入密钥不必写进settings.json。request_accounts表,数据库结构版本从a17c9e4b620f升到c4f1a9d7e250。报表、累计和视图缓存库保持在基线版本。升级前要停服务并备份数据目录,先升级服务端,再升级采集器。attribution重发一次(本机约 10.9 万条),之后照常增量推送。验证
新增测试覆盖了鉴权和格式错误(401、415、400、413)、gzip、只保存规定字段、两种到达顺序、模型映射不被覆盖、
nr:键和 advisor 子事件、占位账户、报表账户分布、旧库迁移,以及额外账户的套餐、额度、时间线隔离和otel-headers。本机端到端:起一个隔离的本地服务端和采集器数据目录,用真实 Claude Code 2.1.301 开启 OTEL 导出,用额外账户(Pro)和默认账户(Team)各跑一次
-p请求,然后让采集器读取这两个会话并推送。服务端两条用量分别归到额外账户和默认账户,额外账户套餐第二轮确认为pro,额度来自它自己的状态栏缓存。未运行:
tests/compose.smoke.ts需要 Docker,已按新的结构版本更新断言。🤖 Generated with Claude Code