: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(setup-detection): stop filing issues for 5xx and network failures (#108139)
posthog[bot]50d275f6e2ea
diff --git a/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.test.ts b/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.test.tsindex 428039fd2e04..50bd341d0322 100644--- a/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.test.ts+++ b/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.test.ts@@ -50,10 +50,17 @@ describe('createSetupDetectionLogic', () => {expect(productSetupStatusLogic({ productKey: ProductKey.LOGS }).values.status).toBe(expected)})- it('fails open to unknown when detection fails before any answer', async () => {- const logic = buildLogic(jest.fn().mockRejectedValue(new Error('network down')))+ // An outage answers null instead of failing, so a backend blip does not file an error+ // tracking issue per product. Other failures still reach the failure path.+ it.each([+ ['a 500', new ApiError('A server error occurred.', 500), 'detectStatusSuccess'],+ ['a dropped connection', new TypeError('Failed to fetch'), 'detectStatusSuccess'],+ ['a 400', new ApiError('Bad request', 400), 'detectStatusFailure'],+ ['an application bug', new Error('x is not a function'), 'detectStatusFailure'],+ ] as const)('fails open to unknown when detection hits %s before any answer', async (_, error, outcome) => {+ const logic = buildLogic(jest.fn().mockRejectedValue(error))logic.mount()- await expectLogic(logic).toFinishAllListeners()+ await expectLogic(logic).toDispatchActions([outcome]).toFinishAllListeners()expect(productSetupStatusLogic({ productKey: ProductKey.LOGS }).values.status).toBe('unknown')})diff --git a/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.ts b/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.tsindex 130c6d233bf3..6f997b50aa18 100644--- a/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.ts+++ b/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.ts@@ -11,7 +11,7 @@ import {} from 'kea'import { loaders } from 'kea-loaders'-import { isScopeNotFoundError } from 'lib/api-error'+import { ApiError, isBrowserNetworkFailure, isScopeNotFoundError } from 'lib/api-error'import { projectLogic } from 'scenes/projectLogic'import { teamLogic } from 'scenes/teamLogic'@@ -182,7 +182,7 @@ export function createSetupDetectionLogic(options: SetupDetectionLogicOptions):detectedStatus: {__default: null as ProductSetupStatus | null,detectStatus: async (_: void, breakpoint: BreakPointFunction): Promise<ProductSetupStatus | null> => {- const status = await detect()+ const status = await detectOrNullOnOutage(detect)breakpoint()return status},@@ -270,6 +270,24 @@ async function detectOrNull(detect: () => Promise<ProductSetupStatus | null>): P}}+// A 5xx or a dropped connection says nothing about setup, and the gate treats null as "cannot+// answer". Throwing would file one error tracking issue per product for each backend blip.+async function detectOrNullOnOutage(+ detect: () => Promise<ProductSetupStatus | null>+): Promise<ProductSetupStatus | null> {+ try {+ return await detect()+ } catch (error) {+ if (+ (error instanceof ApiError && error.status !== undefined && error.status >= 500) ||+ isBrowserNetworkFailure(error)+ ) {+ return null+ }+ throw error+ }+}+function runOnceProjectIsKnown(cache: Record<string, any>,values: Pick<SetupDetectionValues, 'currentProjectId'>,