Skip to content

feat(otel): agentmetry otel, and a receiver that works on what Claude Code sends - #203

Merged
blitzcrieg1 merged 1 commit into
masterfrom
feat/otel-ingest-in-package
Oct 2, 2026
Merged

blitzcrieg1 merged 1 commit into
masterfrom
feat/otel-ingest-in-package

Conversation

@blitzcrieg1

Copy link
Copy Markdown
Owner

What

0.9.0 item (a). Moves the OTel receiver from scripts/ into the package as core/audit/otel_ingest.py, adds agentmetry otel, and keeps scripts/otel_receiver.py as a shim with the prototype's flags.

agentmetry otel                  # 127.0.0.1:4318 -> orchestrator
agentmetry otel --print-env      # what to start Claude Code with
agentmetry otel --print-mapping  # mapped / counted / unmapped, and why

AGENTMETRY_OTEL_PORT sets the port, global --port / AGENTMETRY_URL pick the orchestrator, and --keep-command means what AGENTMETRY_LOG_COMMANDS=1 means for hooks. The receiver binds loopback only.

The prototype did not work on real traffic

Claude Code documents success as the string "true"/"false", and tool_input / tool_parameters as JSON strings. The prototype read them as Python values. I replayed its map_record (from master) on a session in the documented format:

prototype this PR
failed pytest -q tool_called / success tool_failed / error
traits on cat ~/.aws/credentials none credential_access
input hashes across 3 different calls 1 (sha256 of {}) 3
credential-exfil did not fire fires, critical

The [Unreleased] entry said it fired end to end, which was true only of test payloads shaped the way the code expected. The prototype was never released, so the entry is rewritten rather than given a "Fixed" line.

Same code as the hook path, not a copy

Each event goes through the hook client's _hash_tool_args and post_ingest. Enrichment is identical by construction, and an event the orchestrator can't take spools for the boot drain instead of being lost. test_an_event_matches_the_hook_path_for_the_same_call checks that one Bash call gives the same qualified, server, input_hash, traits, mitre and correlation on both paths.

tool_decision: only what the trail can say truthfully

  • A person's yes (user_temporary, user_permanent) becomes approval_response / success with a human initiator. No hook can report this.
  • A config or hook decision is not a human approval. It is counted. Recording it as success would reset the unapproved-write gate on a decision nobody made.
  • A person's no is counted, not forwarded. approval-denied-then-executed binds a denial to the later call by argument hash, else command, else tool name. This event carries no arguments, so it would bind by name and flag every later Bash call as critical. That is the false positive 0.7.0 removed. Binding on tool_use_id is a rule change, so it waits for the freeze to end.

mcp_server_connection has no documented fingerprint, so in practice it is counted. The 23 documented unmapped types are still counted by name, and undocumented ones are counted separately. Prompts, responses and error text are never forwarded. A protobuf export gets a 415 naming http/json, and gzip is accepted.

Verification

  • pytest -q: 1343 passed, 1 skipped (33 new in test_otel_ingest.py)
  • ruff check agentmetry tests: clean
  • benchmark: all cases behaved as recorded
  • ruleset fingerprint: 15846a0915769d4a, unchanged. No frozen file touched.
  • Live run, not a mock: isolated orchestrator on :8010 with temp stores and a temp HOME, the real agentmetry otel CLI on :4399, fixture POSTed over HTTP. Forwarded 4, counted 6 by name, credential-exfil critical on the session. The orchestrator's boot hook install landed in the temp home, and the live configs were untouched.

Docs

README section rewritten (and its four em-dashes gone), CLI reference row added, scripts table row updated. It now says to use one path or the other per Claude Code install, because running both records every tool call twice.

🤖 Generated with Claude Code

… Code sends

The OTel receiver moves from scripts/ into the package as
core/audit/otel_ingest.py, behind `agentmetry otel`. scripts/otel_receiver.py
becomes a shim that keeps the prototype's flags.

The prototype never worked on the stream Claude Code actually exports. Claude
Code documents `success` as the string "true"/"false" and tool_input and
tool_parameters as JSON strings. The prototype read them as Python values, so
bool("false") recorded every failed call as a success, no call was ever
enriched (no traits, no MITRE), and every call carried sha256({}) as its hash.
Replayed on a session in the documented format it fired nothing. The
CHANGELOG said credential-exfil fired end to end; that was true only of test
payloads shaped the way the code expected. The prototype was never released.

Each event now goes through the hook client's own _hash_tool_args and
post_ingest, so enrichment is the same code rather than a copy, and an
undeliverable event spools instead of being lost. A test checks one Bash call
yields identical tool fields on both paths.

tool_decision is mapped only where the trail can say something true. A
person's yes becomes an approval_response. A config or hook decision is not a
human approval and is counted. A person's no is counted, not forwarded: the
denied-then-executed rule binds by argument hash, the event carries no
arguments, and a name-only binding is the false positive 0.7.0 removed.
Binding on tool_use_id is a rule change and waits for the freeze.

The 23 documented unmapped types are still counted by name. Ruleset
fingerprint unchanged (15846a0915769d4a). Verified live on :8010 with a temp
HOME: credential-exfil fires as critical through the CLI path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@blitzcrieg1
blitzcrieg1 merged commit 574cf9d into master Oct 2, 2026
10 checks passed
@blitzcrieg1
blitzcrieg1 deleted the feat/otel-ingest-in-package branch October 2, 2026 14:54
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant