Skip to content

feat(copilot): OTel cache-token parsing (#477) + maintainer review fixes - #498

Merged
iamtoruk merged 3 commits into
mainfrom
copilot-otel-patched
Jun 18, 2026
Merged

feat(copilot): OTel cache-token parsing (#477) + maintainer review fixes#498
iamtoruk merged 3 commits into
mainfrom
copilot-otel-patched

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Supersedes #477. Contains @steelp02's OTel cache-token work (their commits are preserved) plus maintainer review fixes applied on top.

What #477 does

Adds a third copilot data source: VS Code Copilot Chat's OpenTelemetry SQLite store (agent-traces.db), which carries full input/output/cache token counts that the JSONL sources lack. Marks copilot durableSources so OTel-derived cache entries survive VS Code pruning old spans, keeping month-to-date totals monotonic (with a 90-day age-out).

Review outcome

Reviewed for security, correctness, and cross-provider breakage. No vulnerabilities, no blocker bugs. The shared parseProviderSources change is behavior-equivalent for all existing providers (no provider emits duplicate source paths). sqlite is opened read-only via the existing node:sqlite wrapper; a missing/locked/corrupt DB degrades gracefully to JSONL without affecting other providers.

Fixes applied on top (this branch's extra commit)

  • Removed all DEBUG_OTEL console.warn scaffolding from parser.ts and copilot.ts.
  • Parameterized the spans IN (...) query (was string-interpolated trace IDs).
  • Folded the per-chat-span metadata query into the trace-span query (drops an N+1).
  • Guarded epochToISO against null/NaN/0 (new Date(NaN).toISOString() throws).
  • Removed dead code (parseSpanAttributes, OTelSpanRow, unreachable if (!db) return) and unused catch bindings.
  • Documented in docs/providers/copilot.md: Node 22+ requirement for OTel, durable-cache monotonic totals, and the one-time parse-version cache reset on upgrade.

Verification

  • npm run build passes.
  • Full suite: 1176/1177 (the one failure is a pre-existing load-dependent timeout flake in usage-aggregator.test.ts; passes in isolation at ~4s).
  • The PR's own OTel/parser/copilot tests (40) pass.

Known caveat (documented, not a regression)

The first run after upgrade bumps the copilot parse version and discards the prior copilot cache, so spans already pruned from the DB before upgrade are not recoverable. Monotonicity starts from the upgrade point.

steelp02 and others added 3 commits June 10, 2026 22:58
…ests and regression checks.

Signed-off-by: steelp02 <pieter.steel@pfizer.com>
Signed-off-by: steelp02 <pieter.steel@pfizer.com>
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.
@iamtoruk
iamtoruk merged commit 7b484c1 into main Jun 18, 2026
3 checks passed
@iamtoruk
iamtoruk deleted the copilot-otel-patched branch June 18, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants