Skip to content

fix(mcp): Chart the busiest groups and keep empty buckets empty - #2453

Open
sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/chart-series-by-volume
Open

sentry-junior[bot] wants to merge 2 commits into
mainfrom
fix/chart-series-by-volume

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the render_sentry_chart problems in #2451. When the y-axis was p95 and the chart was grouped by release, it showed the five releases with the highest p95. Those were releases with 1–57 events each, all stuck at the 30s pageload cap. Empty buckets were drawn as 0, and every bucket went out as its own object.

Series selection. Top groups are now always ranked by event volume. The tool sends count() as a second yAxis with sort=-count(), because Sentry only sorts top events by a column it selects. I went with "always" rather than "only for non-additive aggregates" for three reasons:

  • One rule is easier to explain: "the 5 values with the most events".
  • It also covers avg, max, failure_rate, and the like.
  • The same request gives each series its event count.

Trace metrics count per metric, so for fn(value,name,type,unit) the ranker is count(value,name,type,unit). A metrics y-axis that doesn't name its metric keeps the old sort by y-axis. On the errors dataset, Discover's top-events query adds the orderby aggregate on its own (auto_aggregations), so -count() works there too.

Empty buckets. The chart no longer uses summarizeSeries, so a missing value stays null and draws as a gap. A bucket with data on both sides empty draws as a dot, and the tooltip says "no data". summarizeSeries and the search_events text output are unchanged.

Payload. This changes the output schema. The result now has:

  • one shared times array;
  • incomplete and outsideRetention as bucket index lists;
  • per series: { label, count, total, values }, where values is an array with nulls.

Non-integer values keep 8 significant digits, which removes float noise. For 7d at 1h with 5 series, the result drops from about 200 KB to about 12 KB. The text content is the same JSON, so the model's copy shrinks too. The view's URI moves to ui://sentry/chart/v3.html because hosts cache views by URI. The tool is experimental, so no stable client sees the schema change.

Clarity.

  • Legend and tooltip labels shorten 40-character SHAs to 7 characters. Hovering a legend entry shows the full value.
  • The legend shows each series' event count, for example 1d7f4b2 · 57 events.
  • Only a single-series chart shows a peak. On a grouped chart, one group's highest bucket would read as the chart's peak, and Sentry's own chart widgets don't show one either.

Offline proof. The events-timeseries mock now honors sort. For grouped requests it returns three busy releases and five sparse ones: 1–57 events, all at 30s, mostly null buckets. Sorting by p95 picks the sparse five, which is the bug in #2451. map/mcp-apps.md gains three claims that mcp-apps-host.mjs drives, and the grouped claim now covers the legend's short labels and event counts, and the absence of a peak:

  • top-by-volume
  • null-gaps
  • compact-result: a 16 KiB budget for 7d/1h × 5 series. That leaves about 30% headroom over ~12 KB and still catches any return to per-bucket objects.

Follow-ups, not in this change:

  • Grouping by release with no environment: filter still lets preview and legacy environments compete for the five slots. Defaulting to production would quietly change what the query means, so I'd rather the tool description tell the model to add environment: when it groups by release.
  • "Open in Sentry" still links to Explore/Discover sorted by the y-axis, so its own top-5 can differ from the chart. Changing the link means confirming how each Explore URL takes a sort on a column that isn't charted.
  • Explore fades low-confidence buckets using the API's per-bucket confidence. The chart could do the same once it has proven useful.

via @dcramer.

--

View Session [Sentry]

render_sentry_chart ranked top groups by the charted aggregate, so p95 by
release picked releases with a handful of events at the 30s pageload cap
and hid the releases carrying the traffic. Rank groups by event count
instead, fetched as a second yAxis, which also gives each series its
count.

Buckets with no data are null instead of 0 and draw as gaps. The result
shares one times array across series and sends per-series value arrays,
so 7d at 1h with 5 series drops from about 200 KB to about 12 KB. The
legend shortens commit SHAs and shows each series' event count, and the
peak describes the busiest series.

The events-timeseries mock now honors sort and returns sparse groups
with null buckets, and the verify-toolkit host checks ranking, gaps, and
the result size.

