Skip to content

Commit 7312ac0

Browse files
jay-tauCopilot
andcommitted
refactor(adapter/copilot): stop reading OpenTelemetry data
The production loader now reads only session-state events.jsonl files. The OTel parser (parse_otel_file and helpers) is retained behind #[allow(dead_code)] so its existing parser unit tests continue to verify the chat-span / inference-log / agent-turn dispatch, but no production code path calls it. The full OTel surface (parser, env vars, coexistence handling) is scheduled for removal in ccusage#1208. Changes: - paths.rs: session_state_paths() replaces all_sources(); removed CopilotSource enum, COPILOT_OTEL_FILE_EXPORTER_PATH env var, and the OTel directory lookup. Tests assert OTel exporter env vars and otel/ subdirectories are now inert. - loader.rs: removed OTel branch from load_entries_inner, the apply_coexistence_rule function, the OtelDedupMode enum, and the COPILOT_OTEL_DEDUP / COPILOT_PREFER_OTEL env vars. Removed 7 OTel-coexistence tests and the two OTel-fixture-using mode tests; the display-mode-without-AIU test now uses a session-state fixture instead. - mod.rs: empty_usage_message() no longer mentions OTel as an alternative source. - parser.rs: added a documentation header explaining the legacy OTel block is reachable only from tests and marked the public entry points with #[allow(dead_code)]. - docs: dropped OTel data-source language from the guide pages, environment-variable table, getting-started, configuration example, and cost-modes `auto` description. Adapter README rewritten to drop the OTel schema, coexistence, and env-var tables; added a short "Legacy OpenTelemetry parser" pointer to ccusage#1208. Verified: 49 copilot tests + 249 crate tests pass. Smoke test against ~/.copilot/session-state/ returns identical totals to Piece E (74 days, $6,473.65, 8.73B tokens). Refs ccusage#1174 Refs ccusage#1208 Co-authored-by: Copilot <[email protected]>
1 parent 06a9cb6 commit 7312ac0

10 files changed

Lines changed: 416 additions & 940 deletions

File tree

