Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"name": "claude-code-tracing",
"source": "./tracing/claude_code",
"description": "Automatic tracing of Claude Code sessions to Arize AX or Phoenix with OpenInference spans",
"version": "1.0.1",
"version": "1.1.0",
"homepage": "https://arize.com",
"repository": "https://github.com/Arize-ai/coding-harness-tracing",
"license": "MIT",
"repository": "https://github.com/lifldev/coding-harness-tracing",
"license": "Apache-2.0",
"keywords": [
"tracing",
"agents",
Expand Down
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
# Arize Coding Harness Tracing

Maintained fork of [Arize Coding Harness Tracing](https://github.com/Arize-ai/coding-harness-tracing)
for Claude Code and Codex sessions in Phoenix. Upstream attribution and the
Apache-2.0 license are retained. Install and update commands below use this fork.

Fork maintenance:

- Keep Claude and Codex response, tool, token and subagent reconstruction covered
by synthetic regression fixtures. Never commit private session transcripts.
- Validate parser changes against saved session records without making model calls.
- Deploy a reviewed commit from a detached worktree and point runtime consumers at
that worktree. Preserve configuration, state, logs and a rollback environment.
- GitHub Actions is disabled on this public fork. Owner-hosted runners must remain
private-only; run tests locally before publishing until an approved CI placement
is configured. Do not enable upstream paid triage automation.

Trace AI coding sessions to [Arize AX](https://arize.com) or [Phoenix](https://github.com/Arize-ai/phoenix) with [OpenInference](https://github.com/Arize-ai/openinference) spans. Each harness integration emits spans for prompts, tool calls, model responses, and session lifecycle events.

Claude Code tracing reconstructs each turn as a `CHAIN` containing per-response `LLM` spans, correlated `TOOL` spans, and a foreground subagent `AGENT` subtree when available. See [Claude Code trace structure and current limitations](tracing/claude_code/README.md#trace-structure) for details.
Claude Code tracing reconstructs each turn as a `CHAIN` with per-response `LLM` spans, correlated `TOOL` spans, and nested foreground or background `AGENT` subtrees when their transcripts are available. See [Claude Code trace structure and limitations](tracing/claude_code/README.md#trace-structure).

Codex tracing reconstructs saved rollout records as a `CHAIN` with per-response `LLM` spans and `TOOL` spans. Code Mode `exec` containers include structured command executions when Codex persists them; model usage is counted once per response. See [Codex trace structure and limitations](tracing/codex/README.md).

## Quick Start

Expand All @@ -11,15 +28,15 @@ You need Python 3.9+ and the harness you want to trace. The commands below are t
### Claude Code

```bash
curl -sSL https://raw.githubusercontent.com/Arize-ai/coding-harness-tracing/main/install.sh | bash -s -- claude
curl -sSL https://raw.githubusercontent.com/lifldev/coding-harness-tracing/main/install.sh | bash -s -- claude
```

The installer registers hooks in `~/.claude/settings.json`. Start a session with `claude`, or `claude -p "hello"`. Spans for that session show up in the project you chose.

To install from the Claude marketplace instead:

```bash
claude plugin marketplace add Arize-ai/coding-harness-tracing
claude plugin marketplace add lifldev/coding-harness-tracing
claude plugin install claude-code-tracing@coding-harness-tracing
```

Expand All @@ -28,10 +45,10 @@ That path skips the wizard, so set backend credentials in `~/.claude/settings.js
### Codex

```bash
curl -sSL https://raw.githubusercontent.com/Arize-ai/coding-harness-tracing/main/install.sh | bash -s -- codex
curl -sSL https://raw.githubusercontent.com/lifldev/coding-harness-tracing/main/install.sh | bash -s -- codex
```

The installer registers hooks in `~/.codex/config.toml`. Codex will not run them until you trust them once: start `codex`, run `/hooks`, and approve each `arize-hook-codex-*` entry. Then run a session, for example:
The installer registers a completion `notify` command in `~/.codex/config.toml`. At the end of each turn, it reconstructs the trace from the local Codex rollout. Then run a session, for example:

```bash
codex exec "explain what this file does" path/to/file.py
Expand All @@ -40,15 +57,15 @@ codex exec "explain what this file does" path/to/file.py
### Cursor

```bash
curl -sSL https://raw.githubusercontent.com/Arize-ai/coding-harness-tracing/main/install.sh | bash -s -- cursor
curl -sSL https://raw.githubusercontent.com/lifldev/coding-harness-tracing/main/install.sh | bash -s -- cursor
```

The installer registers hooks in `~/.cursor/hooks.json`, which applies to the Cursor IDE and the Cursor CLI for your user. Use either as usual; agent activity produces spans in the project you chose.

Cursor 2.5+ can install from the marketplace instead. In a Cursor agent chat, run:

```text
/add-plugin Arize-ai/coding-harness-tracing
/add-plugin lifldev/coding-harness-tracing
```

The plugin skips the wizard. Run the bundled `manage-cursor-tracing` skill once to write credentials. See [Cursor plugin install](tracing/cursor/README.md#plugin-install).
Expand Down
41 changes: 28 additions & 13 deletions core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,21 +644,36 @@ def _inject_openinference_project_resource_attr(span_dict: dict, project_name: s


def _post_otlp(url: str, body: bytes, headers: dict, label: str) -> bool:
"""POST an encoded OTLP payload, logging failures. Returns True on 2xx."""
"""POST one payload with bounded retries for transient transport failures."""
req = urllib.request.Request(url, data=body, headers=headers, method="POST")
try:
with urllib.request.urlopen(req, timeout=10) as resp:
return 200 <= resp.status < 300
except urllib.error.HTTPError as e:
if not req.has_header("User-agent"):
req.add_header("User-Agent", "LiFl-Coding-Harness-Tracing/1.0")
for attempt in range(3):
try:
detail = e.read().decode("utf-8", errors="replace")
except Exception:
detail = ""
error(f"{label} send failed: HTTP {e.code}: {detail or e.reason}")
return False
except Exception as e:
error(f"{label} send failed: {e}")
return False
with urllib.request.urlopen(req, timeout=10) as resp:
return 200 <= resp.status < 300
except urllib.error.HTTPError as e:
try:
detail = e.read(8192).decode("utf-8", errors="replace")
except Exception:
detail = ""
finally:
e.close()
message = f"HTTP {e.code}: {detail or e.reason}"
retryable = e.code in (429, 502, 503, 504)
except (urllib.error.URLError, TimeoutError, ConnectionError) as e:
message = str(e)
retryable = True
except Exception as e:
message = str(e)
retryable = False
if not retryable or attempt == 2:
error(f"{label} send failed: {message}")
return False
# Reuse the encoded payload and IDs if the collector accepted a request
# whose acknowledgement was lost, so it can deduplicate the retry.
time.sleep(0.25 * (2**attempt))
return False


def _extract_span_name(span_dict: dict) -> str:
Expand Down
6 changes: 3 additions & 3 deletions install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ REM install.bat uninstall [harness]
REM install.bat update

REM --- Constants ---
set "REPO_URL=https://github.com/Arize-ai/coding-harness-tracing.git"
set "REPO_URL=https://github.com/lifldev/coding-harness-tracing.git"
if not defined ARIZE_INSTALL_BRANCH set "ARIZE_INSTALL_BRANCH=main"
set "INSTALL_BRANCH=%ARIZE_INSTALL_BRANCH%"
set "TARBALL_URL=https://github.com/Arize-ai/coding-harness-tracing/archive/refs/heads/%INSTALL_BRANCH%.tar.gz"
set "TARBALL_URL=https://github.com/lifldev/coding-harness-tracing/archive/refs/heads/%INSTALL_BRANCH%.tar.gz"
set "INSTALL_DIR=%USERPROFILE%\.arize\harness"
set "VENV_DIR=%INSTALL_DIR%\venv"
set "VENV_PYTHON=%VENV_DIR%\Scripts\python.exe"
Expand Down Expand Up @@ -41,7 +41,7 @@ if /i "%~1"=="--wheel-dir" (
if not exist "%~2\coding_harness_tracing-*.whl" ( echo [arize] No coding_harness_tracing-*.whl in %~2 >&2 & exit /b 1 )
shift & shift & goto :parse_args
)
if /i "%~1"=="--branch" ( set "INSTALL_BRANCH=%~2" & set "TARBALL_URL=https://github.com/Arize-ai/coding-harness-tracing/archive/refs/heads/%~2.tar.gz" & shift & shift & goto :parse_args )
if /i "%~1"=="--branch" ( set "INSTALL_BRANCH=%~2" & set "TARBALL_URL=https://github.com/lifldev/coding-harness-tracing/archive/refs/heads/%~2.tar.gz" & shift & shift & goto :parse_args )

for %%C in (claude codex copilot cursor gemini kiro antigravity opencode omp devin) do if /i "%~1"=="%%C" ( set "COMMAND=%%C" & shift & goto :parse_args )
if /i "%~1"=="update" ( set "COMMAND=update" & shift & goto :parse_args )
Expand Down
6 changes: 3 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

set -euo pipefail

REPO_URL="https://github.com/Arize-ai/coding-harness-tracing.git"
REPO_URL="https://github.com/lifldev/coding-harness-tracing.git"
INSTALL_BRANCH="${ARIZE_INSTALL_BRANCH:-main}"
TARBALL_URL="https://github.com/Arize-ai/coding-harness-tracing/archive/refs/heads/${INSTALL_BRANCH}.tar.gz"
TARBALL_URL="https://github.com/lifldev/coding-harness-tracing/archive/refs/heads/${INSTALL_BRANCH}.tar.gz"
INSTALL_DIR="${HOME}/.arize/harness"
VENV_DIR="${INSTALL_DIR}/venv"
# When set, install from local wheels in this directory instead of fetching the
Expand Down Expand Up @@ -343,7 +343,7 @@ main() {
--branch)
i=$((i + 1))
INSTALL_BRANCH="${args[$i]:-main}"
TARBALL_URL="https://github.com/Arize-ai/coding-harness-tracing/archive/refs/heads/${INSTALL_BRANCH}.tar.gz"
TARBALL_URL="https://github.com/lifldev/coding-harness-tracing/archive/refs/heads/${INSTALL_BRANCH}.tar.gz"
;;
--wheel-dir)
i=$((i + 1))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "coding-harness-tracing"
version = "0.1.0"
version = "0.1.1+lifl.1"
requires-python = ">=3.9"
# python-dotenv parses the credential file for non-interactive installs. It is
# the only runtime dependency; keep it that way. Imported by core/setup alone,
Expand Down
53 changes: 53 additions & 0 deletions tests/core/test_otlp_delivery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import io
import urllib.error
from unittest import mock

import pytest

from core.common import _post_otlp


def _response():
response = mock.MagicMock()
response.status = 200
response.__enter__.return_value = response
return response


def test_sender_identifies_itself_without_mutating_caller_headers():
headers = {"Content-Type": "application/x-protobuf"}
with mock.patch("core.common.urllib.request.urlopen", return_value=_response()) as send:
assert _post_otlp("https://collector.example/v1/traces", b"payload", headers, "Phoenix")
assert send.call_args.args[0].get_header("User-agent") == "LiFl-Coding-Harness-Tracing/1.0"
assert headers == {"Content-Type": "application/x-protobuf"}


@pytest.mark.parametrize("status", [429, 502, 503, 504])
def test_transient_rejection_retries_the_same_payload(status):
rejection = urllib.error.HTTPError("https://collector.example", status, "Retry", {}, io.BytesIO(b"busy"))
with mock.patch("core.common.urllib.request.urlopen", side_effect=[rejection, _response()]) as send:
with mock.patch("core.common.time.sleep") as sleep:
assert _post_otlp("https://collector.example/v1/traces", b"payload", {}, "Phoenix")
assert send.call_count == 2
assert all(call.args[0].data == b"payload" for call in send.call_args_list)
sleep.assert_called_once()


def test_auth_rejection_is_not_retried(capsys):
rejection = urllib.error.HTTPError(
"https://collector.example", 403, "Forbidden", {}, io.BytesIO(b"error code: 1010")
)
with mock.patch("core.common.urllib.request.urlopen", side_effect=rejection) as send:
with mock.patch("core.common.time.sleep") as sleep:
assert not _post_otlp("https://collector.example/v1/traces", b"payload", {}, "Phoenix")
send.assert_called_once()
sleep.assert_not_called()
assert "1010" in capsys.readouterr().err


def test_connection_failure_has_bounded_retries():
with mock.patch("core.common.urllib.request.urlopen", side_effect=urllib.error.URLError("offline")) as send:
with mock.patch("core.common.time.sleep") as sleep:
assert not _post_otlp("https://collector.example/v1/traces", b"payload", {}, "Phoenix")
assert send.call_count == 3
assert sleep.call_count == 2
2 changes: 1 addition & 1 deletion tests/core/test_shell_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def _load(self):
self.text = _read_install_sh()

def test_repo_url(self):
assert "https://github.com/Arize-ai/coding-harness-tracing.git" in self.text
assert "https://github.com/lifldev/coding-harness-tracing.git" in self.text

def test_install_dir(self):
assert "${HOME}/.arize/harness" in self.text
Expand Down
4 changes: 4 additions & 0 deletions tests/tracing/claude/fixtures/async_subagent_main.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"parentUuid":null,"isSidechain":false,"promptId":"prompt-async-1","type":"user","message":{"role":"user","content":"Delegate one read-only subagent in the background to inspect hello.py."},"uuid":"user-async-main-1","timestamp":"2026-01-01T13:00:00.000Z","cwd":"/synthetic/project","sessionId":"session-async-1","version":"2.1.301"}
{"parentUuid":"user-async-main-1","isSidechain":false,"message":{"id":"message-async-main-1","type":"message","role":"assistant","model":"qwen3-coder-next","content":[{"type":"tool_use","id":"tool-async-1","name":"Agent","input":{"description":"Inspect hello.py","prompt":"Read hello.py and report the function and returned string.","subagent_type":"synthetic-explorer","run_in_background":true}}],"usage":{"input_tokens":200,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":30},"stop_reason":"tool_use"},"type":"assistant","uuid":"assistant-async-main-1","timestamp":"2026-01-01T13:00:01.000Z","cwd":"/synthetic/project","sessionId":"session-async-1","version":"2.1.301"}
{"parentUuid":"assistant-async-main-1","isSidechain":false,"promptId":"prompt-async-1","type":"user","message":{"role":"user","content":[{"tool_use_id":"tool-async-1","type":"tool_result","content":[{"type":"text","text":"Async agent launched successfully.\nagentId: agent-1"}]}]},"uuid":"result-async-main-1","timestamp":"2026-01-01T13:00:01.500Z","toolUseResult":{"isAsync":true,"status":"async_launched","agentId":"agent-1","description":"Inspect hello.py","resolvedModel":"qwen3-coder-next","prompt":"Read hello.py and report the function and returned string."},"sourceToolAssistantUUID":"assistant-async-main-1","cwd":"/synthetic/project","sessionId":"session-async-1","version":"2.1.301"}
{"parentUuid":"result-async-main-1","isSidechain":false,"message":{"id":"message-async-main-2","type":"message","role":"assistant","model":"qwen3-coder-next","content":[{"type":"text","text":"LAUNCHED_IN_BACKGROUND"}],"usage":{"input_tokens":220,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5},"stop_reason":"end_turn"},"type":"assistant","uuid":"assistant-async-main-2","timestamp":"2026-01-01T13:00:02.000Z","cwd":"/synthetic/project","sessionId":"session-async-1","version":"2.1.301"}
1 change: 1 addition & 0 deletions tests/tracing/claude/test_claude_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

def test_fixture_set_is_present():
assert {path.name for path in FIXTURES} == {
"async_subagent_main.jsonl",
"main_tool_cycle.jsonl",
"subagent_agent.jsonl",
"subagent_main.jsonl",
Expand Down
Loading