Skip to content

Commit ef1d1a7

Browse files
suryaiyer95claude
andcommitted
feat: add \sql_execute_failure\ telemetry for SQL execution errors
\`core_failure\` is for internal tool failures. SQL execution via the dispatcher is a separate concern — soft errors are returned as results (not thrown), so \`core_failure\` never fires for them. New \`sql_execute_failure\` event captures: warehouse type, query type, error message (truncated to 500 chars), and PII-masked SQL. Fires from the \`sql.execute\` handler catch path. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2e73f2e commit ef1d1a7

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

docs/docs/configure/telemetry.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ We collect the following categories of events:
3434
| `mcp_server_census` | MCP server capabilities after connect (tool and resource counts — no tool names) |
3535
| `context_overflow_recovered` | Context overflow is handled (strategy) |
3636
| `skill_used` | A skill is loaded (skill name and source — `builtin`, `global`, or `project` — no skill content) |
37+
| `sql_execute_failure` | A SQL execution fails (warehouse type, query type, error message, PII-masked SQL — no raw values) |
3738
| `core_failure` | A tool failure occurs — error category, error message (truncated to 500 chars), and PII-masked arguments (string literals in SQL replaced with `?`, sensitive keys like `password`/`token`/`secret` fully redacted) |
3839

3940
Each event includes a timestamp, anonymous session ID, and the CLI version.

packages/opencode/src/altimate/native/connections/register.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ register("sql.execute", async (params: SqlExecuteParams): Promise<SqlExecuteResu
228228
} catch {}
229229
return result
230230
} catch (e) {
231+
const errorMsg = String(e)
231232
try {
232233
Telemetry.track({
233234
type: "warehouse_query",
@@ -239,11 +240,21 @@ register("sql.execute", async (params: SqlExecuteParams): Promise<SqlExecuteResu
239240
duration_ms: Date.now() - startTime,
240241
row_count: 0,
241242
truncated: false,
242-
error: String(e).slice(0, 500),
243+
error: errorMsg.slice(0, 500),
243244
error_category: categorizeQueryError(e),
244245
})
246+
Telemetry.track({
247+
type: "sql_execute_failure",
248+
timestamp: Date.now(),
249+
session_id: Telemetry.getContext().sessionId,
250+
warehouse_type: warehouseType,
251+
query_type: detectQueryType(params.sql),
252+
error_message: errorMsg.slice(0, 500),
253+
masked_sql: Telemetry.maskArgs({ sql: params.sql }),
254+
duration_ms: Date.now() - startTime,
255+
})
245256
} catch {}
246-
return { columns: [], rows: [], row_count: 0, truncated: false, error: String(e) } as SqlExecuteResult & { error: string }
257+
return { columns: [], rows: [], row_count: 0, truncated: false, error: errorMsg } as SqlExecuteResult & { error: string }
247258
}
248259
})
249260

packages/opencode/src/altimate/telemetry/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,16 @@ export namespace Telemetry {
341341
skill_source: "builtin" | "global" | "project"
342342
duration_ms: number
343343
}
344+
| {
345+
type: "sql_execute_failure"
346+
timestamp: number
347+
session_id: string
348+
warehouse_type: string
349+
query_type: string
350+
error_message: string
351+
masked_sql: string
352+
duration_ms: number
353+
}
344354
| {
345355
type: "core_failure"
346356
timestamp: number

0 commit comments

Comments
 (0)