‎docs/guide/configuration.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export AMP_DATA_DIR="$HOME/.local/share/amp"
5656
export PI_AGENT_DIR="$HOME/.pi/agent/sessions"
5757
export KILO_DATA_DIR="$HOME/.local/share/kilo"
5858
export COPILOT_CONFIG_DIR="$HOME/.copilot"
59-
export COPILOT_OTEL_FILE_EXPORTER_PATH="$HOME/.copilot/otel/copilot-otel.jsonl"
6059
```
6160

6261
Use comma-separated directories when you want reports to combine multiple profiles or archives:

‎docs/guide/copilot/index.md‎

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> GitHub Copilot CLI support is experimental.
44
5-
ccusage reads two complementary local data sources from the Copilot CLI directory: the per-session event stream the CLI writes by default (`session-state/<sessionId>/events.jsonl`), and optional OpenTelemetry JSONL exports (`otel/*.jsonl`). Both are consumed automatically when present, with deduplication between them. Reporting uses the same experience as the rest of ccusage: responsive tables, JSON output, LiteLLM-based pricing, cache token accounting, and all-source aggregation.
5+
ccusage reads GitHub Copilot CLI usage from the per-session event stream the CLI writes by default (`~/.copilot/session-state/<sessionId>/events.jsonl`). No configuration is required. Reporting uses the same experience as the rest of ccusage: responsive tables, JSON output, LiteLLM-based pricing, cache token accounting, and all-source aggregation.
66

77
## Focused Views
88

@@ -22,40 +22,23 @@ pnpm dlx ccusage copilot --help
2222

2323
:::
2424

25-
## Data Sources
25+
## Data Source
2626

27-
The Copilot CLI writes per-session events to `~/.copilot/session-state/<sessionId>/events.jsonl` on every install — no configuration is required. This is the primary source ccusage reads. The OpenTelemetry directory and explicit exporter file are only populated when the user has explicitly enabled OTel file export.
27+
The Copilot CLI writes per-session events to `~/.copilot/session-state/<sessionId>/events.jsonl` on every install — no configuration is required.
2828

2929
```text
3030
~/.copilot/
31-
├── session-state/ # primary source — written by default
32-
│ └── <sessionId>/
33-
│ └── events.jsonl
34-
└── otel/ # optional fallback / alternative
35-
└── *.jsonl
31+
└── session-state/
32+
└── <sessionId>/
33+
└── events.jsonl
3634
```
3735

38-
To override the base directory, set `COPILOT_CONFIG_DIR` to point elsewhere; ccusage will look for `session-state/` and `otel/` underneath it.
39-
40-
If you previously relied on the OpenTelemetry-only path described in older versions of this guide, those exports continue to work — both sources are read in parallel and deduplicated. See [Source coexistence](#source-coexistence-otel-session-state) below.
36+
To override the base directory, set `COPILOT_CONFIG_DIR` to point elsewhere; ccusage will look for `session-state/` underneath it.
4137

4238
### session-state event schema
4339

4440
Each `events.jsonl` file contains a stream of JSON records. The adapter reads `session.shutdown` events only; their `data.modelMetrics` map carries per-model token totals (`usage.{inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, reasoningTokens}`) and request counts. A resumed Copilot session produces multiple shutdown events in the same file — each is a per-process snapshot, summed at report time.
4541

46-
### Optional OpenTelemetry export
47-
48-
OTel export still works for users who want it. To enable, set the env vars before starting or resuming a Copilot CLI session:
49-
50-
```bash
51-
export COPILOT_OTEL_ENABLED=true
52-
export COPILOT_OTEL_EXPORTER_TYPE=file
53-
mkdir -p "$HOME/.copilot/otel"
54-
export COPILOT_OTEL_FILE_EXPORTER_PATH="$HOME/.copilot/otel/copilot-otel-$(date +%Y%m%d-%H%M%S).jsonl"
55-
```
56-
57-
Without these variables, ccusage relies on the session-state source — which is the default for every Copilot CLI install.
58-
5942
## Report Views
6043

6144
| Focused view | Description | See also |
@@ -72,7 +55,7 @@ These views support `--json` for structured output, `--compact` for narrow termi
7255

7356
| Mode | What it shows for Copilot |
7457
|---|---|
75-
| `auto` (default) | **True bill, era-aware**: AI Credits for post-cutover sessions (CLI ≥ 1.0.40), premium-request × $0.04 for pre-cutover sessions, token-priced for OTel-only data |
58+
| `auto` (default) | **True bill, era-aware**: AI Credits for post-cutover sessions (CLI ≥ 1.0.40), premium-request × $0.04 for pre-cutover sessions, token-priced for sessions with neither billing field |
7659
| `display` | Source-precomputed only: AI Credits → premium-requests → `$0.00`. No token-priced fallback |
7760
| `credits` | Always AI Credits (`$0.00` when source has no `totalNanoAiu`) |
7861
| `calculate` / `api-equiv` | Always LiteLLM token pricing — what the same usage would have cost via the underlying provider's API |
@@ -102,38 +85,25 @@ See [Cost Modes](/guide/cost-modes) for the full mode reference.
10285

10386
## What Gets Calculated
10487

105-
- **Token usage** — for session-state, `inputTokens` in the source schema already includes both cache reads and cache writes, so ccusage subtracts both to recover the "fresh" input bucket. For OTel, chat spans are preferred with inference logs and agent-turn logs as fallbacks.
106-
- **Cache tokens** — cache read and cache creation token attributes are counted from `cacheReadTokens` / `cacheWriteTokens` (session-state) or the corresponding `gen_ai.usage.cache_*` attributes (OTel).
88+
- **Token usage** — `inputTokens` in the session-state source schema already includes both cache reads and cache writes, so ccusage subtracts both to recover the "fresh" input bucket.
89+
- **Cache tokens** — cache read and cache creation tokens are counted from the source's `cacheReadTokens` / `cacheWriteTokens` fields.
10790
- **Reasoning tokens** — provider-dependent. For OpenAI (`gpt-*`) and Anthropic (`claude-*`) models reasoning is already inside `outputTokens` and is not double-counted. For Google (`gemini-*`) models reasoning is reported separately and is summed into the output cost bucket.
10891
- **Credits** — when present, `totalNanoAiu` is divided by 10⁹ to get the AI Credit count (`1 credit = $0.01`). Always surfaced in JSON; becomes the primary cost basis under `--mode credits`.
10992
- **Pricing** — for non-credits modes, costs are calculated from LiteLLM pricing data using a normalized form of the model name. The raw name (e.g. `claude-opus-4.7-1m-internal`) is preserved in JSON, the table's `Models` column, and `modelsUsed`.
11093

111-
## Source coexistence (OTel + session-state)
112-
113-
When both `~/.copilot/otel/*.jsonl` and `~/.copilot/session-state/<uuid>/events.jsonl` exist, both are loaded. To avoid double-counting, ccusage drops OTel-derived entries whose resolved `session_id` matches a session-state session. The OTel `session_id` is resolved from the existing parser priority chain (`gen_ai.conversation.id`, `copilot_chat.session_id`, `session.id`, `github.copilot.interaction_id`, `gen_ai.response.id`).
114-
115-
> Caveat: whether OTel's `session_id` matches the session-state directory UUID is not yet empirically verified across all Copilot CLI versions. If your IDs do not match, the loose default leaves both sources in place and totals can be inflated. The `COPILOT_OTEL_DEDUP=strict` setting drops OTel wholesale whenever any session-state shutdown is loaded — a conservative anti-double-count if you observe inflated totals.
116-
11794
## Environment Variables
11895

119-
| Variable | Description |
120-
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
121-
| `COPILOT_CONFIG_DIR` | Override the base Copilot directory (default: `~/.copilot`). Both `session-state/` and `otel/` are discovered underneath it. |
122-
| `COPILOT_OTEL_FILE_EXPORTER_PATH` | Add a single explicit OpenTelemetry `.jsonl` file as an additional source (mirrors what the Copilot CLI itself reads when set). |
123-
| `COPILOT_OTEL_DEDUP` | Coexistence policy when both sources contain entries. `loose` (default) — match by session id. `strict` — drop OTel whenever any session-state shutdown is loaded. `off` — disable the dedup step entirely. |
124-
| `COPILOT_PREFER_OTEL` | When set (non-empty / non-zero / not `false`), invert the coexistence rule so OTel wins for any session that appears in both sources. |
125-
| `LOG_LEVEL` | Adjust verbosity (0 silent ... 5 trace) |
96+
| Variable | Description |
97+
| -------------------- | -------------------------------------------------------------------------------------------- |
98+
| `COPILOT_CONFIG_DIR` | Override the base Copilot directory (default: `~/.copilot`). `session-state/` is discovered underneath it. |
99+
| `LOG_LEVEL` | Adjust verbosity (0 silent ... 5 trace) |
126100

127101
## Troubleshooting
128102

129103
::: details No Copilot usage data found
130104
The Copilot CLI writes per-session events to `~/.copilot/session-state/<sessionId>/events.jsonl` automatically. If `ccusage copilot daily` still reports no data, verify that the directory exists and that at least one of the per-session subdirectories contains an `events.jsonl` with a `session.shutdown` event (resumed sessions only produce shutdown rows on graceful exit).
131105

132-
If you have configured `COPILOT_CONFIG_DIR`, make sure it points at the directory that contains `session-state/`. As a fallback, OpenTelemetry file export still works — see the env-var block above.
133-
:::
134-
135-
::: details Inflated totals when OTel export is also enabled
136-
If you have both `~/.copilot/otel/*.jsonl` files and `~/.copilot/session-state/<uuid>/events.jsonl` files for the same Copilot sessions, the same usage may be counted twice. Set `COPILOT_OTEL_DEDUP=strict` to drop the OTel entries whenever a session-state shutdown is present, or unset `COPILOT_OTEL_FILE_EXPORTER_PATH` and remove the `otel/` directory to skip the OTel path entirely.
106+
If you have configured `COPILOT_CONFIG_DIR`, make sure it points at the directory that contains `session-state/`.
137107
:::
138108

139109
::: details Costs showing as $0.00

‎docs/guide/cost-modes.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ For Copilot specifically, `auto` is **era-aware**: it picks the right billing mo
3333

3434
- **Post-cutover sessions** (CLI ≥ 1.0.40, ships `totalNanoAiu`) → AI Credits × $0.01 — what GitHub actually bills against your AI Credit allotment.
3535
- **Pre-cutover sessions** (ships `requests.cost` for premium-request count) → `requests.cost × $0.04` — what GitHub charged at the overage rate. Free-tier rows (`requests.cost == 0` for sonnet/haiku in your subscription) genuinely bill $0 under that model.
36-
- **OTel-only data** (no source-shipped cost) → LiteLLM token pricing as best-effort fallback.
36+
- **Sessions without billing fields** (rare) → LiteLLM token pricing as best-effort fallback.
3737

3838
#### Best for:
3939

‎docs/guide/environment-variables.md‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ ccusage detects supported data source files from conventional locations by defau
2121
| `KILO_DATA_DIR` | Kilo | `~/.local/share/kilo` |
2222
| `KIMI_DATA_DIR` | Kimi | `~/.kimi` |
2323
| `QWEN_DATA_DIR` | Qwen | `~/.qwen` |
24-
| `COPILOT_CONFIG_DIR` | Copilot CLI | `~/.copilot` (base dir; reads `session-state/<sessionId>/events.jsonl` and `otel/*.jsonl` underneath) |
25-
| `COPILOT_OTEL_FILE_EXPORTER_PATH` | Copilot CLI | Explicit OpenTelemetry `.jsonl` file (added on top of the base dir) |
26-
| `COPILOT_OTEL_DEDUP` | Copilot CLI | `loose` (default) / `strict` / `off` — coexistence policy when both OTel and session-state contain entries |
27-
| `COPILOT_PREFER_OTEL` | Copilot CLI | Set (non-empty / non-zero / not `false`) to make OTel win for any session that appears in both sources |
24+
| `COPILOT_CONFIG_DIR` | Copilot CLI | `~/.copilot` (base dir; reads `session-state/<sessionId>/events.jsonl` underneath) |
2825
| `GEMINI_DATA_DIR` | Gemini CLI | `~/.gemini/tmp` |
2926

3027
Example:
@@ -43,7 +40,6 @@ export KILO_DATA_DIR="/path/to/kilo,/archive/kilo"
4340
export KIMI_DATA_DIR="/path/to/kimi,/archive/kimi"
4441
export QWEN_DATA_DIR="/path/to/qwen,/archive/qwen"
4542
export COPILOT_CONFIG_DIR="/path/to/copilot"
46-
export COPILOT_OTEL_FILE_EXPORTER_PATH="/path/to/copilot-otel.jsonl"
4743
export GEMINI_DATA_DIR="/path/to/gemini/tmp,/archive/gemini/tmp"
4844
ccusage daily
4945
```

‎docs/guide/getting-started.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ If ccusage shows no data, check:
175175
- Kimi: `${KIMI_DATA_DIR:-~/.kimi}`
176176
- OpenClaw: `${OPENCLAW_DIR:-~/.openclaw}` (also scans `~/.clawdbot`, `~/.moltbot`, `~/.moldbot`)
177177
- Qwen: `${QWEN_DATA_DIR:-~/.qwen}`
178-
- GitHub Copilot CLI: `${COPILOT_CONFIG_DIR:-~/.copilot}/session-state/<sessionId>/events.jsonl` (default; written by the CLI on every install) or `${COPILOT_CONFIG_DIR:-~/.copilot}/otel/*.jsonl` / `COPILOT_OTEL_FILE_EXPORTER_PATH` for OpenTelemetry exports
178+
- GitHub Copilot CLI: `${COPILOT_CONFIG_DIR:-~/.copilot}/session-state/<sessionId>/events.jsonl` (written by the CLI on every install)
179179

180180
### Custom Data Directory
181181

@@ -196,7 +196,6 @@ export KILO_DATA_DIR="/path/to/kilo"
196196
export KIMI_DATA_DIR="/path/to/kimi"
197197
export QWEN_DATA_DIR="/path/to/qwen"
198198
export COPILOT_CONFIG_DIR="/path/to/copilot"
199-
export COPILOT_OTEL_FILE_EXPORTER_PATH="/path/to/copilot-otel.jsonl"
200199
```
201200

202201
Each source-specific path variable can also contain comma-separated directories:

0 commit comments

Comments
 (0)