feat(usage): add 24h component-cost chart to the usage view#3329
Open
webjunkie wants to merge 3 commits into
Open
feat(usage): add 24h component-cost chart to the usage view#3329webjunkie wants to merge 3 commits into
webjunkie wants to merge 3 commits into
Conversation
New "Last 24 hours" card on the Usage scene: an hourly stacked bar chart of personal PostHog Code spend split into cache read / cache write / uncached input / output components, fetched via the personal spend endpoint's new hourly=true param. Cache-write-dominated bars make cold session revivals (a stale session's whole context re-written to the prompt cache at full price) visually obvious. Hidden gracefully while the backend doesn't return by_hour yet. Generated-By: PostHog Code Task-Id: d7854448-4d18-44e7-b54a-d66e1ccddd0a
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
Contributor
|
Reviews (1): Last reviewed commit: "feat(usage): add 24h component-cost char..." | Re-trigger Greptile |
Generated-By: PostHog Code Task-Id: d7854448-4d18-44e7-b54a-d66e1ccddd0a
Hourly buckets dilute a cold-revival spike when other traffic shares the hour. 5-minute buckets match the prompt-cache TTL, so one bucket is roughly one turn and a revival stands alone. The bucket size now comes from the backend's generalized bucket_minutes param (by_bucket replaces by_hour); fillSpendHours generalizes to fillSpendBuckets and the card is renamed RecentUsageCard. Generated-By: PostHog Code Task-Id: d7854448-4d18-44e7-b54a-d66e1ccddd0a
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.
Problem
The Usage scene shows daily total cost, which is too coarse to explain sudden spend bursts. The most common surprise is a cold session revival: resuming a stale (non-cache-warm) session re-writes its whole context to the prompt cache at the cache-write rate, billing hundreds of thousands of tokens at full price in one turn. At daily, total-cost granularity that's invisible.
Why: we want users to see why a moment was expensive, not just that it was — specifically to surface cold-session revivals at a glance.
Changes
getPersonalSpendAnalysisgains abucketMinutesoption, and the spend-analysis types gain the optionalby_bucketbreakdown, matching the backend change in PostHog/posthog#69891.fillSpendBuckets(zero-filling, bucket-aligned, size-parameterized) added next tofillSpendDaysin@posthog/core/billing.by_bucketyet, so this is safe to merge ahead of the backend rollout.No screenshot: authored in a headless environment; the chart reuses
TimeSeriesBarChartexactly like the existingSpendOverTimeCard, with default stacked layout and a minute-interval x-axis.How did you test this?
fillSpendBucketscases tospendAnalysisFormat.test.ts: bucket alignment + zero-fill at hourly and 5-minute sizes, sub-bucket timestamps landing in their bucket (from review feedback), and the runaway-window cap. Ran them: 21/21 pass.turbo typecheckfor@posthog/core,@posthog/api-client,@posthog/ui: clean.pnpm --filter @posthog/ui test: 1429 tests pass.Automatic notifications
Created with PostHog Code