Skip to content

ref(metrics): Store Conversation Run metrics as rows - #1847

Merged
dcramer merged 9 commits into
mainfrom
fix/dashboard-cache-hit-usage
Sep 11, 2026
Merged

dcramer merged 9 commits into
mainfrom
fix/dashboard-cache-hit-usage

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Store each Conversation Run metric as its own SQL row. A repeated write for the same Run replaces those rows. This removes the custom subtraction code that caused cache token fields to disappear.

The table is reusable for any numeric Run metric. This first pass stores duration, cost, and every token value Junior receives: total, input, output, cached input, cache creation, and reasoning tokens.

The existing Conversation metric fields remain as cached totals for current readers. Each write rebuilds those totals from the metric rows. The migration copies existing duration, token, and cost totals into the new table.

The stats endpoint uses one query to sum every metric by UTC day or hour. The response schema does not change.

Checks

  • GET /api/conversations/stats integration tests cover total, daily, and hourly cache fields.
  • The Conversation SQL store test covers repeated Run writes and all token metric rows.
  • Full @sentry/junior test suite: 2,859 passed, 1 skipped.
  • TypeScript, lint, Prettier, migration metadata, and test architecture checks pass.

via David Cramer.

--

View Junior Session [Sentry]

Co-Authored-By: David Cramer <david@sentry.io>
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Sep 11, 2026 6:52pm UTC

Request Review

Co-Authored-By: David Cramer <david@sentry.io>
Comment thread packages/junior/tests/integration/api/conversations/stats.test.ts Outdated
@dcramer
dcramer marked this pull request as ready for review September 11, 2026 15:37
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Sep 11, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/junior/src/chat/conversations/sql/store.ts Outdated
Co-Authored-By: David Cramer <david@sentry.io>
Co-Authored-By: David Cramer <david@sentry.io>
Co-Authored-By: David Cramer <david@sentry.io>
@sentry-junior sentry-junior Bot changed the title fix(dashboard): Preserve cache token usage ref(metrics): Store Conversation Run metrics as rows Sep 11, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 15d1e3a. Configure here.

Comment thread packages/junior/src/api/conversations/stats.query.ts
Comment thread packages/junior/src/chat/conversations/metrics.ts Outdated
Comment thread packages/junior/src/chat/conversations/sql/store.ts
Co-Authored-By: David Cramer <david@sentry.io>
Co-Authored-By: David Cramer <david@sentry.io>
@dcramer
dcramer merged commit 2b2140d into main Sep 11, 2026
40 checks passed
@dcramer
dcramer deleted the fix/dashboard-cache-hit-usage branch September 11, 2026 18:58

This branch was successfully deployed

1 active deployment
Preview – junior-docs 195075d5 Deployed Sep 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant