: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
fix(alerts): clarify breakdown alert scope (#91808)
posthog[bot]eddbe82885e5
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex b46150a8f76b..c38cbdf7794d 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -5112,6 +5112,10 @@ snapshots:hash: v1.k794b7964.c9bdafae1ad47e45cba8bc136bc1f911fcd38d3f3adc0109c73c608fc7aff1a7.JQQcVBlkdE7zlG0B9V18hFYCe7DRINlSu1YhOXTSNFgproducts-alerts-shared-components--preview--light:hash: v1.k794b7964.b50bab9d45811f65807b4a8f70d7699e3a6622fe934fa972694fc2d96461041e.HFAHjicDLcs7EPMZlhlcmW4_mb6B-V9zulQ9sqcf6Js+ products-alerts-shared-components--preview-breakdown--dark:+ hash: v1.k794b7964.aff80ff28ac505a67d825f095688d9f424cb3d885052e8ef1064f7efd0fae2ae.zyQl0OgEH3hLa51zt2hYN0sPd-50XwnwddfpOzMa3Po+ products-alerts-shared-components--preview-breakdown--light:+ hash: v1.k794b7964.e1839b06a48fc951fa0d80007250480e0070d5c4c8de140dcc94623372c66a85.Ws7QP_xjYLQHx5zUmIIrDyPZUEgTi8VaBsbXqvhQhxcproducts-alerts-shared-components--preview-log-scale--dark:hash: v1.k794b7964.906c1930c0e5ceee290a929d4ba68eb4ff58ce08f6e89f89474ada2fff12505d.U1FElozFVhx4UwEdkRh8KkkZQl-n3074MGTZtdFD5Z4products-alerts-shared-components--preview-log-scale--light:diff --git a/products/alerts/frontend/components/AlertComponents.stories.tsx b/products/alerts/frontend/components/AlertComponents.stories.tsxindex 332ec890ea6c..24f71042d81b 100644--- a/products/alerts/frontend/components/AlertComponents.stories.tsx+++ b/products/alerts/frontend/components/AlertComponents.stories.tsx@@ -450,6 +450,25 @@ function PreviewLogScaleStory(): JSX.Element {)}+function PreviewBreakdownStory(): JSX.Element {+ return (+ <div className="max-w-md border rounded bg-surface-primary p-4">+ <AlertPreviewCard+ alertForm={buildTrendsAlertForm()}+ trendsValues={[20, 30, 40]}+ trendsLabels={PREVIEW_LABELS}+ isBreakdown+ trendsBreakdownSeries={[+ { key: 'chrome', label: 'Chrome', data: [20, 30, 40] },+ { key: 'safari', label: 'Safari', data: [10, 25, 60] },+ ]}+ funnelPreview={null}+ hogqlPreview={null}+ />+ </div>+ )+}+const meta: Meta = {title: 'Products/Alerts/Shared components',parameters: {@@ -482,3 +501,4 @@ export const EvaluationHistory: Story = { render: () => <EvaluationHistoryStoryexport const Preview: Story = { render: () => <PreviewStory /> }export const PreviewRelative: Story = { render: () => <PreviewRelativeStory /> }export const PreviewLogScale: Story = { render: () => <PreviewLogScaleStory /> }+export const PreviewBreakdown: Story = { render: () => <PreviewBreakdownStory /> }diff --git a/products/alerts/frontend/components/AlertDefinitionFields.tsx b/products/alerts/frontend/components/AlertDefinitionFields.tsxindex df30b75b6689..d3de4901c06f 100644--- a/products/alerts/frontend/components/AlertDefinitionFields.tsx+++ b/products/alerts/frontend/components/AlertDefinitionFields.tsx@@ -21,11 +21,6 @@ import { isFunnelsAlertConfig, isHogQLAlertConfig } from 'products/alerts/fronteimport { HogQLAlertPreviewBanner, HogQLAlertPreviewRowsTable } from './HogQLAlertPreview'-const breakdownDisabledReason = (alertMode: 'detector' | 'threshold'): string =>- alertMode === 'detector'- ? 'For trends with breakdown, the detector will independently monitor each breakdown value (up to 25) and fire if any is anomalous.'- : 'For trends with breakdown, the alert will fire if any of the breakdown values breaches the threshold.'-/** Trends: pick which series (or formula) to monitor. */export function TrendsDefinitionFields({alertSeries,@@ -38,6 +33,15 @@ export function TrendsDefinitionFields({isBreakdownValid: booleanalertMode: 'detector' | 'threshold'}): JSX.Element {+ if (isBreakdownValid) {+ return (+ <AlertDefinitionRow label="When">+ <span className="font-medium">+ {alertMode === 'detector' ? 'Any breakdown value (up to 25)' : 'Any breakdown value'}+ </span>+ </AlertDefinitionRow>+ )+ }return (<AlertDefinitionRow label="When"><Group name={['config']}>@@ -52,13 +56,10 @@ export function TrendsDefinitionFields({value: index,})): (alertSeries?.map(({ custom_name, name, event }, index) => ({- label: isBreakdownValid- ? 'any breakdown value'- : `${alphabet[index]} - ${custom_name ?? name ?? event}`,- value: isBreakdownValid ? 0 : index,+ label: `${alphabet[index]} - ${custom_name ?? name ?? event}`,+ value: index,})) ?? [])}- disabledReason={isBreakdownValid && breakdownDisabledReason(alertMode)}/></LemonField></Group>diff --git a/products/alerts/frontend/components/AlertPreviewCard.tsx b/products/alerts/frontend/components/AlertPreviewCard.tsxindex 606af7f22887..38d5bed3cd5a 100644--- a/products/alerts/frontend/components/AlertPreviewCard.tsx+++ b/products/alerts/frontend/components/AlertPreviewCard.tsx@@ -22,14 +22,20 @@ import { HogQLAlertPreviewBanner } from './HogQLAlertPreview'const handleChartError = makeChartErrorHandler('alerts-preview-chart')+interface AlertPreviewChartSeries {+ key: string+ label: string+ data: number[]+}+function AlertPreviewChart({- values,+ series,labels,referenceLines,relative,useLogScale,}: {- values: number[]+ series: AlertPreviewChartSeries[]labels?: string[]referenceLines: AlertThresholdLine[]relative: boolean@@ -39,8 +45,8 @@ function AlertPreviewChart({return (<div className="w-full h-24 flex flex-col"><LineChart- series={[{ key: 'preview', label: 'Value', data: values }]}- labels={labels ?? values.map((_, index) => String(index))}+ series={series}+ labels={labels ?? series[0]?.data.map((_, index) => String(index)) ?? []}theme={theme}config={{hideXAxis: true,@@ -63,6 +69,8 @@ export interface AlertPreviewCardProps {alertForm: AlertFormTypetrendsValues: number[] | nulltrendsLabels?: string[] | null+ isBreakdown?: boolean+ trendsBreakdownSeries?: AlertPreviewChartSeries[] | nullfunnelPreview: FunnelAlertPreview | nullhogqlPreview: HogQLAlertPreview | nullcheckPreview?: TrendsAlertPreviewSeries@@ -74,6 +82,8 @@ export function AlertPreviewCard({alertForm,trendsValues,trendsLabels,+ isBreakdown,+ trendsBreakdownSeries,funnelPreview,hogqlPreview,checkPreview,@@ -88,9 +98,24 @@ export function AlertPreviewCard({alertForm.threshold?.configuration?.type ?? InsightThresholdType.ABSOLUTE): null+ const isBreakdownPreview = isTrendsAlertConfig(config) && isBreakdownconst referenceLines = thresholdReferenceLines(alertForm)- const useLogScale = Boolean(trendsPreview && shouldUseLogScale(trendsPreview.values, referenceLines))+ const useLogScale = Boolean(+ !isBreakdownPreview && trendsPreview && shouldUseLogScale(trendsPreview.values, referenceLines)+ )const checkPreviewValues = checkPreview?.values+ const trendsBreakdownPreviews = trendsBreakdownSeries?.map(({ key, label, data }) => ({+ key,+ label,+ data: deriveTrendsAlertPreviewSeries(+ data,+ trendsLabels ?? undefined,+ alertForm.condition?.type ?? AlertConditionType.ABSOLUTE_VALUE,+ alertForm.threshold?.configuration?.type ?? InsightThresholdType.ABSOLUTE+ ).values,+ }))+ const breakdownPreviewValues = trendsBreakdownPreviews?.flatMap((series) => series.data) ?? []+ const breakdownUseLogScale = shouldUseLogScale(breakdownPreviewValues, referenceLines)const isUnconfiguredAbsoluteThreshold =!alertForm.detector_config &&alertForm.condition?.type === AlertConditionType.ABSOLUTE_VALUE &&@@ -109,10 +134,26 @@ export function AlertPreviewCard({Set less than or more than to preview this alert.</div>)+ } else if (isBreakdownPreview && trendsBreakdownPreviews && breakdownPreviewValues.length > 0) {+ body = (+ <AlertPreviewChart+ series={trendsBreakdownPreviews}+ labels={trendsLabels ?? undefined}+ referenceLines={referenceLines}+ relative={trendsPreview?.relative ?? false}+ useLogScale={breakdownUseLogScale}+ />+ )+ } else if (isBreakdownPreview && !loading) {+ body = (+ <div className="flex h-24 items-center justify-center rounded border border-dashed border-border text-sm text-muted">+ No activity to preview across breakdown values.+ </div>+ )} else if (checkPreviewValues && checkPreviewValues.length > 0) {body = (<AlertPreviewChart- values={checkPreviewValues}+ series={[{ key: 'preview', label: 'Value', data: checkPreviewValues }]}labels={checkPreview.labels}referenceLines={referenceLines}relative={checkPreview.relative}@@ -134,7 +175,7 @@ export function AlertPreviewCard({} else if (isTrendsAlertConfig(config) && trendsPreview && trendsPreview.values.length > 0) {body = (<AlertPreviewChart- values={trendsPreview.values}+ series={[{ key: 'preview', label: 'Value', data: trendsPreview.values }]}labels={trendsPreview.labels}referenceLines={referenceLines}relative={trendsPreview.relative}@@ -166,25 +207,32 @@ export function AlertPreviewCard({}let lastValue: number | null = null- if (checkPreviewValues?.length) {+ if (!isBreakdownPreview && checkPreviewValues?.length) {lastValue = checkPreviewValues[checkPreviewValues.length - 1]- } else if (isTrendsAlertConfig(config) && trendsPreview?.values.length) {+ } else if (isTrendsAlertConfig(config) && trendsPreview?.values.length && !isBreakdownPreview) {lastValue = trendsPreview.values[trendsPreview.values.length - 1]}+ let previewTooltip =+ 'What this alert is watching right now. The dashed lines are your thresholds; points crossing them would fire.'+ if (isBreakdownPreview) {+ previewTooltip = 'Every breakdown value is shown. The dashed lines are your thresholds.'+ } else if (checkPreview !== undefined) {+ previewTooltip = 'Values recorded by recent alert evaluations.'+ }+ let previewTitle = 'Preview'+ if (isBreakdownPreview) {+ previewTitle = 'All breakdown values'+ } else if (checkPreview !== undefined) {+ previewTitle = 'Recent evaluations'+ }+return (<div className="space-y-2"><div className="flex items-center justify-between gap-2"><div className="flex items-center gap-1.5 text-sm font-medium">- <span>{checkPreview !== undefined ? 'Recent evaluations' : 'Preview'}</span>- <Tooltip- title={- checkPreview !== undefined- ? 'Values recorded by recent alert evaluations.'- : 'What this alert is watching right now. The dashed lines are your thresholds; points crossing them would fire.'- }- delayMs={0}- >+ <span>{previewTitle}</span>+ <Tooltip title={previewTooltip} delayMs={0}><IconInfo className="text-muted size-3.5" /></Tooltip></div>diff --git a/products/alerts/frontend/views/EditAlertModal.tsx b/products/alerts/frontend/views/EditAlertModal.tsxindex 0f7ae3453d95..a1229a9f4ff9 100644--- a/products/alerts/frontend/views/EditAlertModal.tsx+++ b/products/alerts/frontend/views/EditAlertModal.tsx@@ -402,6 +402,16 @@ export function EditAlertModal(props: AlertModalProps): JSX.Element {alertForm.config?.type === 'TrendsAlertConfig' ? (alertForm.config.series_index ?? 0) : 0]?.labels ?? null}+ isBreakdown={isBreakdownValid && !isTrendsFunnel}+ trendsBreakdownSeries={+ isBreakdownValid && !isTrendsFunnel+ ? indexedResults?.map((series) => ({+ key: String(series.seriesIndex),+ label: String(series.breakdown_value ?? series.label),+ data: series.data,+ }))+ : undefined+ }funnelPreview={funnelAlertPreview}hogqlPreview={hogqlAlertPreview}checkPreview={checkPreview}