This guide explains how to use the telemetry system in Qwen CLI to capture and analyze API interactions for prompt tuning purposes.
The telemetry system captures:
- User prompts: Exact text sent by users
- API requests: Full context sent to the Qwen API
- API responses: Complete responses from the model
- Tool calls: Function executions and their results
- Performance metrics: Response times and token usage
Telemetry is already configured in .qwen/settings.json:
{
"telemetry": {
"enabled": true,
"target": "local",
"logPrompts": true,
"otlpEndpoint": "http://localhost:4317"
}
}Run the telemetry setup script:
npm run telemetryThis will:
- Download and configure the OpenTelemetry collector
- Start collecting telemetry data locally
- Display real-time logs in debug mode
Run any Qwen CLI commands as normal:
# Interactive mode
npm start
# Non-interactive mode
node bundle/qwen.js -p "Your prompt here"After running some commands, analyze the telemetry:
node scripts/analyze-prompts.jsThis generates:
- Summary statistics
- Prompt patterns analysis
- Model usage metrics
- Full conversation logs in
prompt-analysis.json
Each session contains:
- id: Unique session identifier
- duration: Total session time in seconds
- prompts: All user inputs with timestamps
- responses: All API responses with performance data
- conversations: Paired prompts and responses
{
"sessions": [{
"id": "9e8e480d-2410-4315-8337-65196d1ef5cb",
"conversations": [{
"prompt": "Hello, please respond with a simple greeting",
"response": {
"text": "Hello! How can I assist you today?",
"model": "qwen3-235b-a22b",
"duration": 3510,
"tokens": {
"input": 0,
"output": 0
}
}
}]
}]
}Run your existing prompts and capture metrics:
- Response quality
- Response time
- Token usage
- Success rate for tool calls
The analysis script helps identify:
- Common prompt starters
- Prompt length distribution
- Peak usage hours
- Frequently used tools
Create prompt variations and test:
# Test different phrasings
node bundle/qwen.js -p "List all TypeScript files"
node bundle/qwen.js -p "Show me TypeScript files in the project"
node bundle/qwen.js -p "Find *.ts files"Analyze the results to find:
- Which prompts get better responses
- Which prompts execute faster
- Which prompts use fewer tokens
Based on your analysis, document:
- Effective prompt patterns
- Optimal prompt lengths
- Best practices for tool usage
The prompt-analysis.json file can be imported into:
- Jupyter notebooks for data science analysis
- Excel/Google Sheets for visualization
- Custom analysis scripts
Extend the analysis script to track:
- Specific tool success rates
- Response quality scores
- Custom performance metrics
Create test suites for systematic evaluation:
// test-prompts.js
const prompts = [
"Find all TODO comments",
"Search for TODO markers in code",
"grep TODO comments"
];
for (const prompt of prompts) {
// Run and capture results
}- Telemetry data is stored locally only
- No data is sent to external services
- Sensitive information in prompts is captured, so secure your telemetry logs
- Delete telemetry data with:
rm -rf ~/.qwen/tmp/*
- Ensure telemetry is enabled in settings
- Check collector is running:
ps aux | grep otelcol - Verify OTLP endpoint matches settings
The analysis script handles:
- OTEL collector debug format
- Direct JSON logs
- Multiple log formats
If you see parsing errors, check the collector.log format.
- Consistent Testing: Test prompts at similar times to avoid variance
- Multiple Runs: Run each prompt multiple times for reliable metrics
- Context Matters: Test prompts with different file contexts
- Document Findings: Keep a log of what works best
- Review the Telemetry Technical Documentation
- Explore Multi-Agent System for parallel testing
- Check Integration Tests for automated testing