Skip to content

Commit b86bac0

Browse files
committed
add testing guide
1 parent a7178d2 commit b86bac0

File tree

1 file changed

+343
-0
lines changed

1 file changed

+343
-0
lines changed

telemetry/TEST-NOW.md

Lines changed: 343 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
1+
# Test Telemetry System Right Now
2+
3+
Since you're already in a Claude Code session, here's how to test it immediately:
4+
5+
---
6+
7+
## Option 1: Quick Test in New Terminal (Recommended)
8+
9+
**Why**: Start a fresh Claude Code session with telemetry enabled from the beginning.
10+
11+
### Steps:
12+
13+
1. **Open a new terminal** (keep this session running)
14+
15+
2. **Run the setup**:
16+
```bash
17+
cd /Users/mjs/Documents/code/panaversity-official/tutorsgpt/ch5-6
18+
bash telemetry/enable-telemetry.sh
19+
```
20+
21+
3. **Start Claude Code with telemetry**:
22+
```bash
23+
~/.claude-code-telemetry/claude-with-telemetry.sh
24+
```
25+
26+
4. **Do some normal work** (2-3 minutes):
27+
- Ask a question: "What files are in this directory?"
28+
- Edit a file: "Add a comment to README.md"
29+
- Run a command: "List Python files"
30+
31+
5. **Exit Claude Code** (Ctrl+C or type "exit")
32+
33+
6. **Parse your session**:
34+
```bash
35+
python3 telemetry/parser.py
36+
```
37+
38+
7. **Analyze results**:
39+
```bash
40+
python3 telemetry/analyze.py
41+
```
42+
43+
8. **Review the data**:
44+
```bash
45+
cat ~/.claude-code-telemetry/latest-report.json
46+
```
47+
48+
**Expected Results**:
49+
- ✅ Events count > 0 (should see user_prompt, api_request, tool_result)
50+
- ✅ Cost > $0.00 (should show actual API costs)
51+
- ✅ Tokens > 0 (should show token usage)
52+
- ✅ Sessions: 1
53+
54+
---
55+
56+
## Option 2: Test with Existing Setup (Already Done)
57+
58+
**Why**: We already created the setup, just need to use it.
59+
60+
### Steps:
61+
62+
1. **The setup is already complete**:
63+
```bash
64+
ls -la ~/.claude-code-telemetry/
65+
```
66+
Should show: `env.sh`, `claude-with-telemetry.sh`, `logs/`, `data/`
67+
68+
2. **In a new terminal, start collecting**:
69+
```bash
70+
~/.claude-code-telemetry/claude-with-telemetry.sh
71+
```
72+
73+
3. **Work normally, then analyze**:
74+
```bash
75+
python3 telemetry/parser.py
76+
python3 telemetry/analyze.py
77+
```
78+
79+
---
80+
81+
## Option 3: Test with Sample Data (Instant)
82+
83+
**Why**: See the system work immediately without waiting for real data.
84+
85+
### Steps:
86+
87+
1. **The test data is already there**:
88+
```bash
89+
ls ~/.claude-code-telemetry/logs/
90+
```
91+
You should see: `session-test.log` and `session-real-format.log`
92+
93+
2. **Parse it**:
94+
```bash
95+
python3 telemetry/parser.py
96+
```
97+
98+
3. **Analyze it**:
99+
```bash
100+
python3 telemetry/analyze.py
101+
```
102+
103+
4. **Check the results**:
104+
```bash
105+
cat ~/.claude-code-telemetry/latest-report.json
106+
```
107+
108+
**What You'll See**:
109+
```
110+
📊 SUMMARY
111+
Total Sessions: 2
112+
Total Events: 9
113+
Total Metrics: 8
114+
Total Api Requests: 4
115+
Estimated Total Cost Usd: 0.0321
116+
Estimated Total Tokens: 1,704
117+
118+
💰 COST ANALYSIS
119+
Total Cost: $0.0321 USD
120+
Total Tokens: 1,704
121+
Sessions Analyzed: 2
122+
123+
Top Sessions by Cost:
124+
1. session-real-format.log
125+
Cost: $0.0248, Tokens: 1,234, API Calls: 2
126+
2. session-test.log
127+
Cost: $0.0073, Tokens: 470, API Calls: 2
128+
```
129+
130+
---
131+
132+
## Option 4: Test Current Session (Advanced)
133+
134+
**Problem**: This session didn't start with telemetry enabled, so it won't be capturing to a file.
135+
136+
**Workaround**: We can still test the parser/analyzer on any log file.
137+
138+
### Create a Test Log Manually:
139+
140+
```bash
141+
# Create a fake session log
142+
cat > ~/.claude-code-telemetry/logs/session-manual-test.log << 'EOF'
143+
Session started at 2025-01-12 22:00:00
144+
145+
LogRecord #0
146+
Body: Str({"event":"claude_code.user_prompt","prompt_length":25,"session_id":"test-123"})
147+
148+
LogRecord #1
149+
Body: Str({"event":"claude_code.api_request","tokens":350,"cost":0.0035,"model":"claude-sonnet-4.5"})
150+
151+
LogRecord #2
152+
Body: Str({"event":"claude_code.tool_result","tool":"Read","file":"README.md","success":true})
153+
EOF
154+
155+
# Parse it
156+
python3 telemetry/parser.py
157+
158+
# Analyze it
159+
python3 telemetry/analyze.py
160+
```
161+
162+
---
163+
164+
## What to Verify
165+
166+
After running any of the above, check:
167+
168+
### 1. Parser Output ✅
169+
```bash
170+
cat ~/.claude-code-telemetry/data/session-*.json | python3 -m json.tool | head -30
171+
```
172+
173+
**Should show**:
174+
- session metadata (session_id, team, project)
175+
- events array with parsed events
176+
- metrics array with parsed metrics
177+
- events_count > 0
178+
- metrics_count >= 0
179+
180+
### 2. Analyzer Output ✅
181+
```bash
182+
python3 telemetry/analyze.py | grep -A 10 "SUMMARY"
183+
```
184+
185+
**Should show**:
186+
- Total sessions
187+
- Total events (should be > 0)
188+
- Total API requests
189+
- Cost in USD (should be > 0 if API calls present)
190+
- Tokens (should be > 0 if API calls present)
191+
192+
### 3. Report File ✅
193+
```bash
194+
cat ~/.claude-code-telemetry/latest-report.json | python3 -m json.tool | grep -A 5 "summary"
195+
```
196+
197+
**Should contain**:
198+
- JSON with summary, costs, errors sections
199+
- All numbers matching console output
200+
201+
---
202+
203+
## Troubleshooting
204+
205+
### Parser finds 0 events?
206+
207+
**Check log format**:
208+
```bash
209+
head -20 ~/.claude-code-telemetry/logs/session-*.log
210+
```
211+
212+
**Should see**:
213+
- Either simple format: `claude_code.user_prompt: {"data": ...}`
214+
- Or OTEL format: `Body: Str({"event":"claude_code.api_request",...})`
215+
216+
**If you see neither**:
217+
- Log might be from Claude Code without telemetry enabled
218+
- Try creating a new session with telemetry enabled
219+
220+
### Analyzer shows $0.00 cost?
221+
222+
**Check if events were parsed**:
223+
```bash
224+
cat ~/.claude-code-telemetry/data/session-*.json | grep -c "api_request"
225+
```
226+
227+
**Should be > 0**. If 0:
228+
- No API requests in that session
229+
- Or parser didn't find them (check log format)
230+
231+
### No log files found?
232+
233+
**Check directory exists**:
234+
```bash
235+
ls -la ~/.claude-code-telemetry/logs/
236+
```
237+
238+
**If empty**:
239+
- Run setup: `bash telemetry/enable-telemetry.sh`
240+
- Start session: `~/.claude-code-telemetry/claude-with-telemetry.sh`
241+
- Or use test data (Option 3 above)
242+
243+
---
244+
245+
## Quick Verification Script
246+
247+
Run this to test everything at once:
248+
249+
```bash
250+
#!/bin/bash
251+
echo "🧪 Testing Telemetry System..."
252+
echo ""
253+
254+
# Check setup
255+
echo "1. Checking setup..."
256+
if [ -f ~/.claude-code-telemetry/env.sh ]; then
257+
echo " ✅ Setup complete"
258+
else
259+
echo " ❌ Setup missing - run: bash telemetry/enable-telemetry.sh"
260+
exit 1
261+
fi
262+
263+
# Check logs
264+
echo "2. Checking logs..."
265+
LOG_COUNT=$(ls ~/.claude-code-telemetry/logs/*.log 2>/dev/null | wc -l)
266+
echo " Found $LOG_COUNT log file(s)"
267+
268+
if [ $LOG_COUNT -eq 0 ]; then
269+
echo " ⚠️ No logs yet - start a session or use test data"
270+
fi
271+
272+
# Run parser
273+
echo "3. Running parser..."
274+
python3 telemetry/parser.py > /tmp/parser-output.txt 2>&1
275+
if [ $? -eq 0 ]; then
276+
echo " ✅ Parser succeeded"
277+
grep "Parsed" /tmp/parser-output.txt | tail -5
278+
else
279+
echo " ❌ Parser failed"
280+
cat /tmp/parser-output.txt
281+
exit 1
282+
fi
283+
284+
# Check parsed data
285+
echo "4. Checking parsed data..."
286+
JSON_COUNT=$(ls ~/.claude-code-telemetry/data/*.json 2>/dev/null | wc -l)
287+
echo " Found $JSON_COUNT parsed session(s)"
288+
289+
# Run analyzer
290+
echo "5. Running analyzer..."
291+
python3 telemetry/analyze.py > /tmp/analyzer-output.txt 2>&1
292+
if [ $? -eq 0 ]; then
293+
echo " ✅ Analyzer succeeded"
294+
grep -A 5 "SUMMARY" /tmp/analyzer-output.txt
295+
else
296+
echo " ❌ Analyzer failed"
297+
cat /tmp/analyzer-output.txt
298+
exit 1
299+
fi
300+
301+
echo ""
302+
echo "✅ All tests passed!"
303+
echo ""
304+
echo "📊 View full report:"
305+
echo " python3 telemetry/analyze.py"
306+
echo ""
307+
echo "📁 View parsed data:"
308+
echo " ls -lh ~/.claude-code-telemetry/data/"
309+
```
310+
311+
Save as `test-telemetry.sh` and run:
312+
```bash
313+
chmod +x test-telemetry.sh
314+
./test-telemetry.sh
315+
```
316+
317+
---
318+
319+
## Recommended Test Flow
320+
321+
**For first-time validation**:
322+
323+
1. ✅ Use Option 3 (test with sample data) - **instant verification**
324+
2. ✅ Use Option 1 (new session) - **real-world validation**
325+
3. ✅ Review outputs to confirm accuracy
326+
4. ✅ Share with team if all looks good
327+
328+
**Time required**: 5 minutes total
329+
330+
---
331+
332+
## Success Criteria
333+
334+
After testing, you should see:
335+
336+
- ✅ Parser completes without errors
337+
- ✅ Events count > 0
338+
- ✅ Cost/tokens extracted correctly
339+
- ✅ Analyzer produces readable report
340+
- ✅ JSON files created in data directory
341+
- ✅ Report matches what you expect
342+
343+
If all ✅, the system is working correctly!

0 commit comments

Comments
 (0)