Sentry used a coding agent on its own traces and cut hundreds of millions of queries a week
Brief
Sentry's engineer wired a coding agent to Sentry MCP, ran it against Sentry's own traces, and used the resulting small fixes to remove hundreds of millions of queries a week.
How the agent was used
- Agent used was Claude with Opus 5.5, connected to Sentry MCP and pointed at Sentry's own org and project.
- Agent sorted spans by execution frequency and duration, returning file and line, estimated weekly volume and a link to an example trace.
- Short follow-up prompts steered it (e.g. "look for database heavy issues", "rpc might also be interesting", "lets not touch that area").
- The agent read code and git history, assessed risk, validated SQL with EXPLAIN ANALYZE on a read-only database mirror, then opened draft PRs.
What the traces revealed
- Django SDK instrumentation made query spans include SQL as their description; spans could be grouped by description into a ranked list of expensive work.
- Query-source attributes gave file and line; the user_agent attribute showed one busy endpoint was mostly sentry-cli set-commits --auto, with one org of ~16k repositories paging roughly every 40 seconds.
Measured results
- Skipping a query when the property does not exist on the event removed an UPDATE running ~10k/s on the US attachments database; commits there fell ~17% and link_event_to_user_report went ~6ms → ~2.5ms.
- Reusing the already loaded project removed an estimated ~143M extra SELECTs a week; save_issue_occurrence p50 went ~35ms → ~30ms and p95 ~95ms → ~61ms versus the same hours the previous day.
- A rearranged GroupHistory query's disk reads fell to nearly zero (it was ~8% of primary disk reads in EU Germany, ~3% in US); status changes were ~30% faster in US and ~13% faster in EU.
- Eager-loading app and token cut two selects from ~1.9% to ~0.16% of control-database query volume (~29M fewer queries a day).
- A missing repository-pagination index cut average DB execution ~69% (30ms → 9.2ms) with ~52% fewer cached block accesses; batching cache writes took ~51ms → ~1.2ms.
- A detector query on the mirror fell from 180ms to 0.2ms with a warm cache; the GroupHistory rewrite went from 935ms to 0.4ms for the busiest group on the mirror with a warm cache.
Caveats and trying it yourself
- Query volumes and daily savings are estimates based on sampled spans and observed traffic.
- Setup: sign up for Sentry, give your coding agent access to Sentry MCP, then prompt it — starting general, then narrowing to things like N+1 queries, SELECT * on hot paths, or missing-index pagination.
Generated by AI from the original article. Check the source for full details.