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
feat: track per-generation token usage in telemetry (#336)
- Emit `generation` telemetry event on every LLM step-finish with model_id,
provider_id, agent, finish_reason, cost, duration_ms, and token breakdown
- Token fields are flat to comply with Azure App Insights custom measurements
schema: `tokens_input`, `tokens_output`, and optionally `tokens_reasoning`,
`tokens_cache_read`, `tokens_cache_write`
- Optional token fields are only included when the provider actually returns
them — reasoning only for reasoning models, cache fields only when active
- Remove unused `TokensPayload` type and special-case serializer handler
- Step duration tracked from `start-step` to `finish-step` events
- Update telemetry.md with accurate generation event field description
- Update existing tests for flat token field shape
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/docs/reference/telemetry.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
@@ -11,7 +11,7 @@ We collect the following categories of events:
11
11
|`session_start`| A new CLI session begins |
12
12
|`session_end`| A CLI session ends (includes duration) |
13
13
|`session_forked`| A session is forked from an existing one |
14
-
|`generation`| An AI model generation completes (model ID, token counts, duration — no prompt content)|
14
+
|`generation`| An AI model generation (step) completes — model ID, provider ID, agent, finish reason, cost, duration, and token breakdown: input, output, and when available: reasoning tokens (reasoning models only), cache-read tokens (prompt cache hit), cache-write tokens (new cache entry). No prompt content.|
15
15
|`tool_call`| A tool is invoked (tool name and category — no arguments or output) |
16
16
|`native_call`| A native engine call completes (method name and duration — no arguments) |
17
17
|`command`| A CLI command is executed (command name only) |
0 commit comments