Skip to content

: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.

chore(logs): move the alert simulation chart to quill charts (#78837)

Sam Pennington0b9c67be8413
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index c207f51429db..450e34846f9e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -3402,6 +3402,9 @@ importers:
'@posthog/products-error-tracking':
specifier: workspace:*
version: link:../error_tracking
+ '@posthog/quill-charts':
+ specifier: workspace:*
+ version: link:../../packages/quill/packages/charts
'@storybook/react':
specifier: 'catalog:'
diff --git a/products/logs/frontend/components/LogsAlerting/LogsAlertSimulation.tsx b/products/logs/frontend/components/LogsAlerting/LogsAlertSimulation.tsx
index b3c50678ae6b..a9323a8969f9 100644
--- a/products/logs/frontend/components/LogsAlerting/LogsAlertSimulation.tsx
+++ b/products/logs/frontend/components/LogsAlerting/LogsAlertSimulation.tsx
@@ -1,10 +1,13 @@
import { useActions, useValues } from 'kea'
+import { useMemo } from 'react'
import { LemonButton, LemonSelect, LemonSkeleton, LemonTag } from '@posthog/lemon-ui'
+import { DefaultTooltip, type Series, TimeSeriesBarChart, type TimeSeriesBarChartConfig } from '@posthog/quill-charts'
+import { useChartConfig, useChartTheme } from 'lib/charts/hooks'
+import { getColorVar } from 'lib/colors'
import { TZLabel } from 'lib/components/TZLabel'
import { dayjs } from 'lib/dayjs'
-import { useChart } from 'lib/hooks/useChart'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { humanFriendlyDuration } from 'lib/utils/durations'
@@ -19,110 +22,84 @@ const SIMULATION_RANGE_OPTIONS = [
{ value: '-7d', label: 'Last 7 days' },
]
-const CHART_COLORS = {
- normal: { bg: 'rgba(99, 102, 241, 0.6)', border: 'rgba(67, 56, 202, 1)' },
- breached: { bg: 'rgba(245, 158, 11, 0.6)', border: 'rgba(180, 83, 9, 1)' },
- fired: { bg: 'rgba(220, 38, 38, 0.7)', border: 'rgba(153, 27, 27, 1)' },
- threshold: { border: 'rgba(220, 38, 38, 0.5)' },
-} as const
+function BucketTooltipDetails({ bucket }: { bucket: LogsAlertSimulateBucketApi | undefined }): JSX.Element | null {
+ if (!bucket) {
+ return null
+ }
+ const details = [`State: ${bucket.state}`]
+ if (bucket.threshold_breached) {
+ details.push('Threshold breached')
+ }
+ if (bucket.notification === 'fire') {
+ details.push('Notification sent')
+ } else if (bucket.notification === 'resolve') {
+ details.push('Resolved notification sent')
+ }
+ return (
+ <div className="flex flex-col text-left">
+ {details.map((detail) => (
+ <span key={detail}>{detail}</span>
+ ))}
+ </div>
+ )
+}
function SimulationChart({ result }: { result: LogsAlertSimulateResponseApi }): JSX.Element {
- const { canvasRef } = useChart({
- getConfig: () => ({
- type: 'bar' as const,
- data: {
- labels: result.buckets.map((b: LogsAlertSimulateBucketApi) =>
- dayjs(b.timestamp).format('MMM D, HH:mm')
- ),
- datasets: [
- {
- label: 'Log count',
- data: result.buckets.map((b: LogsAlertSimulateBucketApi) => b.count),
- backgroundColor: result.buckets.map((b: LogsAlertSimulateBucketApi) =>
- b.notification === 'fire'
- ? CHART_COLORS.fired.bg
- : b.threshold_breached
- ? CHART_COLORS.breached.bg
- : CHART_COLORS.normal.bg
- ),
- borderColor: result.buckets.map((b: LogsAlertSimulateBucketApi) =>
- b.notification === 'fire'
- ? CHART_COLORS.fired.border
- : b.threshold_breached
- ? CHART_COLORS.breached.border
- : CHART_COLORS.normal.border
- ),
- borderWidth: 1,
- },
- {
- label: `Threshold (${result.threshold_count})`,
- data: Array(result.buckets.length).fill(result.threshold_count),
- type: 'line' as const,
- borderColor: CHART_COLORS.threshold.border,
- borderWidth: 1.5,
- borderDash: [4, 4],
- pointRadius: 0,
- fill: false,
- },
- ],
- },
- options: {
- responsive: true,
- maintainAspectRatio: false,
- plugins: {
- crosshair: false,
- legend: {
- display: true,
- position: 'bottom' as const,
- labels: {
- boxWidth: 8,
- boxHeight: 2,
- font: { size: 10 },
- padding: 8,
- },
- },
- tooltip: {
- enabled: true,
- callbacks: {
- label: (ctx) => {
- const bucket = result.buckets[ctx.dataIndex]
- if (!bucket) {
- return `Count: ${ctx.parsed.y}`
- }
- const lines = [`Count: ${ctx.parsed.y}`, `State: ${bucket.state}`]
- if (bucket.threshold_breached) {
- lines.push('Threshold breached')
- }
- if (bucket.notification === 'fire') {
- lines.push('Notification sent')
- } else if (bucket.notification === 'resolve') {
- lines.push('Resolved notification sent')
- }
- return lines
- },
- },
- },
+ const { labels, series } = useMemo(
+ () => ({
+ labels: result.buckets.map((b: LogsAlertSimulateBucketApi) => b.timestamp),
+ series: [
+ {
+ key: 'count',
+ label: 'Log count',
+ data: result.buckets.map((b: LogsAlertSimulateBucketApi) => b.count),
+ // One series with per-bar colors, so a bucket's simulated outcome is visible without
+ // splitting the counts across three mutually exclusive series.
+ bars: result.buckets.map((b: LogsAlertSimulateBucketApi) => {
+ if (b.notification === 'fire') {
+ return { color: getColorVar('danger') }
+ }
+ return b.threshold_breached ? { color: getColorVar('warning') } : {}
+ }),
},
- scales: {
- x: {
- display: true,
- ticks: { maxTicksLimit: 12, font: { size: 10 }, maxRotation: 45 },
- },
- y: {
- display: true,
- beginAtZero: true,
- ticks: { maxTicksLimit: 5, font: { size: 10 } },
- grid: { drawTicks: false },
- },
+ ] as Series[],
+ }),
+ [result]
+ )
+
+ const theme = useChartTheme()
+ const config = useChartConfig<TimeSeriesBarChartConfig>(
+ () => ({
+ showCrosshair: false,
+ // Buckets are minutes apart, and the surrounding incident table renders in local time.
+ xAxis: { interval: 'minute', timezone: dayjs.tz.guess() },
+ goalLines: [
+ {
+ value: result.threshold_count,
+ label: 'Threshold',
+ displayLabel: true,
},
- },
+ ],
}),
- deps: [result],
- })
+ [result.threshold_count]
+ )
return (
- <div className="h-56">
- <canvas ref={canvasRef} />
+ // Quill charts fill a *flex* parent (their root is flex-1), so the sized container must be a flex column.
+ <div className="h-56 flex flex-col">
+ <TimeSeriesBarChart
+ series={series}
+ labels={labels}
+ theme={theme}
+ config={config}
+ tooltip={(ctx) => (
+ <DefaultTooltip
+ {...ctx}
+ labelFormatter={(label) => dayjs(label).format('MMM D, HH:mm')}
+ footer={<BucketTooltipDetails bucket={result.buckets[ctx.dataIndex]} />}
+ />
+ )}
+ />
</div>
)
}
diff --git a/products/logs/package.json b/products/logs/package.json
index 84591d978241..ee13feb1c866 100644
--- a/products/logs/package.json
+++ b/products/logs/package.json
@@ -4,6 +4,7 @@
"backend:test": "pytest -c ../../pytest.ini --rootdir ../.. backend/ skills/ -v --tb=short"
},
"dependencies": {
+ "@posthog/quill-charts": "workspace:*",
"kea": "catalog:",
"kea-forms": "catalog:",
"kea-loaders": "catalog:",