Skip to content

feat(cli): Add an anonymous Snake leaderboard - #1437

Draft
sergical wants to merge 2 commits into
feat/cli-gamesfrom
feat/cli-games-leaderboard
Draft

sergical wants to merge 2 commits into
feat/cli-gamesfrom
feat/cli-games-leaderboard

Conversation

@sergical

@sergical sergical commented Oct 7, 2026

Copy link
Copy Markdown
Member

Adds sentry games leaderboard, which shows the top 10 Snake scores from the last 30 days. Stacked on #1435.

Scores (CLI)

  • A finished game sends one snake.score metric to the CLI telemetry project. Its only custom attribute is a random handle such as brave-otter-42, stored in the local metadata table.
  • The metric goes out in a new trace with the user cleared on both scopes. beforeSendMetric keeps only handle, sentry.release, sentry.environment and sentry.sdk.* for this metric.
  • Nothing is sent when telemetry is off (SENTRY_CLI_NO_TELEMETRY, DO_NOT_TRACK, or the stored preference).

Endpoint (sentry-mcp Worker)

  • GET /api/games/snake/leaderboard queries the tracemetrics dataset for max(value) per handle, with value:<=10000.
  • It rate-limits by hashed IP (30/min) and caches the result in KV for 5 minutes.
  • It checks the upstream rows against the handle format and the score bounds. Every failure returns a generic error. The token, URL and upstream text never reach the response or the logs.
  • The CLI validates each row again and drops rows that fail, so server text cannot write control sequences to the terminal.

Setup before deploy

  1. Create a token on a bot account that is only a member of the team that owns the CLI project, with the org:read scope only.
  2. npx wrangler secret put SENTRY_GAMES_READ_TOKEN from packages/mcp-cloudflare.
  3. Optional: turn on "Prevent storing IP addresses" on the CLI project. This also affects the rest of the CLI telemetry.

Known limit: the DSN is public, so anyone can submit a score. The handle format and the 10,000 cap block only impossible values.

Breaking Changes: None

@sergical
sergical force-pushed the feat/cli-games-leaderboard branch from 4ad0467 to f775f5e Compare October 7, 2026 15:17
A finished Snake game sends one snake.score metric tagged only with a
random player handle. It goes out in a new trace with the user cleared,
and beforeSendMetric keeps only an attribute allowlist. Nothing is sent
when telemetry is off.

The sentry-mcp Worker serves GET /api/games/snake/leaderboard. It reads
the top 10 scores of the last 30 days with a read-only token, caches the
result in KV, rate-limits by hashed IP, and returns only generic errors.
`sentry games leaderboard` validates every row again before it prints.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sergical
sergical force-pushed the feat/cli-games-leaderboard branch from f775f5e to 49149a9 Compare October 7, 2026 15:25
Score reporting runs from the game timer, so a database or transport error
could crash sentry init. It now logs the error and skips the score.

Handles had only 102,400 values, so two players were likely to share one
after a few hundred players. Four-digit suffixes give about 10 million. An
old two-digit handle is replaced the next time it is read.

Co-authored-by: Claude <claude@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant