: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 errors for expected probe failures (#129811)
Rafael Audiberte6b850cbc560
diff --git a/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.test.ts b/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.test.tsindex e9f25fa3bf06..e5b054eb99db 100644--- a/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.test.ts+++ b/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.test.ts@@ -50,13 +50,29 @@ describe('createSetupDetectionLogic', () => {expect(productSetupStatusLogic({ productKey: ProductKey.LOGS }).values.status).toBe(expected)})- // An outage or a 403 answers null instead of failing, so it does not file an error- // tracking issue per product. Other failures still reach the failure path.+ // An outage, a 403, a route a deploy has not rolled out yet, or a bodiless 4xx answers null+ // instead of failing, so it 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 403', new ApiError('You do not have permission.', 403), 'detectStatusSuccess'],['a dropped connection', new TypeError('Failed to fetch'), 'detectStatusSuccess'],- ['a 400', new ApiError('Bad request', 400), 'detectStatusFailure'],+ [+ 'a 404 for a route not yet deployed',+ new ApiError('Not found.', 404, undefined, { detail: 'Not found.' }),+ 'detectStatusSuccess',+ ],+ ['a 400 with an empty body', new ApiError(undefined, 400, undefined, null), 'detectStatusSuccess'],+ [+ 'a 400 with a detail',+ new ApiError('Bad request', 400, undefined, { detail: 'Bad request' }),+ 'detectStatusFailure',+ ],+ [+ 'a 404 for a deleted project',+ new ApiError('Project not found.', 404, undefined, { detail: 'Project not found.' }),+ '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))diff --git a/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.ts b/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.tsindex d5b9d6b720e7..dd177f02381e 100644--- a/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.ts+++ b/frontend/src/lib/components/ProductEmptyState/setupDetectionLogic.ts@@ -11,7 +11,13 @@ import {} from 'kea'import { loaders } from 'kea-loaders'-import { ApiError, isBrowserNetworkFailure, isScopeNotFoundError } from 'lib/api-error'+import {+ ApiError,+ isBrowserNetworkFailure,+ isScopeNotFoundError,+ isUnavailableEndpointError,+ readableErrorMessage,+} from 'lib/api-error'import { projectLogic } from 'scenes/projectLogic'import { teamLogic } from 'scenes/teamLogic'@@ -297,16 +303,31 @@ async function detectOrNullOnOutageOrForbidden(onForbidden()return null}- if (- (error instanceof ApiError && error.status !== undefined && error.status >= 500) ||- isBrowserNetworkFailure(error)- ) {+ if (isBrowserNetworkFailure(error) || isUnanswerableProbeResponse(error)) {return null}throw error}}+// A 404 or 405 for an endpoint is what a deploy in progress looks like, when the new frontend+// reaches a backend pod that does not serve the probe route yet. A 4xx without a readable body+// did not come from our API code (a proxy in front of it sent it), so it is not a probe bug either.+// A dead-scope 404 is excluded, because `detectStatusFailure` must stop the poll for it, and a 4xx+// that carries a detail is excluded, so a real probe bug such as a bad parameter stays visible.+function isUnanswerableProbeResponse(error: unknown): boolean {+ if (!(error instanceof ApiError) || error.status === undefined) {+ return false+ }+ if (error.status >= 500) {+ return true+ }+ if (error.status < 400 || isScopeNotFoundError(error)) {+ return false+ }+ return isUnavailableEndpointError(error) || readableErrorMessage(error.data) === undefined+}+function runOnceProjectIsKnown(cache: Record<string, any>,values: Pick<SetupDetectionValues, 'currentProjectId'>,