drtrace 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -4
- package/agents/CONTRIBUTING.md +0 -0
- package/agents/README.md +0 -0
- package/agents/daemon-method-selection.md +126 -227
- package/agents/integration-guides/cpp-best-practices.md +0 -0
- package/agents/integration-guides/cpp-ros-integration.md +0 -0
- package/agents/log-analysis.md +3 -89
- package/agents/log-help.md +6 -79
- package/agents/log-init.md +4 -0
- package/agents/log-it.md +4 -0
- package/bin/cli.js +98 -0
- package/bin/init.js +0 -0
- package/dist/bin/cli.js +98 -0
- package/dist/browser.d.ts +28 -0
- package/dist/browser.js +91 -0
- package/dist/cli/grep.d.ts +27 -0
- package/dist/cli/grep.js +251 -0
- package/dist/cli/status.d.ts +11 -0
- package/dist/cli/status.js +78 -0
- package/dist/client.d.ts +0 -0
- package/dist/client.js +0 -0
- package/dist/config-schema.d.ts +0 -0
- package/dist/config-schema.js +0 -0
- package/dist/config.d.ts +0 -0
- package/dist/config.js +0 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/init.d.ts +2 -0
- package/dist/init.js +23 -18
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +30 -4
- package/dist/node.d.ts +13 -0
- package/dist/node.js +67 -0
- package/dist/queue.d.ts +0 -0
- package/dist/queue.js +0 -0
- package/dist/resources/agents/CONTRIBUTING.md +0 -0
- package/dist/resources/agents/README.md +0 -0
- package/dist/resources/agents/daemon-method-selection.md +126 -227
- package/dist/resources/agents/integration-guides/cpp-best-practices.md +0 -0
- package/dist/resources/agents/integration-guides/cpp-ros-integration.md +0 -0
- package/dist/resources/agents/log-analysis.md +3 -89
- package/dist/resources/agents/log-help.md +6 -79
- package/dist/resources/agents/log-init.md +4 -0
- package/dist/resources/agents/log-it.md +4 -0
- package/dist/resources/cpp/drtrace_sink.hpp +1 -0
- package/dist/transport.d.ts +0 -0
- package/dist/transport.js +5 -1
- package/dist/types.d.ts +8 -2
- package/dist/types.js +0 -0
- package/package.json +22 -5
- package/dist/bin/init.js +0 -31
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ This runs an interactive setup wizard that creates the `_drtrace/` configuration
|
|
|
23
23
|
- Configuration guide (`README.md`)
|
|
24
24
|
- Default agent specification
|
|
25
25
|
|
|
26
|
-
###
|
|
26
|
+
### Node.js Usage
|
|
27
27
|
|
|
28
28
|
```typescript
|
|
29
29
|
import { DrTrace } from 'drtrace';
|
|
@@ -39,7 +39,6 @@ const client = DrTrace.init();
|
|
|
39
39
|
// flushIntervalMs: 1000,
|
|
40
40
|
// maxRetries: 3,
|
|
41
41
|
// maxQueueSize: 10000,
|
|
42
|
-
// timeoutMs: 5000,
|
|
43
42
|
// });
|
|
44
43
|
|
|
45
44
|
// Attach to console
|
|
@@ -50,6 +49,48 @@ console.log('This is captured by DrTrace');
|
|
|
50
49
|
console.error('Errors are also captured');
|
|
51
50
|
```
|
|
52
51
|
|
|
52
|
+
### Browser Usage (React, Vue, etc.)
|
|
53
|
+
|
|
54
|
+
In browser environments, you must provide `applicationId` and `daemonUrl` explicitly since the browser cannot read config files from the filesystem.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { DrTrace } from 'drtrace'; // Auto-selects browser entry point
|
|
58
|
+
|
|
59
|
+
// Browser requires explicit options (no config file loading)
|
|
60
|
+
const client = DrTrace.init({
|
|
61
|
+
applicationId: 'my-react-app',
|
|
62
|
+
daemonUrl: 'http://localhost:8001',
|
|
63
|
+
moduleName: 'frontend', // Optional: helps identify log source
|
|
64
|
+
batchSize: 50,
|
|
65
|
+
flushIntervalMs: 1000,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Attach to console
|
|
69
|
+
client.attachToConsole();
|
|
70
|
+
|
|
71
|
+
// Objects are serialized properly
|
|
72
|
+
console.log({ user: 'john', action: 'login' }); // Logs as JSON
|
|
73
|
+
console.error('Something went wrong', new Error('Details'));
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Important for Browser:**
|
|
77
|
+
- `applicationId` is **required** - throws error if missing
|
|
78
|
+
- `daemonUrl` is **required** - throws error if missing
|
|
79
|
+
- CORS must be enabled on the daemon (enabled by default)
|
|
80
|
+
- Objects and errors are automatically serialized to JSON
|
|
81
|
+
|
|
82
|
+
#### CORS Configuration
|
|
83
|
+
|
|
84
|
+
The DrTrace daemon allows all origins by default. To restrict origins:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Allow specific origins
|
|
88
|
+
export DRTRACE_CORS_ORIGINS="http://localhost:3000,https://myapp.com"
|
|
89
|
+
|
|
90
|
+
# Start daemon
|
|
91
|
+
uvicorn drtrace_service.api:app --host localhost --port 8001
|
|
92
|
+
```
|
|
93
|
+
|
|
53
94
|
## Starting the DrTrace Daemon
|
|
54
95
|
|
|
55
96
|
**Important**: The DrTrace daemon must be running before your application can send logs.
|
|
@@ -155,13 +196,13 @@ Create a new DrTrace client instance.
|
|
|
155
196
|
|
|
156
197
|
**Options:**
|
|
157
198
|
- `applicationId` (required) - Unique application identifier
|
|
158
|
-
- `daemonUrl` (optional) - DrTrace daemon URL (default: `http://localhost:8001`)
|
|
199
|
+
- `daemonUrl` (required in browser, optional in Node.js) - DrTrace daemon URL (default: `http://localhost:8001`)
|
|
200
|
+
- `moduleName` (optional) - Module/component name for log grouping (default: `'default'`)
|
|
159
201
|
- `enabled` (optional) - Enable/disable DrTrace (default: `true`)
|
|
160
202
|
- `batchSize` (optional) - Batch size for log batching (default: `50`)
|
|
161
203
|
- `flushIntervalMs` (optional) - Flush interval in milliseconds (default: `1000`)
|
|
162
204
|
- `maxRetries` (optional) - Retry attempts for failed sends with exponential backoff (default: `3`)
|
|
163
205
|
- `maxQueueSize` (optional) - Maximum queued log entries before oldest entries are dropped (default: `10000`)
|
|
164
|
-
- `timeoutMs` (optional) - Request timeout per batch in milliseconds (default: `5000`)
|
|
165
206
|
|
|
166
207
|
### `client.attachToConsole()`
|
|
167
208
|
|
package/agents/CONTRIBUTING.md
CHANGED
|
File without changes
|
package/agents/README.md
CHANGED
|
File without changes
|
|
@@ -1,83 +1,97 @@
|
|
|
1
1
|
# Daemon Method Selection Guide
|
|
2
|
-
|
|
3
2
|
**Purpose**: Guide for AI agents to choose the right method for daemon interaction.
|
|
3
|
+
**Key Principle**: For AI agents, prefer interaction with daemon in this order (most preferred to least, if a method is unavailable, fall back to the next):
|
|
4
|
+
- **CLI**: if available on client machine (check `## CLI Approach` below).
|
|
5
|
+
- **HTTP/curl**: for complex interactions without dependencies (check `## HTTP/curl Approach` below).
|
|
6
|
+
- **Python code**: when rich queries are needed (check `## Python code Approach` below).
|
|
7
|
+
## CLI Approach
|
|
8
|
+
If `drtrace` CLI is installed on the client machine:
|
|
9
|
+
- Check with: `drtrace --version`
|
|
10
|
+
- Prefer CLI commands: `drtrace grep`, `drtrace tail`, `drtrace status`
|
|
11
|
+
- Benefit: no HTTP overhead and faster queries
|
|
12
|
+
### Query Filter Rule: Mutually Exclusive
|
|
13
|
+
When querying logs, use **either** `message_contains` **or** `message_regex`, **NOT both**.
|
|
14
|
+
|
|
15
|
+
| Filter | Use Case | Example |
|
|
16
|
+
| ------------------ | ---------------- | --------------------------------------------- |
|
|
17
|
+
| `message_contains` | Substring search | "timeout" matches "Connection timeout error" |
|
|
18
|
+
| `message_regex` | Regex patterns | "(db\|cache).*timeout" matches service errors |
|
|
19
|
+
**Error if both used**: API returns 400 "Cannot use both filters".
|
|
20
|
+
### Examples
|
|
21
|
+
**CLI - Substring Search**:
|
|
22
|
+
```bash
|
|
23
|
+
drtrace grep "timeout" --since 1h
|
|
24
|
+
```
|
|
25
|
+
**CLI - Regex Search** (with `-E`):
|
|
26
|
+
```bash
|
|
27
|
+
drtrace grep -E "(db|cache).*timeout" --since 1h
|
|
28
|
+
```
|
|
29
|
+
## HTTP/curl Approach
|
|
30
|
+
### Check Daemon Status
|
|
4
31
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Priority Order for AI Agents
|
|
10
|
-
|
|
11
|
-
| Priority | Method | When to Use |
|
|
12
|
-
|----------|--------|-------------|
|
|
13
|
-
| **1st** | HTTP/curl | Default - works without dependencies |
|
|
14
|
-
| **2nd** | Python code | When rich SDK features needed |
|
|
15
|
-
| **3rd** | CLI commands | Last resort - requires subprocess |
|
|
16
|
-
|
|
17
|
-
### Why HTTP-First for AI Agents?
|
|
18
|
-
|
|
19
|
-
- **No dependencies**: Just HTTP requests - works in any environment
|
|
20
|
-
- **Simpler**: curl commands are self-contained and portable
|
|
21
|
-
- **Faster**: No import overhead or Python interpreter startup
|
|
22
|
-
- **Universal**: Works from any language or tool
|
|
23
|
-
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
## Discovery First: OpenAPI Schema
|
|
27
|
-
|
|
32
|
+
```bash
|
|
33
|
+
curl http://localhost:8001/status
|
|
34
|
+
```
|
|
35
|
+
### Discovery API via OpenAPI Schema
|
|
28
36
|
**CRITICAL**: Before making any API call, fetch `/openapi.json` to discover:
|
|
29
37
|
- Available endpoints
|
|
30
38
|
- Correct field names (e.g., `ts` not `timestamp`)
|
|
31
39
|
- Request/response schemas
|
|
32
|
-
|
|
33
40
|
```bash
|
|
34
41
|
# Always fetch schema first
|
|
35
42
|
curl http://localhost:8001/openapi.json
|
|
36
43
|
```
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
### Common Endpoints (for Quick Reference)
|
|
45
|
+
**Note**: Always verify via `/openapi.json` - this list is for reference only (*API field names can change between versions. Using OpenAPI ensures compatibility*).
|
|
46
|
+
|
|
47
|
+
| Endpoint | Method | Purpose |
|
|
48
|
+
| ---------------------- | ------ | -------------------- |
|
|
49
|
+
| `/status` | GET | Health check |
|
|
50
|
+
| `/openapi.json` | GET | API schema |
|
|
51
|
+
| `/logs/query` | GET | Query logs |
|
|
52
|
+
| `/logs/ingest` | POST | Ingest logs |
|
|
53
|
+
| `/analysis/why` | GET | Root cause analysis |
|
|
54
|
+
| `/analysis/time-range` | GET | Time range analysis |
|
|
55
|
+
| `/help/guide/start` | POST | Start setup guide |
|
|
56
|
+
| `/help/guide/current` | GET | Current setup step |
|
|
57
|
+
| `/help/troubleshoot` | POST | Troubleshooting help |
|
|
58
|
+
### Examples
|
|
59
|
+
**HTTP - Substring Search**:
|
|
60
|
+
```bash
|
|
61
|
+
curl "http://localhost:8001/logs/query?message_contains=timeout&since=1h"
|
|
49
62
|
```
|
|
50
|
-
|
|
51
|
-
**Why this matters**: API field names can change between versions. Using OpenAPI ensures compatibility.
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
## Method 1: HTTP/curl (Preferred)
|
|
56
|
-
|
|
57
|
-
### Check Daemon Status
|
|
58
|
-
|
|
63
|
+
**HTTP - Regex Search**:
|
|
59
64
|
```bash
|
|
60
|
-
curl http://localhost:8001/
|
|
65
|
+
curl "http://localhost:8001/logs/query?message_regex=(db|cache).*timeout&since=1h"
|
|
61
66
|
```
|
|
62
|
-
|
|
63
|
-
### Query Logs
|
|
64
|
-
|
|
67
|
+
**HTTP - Query Logs**:
|
|
65
68
|
```bash
|
|
66
69
|
# Get logs from last 5 minutes
|
|
67
70
|
START_TS=$(python3 -c "import time; print(time.time() - 300)")
|
|
68
71
|
END_TS=$(python3 -c "import time; print(time.time())")
|
|
69
|
-
|
|
70
72
|
curl "http://localhost:8001/logs/query?start_ts=${START_TS}&end_ts=${END_TS}&application_id=myapp&limit=100"
|
|
71
73
|
```
|
|
72
|
-
|
|
73
|
-
### Root Cause Analysis
|
|
74
|
-
|
|
74
|
+
**HTTP - Query with filter**:
|
|
75
75
|
```bash
|
|
76
76
|
curl "http://localhost:8001/analysis/why?application_id=myapp&start_ts=${START_TS}&end_ts=${END_TS}&min_level=ERROR"
|
|
77
77
|
```
|
|
78
|
+
## Python code Approach
|
|
79
|
+
Use when you need rich SDK features or the HTTP method fails.
|
|
80
|
+
### Examples
|
|
81
|
+
**Get OpenAPI json for API information**
|
|
82
|
+
```python
|
|
83
|
+
import requests
|
|
78
84
|
|
|
79
|
-
|
|
85
|
+
base_url = "http://localhost:8001"
|
|
86
|
+
|
|
87
|
+
# Fetch schema to discover endpoints and field names
|
|
88
|
+
schema = requests.get(f"{base_url}/openapi.json", timeout=5).json()
|
|
89
|
+
paths = schema.get("paths", {})
|
|
90
|
+
components = schema.get("components", {}).get("schemas", {})
|
|
80
91
|
|
|
92
|
+
# Use discovered field names, not hardcoded ones
|
|
93
|
+
```
|
|
94
|
+
**Python requests (HTTP method)**
|
|
81
95
|
```python
|
|
82
96
|
import requests
|
|
83
97
|
import time
|
|
@@ -109,190 +123,75 @@ for log in logs:
|
|
|
109
123
|
level = log.get("level")
|
|
110
124
|
message = log.get("message")
|
|
111
125
|
```
|
|
126
|
+
## When to Use Each Method
|
|
112
127
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
### Setup Help
|
|
139
|
-
|
|
140
|
-
```python
|
|
141
|
-
from drtrace_service.help_agent_interface import (
|
|
142
|
-
start_setup_guide,
|
|
143
|
-
get_current_step,
|
|
144
|
-
complete_step,
|
|
145
|
-
troubleshoot,
|
|
146
|
-
)
|
|
147
|
-
from pathlib import Path
|
|
148
|
-
import asyncio
|
|
149
|
-
|
|
150
|
-
project_root = Path(".")
|
|
151
|
-
|
|
152
|
-
# Start setup guide
|
|
153
|
-
guide = await start_setup_guide(language="python", project_root=project_root)
|
|
154
|
-
|
|
155
|
-
# Get current step
|
|
156
|
-
current = await get_current_step(project_root=project_root)
|
|
157
|
-
|
|
158
|
-
# Mark step complete
|
|
159
|
-
next_step = await complete_step(step_number=1, project_root=project_root)
|
|
160
|
-
|
|
161
|
-
# Troubleshoot
|
|
162
|
-
help_text = await troubleshoot("daemon not connecting", project_root=project_root)
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### Setup Suggestions
|
|
166
|
-
|
|
128
|
+
| Scenario | Recommended Method |
|
|
129
|
+
| ----------------------------- | ------------------ |
|
|
130
|
+
| Simple queries (status, logs) | CLI, HTTP/curl |
|
|
131
|
+
| Complex analysis | HTTP or Python |
|
|
132
|
+
| Rich markdown output needed | Python SDK |
|
|
133
|
+
| Running outside Python | CLI, HTTP/curl |
|
|
134
|
+
| Setup guide interaction | Python SDK |
|
|
135
|
+
| Debugging integration | CLI commands |
|
|
136
|
+
| Script automation | CLI, HTTP/curl |
|
|
137
|
+
## Important Notes
|
|
138
|
+
### Timestamps Are UTC
|
|
139
|
+
All timestamps in DrTrace API are **UTC Unix timestamps**:
|
|
140
|
+
|
|
141
|
+
| Field/Param | Format | Timezone |
|
|
142
|
+
| -------------------- | -------------------- | -------- |
|
|
143
|
+
| `ts` (in logs) | Unix float | UTC |
|
|
144
|
+
| `start_ts`, `end_ts` | Unix float | UTC |
|
|
145
|
+
| `since`, `until` | Relative or ISO 8601 | UTC |
|
|
146
|
+
**Key Rules**:
|
|
147
|
+
- ISO 8601 without timezone (e.g., `2025-12-31T02:44:03`) is interpreted as **UTC**, not local time
|
|
148
|
+
- Relative times (`5m`, `1h`) are relative to server's current UTC time
|
|
149
|
+
- To query with local time, include timezone offset: `2025-12-31T09:44:03+07:00`
|
|
150
|
+
#### Converting Local Time to UTC
|
|
151
|
+
**Python:**
|
|
167
152
|
```python
|
|
168
|
-
from
|
|
169
|
-
from pathlib import Path
|
|
170
|
-
import asyncio
|
|
153
|
+
from datetime import datetime, timezone, timedelta
|
|
171
154
|
|
|
172
|
-
|
|
155
|
+
# Local time (e.g., 2025-12-31 09:44:03 in GMT+7)
|
|
156
|
+
local_time = datetime(2025, 12, 31, 9, 44, 3)
|
|
173
157
|
|
|
174
|
-
#
|
|
175
|
-
|
|
158
|
+
# Method 1: If you know your timezone offset
|
|
159
|
+
local_tz = timezone(timedelta(hours=7)) # GMT+7
|
|
160
|
+
local_aware = local_time.replace(tzinfo=local_tz)
|
|
161
|
+
utc_time = local_aware.astimezone(timezone.utc)
|
|
162
|
+
unix_ts = utc_time.timestamp()
|
|
163
|
+
print(f"UTC Unix timestamp: {unix_ts}")
|
|
176
164
|
|
|
177
|
-
#
|
|
178
|
-
|
|
179
|
-
|
|
165
|
+
# Method 2: Using system timezone
|
|
166
|
+
import time
|
|
167
|
+
unix_ts = time.mktime(local_time.timetuple())
|
|
180
168
|
```
|
|
181
|
-
|
|
182
|
-
---
|
|
183
|
-
|
|
184
|
-
## Method 3: CLI Commands (Last Resort)
|
|
185
|
-
|
|
186
|
-
Use only when HTTP and Python methods are unavailable.
|
|
187
|
-
|
|
188
|
-
### Check Status
|
|
189
|
-
|
|
169
|
+
**Bash:**
|
|
190
170
|
```bash
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
### Analyze Errors
|
|
171
|
+
# Convert local time to Unix timestamp
|
|
172
|
+
date -d "2025-12-31 09:44:03" +%s
|
|
195
173
|
|
|
196
|
-
|
|
197
|
-
|
|
174
|
+
# Convert with explicit timezone
|
|
175
|
+
TZ=UTC date -d "2025-12-31T02:44:03" +%s
|
|
198
176
|
```
|
|
199
|
-
|
|
200
|
-
### Setup Help
|
|
201
|
-
|
|
177
|
+
#### API Query Examples with Timezone
|
|
202
178
|
```bash
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
```
|
|
179
|
+
# Option 1: Include timezone in ISO 8601 (recommended for local time)
|
|
180
|
+
curl "http://localhost:8001/logs/query?since=2025-12-31T09:44:03%2B07:00"
|
|
206
181
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
## Error Handling and Fallback Chain
|
|
182
|
+
# Option 2: Use relative time (always relative to server UTC time)
|
|
183
|
+
curl "http://localhost:8001/logs/query?since=5m"
|
|
210
184
|
|
|
211
|
-
|
|
212
|
-
|
|
185
|
+
# Option 3: Convert to UTC Unix timestamp first
|
|
186
|
+
UTC_TS=$(TZ=UTC date -d "2025-12-31T02:44:03" +%s)
|
|
187
|
+
curl "http://localhost:8001/logs/query?start_ts=$UTC_TS"
|
|
213
188
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
base_url = "http://localhost:8001"
|
|
217
|
-
|
|
218
|
-
# Method 1: HTTP (Preferred)
|
|
219
|
-
try:
|
|
220
|
-
# Check status first
|
|
221
|
-
status = requests.get(f"{base_url}/status", timeout=2)
|
|
222
|
-
if status.status_code == 200:
|
|
223
|
-
# Make actual request...
|
|
224
|
-
return "Success via HTTP"
|
|
225
|
-
except requests.exceptions.RequestException:
|
|
226
|
-
pass # Fall through to Python
|
|
227
|
-
|
|
228
|
-
# Method 2: Python (Fallback)
|
|
229
|
-
try:
|
|
230
|
-
from drtrace_service.agent_interface import process_agent_query
|
|
231
|
-
import asyncio
|
|
232
|
-
response = asyncio.run(process_agent_query(query))
|
|
233
|
-
return response
|
|
234
|
-
except ImportError:
|
|
235
|
-
pass # Fall through to CLI
|
|
236
|
-
|
|
237
|
-
# Method 3: CLI (Last Resort)
|
|
238
|
-
import subprocess
|
|
239
|
-
result = subprocess.run(
|
|
240
|
-
["python", "-m", "drtrace_service", "status"],
|
|
241
|
-
capture_output=True,
|
|
242
|
-
text=True
|
|
243
|
-
)
|
|
244
|
-
if result.returncode == 0:
|
|
245
|
-
return result.stdout
|
|
246
|
-
|
|
247
|
-
# All methods failed
|
|
248
|
-
return """
|
|
249
|
-
Daemon is not available.
|
|
250
|
-
|
|
251
|
-
Next Steps:
|
|
252
|
-
1. Start daemon: python -m drtrace_service
|
|
253
|
-
2. Verify: curl http://localhost:8001/status
|
|
254
|
-
"""
|
|
189
|
+
# Option 4: Use ISO 8601 in UTC (note: no timezone = UTC)
|
|
190
|
+
curl "http://localhost:8001/logs/query?since=2025-12-31T02:44:03"
|
|
255
191
|
```
|
|
256
|
-
|
|
192
|
+
#### Common Timezone Pitfalls
|
|
193
|
+
1. **ISO 8601 Without Timezone**: Interpreted as UTC, not local time. If you pass `2025-12-31T09:44:03` thinking it's local 9:44 AM, it will be treated as 9:44 AM UTC.
|
|
194
|
+
2. **Server vs Client Timezone**: If your server is in a different timezone than your client, always use explicit UTC timestamps or include timezone offsets.
|
|
195
|
+
3. **Relative Times**: `since=5m` means 5 minutes before server's current UTC time, regardless of your local timezone.
|
|
257
196
|
---
|
|
258
|
-
|
|
259
|
-
## When to Use Each Method
|
|
260
|
-
|
|
261
|
-
| Scenario | Recommended Method |
|
|
262
|
-
|----------|-------------------|
|
|
263
|
-
| Simple queries (status, logs) | HTTP/curl |
|
|
264
|
-
| Complex analysis | HTTP or Python |
|
|
265
|
-
| Rich markdown output needed | Python SDK |
|
|
266
|
-
| Running outside Python | HTTP/curl |
|
|
267
|
-
| Setup guide interaction | Python SDK |
|
|
268
|
-
| Debugging integration | CLI commands |
|
|
269
|
-
| Script automation | HTTP/curl |
|
|
270
|
-
|
|
271
|
-
---
|
|
272
|
-
|
|
273
|
-
## Quick Reference: Common Endpoints
|
|
274
|
-
|
|
275
|
-
**Note**: Always verify via `/openapi.json` - this list is for reference only.
|
|
276
|
-
|
|
277
|
-
| Endpoint | Method | Purpose |
|
|
278
|
-
|----------|--------|---------|
|
|
279
|
-
| `/status` | GET | Health check |
|
|
280
|
-
| `/openapi.json` | GET | API schema |
|
|
281
|
-
| `/logs/query` | GET | Query logs |
|
|
282
|
-
| `/logs/ingest` | POST | Ingest logs |
|
|
283
|
-
| `/analysis/why` | GET | Root cause analysis |
|
|
284
|
-
| `/analysis/time-range` | GET | Time range analysis |
|
|
285
|
-
| `/help/guide/start` | POST | Start setup guide |
|
|
286
|
-
| `/help/guide/current` | GET | Current setup step |
|
|
287
|
-
| `/help/troubleshoot` | POST | Troubleshooting help |
|
|
288
|
-
|
|
289
|
-
---
|
|
290
|
-
|
|
291
|
-
## Related Documentation
|
|
292
|
-
|
|
293
|
-
- `docs/daemon-interaction-guide.md` - OpenAPI discovery details
|
|
294
|
-
- `docs/api-reference.md` - Complete API reference
|
|
295
|
-
|
|
296
|
-
---
|
|
297
|
-
|
|
298
|
-
**Last Updated**: 2025-12-29
|
|
197
|
+
**Last Updated**: 2026-01-06
|
|
File without changes
|
|
File without changes
|
package/agents/log-analysis.md
CHANGED
|
@@ -11,26 +11,7 @@ You must fully embody this agent's persona and follow all activation instruction
|
|
|
11
11
|
<step n="1">Load persona from this current agent file (already in context)</step>
|
|
12
12
|
<step n="2">Remember: You are a Log Analysis Specialist</step>
|
|
13
13
|
<step n="3">READ the entire story file BEFORE any analysis - understand the query parsing rules</step>
|
|
14
|
-
<step n="4">When processing a user query,
|
|
15
|
-
|
|
16
|
-
**Method 1 (Preferred)**: Python code
|
|
17
|
-
- Try: `from drtrace_service.agent_interface import process_agent_query, check_daemon_status`
|
|
18
|
-
- If import succeeds: Use `response = await process_agent_query(user_query)` or `asyncio.run(process_agent_query(user_query))`
|
|
19
|
-
- Return the response string directly (it's already formatted markdown)
|
|
20
|
-
|
|
21
|
-
**Method 2 (Fallback)**: HTTP API
|
|
22
|
-
- If Python import fails: Use HTTP requests to call DrTrace API endpoints
|
|
23
|
-
- **CRITICAL**: First fetch `/openapi.json` to discover field names (e.g., timestamp is `ts`, NOT `timestamp`)
|
|
24
|
-
- Check status: `GET http://localhost:8001/status`
|
|
25
|
-
- For analysis: `GET http://localhost:8001/analysis/why?application_id=X&start_ts=Y&end_ts=Z`
|
|
26
|
-
- Parse the JSON response using field names from OpenAPI schema
|
|
27
|
-
|
|
28
|
-
**Method 3 (Last resort)**: CLI commands
|
|
29
|
-
- If both Python and HTTP fail: Execute `python -m drtrace_service why --application-id X --since 5m`
|
|
30
|
-
- Parse the CLI output and format for the user
|
|
31
|
-
|
|
32
|
-
**Important**: Always check daemon status first. If daemon is unavailable, return clear error message with next steps.
|
|
33
|
-
</step>
|
|
14
|
+
<step n="4">When processing a user query, check `agents/daemon-method-selection.md` for details.</step>
|
|
34
15
|
<step n="5">If information is missing, ask the user for clarification with helpful suggestions</step>
|
|
35
16
|
<step n="6">If daemon is unavailable, provide clear error message and next steps</step>
|
|
36
17
|
<step n="7">Show greeting, then display numbered list of ALL menu items from menu section</step>
|
|
@@ -65,77 +46,12 @@ You must fully embody this agent's persona and follow all activation instruction
|
|
|
65
46
|
|
|
66
47
|
**Priority Order**: HTTP/curl (preferred) → Python SDK → CLI (last resort)
|
|
67
48
|
|
|
68
|
-
### Quick Reference: Analysis API Operations
|
|
69
|
-
|
|
70
|
-
| Operation | HTTP (Preferred) | Python SDK |
|
|
71
|
-
|-----------|------------------|------------|
|
|
72
|
-
| Query logs | `GET /logs/query` | `process_agent_query("show logs...")` |
|
|
73
|
-
| Root cause | `GET /analysis/why` | `process_agent_query("explain error...")` |
|
|
74
|
-
| Check status | `GET /status` | `check_daemon_status()` |
|
|
75
|
-
|
|
76
|
-
### HTTP/curl Examples (Preferred)
|
|
77
|
-
|
|
78
|
-
```bash
|
|
79
|
-
# Check daemon status
|
|
80
|
-
curl http://localhost:8001/status
|
|
81
|
-
|
|
82
|
-
# Query logs from last 5 minutes
|
|
83
|
-
START_TS=$(python3 -c "import time; print(time.time() - 300)")
|
|
84
|
-
END_TS=$(python3 -c "import time; print(time.time())")
|
|
85
|
-
|
|
86
|
-
curl "http://localhost:8001/logs/query?start_ts=${START_TS}&end_ts=${END_TS}&application_id=myapp&limit=100"
|
|
87
|
-
|
|
88
|
-
# Root cause analysis
|
|
89
|
-
curl "http://localhost:8001/analysis/why?application_id=myapp&start_ts=${START_TS}&end_ts=${END_TS}&min_level=ERROR"
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### Python SDK Examples (Fallback)
|
|
93
|
-
|
|
94
|
-
```python
|
|
95
|
-
from drtrace_service.agent_interface import process_agent_query, check_daemon_status
|
|
96
|
-
import asyncio
|
|
97
|
-
|
|
98
|
-
# Check daemon first
|
|
99
|
-
status = await check_daemon_status()
|
|
100
|
-
if not status.get("available"):
|
|
101
|
-
print("Daemon not available")
|
|
102
|
-
|
|
103
|
-
# Process query - returns formatted markdown
|
|
104
|
-
response = await process_agent_query("explain error from 9:00 to 10:00 for app myapp")
|
|
105
|
-
|
|
106
|
-
# Non-async context
|
|
107
|
-
response = asyncio.run(process_agent_query("show logs from last 5 minutes"))
|
|
108
|
-
```
|
|
109
|
-
|
|
110
49
|
**Key Points:**
|
|
111
50
|
- **Package**: `drtrace_service` (NOT `drtrace_client`)
|
|
112
51
|
- **Returns**: Formatted markdown string ready to display
|
|
113
52
|
- **Async**: Functions are async, use `await` or `asyncio.run()`
|
|
114
53
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
1. **HTTP/curl (Preferred)**: Simple, no dependencies
|
|
118
|
-
2. **Python SDK (Fallback)**: Rich async features when HTTP unavailable
|
|
119
|
-
3. **CLI (Last Resort)**: `python -m drtrace_service why ...`
|
|
120
|
-
|
|
121
|
-
**Important**: Always fetch `/openapi.json` first when using HTTP to discover correct field names (e.g., `ts` not `timestamp`).
|
|
122
|
-
|
|
123
|
-
See `agents/daemon-method-selection.md` for complete fallback implementation.
|
|
124
|
-
|
|
125
|
-
### Quick Reference: Endpoints
|
|
126
|
-
|
|
127
|
-
| Endpoint | Purpose |
|
|
128
|
-
|----------|---------|
|
|
129
|
-
| `GET /status` | Health check |
|
|
130
|
-
| `GET /logs/query` | Query logs |
|
|
131
|
-
| `GET /analysis/why` | Root cause analysis |
|
|
132
|
-
| `GET /analysis/time-range` | Time range analysis |
|
|
133
|
-
| `GET /analysis/cross-module` | Cross-module analysis |
|
|
134
|
-
|
|
135
|
-
**Parameters** (verify via `/openapi.json`):
|
|
136
|
-
- `start_ts`, `end_ts`: Unix timestamps (floats)
|
|
137
|
-
- `min_level`: DEBUG, INFO, WARN, ERROR, CRITICAL
|
|
138
|
-
- `limit`: defaults to 100, max 1000
|
|
54
|
+
**Best Practice**: See `docs/agent-design-best-practices.md` → "DrTrace Query Constraints" for detailed guidance.
|
|
139
55
|
|
|
140
56
|
<menu>
|
|
141
57
|
<item cmd="*analyze">[A] Analyze logs for a time range</item>
|
|
@@ -212,6 +128,4 @@ See `agents/daemon-method-selection.md` for complete fallback implementation.
|
|
|
212
128
|
|
|
213
129
|
</capabilities>
|
|
214
130
|
</agent>
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
|
|
131
|
+
```
|