Skip to content

Translate Claude Code's telemetry into runs - #2

Merged
ynishi merged 1 commit into
mainfrom
feat/otel-adapter
Nov 9, 2026
Merged

ynishi merged 1 commit into
mainfrom
feat/otel-adapter

Conversation

@ynishi

@ynishi ynishi commented Nov 9, 2026

Copy link
Copy Markdown
Owner

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 a
    request's terms by model. No prices are built in.
  • infra::claude_code: groups records by session.id, orders them
    (event.sequence, else time, else input order), and builds the tree of
    agents from agent_id and parent_agent_id. Claude Code before 2.1.310
    sends 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_run takes each end's harness version from the
    telemetry, else from the caller's context, and refuses when neither has it.
  • What cannot be read or placed (no session, a parent never seen, an unknown
    tool, an unreadable attribute, a name that is not a role key) becomes a
    Note with its reason, and is never guessed.
  • The module doc carries the pipeline, the placement rules and the known
    limits. serde_json is added as a workspace dependency.

Verified

  • just pre-push (branch-check, commit-msg-check, check: fmt, clippy with
    warnings denied, tests, rustdoc with warnings denied, cargo deny): exit 0.
    Tests: 15 unit and 8 integration in retarget, 55 in retarget-core.
  • The fixtures are synthetic, written by hand from Claude Code's published
    description of its events. Every id starts with test-, and a test walks
    them to check they carry no account, user or organisation attribute.

Not covered

  • Not yet checked against a captured session. Whether event.name carries
    a claude_code. prefix is unconfirmed, so both forms are accepted.
  • Nothing links an Agent tool call to the subagent it started; the tree is
    built from the agents' parents.
  • A subagent its user named custom cannot be told from names replaced by
    custom; telling them apart needs a change to the domain.
  • Whether event.sequence restarts when a session is resumed is not
    confirmed.
  • No CLI, no collector server, and no lever writes.

Reviewed by

  • Design: an independent design-review agent and an architecture rule
    checker (both AI agents); the findings are folded into the design.
  • Code: /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.
  • Disclosure: a leak-rule checker (an AI agent) on the commit, against
    PUBLIC_DEVELOPMENT.md.
  • No person has reviewed the code yet.

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.
@ynishi
ynishi merged commit 0c000ef into main Nov 9, 2026
1 check passed
@ynishi
ynishi deleted the feat/otel-adapter branch November 9, 2026 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant