Repository navigation
fix(mcp): Chart the busiest groups and keep empty buckets empty - #2453
sentry-junior[bot] wants to merge 2 commits into
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📊 MCP Server Token Cost ReportSummary
Per-Tool Breakdown
Note: This measures the static overhead of tool definitions sent to LLM clients with every request. Lower is better. MCP Apps viewsEach
The budget applies to raw bytes, and the view's generator fails over it. |
|
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 |
|
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 |
| 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); | ||
| }); | ||
|
|
There was a problem hiding this comment.
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
handlersetstopEvents.rankBytocountYAxis(e.g.count()) so the timeseries request usessort=-count()for grouped charts.- The same handler still calls
getEventsExplorerUrl(..., \-${params.yAxis}`, [params.yAxis], ...)with nocountYAxis, so spans/errors explorer URLs keepsort=-p95(span.duration)` (and only that y-axis). buildSpansExplorerUrl/buildDiscoverUrlput thatsorton 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.urlsort/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>
|
I compared this with Sentry's own chart code (TimeSeriesWidget, the Explore charts, 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 |
Fixes the
render_sentry_chartproblems 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 secondyAxiswithsort=-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:avg,max,failure_rate, and the like.Trace metrics count per metric, so for
fn(value,name,type,unit)the ranker iscount(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 staysnulland draws as a gap. A bucket with data on both sides empty draws as a dot, and the tooltip says "no data".summarizeSeriesand the search_events text output are unchanged.Payload. This changes the output schema. The result now has:
timesarray;incompleteandoutsideRetentionas bucket index lists;{ label, count, total, values }, wherevaluesis 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.htmlbecause hosts cache views by URI. The tool is experimental, so no stable client sees the schema change.Clarity.
1d7f4b2 · 57 events.Offline proof. The
events-timeseriesmock now honorssort. 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.mdgains three claims thatmcp-apps-host.mjsdrives, and thegroupedclaim now covers the legend's short labels and event counts, and the absence of a peak:top-by-volumenull-gapscompact-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:
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 addenvironment:when it groups by release.confidence. The chart could do the same once it has proven useful.via @dcramer.
--
View Session [Sentry]