Elffuss BraidHub

kikocis/continue public

main · 11.8 KiBRenderedRawPermalink
1# OTLP Metrics Specification for Continue CLI
2
3This document specifies the OpenTelemetry Protocol (OTLP) metrics that should be emitted by the Continue CLI to provide comprehensive observability and usage monitoring. The metrics are designed to be compatible with Claude Code dashboards for easy migration.
4
5## Overview
6
7The Continue CLI should emit metrics that provide insights into:
8
9- Usage patterns and session analytics
10- Performance and reliability
11- Tool usage and effectiveness
12- Error rates and types
13- Resource utilization
14- Code modification tracking
15
16## Configuration
17
18### Environment Variables
19
20| Environment Variable | Description | Example Values |
21| ------------------------------- | --------------------------------------------------------- | ------------------------------------ |
22| `CONTINUE_CLI_ENABLE_TELEMETRY` | Enables telemetry collection (required) | `1` |
23| `OTEL_METRICS_EXPORTER` | Metrics exporter type(s) (comma-separated) | `console`, `otlp`, `prometheus` |
24| `OTEL_LOGS_EXPORTER` | Logs/events exporter type(s) (comma-separated) | `console`, `otlp` |
25| `OTEL_EXPORTER_OTLP_PROTOCOL` | Protocol for OTLP exporter (all signals) | `grpc`, `http/json`, `http/protobuf` |
26| `OTEL_EXPORTER_OTLP_ENDPOINT` | OTLP collector endpoint (all signals) | `http://localhost:4317` |
27| `OTEL_EXPORTER_OTLP_HEADERS` | Authentication headers for OTLP | `Authorization=Bearer token` |
28| `OTEL_METRIC_EXPORT_INTERVAL` | Export interval in milliseconds (default: 60000) | `5000`, `60000` |
29| `OTEL_LOGS_EXPORT_INTERVAL` | Logs export interval in milliseconds (default: 5000) | `1000`, `10000` |
30| `OTEL_LOG_USER_PROMPTS` | Enable logging of user prompt content (default: disabled) | `1` to enable |
31
32### Metrics Cardinality Control
33
34| Environment Variable | Description | Default Value | Example to Disable |
35| ----------------------------------- | ---------------------------------------------- | ------------- | ------------------ |
36| `OTEL_METRICS_INCLUDE_SESSION_ID` | Include session.id attribute in metrics | `true` | `false` |
37| `OTEL_METRICS_INCLUDE_VERSION` | Include app.version attribute in metrics | `false` | `true` |
38| `OTEL_METRICS_INCLUDE_ACCOUNT_UUID` | Include user.account_uuid attribute in metrics | `true` | `false` |
39
40## Standard Attributes
41
42All metrics and events share these standard attributes:
43
44| Attribute | Description | Controlled By |
45| ------------------- | ------------------------------------------------------------- | --------------------------------------------------- |
46| `session.id` | Unique session identifier | `OTEL_METRICS_INCLUDE_SESSION_ID` (default: true) |
47| `app.version` | Current Continue CLI version | `OTEL_METRICS_INCLUDE_VERSION` (default: false) |
48| `organization.id` | Organization UUID (when authenticated) | Always included when available |
49| `user.account_uuid` | Account UUID (when authenticated) | `OTEL_METRICS_INCLUDE_ACCOUNT_UUID` (default: true) |
50| `terminal.type` | Terminal type (e.g., `iTerm.app`, `vscode`, `cursor`, `tmux`) | Always included when detected |
51
52## Core Metrics
53
54### ✅ `continue_cli_session_count`
55
56**Type:** Counter
57**Unit:** `count`
58**Description:** Count of CLI sessions started
59
60**Attributes:**
61
62- All [standard attributes](#standard-attributes)
63
64**Implementation:** Track in `src/commands/chat.ts` when session starts
65
66---
67
68### ✅ `continue_cli_lines_of_code_count`
69
70**Type:** Counter
71**Unit:** `count`
72**Description:** Count of lines of code modified
73
74**Attributes:**
75
76- All [standard attributes](#standard-attributes)
77- `type`: (`"added"`, `"removed"`)
78
79**Implementation:** Track in `src/tools/writeFile.ts` by analyzing file diffs
80
81---
82
83### ✅ `continue_cli_pull_request_count`
84
85**Type:** Counter
86**Unit:** `count`
87**Description:** Number of pull requests created
88
89**Attributes:**
90
91- All [standard attributes](#standard-attributes)
92
93**Implementation:** Track when `runTerminalCommand` executes git/gh commands for PR creation
94
95---
96
97### ✅ `continue_cli_commit_count`
98
99**Type:** Counter
100**Unit:** `count`
101**Description:** Number of git commits created
102
103**Attributes:**
104
105- All [standard attributes](#standard-attributes)
106
107**Implementation:** Track when `runTerminalCommand` executes `git commit` commands
108
109---
110
111### ✅ `continue_cli_cost_usage`
112
113**Type:** Counter
114**Unit:** `USD`
115**Description:** Cost of the Continue CLI session
116
117**Attributes:**
118
119- All [standard attributes](#standard-attributes)
120- `model`: Model identifier (e.g., "claude-3-5-sonnet-20241022", "gpt-4")
121
122**Implementation:** Calculate costs based on token usage and model pricing in `src/streamChatResponse.ts`
123
124---
125
126### ✅ `continue_cli_token_usage`
127
128**Type:** Counter
129**Unit:** `tokens`
130**Description:** Number of tokens used
131
132**Attributes:**
133
134- All [standard attributes](#standard-attributes)
135- `type`: (`"input"`, `"output"`, `"cacheRead"`, `"cacheCreation"`)
136- `model`: Model identifier (e.g., "claude-3-5-sonnet-20241022", "gpt-4")
137
138**Implementation:** Track in `src/streamChatResponse.ts` after each API response
139
140---
141
142### ❌ `continue_cli_code_edit_tool_decision`
143
144**Type:** Counter
145**Unit:** `count`
146**Description:** Count of code editing tool permission decisions
147
148**Attributes:**
149
150- All [standard attributes](#standard-attributes)
151- `tool`: Tool name (`"writeFile"`, `"runTerminalCommand"`, etc.)
152- `decision`: User decision (`"accept"`, `"reject"`)
153- `language`: Programming language of the edited file (e.g., `"TypeScript"`, `"Python"`, `"JavaScript"`, `"Markdown"`). Returns `"unknown"` for unrecognized file extensions.
154
155**Implementation:** Track in tool execution when user confirmation is required (if implemented)
156
157---
158
159### ✅ `continue_cli_active_time_total`
160
161**Type:** Counter
162**Unit:** `s`
163**Description:** Total active time in seconds
164
165**Attributes:**
166
167- All [standard attributes](#standard-attributes)
168
169**Implementation:** Track in TUI mode (`src/ui/TUIChat.tsx`) and standard chat mode, measuring time during active interactions
170
171## Core Events
172
173### ✅ User Prompt Event
174
175**Event Name:** `continue_cli_user_prompt`
176
177**Attributes:**
178
179- All [standard attributes](#standard-attributes)
180- `event.name`: `"user_prompt"`
181- `event.timestamp`: ISO 8601 timestamp
182- `prompt_length`: Length of the prompt
183- `prompt`: Prompt content (redacted by default, enable with `OTEL_LOG_USER_PROMPTS=1`)
184
185**Implementation:** Log in `src/streamChatResponse.ts` when user message is added to chat history
186
187---
188
189### ✅ Tool Result Event
190
191**Event Name:** `continue_cli_tool_result`
192
193**Attributes:**
194
195- All [standard attributes](#standard-attributes)
196- `event.name`: `"tool_result"`
197- `event.timestamp`: ISO 8601 timestamp
198- `tool_name`: Name of the tool
199- `success`: `"true"` or `"false"`
200- `duration_ms`: Execution time in milliseconds
201- `error`: Error message (if failed)
202- `decision`: Either `"accept"` or `"reject"` (if applicable)
203- `source`: Decision source - `"config"`, `"user_permanent"`, `"user_temporary"`, `"user_abort"`, or `"user_reject"` (if applicable)
204- `tool_parameters`: JSON string containing tool-specific parameters (when available)
205
206**Implementation:** Log in `src/tools/index.ts` `executeToolCall` function
207
208---
209
210### ✅ API Request Event
211
212**Event Name:** `continue_cli_api_request`
213
214**Attributes:**
215
216- All [standard attributes](#standard-attributes)
217- `event.name`: `"api_request"`
218- `event.timestamp`: ISO 8601 timestamp
219- `model`: Model identifier
220- `duration_ms`: Request duration in milliseconds
221- `success`: `"true"` or `"false"`
222- `error`: Error message (if failed)
223- `input_tokens`: Number of input tokens
224- `output_tokens`: Number of output tokens
225- `cost_usd`: Request cost in USD
226
227**Implementation:** Log in `src/streamChatResponse.ts` for each API request
228
229## Additional Metrics
230
231These metrics are unique to Continue CLI and provide additional insights without conflicting with compatibility:
232
233### Authentication Metrics
234
235#### ✅ `continue_cli_auth_attempts`
236
237**Type:** Counter
238**Unit:** `{attempt}`
239**Description:** Authentication attempts
240
241**Labels:**
242
243- All [standard attributes](#standard-attributes)
244- `result`: `success` | `failure` | `cancelled`
245- `method`: `workos` | `token`
246
247**Implementation:** Track in `src/auth/workos.ts`
248
249### MCP Integration Metrics
250
251#### ❌ `continue_cli_mcp_connections`
252
253**Type:** Gauge
254**Unit:** `{connection}`
255**Description:** Active MCP connections
256
257**Labels:**
258
259- All [standard attributes](#standard-attributes)
260- `server_name`: MCP server identifier
261- `status`: `connected` | `disconnected` | `error`
262
263**Implementation:** Track in `src/mcp.ts`
264
265### Performance Metrics
266
267#### ❌ `continue_cli_startup_time`
268
269**Type:** Histogram
270**Unit:** `ms`
271**Description:** Time from CLI start to ready state
272
273**Labels:**
274
275- All [standard attributes](#standard-attributes)
276- `mode`: `tui` | `headless` | `standard`
277- `cold_start`: `true` | `false`
278
279**Implementation:** Track in `src/index.ts` and `src/commands/chat.ts`
280
281#### ✅ `continue_cli_response_time`
282
283**Type:** Histogram
284**Unit:** `ms`
285**Description:** LLM response time metrics (supplements API request events)
286
287**Labels:**
288
289- All [standard attributes](#standard-attributes)
290- `model`: Model identifier
291- `metric_type`: `time_to_first_token` | `total_response_time`
292- `has_tools`: `true` | `false`
293
294**Implementation:** Track in `src/streamChatResponse.ts`
295
296## Implementation Guidelines
297
298### Migration from Claude Code Dashboards
299
300The core metrics (`session_count`, `lines_of_code_count`, `token_usage`, `cost_usage`, etc.) use identical naming and attribute structures to Claude Code, allowing for easy dashboard migration by simply changing the metric prefix from `claude_code_*` to `continue_cli_*`.
301
302### Privacy Considerations
303
304- **No PII**: Avoid logging file paths, user content, or other personally identifiable information
305- **Redacted by Default**: User prompts are redacted unless `OTEL_LOG_USER_PROMPTS=1`
306- **Configurable Attributes**: Use cardinality control variables to manage data granularity
307- **Opt-out**: Provide mechanism to disable telemetry entirely
308
309### Resource Attributes
310
311All metrics should include these resource attributes:
312
313- `service.name`: `continue-cli`
314- `service.version`: CLI version
315- `deployment.environment`: `development` | `production`
316- `os.type`: Operating system
317- `process.pid`: Process ID
318
319### Implementation Points
320
3211. **Session Tracking**: Initialize session ID and track lifecycle in `src/commands/chat.ts`
3222. **Token/Cost Tracking**: Implement in `src/streamChatResponse.ts` with model-specific pricing
3233. **Tool Usage**: Track in `src/tools/index.ts` and individual tool implementations
3244. **File Operations**: Implement diff analysis in `src/tools/writeFile.ts` for LOC tracking
3255. **Command Detection**: Parse git/gh commands in `src/tools/runTerminalCommand.ts`
3266. **Authentication**: Track auth flows in `src/auth/workos.ts`
3277. **Performance**: Add timing measurements throughout the application lifecycle
328
329## Implementation Status
330
331✅ = Implemented
332❌ = Not implemented yet
333
334**Core metrics:** 6/7 implemented (83%)
335**Core events:** 3/3 implemented (100%)
336**Additional metrics:** 4/7 implemented (57%)
337
338**Missing implementations:**
339
340- `continue_cli_code_edit_tool_decision` - requires user confirmation UI
341- `continue_cli_mcp_connections` - needs MCP service monitoring
342- `continue_cli_startup_time` - needs startup time tracking