Repository navigation
Translate Claude Code's telemetry into runs - #2
Merged
Merged
Conversation
The domain's runs had no way in from a real harness. Claude Code can send OpenTelemetry events as OTLP/JSON logs, and those events, not its metrics, carry each request's cost, its split by cache lifetime and the agent that made it. This adds the adapters that turn them into runs. - otlp: reads the OTLP/JSON encoding of logs into flat records. It is the encoding only, so another harness that sends it can share it. - price: a price table the caller passes in, to price a request's terms by model. No prices are built in: they change, and the product's tuned data does not live in this tree. - claude_code: groups records by session and orders them, then builds the tree of agents from agent_id and parent_agent_id. Older harnesses send neither, so their subagents are grouped by agent type instead. A request keeps the cost the harness reported and has its terms priced when the model is in the table. What cannot be read or placed (a record without a session, a parent never seen, a tool call whose success is unknown) is recorded as a note and left out, not guessed. into_run takes the harness version from the telemetry when it is sent, else from the caller's context. The reading follows Claude Code's published description of its events and is checked against hand-written records, not yet a captured session; the module doc says so. The fixtures are synthetic, with test- ids, and a test walks them to check they carry no identifying data. serde_json is added as a workspace dependency, and thiserror is now used by the umbrella crate.
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.
What changed
The domain's runs get their first way in from a real harness: Claude Code's
OpenTelemetry events, sent as OTLP/JSON logs, become sessions and then runs.
The events are read rather than the metrics because only they carry each
request's cost, its split by cache lifetime and the agent that made it.
infra::otlp: reads the OTLP/JSON encoding of logs into flat records,each with its resource's attributes under its own. It knows the encoding
and nothing of any harness.
infra::price: a price table the caller passes in, to price arequest's terms by model. No prices are built in.
infra::claude_code: groups records bysession.id, orders them(
event.sequence, else time, else input order), and builds the tree ofagents from
agent_idandparent_agent_id. Claude Code before 2.1.310sends neither, so its subagents are grouped by agent type. A request keeps
the cost the harness reported and has its terms priced when its model is
in the table.
into_runtakes each end's harness version from thetelemetry, else from the caller's context, and refuses when neither has it.
tool, an unreadable attribute, a name that is not a role key) becomes a
Notewith its reason, and is never guessed.limits.
serde_jsonis added as a workspace dependency.Verified
just pre-push(branch-check, commit-msg-check, check: fmt, clippy withwarnings denied, tests, rustdoc with warnings denied,
cargo deny): exit 0.Tests: 15 unit and 8 integration in
retarget, 55 inretarget-core.description of its events. Every id starts with
test-, and a test walksthem to check they carry no account, user or organisation attribute.
Not covered
event.namecarriesa
claude_code.prefix is unconfirmed, so both forms are accepted.built from the agents' parents.
customcannot be told from names replaced bycustom; telling them apart needs a change to the domain.event.sequencerestarts when a session is resumed is notconfirmed.
Reviewed by
checker (both AI agents); the findings are folded into the design.
/code-review(an AI agent); eight of its ten findings are fixed,and the two left are listed above or are a refactor. The architecture rule
checker re-ran on the code with no violations.
PUBLIC_DEVELOPMENT.md.