Maintainer review fixes on top of the OTel cache-token work: - Remove all DEBUG_OTEL console.warn scaffolding from parser.ts and copilot.ts (gated but unlike the rest of the codebase). - Parameterize the spans IN (...) query instead of string-interpolating trace IDs. - Fold the per-chat-span metadata query into the trace-span query to drop the N+1 (one query per chat span -> one per conversation). - Guard epochToISO against null/NaN/0 so a malformed start_time_ms row no longer throws on new Date(NaN).toISOString(). - Remove dead code: parseSpanAttributes, OTelSpanRow, and the unreachable `if (!db) return`; drop unused catch bindings. - Note in parseProviderSources that the non-durable append path assumes unique source paths. - Document the OTel source in docs/providers/copilot.md: Node 22+ requirement, durable-cache monotonic totals, and the one-time parse-version cache reset on upgrade.
3.4 KiB
Copilot
GitHub Copilot Chat (CLI and VS Code extension transcripts).
- Source:
src/providers/copilot.ts - Loading: eager (
src/providers/index.ts:3) - Test:
tests/providers/copilot.test.ts(401 lines)
Where it reads from
Two JSONL locations plus an optional OpenTelemetry SQLite source (see below). All discovered sources are walked on every run; results merge and dedupe.
- Legacy CLI sessions:
~/.copilot/session-state/ - VS Code transcripts:
~/Library/Application Support/Code/User/workspaceStorage/<hash>/GitHub.copilot-chat/transcripts/and equivalents on Windows / Linux - OTel SQLite store: VS Code Copilot Chat's
agent-traces.db(see the OTel section). Preferred when present because it carries full input / output / cache token counts; the JSONL sources only record output tokens.
Storage format
JSONL in the first two locations (schemas differ; the parser switches by detecting which schema the first event uses), and a SQLite DB for the OTel source.
OpenTelemetry (OTel) source
When VS Code Copilot Chat's agent-traces.db exists, the parser reads per-LLM-call token
breakdowns (input, output, cache-read, cache-creation) from it, which the JSONL sources do
not record. Discovery is skipped with CODEBURN_COPILOT_DISABLE_OTEL=1, and the DB path
can be overridden with CODEBURN_COPILOT_OTEL_DB.
- Requires Node 22+. The OTel source uses the built-in
node:sqlitemodule (the same backend as Cursor / OpenCode). On Node 20, or if the DB is missing / locked / corrupt / wrong-schema, OTel is skipped and the JSONL/transcript sources are used as a fallback. - Durable cache (monotonic totals). Copilot is marked
durableSources: OTel-derived cache entries are never evicted when VS Code prunes old spans from the DB, so month-to-date totals do not drop as the DB rotates. Entries age out after 90 days. - Upgrade note. The first run after upgrading to the OTel version bumps the copilot parse version, which discards the prior copilot cache. Spans already pruned from the DB before the upgrade cannot be recovered, so monotonicity starts from the upgrade point, not retroactively.
Caching
None for the JSONL sources. The OTel source uses a durable cache (see above).
Deduplication
Per messageId in both formats (copilot.ts:118 for legacy, copilot.ts:245 for transcripts).
Model inference
Copilot does not always tag the model on each message. The parser infers it from the tool-call ID prefix:
| Prefix | Inferred model family |
|---|---|
toolu_bdrk_, toolu_vrtx_, tooluse_, toolu_ |
Anthropic |
call_ |
OpenAI |
See copilot.ts:176-213.
Quirks
toolRequestscan be missing or non-array on older sessions; the parser guards against that (copilot.ts:126,:260).- When
outputTokensis missing the parser falls back to char-counting (CHARS_PER_TOKEN = 4,copilot.ts:252-254). - A single chat may be mirrored across both legacy and transcript paths if the user upgraded; the dedup
messageIdcollision handles this.
When fixing a bug here
- Determine which schema reproduces the bug. The two parsers share little code on purpose; do not unify them unless you understand both formats.
- If the model is misidentified, look at the tool-call ID prefix list and consider whether a new prefix should be added.
- New fixtures go under
tests/fixtures/copilot/and are referenced fromtests/providers/copilot.test.ts.