Repository navigation
feat(cli): Add sentry games leaderboard - #1437
Conversation
f775f5e to
49149a9
Compare
ba78133 to
2e16786
Compare
dd48465 to
e167a54
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
e167a54 to
73367ce
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 73367ce. Configure here.
32293fa to
d1efe47
Compare
038a46a to
5672812
Compare
5672812 to
8101f2c
Compare
8101f2c to
7b6e3a5
Compare
7b6e3a5 to
cb0ec05
Compare
cb0ec05 to
73fe47c
Compare
870f494 to
159de2b
Compare
73fe47c to
48c9e53
Compare
Report each finished Snake run as an anonymous `snake.score` metric, tagged only with a random local player handle, and show the top scores of the last 30 days with `sentry games leaderboard`. Scores are sent only when telemetry is on, in their own trace with the user cleared, and `beforeSendMetric` keeps only allowlisted attributes. The new `@sentry/games-api` Worker reads the metric from Sentry with a read-only token and serves the top 10, with a 5 minute cache and a per-IP rate limit. Its README describes the whole data flow and where to change it. Co-authored-by: Claude <[email protected]>
Co-authored-by: Claude <[email protected]>
The score flush ran unawaited, so on macOS the force-exit timer could stop the upload when the player quit right after game over. The command now waits for pending scores, bounded by the 3 s flush timeout, after it restores the terminal. Co-authored-by: Claude <[email protected]>
159de2b to
bec0f47
Compare
48c9e53 to
d1a3a7f
Compare
There was a problem hiding this comment.
The privacy design (separate trace, cleared user, allowlist scrubber, re-validation on both sides) holds up. Most of what's below is about matching patterns the repo already has.
-
Shared contract is copied, not shared. The handle regex,
snake.score, andMAX_SNAKE_SCOREare defined inlib/games/player.ts/score.ts, again ingames-api/src/leaderboard.tsbehind a "Must match the CLI" comment, andsnake.scoreis hard-coded a third time inscrubAnonymousMetricintelemetry.ts. The README's "they must match" row admits the drift risk. The repo already handles this case: contracts shared by the CLI and a Worker live in a@sentry/toolkit-coresubpath export (docs-mcpimports@sentry/toolkit-core/mcp-limitsso it applies the same limits as the main MCP server). Add a small@sentry/toolkit-core/gamesmodule with those constants, import it fromplayer.ts,score.ts,telemetry.ts, and the Worker, and drop the comment and README row. Both directions are allowed by the dependency rule inAGENTS.md, and it also avoids thetelemetry.ts→score.tsimport cycle that probably caused the literal. -
games leaderboarddoesn't followpackages/cli/AGENTS.md.formatLeaderboardHumancallsgetPlayerHandle()to add(you), so--jsonusers can't tell which row is theirs. The "Declaring Command Output" rules sayoutput.humanmust get the same data that's serialized, with no separate data path. Put the handle (or a per-entryyouflag) into the yielded data.- The HTTP client and its schemas sit in the command file. Under "Command File Structure", that goes in
src/lib, likelib/api/status-page.tsandlib/docs-service.tsdo for their non-Sentry services. - Network and HTTP failures throw
new CliError(msg), which exits 1. The error hierarchy reserves 3x exit codes for API/network failures, anddocs-service.tsusesApiError/CliError(…, EXIT.API)for the same kind of failure. - Building a
Writerbuffer aroundwriteTablereimplementsformatTable. ReturnformatTable(...)instead, asdocs/list.tsandexplore.tsdo.
-
games-apidiverges from the repo's two existing Workers.- Both
docs-mcpandmcp-cloudflareexportSentry.withSentry(...). This Worker only usesconsole.warn, so an expired or revoked read token shows up as silent 502s that nobody gets alerted about. - A standalone private Worker has a home and an ownership model in this repo:
apps/docs-mcpis listed indocs/README.md, has a "Deployment ownership" section, and is deployed by a gated workflow.docs/operations/github-actions.mdsays deployments are the case where a new workflow fits and that manual deploys of new revisions aren't the path. This package is underpackages/, isn't in the rootAGENTS.mdstructure or the docs index, hard-codesaccount_id(the others getCLOUDFLARE_ACCOUNT_IDfrom CI), and is deployed withpnpm run deployfrom a laptop. At minimum, list it in the docs index andAGENTS.mdand state who deploys it. Ideally, move it toapps/and give it a deploy job likedeploy-docs-mcp.yml. - Smaller point: the rate-limit block is copied from
routes/search.tsinstead of thecheckRateLimitshape inmcp-cloudflare/src/server/utils/rate-limiter.ts, and it fails closed (503) where that helper fails open. If failing closed is intended, add a one-line note.
- Both
Share the handle format, metric name, and score limit through @sentry/toolkit-core/games, so the CLI and the Worker cannot drift. In the CLI, move the leaderboard client to lib/games, exit with the API code on network and HTTP failures, render with formatTable, and put a `you` flag on each entry so JSON and human output carry the same data. Move the Worker to apps/games-api. Wrap it in Sentry.withSentry so upstream and token failures are reported, make the rate limiter fail open like mcp-cloudflare, read the account from CLOUDFLARE_ACCOUNT_ID, and deploy it from a gated workflow after the main Test run. Document its ownership in its README, the docs index, and AGENTS.md. Co-authored-by: Claude <[email protected]>
|
Addressed in 611f348:
Created with Claude Code |
Turn off collection of the client IP, headers, cookies, bodies and query strings through the SDK's dataCollection option, so spans and events both omit them. A new test sends a request through the production wrapper and checks the emitted envelope. Give the Cloudflare credentials only to the deploy workflow steps that use them, so dependency install scripts cannot read them. Co-authored-by: Claude <[email protected]>

