Skip to content

v0.1.2

Choose a tag to compare

@Albert-code-1114 Albert-code-1114 released this 12 Oct 14:50
· 2 commits to main since this release

What changed

Fixed — one API call was being billed twice

Copilot Chat writes two records per model call: a
gen_ai.client.inference.operation.details record, and a second record with no
event.name at all. They share gen_ai.response.id but not a span, and only
one of the two carries gen_ai.usage.cache_read.input_tokens. The span-based
de-duplication id therefore never paired them, so every call was counted at its
full prompt size twice over.

Measured over one live export file (57.9 MB):

Fact Count
usage records 1,800
distinct gen_ai.response.id 923
ids that repeat 837
…with byte-identical token counts 817
…with a different cache_read value 827

Records are now paired by gen_ai.response.id and merged per field with a
maximum, never a sum
: the two records are two views of one response, so summing
re-bills the whole prompt while the max keeps it counted once and still picks up
the cache figure that only one side has. On the same day of real traffic the
figure went from 29.8M → 2.97M.

Added — per-route split: your endpoint vs Copilot's own models

The split is driven by the server.address each record carries — the host that
actually answered the request — with copilotOtelUsage.gatewayModels as a
name-based net for the paired record that omits the host. It works with no
configuration at all
: a host that is not GitHub's own is treated as yours.

The short model name is deliberately not used as a discriminator:
gen_ai.provider.name is github for both routes, and deepseek-flash is a
substring of deepseek-v4-flash-ascend1.

  • copilotOtelUsage.statusBarScope (all / gateway / internal), switchable
    without opening settings via 切换统计范围. When a scope hides a route that has
    traffic, the status bar appends ↑ <amount> so a number is never silently partial.
  • Details panel and Markdown report gained a 按链路 section above 按模型.
  • copilotOtelUsage.showGroups turns the section off.
  • The cost format intentionally ignores the scope: pricing rules match by model
    name, so restricting the scope would produce a misleading estimate.

Also in 0.1.1 (included here)

  • The total no longer counts cache-read tokens: the wire format reports cache
    reads inside input, and they were being added to output as if fresh. The
    total is now (input − cached) + output — billable tokens, the same rule
    gateways use.
  • Removed a dead resourceSpans fan-out in the OTel reader: the live file
    contains 2,234 flat log records and 6,474 metric envelopes, but zero
    resourceSpans.
  • Fixed a "no-id fingerprint" de-dupe path that stored an object and compared it
    with now - seenAt — which is NaN, so it never matched anything.
  • Added .vscodeignore: the packaged vsix carries only the runtime.

Install

code --install-extension copilot-otel-usage-0.1.2.vsix

sha256: 8C90932F5E7763971BC123B9F39AEB0A0AEA0C101C2233A4BDB800246C1BB63E

Upgrading from 0.1.1 or 0.1.0? The stored state still holds the pre-fix
totals. After installing: reload the window → run
Copilot Token Usage: 重置今日统计 → run 重新扫描数据源.

Verification

4/4 suites pass: parser 38 assertions, otel 40, smoke 19, activation harness 15
(the last one drives the real cycleScope command and asserts the status bar
text at all three scopes).