Refs #2451

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
cli Ready Ready Preview Nov 20, 2026 11:08pm UTC
sentry-local Ready Ready Preview Nov 20, 2026 11:08pm UTC

Request Review

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

📊 MCP Server Token Cost Report

Summary

  • Total Tokens: 65205 tokens
  • Tool Count: 74 tools
  • Average: 881 tokens/tool

Per-Tool Breakdown

Tool Tokens % of Total
get_issue_details 3938 6%
get_alert_rule 2245 3.4%
find_releases 1805 2.8%
get_issue_activity 1759 2.7%
update_alert_rule 1653 2.5%
get_replay_details 1602 2.5%
create_alert_rule 1506 2.3%
get_monitor_details 1501 2.3%
update_metric_monitor 1479 2.3%
create_metric_monitor 1458 2.2%
get_event_stacktrace 1381 2.1%
update_issue 1380 2.1%
get_snapshot 1308 2%
get_profile 1291 2%
get_agent_conversation_details 1278 2%
find_monitors 1261 1.9%
search_logs 1248 1.9%
search_traces 1246 1.9%
get_alert_options 1236 1.9%
search_profiles 1228 1.9%
search_metrics 1216 1.9%
search_errors 1214 1.9%
get_profile_details 1200 1.8%
get_uptime_monitor_details 1163 1.8%
create_monitor 1135 1.7%
onboarding_status_update 1109 1.7%
search_issue_events 1103 1.7%
search_replays 1095 1.7%
find_related_issues 1068 1.6%
get_release_details 1056 1.6%
get_dashboard_details 1052 1.6%
search_issues 977 1.5%
search_docs 973 1.5%
find_alert_rules 908 1.4%
update_uptime_monitor 873 1.3%
create_uptime_monitor 871 1.3%
search_agent_conversations 830 1.3%
find_dropped_events 819 1.3%
get_metric_monitor_details 797 1.2%
create_project 793 1.2%
update_dsn 765 1.2%
get_issue_user_reports 630 1%
get_latest_base_snapshot 623 1%
find_dashboards 553 0.8%
link_issue 545 0.8%
find_uptime_monitors 537 0.8%
get_issue_breadcrumbs 492 0.8%
unlink_issue 476 0.7%
find_metric_monitors 471 0.7%
get_issue_tag_values 469 0.7%
update_project 441 0.7%
get_sentry_resource 429 0.7%
submit_feedback_to_sentry_team 426 0.7%
add_issue_note 404 0.6%
delete_monitor_environment 363 0.6%
find_teams 351 0.5%
find_projects 346 0.5%
delete_alert_rule 345 0.5%
delete_uptime_monitor 333 0.5%
delete_metric_monitor 331 0.5%
create_dsn 326 0.5%
add_team_to_project 324 0.5%
remove_team_from_project 320 0.5%
find_dsns 319 0.5%
find_organizations 311 0.5%
get_snapshot_image 302 0.5%
analyze_issue_with_seer 300 0.5%
get_event_attachment 299 0.5%
get_trace_details 282 0.4%
create_team 266 0.4%
get_span_details 263 0.4%
whoami 261 0.4%
get_sentry_mcp_info 142 0.2%
get_doc 102 0.2%

Note: This measures the static overhead of tool definitions sent to LLM clients with every request. Lower is better.

MCP Apps views

Each ui:// view as a host receives it from resources/read.

View MIME type Raw Gzip Brotli Budget % of budget
ui://sentry/chart/v3.html text/html;profile=mcp-app 17,018 B 7,155 B 6,370 B 24,576 B 69.2%

The budget applies to raw bytes, and the view's generator fails over it.

@dcramer

dcramer commented Nov 20, 2026

Copy link
Copy Markdown
Member

You can also look at how the Century application itself is doing this and see if there are patterns we should copy from there or if there's a better visual or something along those lines. Come back because I don't want a really complicated first implementation when we haven't proven value here, but it has to be performant. It has to be useful. It has to be correct

@dcramer
dcramer marked this pull request as ready for review November 20, 2026 22:52
@dcramer
dcramer requested a review from a team as a code owner November 20, 2026 22:52
@sentry-junior
sentry-junior Bot requested a review from dcramer November 20, 2026 22:52
@dcramer

