You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7312ac0
Browse filesBrowse the repository at this point in the historyBrowse files
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]>
Copy file name to clipboardExpand all lines: docs/guide/copilot/index.md
+15-45Lines changed: 15 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
> GitHub Copilot CLI support is experimental.
4
4
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.
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.
28
28
29
29
```text
30
30
~/.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
36
34
```
37
35
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.
41
37
42
38
### session-state event schema
43
39
44
40
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.
45
41
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:
Without these variables, ccusage relies on the session-state source — which is the default for every Copilot CLI install.
58
-
59
42
## Report Views
60
43
61
44
| Focused view | Description | See also |
@@ -72,7 +55,7 @@ These views support `--json` for structured output, `--compact` for narrow termi
72
55
73
56
| Mode | What it shows for Copilot |
74
57
|---|---|
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|
76
59
|`display`| Source-precomputed only: AI Credits → premium-requests → `$0.00`. No token-priced fallback |
77
60
|`credits`| Always AI Credits (`$0.00` when source has no `totalNanoAiu`) |
78
61
|`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.
102
85
103
86
## What Gets Calculated
104
87
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.
107
90
-**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.
108
91
-**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`.
109
92
-**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`.
110
93
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.
|`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. |
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).
131
105
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/`.
Copy file name to clipboardExpand all lines: docs/guide/cost-modes.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ For Copilot specifically, `auto` is **era-aware**: it picks the right billing mo
33
33
34
34
-**Post-cutover sessions** (CLI ≥ 1.0.40, ships `totalNanoAiu`) → AI Credits × $0.01 — what GitHub actually bills against your AI Credit allotment.
35
35
-**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.
- 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)
0 commit comments