Adds
sentry games leaderboard, which shows the top 10 Snake scores from the last 30 days. Stacked on #1432.The leaderboard is a working example of Sentry application metrics: the CLI emits a metric and the Worker reads it back, with no database.
apps/games-api/README.mddescribes the full data flow and lists which file to edit for each kind of change.Scores (CLI)
snake.scoremetric to the CLI telemetry project. Its only custom attribute is a random handle such asbrave-otter-4242, stored in the localmetadatatable.beforeSendMetrickeeps onlyhandle,sentry.release,sentry.environmentandsentry.sdk.*for this metric.@sentry/toolkit-core/games, which the CLI and the Worker both import.SENTRY_CLI_NO_TELEMETRY,DO_NOT_TRACK, or the stored preference).Endpoint (new
apps/games-apiWorker)sentry-games-api, onhttps://games.sentry.new. The MCP server is not changed: the read token never shares a Worker with its OAuth secrets.GET /v1/snake/leaderboardqueries thetracemetricsdataset formax(value)per handle, withvalue:<=10000.checkRateLimitin mcp-cloudflare. It caches the result with the Workers Cache API for 5 minutes.Sentry.withSentryreports upstream and missing-token failures tosentry-developer-experience/games-api. The SDK does not collect the client IP, headers, cookies, bodies or query strings. A test checks the emitted envelope through the production wrapper.--jsonentries carry ayouflag.Impact on other commands: +600 bytes on the startup path of every command (the metric scrubber in
telemetry.tsand theSENTRY_GAMES_API_URLregistry entry). The rest loads only forsentry games.Deployment. The Worker runs on the Sentry Internal Cloudflare account. The
Deploy Games APIworkflow deploys it after a successfulTestpush run onmain, the same gate asDeploy Docs MCP. Only the credential check andwrangler deploysteps receive the Cloudflare credentials. The MCP Workers use a different account, so the workflow has its own secrets. All of them are set:productionenvironment:GAMES_API_CLOUDFLARE_API_TOKEN(Workers Scripts: Edit on Sentry Internal; Workers Routes: Edit and Zone: Read onsentry.new) andGAMES_API_CLOUDFLARE_ACCOUNT_ID. The token is a personal token for now; replace it with an account-owned token when a Sentry Internal Super Administrator can create one.SENTRY_GAMES_READ_TOKEN(a bot token withorg:readonly, on a user that is a member only of the CLI team) andSENTRY_DSN.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
Created with Claude Code