: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(metrics): fail characterize silently instead of toasting (#110167)
Frank Hamand56bde8e9850f
diff --git a/products/metrics/frontend/components/metricsViewerLogic.test.ts b/products/metrics/frontend/components/metricsViewerLogic.test.tsindex 8b075d09cb57..d98c9208fcf3 100644--- a/products/metrics/frontend/components/metricsViewerLogic.test.ts+++ b/products/metrics/frontend/components/metricsViewerLogic.test.ts@@ -1,6 +1,8 @@import { router } from 'kea-router'import { expectLogic } from 'kea-test-utils'+import { lemonToast } from '@posthog/lemon-ui'+import { NEW_QUERY_STARTED_ERROR_MESSAGE } from 'lib/utils/kea-logic-builders'import { insightsApi } from 'scenes/insights/utils/api'@@ -266,6 +268,20 @@ describe('metricsViewerLogic', () => {expect(firstSignal?.aborted).toBe(true)})+ it('hides the anomaly badge silently when characterize fails', async () => {+ jest.mocked(metricsCharacterizeCreate).mockRejectedValue({ status: 500, detail: 'boom' })+ const toastSpy = jest.spyOn(lemonToast, 'error')+ logic.actions.setMetricName('requests_total')++ await expectLogic(logic, () => {+ logic.actions.fetchAnomaly({})+ }).toDispatchActions(['fetchAnomalySuccess'])++ expect(logic.values.anomalyReport).toBeNull()+ expect(toastSpy).not.toHaveBeenCalled()+ toastSpy.mockRestore()+ })+it('names a formula insight after the formula and its inputs', async () => {jest.mocked(insightsApi.create).mockImplementation(async (insight: any) => ({ id: 1, short_id: 'abc123', ...insight }) as anydiff --git a/products/metrics/frontend/components/metricsViewerLogic.tsx b/products/metrics/frontend/components/metricsViewerLogic.tsxindex 6aeca5cb3e13..b49522fa8628 100644--- a/products/metrics/frontend/components/metricsViewerLogic.tsx+++ b/products/metrics/frontend/components/metricsViewerLogic.tsx@@ -1242,17 +1242,27 @@ export const metricsViewerLogic = kea<metricsViewerLogicType>([await breakpoint(300)const controller = new AbortController()actions.cancelInProgressAnomaly(controller)- const report = await metricsCharacterizeCreate(- String(values.currentTeamId),- {- query: {- ...anomalyQuery,- anomalyFrom,- anomalyTo: toISO,+ let report: _MetricAnomalyReportApi+ try {+ report = await metricsCharacterizeCreate(+ String(values.currentTeamId),+ {+ query: {+ ...anomalyQuery,+ anomalyFrom,+ anomalyTo: toISO,+ },},- },- { signal: controller.signal }- )+ { signal: controller.signal }+ )+ } catch (error: any) {+ if (error?.name === 'AbortError') {+ throw error+ }+ // The badge is a nice-to-have: a failed characterization hides it rather than toasting.+ actions.setAnomalyAbortController(null)+ return null+ }breakpoint()actions.setAnomalyAbortController(null)return report