:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(error-tracking): render rate limit charts via quill-charts directly (#70837)
Sam Pennington8fa8d0bd0a26
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex abdc4328faad..5ee07756beec 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -2148,6 +2148,22 @@ snapshots:hash: v1.k794b7964.9780bdf035a5bb22ce936937ce521d595eb15d7011129e7a1711de4b5474a360.XpzcHtsJC2xOCzqmbWID_XZ69gn1dQr--ugFlJ0uhawerrortracking-exceptioncard--exception-card-session-timeline-without-steps--light:hash: v1.k794b7964.d70d5f3dbdd36a4d42419973acec641ce0fde71a03abc6be8310f01a2c4dfe59.O6G9HRSQZkJp0TeO69qBJSDM20lECZtk-Dx67ZiC3kw+ errortracking-ratelimithistorychart--empty--dark:+ hash: v1.k794b7964.ba7eeab8b8da615a5f0641fa228edd6495cdba345860cbe418d736c1d6fbf5ad.Y17RTMCD78FYAVkdyD82nihxohmoVy0ye_eyLjzeTxQ+ errortracking-ratelimithistorychart--empty--light:+ hash: v1.k794b7964.f66957e8ff9ff2c64855e11cf8b302ef26e0685aee10fafb13fca532c8961c02.Hyr9wVcI0QF623YXZJo8P_0SErQ9g8760pFI1R9oyvw+ errortracking-ratelimithistorychart--with-activity--dark:+ hash: v1.k794b7964.9b619dd5750680566aea59cc7fb2a6ef4ee85764af540a290c6f91dec5c23dcd.tbNJeDRIA0crj-Os1-o5SSfDUv3u4VvOWrcBENc1vRU+ errortracking-ratelimithistorychart--with-activity--light:+ hash: v1.k794b7964.052aa085a958ff352472e76c6a0c7d4cb9420bc6e716b7bf344019f37a197018.rA9Lc4XyAbqkB1FUONUczhI39jVYe4QWQ6rksTxIlR0+ errortracking-ratelimitsimulationchart--no-limit--dark:+ hash: v1.k794b7964.6e4af837dc72dae0369f4c30c23dee98b8eebd01705c567ec1b3cb454e95eea6.ZCrDQfeX1Lxe93fRze8BuTQPpe11oqUHHdDyItofwL0+ errortracking-ratelimitsimulationchart--no-limit--light:+ hash: v1.k794b7964.cc6d841d30ef58412615b7dcb40a58bc99801a72f3048d875571625baf908c48.m6gBbseNOsfGd8XctUV3hYE_lBbSDMsjrSI1u6CEhfY+ errortracking-ratelimitsimulationchart--with-limit--dark:+ hash: v1.k794b7964.36082d7a3d4f26790b7e0bcc375133d7be27859f74067cad741da2f43222f15d.uxy9IHbuHm0USQ0tV68-SF2-mDjQPBa75Xc4QL8BNTc+ errortracking-ratelimitsimulationchart--with-limit--light:+ hash: v1.k794b7964.47b8236e3e4267d3071cec95282aca96a754f187c46803d1993cc39be7618b7c.DcIPXfSYV8tZEPZms6uKa7OOBiG5L0N71go5E93ltnEerrortracking-stacktraceactions--default--dark:hash: v1.k794b7964.7d61dd20494b606d206e11b3b75c960a2167b74d7cde152896bda3f9e83b087d.B9ZzsaGlT7qCeZd8c1a84JkWecl6R-c7moayDeypC5cerrortracking-stacktraceactions--default--light:diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitHistoryChart.stories.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitHistoryChart.stories.tsxnew file mode 100644index 000000000000..47f055d769f3--- /dev/null+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitHistoryChart.stories.tsx@@ -0,0 +1,60 @@+import { Meta, StoryObj } from '@storybook/react'+import { ReactNode } from 'react'++import { dayjs } from 'lib/dayjs'++import { RateLimitHistoryBucket } from './rateLimitConfigLogic'+import { RateLimitHistoryChart } from './RateLimitHistoryChart'+import { getBucketTimeline } from './RateLimitSimulationChart'++const meta: Meta<typeof RateLimitHistoryChart> = {+ title: 'ErrorTracking/RateLimitHistoryChart',+ component: RateLimitHistoryChart,+ parameters: {+ layout: 'centered',+ testOptions: { snapshotBrowsers: ['chromium'] },+ },+}+export default meta++type Story = StoryObj<typeof RateLimitHistoryChart>++const BUCKET_MINUTES = 60++/** Deterministic recorded/dropped/bypassed counts aligned to the chart's own bucket timeline —+ * the rendered bars are stable across runs even though the timeline is anchored to `Date.now()`+ * (the bucket dates themselves never render: the x-axis is hidden). */+function exampleHistory(): RateLimitHistoryBucket[] {+ return getBucketTimeline(BUCKET_MINUTES).map((ms, i) => {+ const wave = Math.max(0, Math.round(70 + 50 * Math.sin(i / 7)))+ const overage = Math.max(0, Math.round(30 * Math.sin(i / 4) - 12))+ return {+ bucket: dayjs(ms).toISOString(),+ recorded: wave,+ dropped: overage,+ bypassed: i % 9 === 0 ? 5 : 0,+ }+ })+}++function Stage({ children }: { children: ReactNode }): JSX.Element {+ // eslint-disable-next-line react/forbid-dom-props+ return <div style={{ width: 760 }}>{children}</div>+}++/** Stacked recorded/dropped/bypassed bars with the danger/warning series colors. */+export const WithActivity: Story = {+ render: () => (+ <Stage>+ <RateLimitHistoryChart history={exampleHistory()} bucketMinutes={BUCKET_MINUTES} />+ </Stage>+ ),+}++export const Empty: Story = {+ render: () => (+ <Stage>+ <RateLimitHistoryChart history={[]} bucketMinutes={BUCKET_MINUTES} />+ </Stage>+ ),+}diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitHistoryChart.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitHistoryChart.tsxindex 3901634f5e73..e7f5f673feb7 100644--- a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitHistoryChart.tsx+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitHistoryChart.tsx@@ -1,13 +1,13 @@import { useMemo } from 'react'+import { type Series, TimeSeriesBarChart } from '@posthog/quill-charts'++import { useChartConfig, useChartTheme } from 'lib/charts/hooks'import { getColorVar } from 'lib/colors'import { dayjs } from 'lib/dayjs'-import { LineGraph } from '~/queries/nodes/DataVisualization/Components/Charts/LineGraph'-import { ChartDisplayType } from '~/types'-import { getBucketOption, RateLimitHistoryBucket } from './rateLimitConfigLogic'-import { formatBucketLabel, getBucketTimeline } from './RateLimitSimulationChart'+import { buildRateLimitBarChartConfig, formatBucketLabel, getBucketTimeline } from './RateLimitSimulationChart'function fillHistoryBuckets(history: RateLimitHistoryBucket[], bucketMinutes: number): RateLimitHistoryBucket[] {const bucketMs = getBucketOption(bucketMinutes).minutes * 60_000@@ -36,59 +36,26 @@ export function RateLimitHistoryChart({bucketMinutes: numberemptyMessage?: string}): JSX.Element {- const { xData, yData, isEmpty } = useMemo(() => {+ const { labels, series, isEmpty } = useMemo(() => {const filled = fillHistoryBuckets(history, bucketMinutes)- const labels = filled.map((b) => formatBucketLabel(b.bucket, bucketMinutes))const recorded = filled.map((b) => b.recorded)const dropped = filled.map((b) => b.dropped)const bypassed = filled.map((b) => b.bypassed)return {isEmpty: recorded.every((c) => c === 0) && dropped.every((c) => c === 0) && bypassed.every((c) => c === 0),- xData: {- column: {- name: 'bucket',- type: { name: 'STRING' as const, isNumerical: false },- label: 'Bucket',- dataIndex: 0,- },- data: labels,- },- yData: [- {- column: {- name: 'recorded',- type: { name: 'INTEGER' as const, isNumerical: true },- label: 'Recorded',- dataIndex: 0,- },- data: recorded,- settings: { display: { displayType: 'bar' as const } },- },- {- column: {- name: 'dropped',- type: { name: 'INTEGER' as const, isNumerical: true },- label: 'Dropped',- dataIndex: 0,- },- data: dropped,- settings: { display: { displayType: 'bar' as const, color: getColorVar('danger') } },- },- {- column: {- name: 'bypassed',- type: { name: 'INTEGER' as const, isNumerical: true },- label: 'Bypassed',- dataIndex: 0,- },- data: bypassed,- settings: { display: { displayType: 'bar' as const, color: getColorVar('warning') } },- },- ],+ labels: filled.map((b) => formatBucketLabel(b.bucket, bucketMinutes)),+ series: [+ { key: 'recorded', label: 'Recorded', data: recorded },+ { key: 'dropped', label: 'Dropped', data: dropped, color: getColorVar('danger') },+ { key: 'bypassed', label: 'Bypassed', data: bypassed, color: getColorVar('warning') },+ ] as Series[],}}, [history, bucketMinutes])+ const theme = useChartTheme()+ const config = useChartConfig(() => buildRateLimitBarChartConfig('stacked'), [])+if (isEmpty) {return (<div className="h-80 border rounded flex items-center justify-center text-muted-foreground text-sm p-4 text-center">@@ -98,14 +65,9 @@ export function RateLimitHistoryChart({}return (- <div className="h-80 border rounded">- <LineGraph- className="h-full p-4"- xData={xData}- yData={yData}- visualizationType={ChartDisplayType.ActionsStackedBar}- chartSettings={{ showXAxisTicks: false, showXAxisBorder: false }}- />+ // Quill charts fill a *flex* parent (their root is flex-1), so the sized container must be a flex column.+ <div className="h-80 border rounded p-4 flex flex-col">+ <TimeSeriesBarChart series={series} labels={labels} theme={theme} config={config} /></div>)}diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.stories.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.stories.tsxnew file mode 100644index 000000000000..c901747714df--- /dev/null+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.stories.tsx@@ -0,0 +1,54 @@+import { Meta, StoryObj } from '@storybook/react'+import { ReactNode } from 'react'++import { dayjs } from 'lib/dayjs'++import { ExceptionVolumeBucket } from './rateLimitConfigLogic'+import { getBucketTimeline, RateLimitSimulationChart } from './RateLimitSimulationChart'++const meta: Meta<typeof RateLimitSimulationChart> = {+ title: 'ErrorTracking/RateLimitSimulationChart',+ component: RateLimitSimulationChart,+ parameters: {+ layout: 'centered',+ testOptions: { snapshotBrowsers: ['chromium'] },+ },+}+export default meta++type Story = StoryObj<typeof RateLimitSimulationChart>++const BUCKET_MINUTES = 60++/** Deterministic wave of exception counts aligned to the chart's own bucket timeline — the+ * rendered bars are stable across runs even though the timeline is anchored to `Date.now()`+ * (the bucket dates themselves never render: the x-axis is hidden). */+function exampleVolume(): ExceptionVolumeBucket[] {+ return getBucketTimeline(BUCKET_MINUTES).map((ms, i) => ({+ bucket: dayjs(ms).toISOString(),+ count: Math.max(0, Math.round(60 + 55 * Math.sin(i / 6) + 20 * Math.sin(i / 2))),+ }))+}++function Stage({ children }: { children: ReactNode }): JSX.Element {+ // eslint-disable-next-line react/forbid-dom-props+ return <div style={{ width: 760 }}>{children}</div>+}++/** Stacked within/above-limit split with the goal line marking the configured limit. */+export const WithLimit: Story = {+ render: () => (+ <Stage>+ <RateLimitSimulationChart volume={exampleVolume()} rateLimit={80} bucketMinutes={BUCKET_MINUTES} />+ </Stage>+ ),+}++/** No limit configured — a plain single-series bar chart, no goal line. */+export const NoLimit: Story = {+ render: () => (+ <Stage>+ <RateLimitSimulationChart volume={exampleVolume()} rateLimit={null} bucketMinutes={BUCKET_MINUTES} />+ </Stage>+ ),+}diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.tsxindex 4fafcb95877a..4d9689565ae6 100644--- a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.tsx+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.tsx@@ -1,12 +1,12 @@import { useMemo } from 'react'+import { type Series, TimeSeriesBarChart, type TimeSeriesBarChartConfig } from '@posthog/quill-charts'++import { useChartConfig, useChartTheme } from 'lib/charts/hooks'import { getColorVar } from 'lib/colors'import { dayjs } from 'lib/dayjs'import { pluralize } from 'lib/utils/strings'-import { LineGraph } from '~/queries/nodes/DataVisualization/Components/Charts/LineGraph'-import { ChartDisplayType } from '~/types'-import { ExceptionVolumeBucket, getBucketOption } from './rateLimitConfigLogic'export function formatTotalDuration(bucketMinutes: number): string {@@ -53,6 +53,25 @@ export function formatBucketLabel(iso: string, bucketMinutes: number): string {return ts.format('MMM D, HH:mm')}+/** Shared config for the rate limit bar charts: hidden bucket ticks, stacked bars, default tooltip+ * with a total row. */+export function buildRateLimitBarChartConfig(+ barLayout: NonNullable<TimeSeriesBarChartConfig['barLayout']>+): TimeSeriesBarChartConfig {+ return {+ xAxis: { hide: true },+ showAxisLines: { x: false, y: true },+ barLayout,+ legend: { show: false },+ tooltip: {+ placement: 'cursor',+ pinnable: true,+ sortedByValue: true,+ showTotal: true,+ },+ }+}+export function RateLimitSimulationChart({volume,rateLimit,@@ -64,91 +83,55 @@ export function RateLimitSimulationChart({}): JSX.Element {const hasLimit = !!rateLimit && rateLimit > 0- const { xData, yData } = useMemo(() => {+ const { labels, series } = useMemo(() => {const filled = fillBuckets(volume, bucketMinutes)const labels = filled.map((b) => formatBucketLabel(b.bucket, bucketMinutes))const counts = filled.map((b) => b.count)- const xAxis = {- column: {- name: 'bucket',- type: { name: 'STRING' as const, isNumerical: false },- label: 'Bucket',- dataIndex: 0,- },- data: labels,- }if (!hasLimit || rateLimit === null) {return {- xData: xAxis,- yData: [- {- column: {- name: 'count',- type: { name: 'INTEGER' as const, isNumerical: true },- label: 'Exceptions',- dataIndex: 0,- },- data: counts,- settings: { display: { displayType: 'bar' as const } },- },- ],+ labels,+ series: [{ key: 'count', label: 'Exceptions', data: counts }] as Series[],}}- const within = counts.map((c) => Math.min(c, rateLimit))- const above = counts.map((c) => Math.max(c - rateLimit, 0))return {- xData: xAxis,- yData: [- {- column: {- name: 'within',- type: { name: 'INTEGER' as const, isNumerical: true },- label: 'Within limit',- dataIndex: 0,- },- data: within,- settings: { display: { displayType: 'bar' as const } },- },+ labels,+ series: [+ { key: 'within', label: 'Within limit', data: counts.map((c) => Math.min(c, rateLimit)) },{- column: {- name: 'above',- type: { name: 'INTEGER' as const, isNumerical: true },- label: 'Would be dropped',- dataIndex: 0,- },- data: above,- settings: { display: { displayType: 'bar' as const, color: getColorVar('danger') } },+ key: 'above',+ label: 'Would be dropped',+ data: counts.map((c) => Math.max(c - rateLimit, 0)),+ color: getColorVar('danger'),},- ],+ ] as Series[],}}, [volume, bucketMinutes, hasLimit, rateLimit])- const goalLines = useMemo(() => {+ const theme = useChartTheme()+ const config = useChartConfig<TimeSeriesBarChartConfig>(() => {+ const base = buildRateLimitBarChartConfig(hasLimit ? 'stacked' : 'grouped')if (!hasLimit || rateLimit === null) {- return []+ return base}const option = getBucketOption(bucketMinutes)- return [- {- label: `Limit: ${rateLimit} per ${option.label}`,- value: rateLimit,- displayLabel: true,- },- ]+ return {+ ...base,+ goalLines: [+ {+ label: `Limit: ${rateLimit} per ${option.label}`,+ value: rateLimit,+ displayLabel: true,+ },+ ],+ }}, [hasLimit, rateLimit, bucketMinutes])return (- <div className="h-80 border rounded">- <LineGraph- className="h-full p-4"- xData={xData}- yData={yData}- visualizationType={hasLimit ? ChartDisplayType.ActionsStackedBar : ChartDisplayType.ActionsBar}- chartSettings={{ showXAxisTicks: false, showXAxisBorder: false }}- goalLines={goalLines}- />+ // Quill charts fill a *flex* parent (their root is flex-1), so the sized container must be a flex column.+ <div className="h-80 border rounded p-4 flex flex-col">+ <TimeSeriesBarChart series={series} labels={labels} theme={theme} config={config} /></div>)}