Skip to content

Commit 695fd30

Browse files
Nehanthclaude
andcommitted
docs: add MLflow tracing guide for Claude Code on RHOAI
Documents MLflow autolog integration with Claude Code across Vertex AI, vLLM, and OGX backends. Covers RHAIENG-4751, 4752, 4753, and 4754 — telemetry investigation, tool call tracing prototype, session-level metrics, and RHOAI 3.5 setup guide and recommendation. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 237a0b5 commit 695fd30

7 files changed

Lines changed: 273 additions & 0 deletions

File tree

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
# MLflow Tracing for Claude Code Agent Runtimes on RHOAI
2+
3+
We deployed Claude Code as a containerized agent on Red Hat OpenShift AI and wired it up to the MLflow instance running on the same cluster. To validate the full tracing stack, we ran the same prompt — **"build me a tetris game"** — through three different backends: Vertex AI (Google Cloud), vLLM directly, and OGX routing to vLLM. In all three cases, MLflow captured the complete session trace including every tool call, token usage, latency, and the full execution waterfall. The sections below document the telemetry investigation, the tracing prototype, session-level metrics, and the setup guide for productizing this on RHOAI 3.5.
4+
5+
---
6+
7+
## RHAIENG-4751 — Inventory OGX Telemetry Hooks and MLflow Integration Points
8+
9+
### Summary
10+
11+
Agent-level instrumentation via `mlflow autolog claude` works out of the box with any backend. Swapping Vertex AI for vLLM or OGX produces the same trace schema with no changes to the tracing setup. If server-side OGX OTel spans are needed in future, they would be added to the Claude Code stop hook.
12+
13+
### OGX Telemetry Capabilities
14+
15+
OGX 1.0.2 emits structured logs per request:
16+
17+
```text
18+
INFO Using native /v1/messages passthrough
19+
base_url=http://vllm-120b-predictor.gpt-oss.svc.cluster.local
20+
model=vllm/gpt-oss-120b
21+
HTTP 200
22+
```
23+
24+
| Signal | Available |
25+
|---|---|
26+
| Model name ||
27+
| Backend / provider URL ||
28+
| Passthrough status ||
29+
| HTTP status code ||
30+
| Per-request latency ||
31+
32+
### Agent-side OTel Spans (what we capture today)
33+
34+
The spans produced by `mlflow autolog claude` are OTel spans. Every session captures:
35+
36+
| Field | Example |
37+
|---|---|
38+
| Token count | 29,629 (input + output) |
39+
| Session latency | 39.62s |
40+
| Tool call sequence | tool_AskUserQuestion → llm → tool_Write → tool_Read → ... |
41+
| Prompt / response | Full input and output text |
42+
| Session ID | Links multi-turn conversations |
43+
| Model | `gpt-oss-120b`, `claude-sonnet-4-5-20250929`, etc. |
44+
| Status | OK / error |
45+
46+
This works the same whether the backend is Vertex AI, vLLM directly, or OGX → vLLM. If server-side OGX spans are needed in future, they would be added to the same Claude Code stop hook.
47+
48+
### Integration Path
49+
50+
The Claude Code stop hook is the right integration path. It already captures everything out of the box — tool calls, token usage, latency, session ID — and works the same across Vertex AI, vLLM, and OGX without any changes. If additional server-side metrics are needed (e.g. per-hop vLLM latency, OGX routing decisions), they can be added directly to the same hook since the infrastructure is already there.
51+
52+
### Evidence: Same Traces Across All Three Backends
53+
54+
We ran **"build me a tetris game"** against all three backends. All three produced the same trace schema.
55+
56+
#### Backend 1: Vertex AI
57+
58+
| Field | Value |
59+
|---|---|
60+
| Model | `claude-sonnet-4-5-20250929` |
61+
| Tokens | 18,504 |
62+
| Latency | 2.90 min |
63+
| Trace ID | `tr-c59dcf7c76c26e4d55255a32694a9bb7` |
64+
65+
![Vertex trace](screenshots/vertex-trace.png)
66+
67+
#### Backend 2: vLLM direct
68+
69+
| Field | Value |
70+
|---|---|
71+
| Model | `gpt-oss-120b` |
72+
| Tokens | 46,211 |
73+
| Latency | 37.82s |
74+
| Trace ID | `tr-39a858c94eb86c3be340e23541717fe8` |
75+
76+
![vLLM trace](screenshots/vllm-trace.png)
77+
78+
#### Backend 3: OGX 1.0.2 → vLLM
79+
80+
| Field | Value |
81+
|---|---|
82+
| Model | `gpt-oss-120b` |
83+
| Tokens | 29,629 |
84+
| Latency | 39.62s |
85+
| Trace ID | `tr-26175953d7cb441e3e2da1cc5fc24607` |
86+
87+
![OGX trace](screenshots/ogx-trace.png)
88+
89+
---
90+
91+
## RHAIENG-4752 & RHAIENG-4753 — Tool Call Traces & Agent Execution Metrics
92+
93+
### Summary
94+
95+
**RHAIENG-4752** — We prototyped tool call tracing using `mlflow autolog claude`. Every tool Claude Code calls (Write, Read, Edit, Bash, AskUserQuestion, etc.) is captured as a span in MLflow with the tool name, input parameters, output/result, and latency. Tested across three backends with a real coding task — Vertex AI produced 15 spans, vLLM and OGX produced 8 each. MLflow integration works end-to-end. The stop-hook fires after the session so there is no latency impact.
96+
97+
**RHAIENG-4753** — On top of the tool call spans, each trace also captures higher-level session metrics: session ID, total duration, input/output token counts, and the full tool call sequence as a waterfall. This answers "what did the agent do and how much did it cost?" for any session. Validated with a complete multi-turn coding task ("build me a tetris game") across all three backends.
98+
99+
As you can see in the results below.
100+
101+
### Trace Schema
102+
103+
```text
104+
claude_code_conversation (root)
105+
├── tool_AskUserQuestion — question asked + user answer
106+
├── tool_EnterPlanMode — agent enters planning
107+
├── llm — LLM inference call
108+
├── tool_Bash — command + output
109+
├── tool_Write — file path + content written
110+
├── tool_Read — file path + content read
111+
├── tool_Edit — file path + diff applied
112+
├── tool_ExitPlanMode — exits planning
113+
└── llm — final response
114+
```
115+
116+
Each span captures: tool name, input parameters, output/result, and per-span latency. Session-level fields on every trace:
117+
118+
| Field | Captured |
119+
|---|---|
120+
| Session ID ||
121+
| Total duration ||
122+
| Input tokens ||
123+
| Output tokens ||
124+
| Total tokens ||
125+
| Tool call sequence (waterfall) ||
126+
| Model ||
127+
| Status ||
128+
129+
### Results: "Build me a Tetris game"
130+
131+
#### Backend 1: Vertex AI (`claude-sonnet-4-5-20250929`)
132+
133+
| Metric | Value |
134+
|---|---|
135+
| Session ID | `b679dc2c-...` |
136+
| Tokens | 18,504 |
137+
| Latency | 2.90 min |
138+
| Spans | 15 |
139+
| Trace ID | `tr-c59dcf7c76c26e4d55255a32694a9bb7` |
140+
141+
![Vertex waterfall](screenshots/vertex-summary.png)
142+
143+
---
144+
145+
#### Backend 2: vLLM direct (`gpt-oss-120b`)
146+
147+
| Metric | Value |
148+
|---|---|
149+
| Session ID | `cc76b223-...` |
150+
| Tokens | 46,211 |
151+
| Latency | 37.82s |
152+
| Spans | 8 |
153+
| Trace ID | `tr-39a858c94eb86c3be340e23541717fe8` |
154+
155+
![vLLM waterfall](screenshots/vllm-summary.png)
156+
157+
---
158+
159+
#### Backend 3: OGX 1.0.2 → vLLM (`gpt-oss-120b`)
160+
161+
| Metric | Value |
162+
|---|---|
163+
| Session ID | `980fbcb8-...` |
164+
| Tokens | 29,629 |
165+
| Latency | 39.62s |
166+
| Spans | 8 |
167+
| Trace ID | `tr-26175953d7cb441e3e2da1cc5fc24607` |
168+
169+
![OGX waterfall](screenshots/ogx-summary.png)
170+
171+
---
172+
173+
## RHAIENG-4754 — Observability Setup Guide & RHOAI 3.5 Recommendation
174+
175+
### Summary
176+
177+
MLflow integration works. This guide documents how to hook Claude Code, OGX, and MLflow together on RHOAI — assuming all three are already deployed on the cluster. The setup requires the Red Hat MLflow fork for RHOAI 3.4, which will be replaced by upstream MLflow 3.11 in a future release.
178+
179+
### Prerequisites
180+
181+
The following must already be running on the cluster:
182+
183+
- Claude Code container deployed (see [PR #92](https://github.com/red-hat-data-services/agentic-starter-kits/pull/92))
184+
- OGX deployed and serving a model
185+
- MLflow instance running via the ODH/RHOAI operator with a workspace matching your namespace
186+
187+
### Step-by-Step Setup
188+
189+
#### 1. Add Python + MLflow to the Containerfile
190+
191+
The ODH build of MLflow uses the Red Hat fork which includes the `kubernetes-namespaced` auth plugin not yet in upstream 3.10.x:
192+
193+
```dockerfile
194+
RUN microdnf install -y python3.12 python3.12-pip
195+
RUN python3.12 -m pip install --no-cache-dir \
196+
'mlflow[kubernetes] @ git+https://github.com/red-hat-data-services/mlflow.git@rhoai-3.4'
197+
```
198+
199+
> This fork requirement will go away when RHOAI ships MLflow 3.11, at which point replace with `mlflow[kubernetes]>=3.11`.
200+
201+
#### 2. Grant RBAC to the pod's service account
202+
203+
```bash
204+
oc adm policy add-role-to-user edit -z default -n <your-namespace>
205+
```
206+
207+
#### 3. Add MLflow env vars to the deployment
208+
209+
```yaml
210+
- name: MLFLOW_TRACKING_URI
211+
value: "https://mlflow.redhat-ods-applications.svc:8443"
212+
- name: MLFLOW_TRACKING_AUTH
213+
value: "kubernetes-namespaced"
214+
- name: MLFLOW_WORKSPACE
215+
value: "<your-namespace>"
216+
- name: MLFLOW_EXPERIMENT_NAME
217+
value: "claude-code-traces"
218+
- name: MLFLOW_TRACKING_INSECURE_TLS
219+
value: "true"
220+
```
221+
222+
#### 4. Add OGX env vars to point Claude Code at OGX
223+
224+
```yaml
225+
- name: ANTHROPIC_BASE_URL
226+
value: "https://<your-ogx-route>"
227+
- name: ANTHROPIC_API_KEY
228+
value: "fake"
229+
- name: ANTHROPIC_CUSTOM_MODEL_OPTION
230+
value: "vllm/<your-model-name>"
231+
```
232+
233+
#### 5. Wire up autolog in the entrypoint
234+
235+
The entrypoint runs `mlflow autolog claude` at startup and injects auth into the generated `.claude/settings.json`:
236+
237+
```bash
238+
mlflow autolog claude -u "${MLFLOW_TRACKING_URI}" -n "${MLFLOW_EXPERIMENT_NAME}" /workspace
239+
240+
python3.12 -c '
241+
import json, os
242+
sf = "/workspace/.claude/settings.json"
243+
with open(sf) as f: s = json.load(f)
244+
env = s.setdefault("env", {})
245+
env["MLFLOW_TRACKING_AUTH"] = "kubernetes-namespaced"
246+
env["MLFLOW_WORKSPACE"] = os.environ["MLFLOW_WORKSPACE"]
247+
env["MLFLOW_TRACKING_INSECURE_TLS"] = "true"
248+
with open(sf, "w") as f: json.dump(s, f, indent=2)
249+
'
250+
```
251+
252+
#### 6. Verify
253+
254+
```bash
255+
# Check startup logs
256+
oc logs deployment/<claude-deployment> | grep -i mlflow
257+
258+
# Run a test
259+
oc exec deployment/<claude-deployment> -- bash -c '
260+
export HOME=/home/claude-agent && cd /workspace
261+
~/.claude/claude-run -p "What is 2+2?"
262+
'
263+
264+
# Confirm trace was created by checking your MLflow UI under your experiment on your RHOAI MLflow instance
265+
```
266+
267+
### Recommendation for RHOAI 3.5
268+
269+
**Productize `mlflow autolog claude` as the agent tracing path.**
270+
271+
It works across all backends (Vertex AI, vLLM, OGX) with no changes to the tracing setup. It captures tool calls, token usage, latency, and session metadata out of the box. The only overhead is the stop-hook which runs after the session ends — zero impact on agent response times.
272+
273+
When RHOAI ships MLflow 3.11, drop the Red Hat fork and use upstream `mlflow[kubernetes]>=3.11`.
348 KB
Loading
390 KB
Loading
290 KB
Loading
428 KB
Loading
359 KB
Loading
384 KB
Loading

0 commit comments

Comments
 (0)