: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(tracing): keep loading state during superseded queries (#74109)
Frank Hamand55b779ece700
diff --git a/products/tracing/frontend/tracingDataLogic.test.ts b/products/tracing/frontend/tracingDataLogic.test.tsindex ad31e7ce8314..dfc5c1815435 100644--- a/products/tracing/frontend/tracingDataLogic.test.ts+++ b/products/tracing/frontend/tracingDataLogic.test.ts@@ -9,7 +9,7 @@ import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'import { AggregatedSpanRow } from '~/queries/schema/schema-general'import { initKeaTests } from '~/test/init'-import { tracingDataLogic } from './tracingDataLogic'+import { NEW_QUERY_STARTED_ERROR_MESSAGE, tracingDataLogic } from './tracingDataLogic'import { tracingFiltersLogic } from './tracingFiltersLogic'import type { Span } from './types'@@ -319,6 +319,54 @@ describe('tracingDataLogic', () => {})})+ describe('loading state across superseded queries', () => {+ let toastSpy: jest.SpyInstance++ beforeEach(() => {+ silenceKeaLoadersErrors()+ toastSpy = jest.spyOn(lemonToast, 'error').mockReturnValue(undefined as any)+ })++ afterEach(() => {+ toastSpy.mockRestore()+ })++ it.each([+ {+ name: 'spans',+ apiMethod: 'listSpans' as const,+ start: (l: typeof logic) => l.actions.fetchSpans(),+ fail: (l: typeof logic, error: string) => l.actions.fetchSpansFailure(error),+ loadingValue: (l: typeof logic) => l.values.spansLoading,+ },+ {+ name: 'aggregation',+ apiMethod: 'aggregate' as const,+ start: (l: typeof logic) => l.actions.fetchAggregation(),+ fail: (l: typeof logic, error: string) => l.actions.fetchAggregationFailure(error),+ loadingValue: (l: typeof logic) => l.values.aggregationLoading,+ },+ ])(+ 'keeps $name loading on a superseded query but clears it on a real failure',+ ({ apiMethod, start, fail, loadingValue }) => {+ // Newer query in flight forever, so loading stays owned by it.+ const apiSpy = jest.spyOn(api.tracing, apiMethod).mockReturnValue(new Promise(() => {}) as any)+ logic = mountWithSpans([])+ start(logic)+ expect(loadingValue(logic)).toBe(true)++ // The previous request's abort must NOT drop the flag mid-flight.+ fail(logic, NEW_QUERY_STARTED_ERROR_MESSAGE)+ expect(loadingValue(logic)).toBe(true)++ // A genuine failure still resets it.+ fail(logic, 'boom')+ expect(loadingValue(logic)).toBe(false)+ apiSpy.mockRestore()+ }+ )+ })+describe('keyed instances', () => {it('re-runs the query when its filters change, with no URL involvement', async () => {// The embed-critical wiring: filter changes must re-query inside the keyed stack.diff --git a/products/tracing/frontend/tracingDataLogic.ts b/products/tracing/frontend/tracingDataLogic.tsindex 7b285fe2d3d2..89727d9d88c8 100644--- a/products/tracing/frontend/tracingDataLogic.ts+++ b/products/tracing/frontend/tracingDataLogic.ts@@ -757,10 +757,12 @@ export const tracingDataLogic = kea<tracingDataLogicType>([{fetchSpans: () => true,fetchSpansSuccess: () => false,- fetchSpansFailure: () => false,+ // A superseded query is aborted by the newer one that already re-set loading true;+ // keep loading so the list holds its spinner instead of flashing "No spans found".+ fetchSpansFailure: (state, { error }) => (isUserInitiatedError(error) ? state : false),fetchNextPage: () => true,fetchNextPageSuccess: () => false,- fetchNextPageFailure: () => false,+ fetchNextPageFailure: (state, { error }) => (isUserInitiatedError(error) ? state : false),},],sparklineLoading: [@@ -792,7 +794,7 @@ export const tracingDataLogic = kea<tracingDataLogicType>([{fetchAggregation: () => true,fetchAggregationSuccess: () => false,- fetchAggregationFailure: () => false,+ fetchAggregationFailure: (state, { error }) => (isUserInitiatedError(error) ? state : false),},],spanTreeLoading: [