dcramer commented Nov 20, 2026

Copy link
Copy Markdown
Member

Also, this MCP server token cost report is pretty noisy. Let's kick off another thread that just keeps that in CI with a status detail thing, which I think we already have. And there's not a budget for the MCP UI stuff. It's just more that each thing should hard fail if it goes over it, over like something that's a reasonable amount of bytes

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 20, 2026
Comment on lines +167 to +205
it("charts the busiest releases, keeps empty buckets null, and stays small for 7d at 1h", async () => {
const chart = getStructuredContent<ChartResult>(
await renderSentryChart.handler(
{
...baseParams,
dataset: "spans",
query: "is_transaction:true",
yAxis: "p95(span.duration)",
groupBy: "release",
period: "7d",
interval: "1h",
},
context,
),
);

expect(chart.times).toHaveLength(168);
expect(
chart.series.map(({ label, count }) => [label.slice(0, 8), count]),
).toEqual([
["3f9c2e1a", 20160],
["8b41d07c", 10080],
["c05e9a3f", 3360],
["1d7f4b2e", 57],
["e2a86c91", 23],
]);
for (const series of chart.series) {
expect(series.values).toHaveLength(168);
expect(series.values).not.toContain(0);
}
const sparse = chart.series[4]?.values ?? [];
expect(sparse.filter((value) => value === null)).toHaveLength(164);
expect(chart.peak?.series).toBe(chart.series[0]?.label);
expect(chart.peak?.value).toBeLessThan(30_000);
// 5 series of 168 buckets is about 12 KB; one object per bucket, as
// before, came to about 200 KB.
expect(JSON.stringify(chart).length).toBeLessThan(16 * 1024);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Grouped chart Open-in-Sentry URL still sorts by y-axis, not event volume

Grouped charts now rank series with sort=-count() (or the metric count), but getEventsExplorerUrl still gets -${params.yAxis}. Open in Sentry reorders groups by p95/avg/etc. and can surface the sparse high-percentile releases this change just stopped charting. When countYAxis is set, pass that as the explorer sort and include it in the aggregate fields.

Evidence
  • handler sets topEvents.rankBy to countYAxis (e.g. count()) so the timeseries request uses sort=-count() for grouped charts.
  • The same handler still calls getEventsExplorerUrl(..., \-${params.yAxis}`, [params.yAxis], ...)with nocountYAxis, so spans/errors explorer URLs keep sort=-p95(span.duration)` (and only that y-axis).
  • buildSpansExplorerUrl / buildDiscoverUrl put that sort on the link the chart view opens.
  • The new busiest-releases test covers the p95-by-release case from render_sentry_chart top-N groups pick low-sample series #2451 but never asserts chart.url sort/fields, so the mismatch is uncaught.

Identified by Warden · code-review · UYK-BSJ

Across groups, the highest bucket headlines one group and reads as the
chart's peak. Sentry's own chart widgets show no peak, so grouped charts
now return peak null and the view omits it. Bumps the view to v3.

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
@sentry-junior

sentry-junior Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

I compared this with Sentry's own chart code (TimeSeriesWidget, the Explore charts, getShortCommitHash). This PR follows the same patterns: empty buckets stay null and draw as gaps, incomplete buckets are a dashed segment, and 40-character SHAs become 7 characters, as getShortCommitHash does.

The one deliberate difference is which groups get charted. Explore sorts top groups by the y-axis by default and relies on a person to re-sort, with its low-confidence fading and footer to flag thin data. The tool has nobody to re-sort, so it ranks by event count and shows each series' count in the legend. That's one extra aggregate in the same request and no extra payload.

I also dropped the peak line for grouped charts, since Sentry doesn't headline one and it reads as ambiguous there (6cede74).

I'm keeping v1 at that. Using the API's per-bucket confidence for fading, like Explore does, would be a good follow-up once this proves useful.

This branch was successfully deployed

3 active deployments
Preview – sentry-local — 6cede74d Deployed Nov 20, 2026 by vercel[bot]
Preview – cli — 6cede74d Deployed Nov 20, 2026 by vercel[bot]
Actions — 6cede74d Deployed Nov 20, 2026 by sentry-junior[bot] via eval #2010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant