Repository navigation
bodylog: export actual_usage's cached_tokens as its own counter - #31
Draft
zhanghaohit wants to merge 1 commit into
Draft
zhanghaohit wants to merge 1 commit into
zhanghaohit wants to merge 1 commit into
Conversation
bodylog_cached_tokens_total counts usage.prompt_tokens_details.cached_tokens -- what clients and billing see. Some sglang builds also return actual_usage with the engine's own count, which can differ (e.g. 2048 vs 3072), and that number reached no metric. listener: the details line gets actual_cached_tokens, from resp_meta.actual_usage.prompt_tokens_details.cached_tokens, only when that is a number, so "not reported" and "reported 0" stay apart; the DuckDB details schema gains the column (older files read it as NULL). exporter: bodylog_actual_cached_tokens_total, same labels as bodylog_cached_tokens_total, fed only by lines that carry the field.
zhanghaohit
marked this pull request as draft
November 10, 2026 09:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
metrics/details/<date>.jsonl, what the exporter tails) getsactual_cached_tokens, taken fromresp_meta.actual_usage.prompt_tokens_details.cached_tokens.actual_usage, or withcached_tokens: null, has no field, so "not reported" and "reported 0" stay apart.bodylog_actual_cached_tokens_total, with the same labels asbodylog_cached_tokens_total(service, route, backend, model). Only lines that carry the field feed it.Why
bodylog_cached_tokens_totalcountsusage.prompt_tokens_details.cached_tokens, which is what clients and billing see. Some sglang builds also returnactual_usagewith the engine's own count, and it can differ:Since #30 the bodylog keeps
actual_usageinresp_meta, but the number reached no metric. With both counters, a dashboard can show the reported and the engine-side hit rate side by side.Tests
TestDetailActualCachedTokenscovers:null, noprompt_tokens_details, and absent;cached_tokensstays at usage's figure in every case;TestActualCachedTokensCounter: three lines with 3072 / 0 / no field.bodylog_cached_tokens_total= 3 × 2048 andbodylog_actual_cached_tokens_total= 3072. Fails on the previousmetrics.go.go test ./...passes in both modules.