: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): refetch the sparkline when refresh is clicked (#93327)
Jon McCallum9fc2dde661f5
diff --git a/products/tracing/frontend/TracingFilterBar.tsx b/products/tracing/frontend/TracingFilterBar.tsxindex bcb5051d12aa..06174c119e76 100644--- a/products/tracing/frontend/TracingFilterBar.tsx+++ b/products/tracing/frontend/TracingFilterBar.tsx@@ -38,7 +38,7 @@ const taxonomicGroupTypes = [export function TracingFilterBar(): JSX.Element {const { spansLoading } = useValues(tracingDataLogic)- const { runQuery } = useActions(tracingDataLogic)+ const { refreshQuery } = useActions(tracingDataLogic)const { filters, utcDateRange, timezone } = useValues(tracingFiltersLogic)const { setDateRange, setTimezone, setServiceNames, setFilterGroup } = useActions(tracingFiltersLogic)const { dateRange, serviceNames, filterGroup } = filters@@ -69,7 +69,7 @@ export function TracingFilterBar(): JSX.Element {size="small"icon={<IconRefresh />}type="secondary"- onClick={() => runQuery()}+ onClick={() => refreshQuery()}loading={spansLoading}/><SavedViewsButton />diff --git a/products/tracing/frontend/tracingDataLogic.test.ts b/products/tracing/frontend/tracingDataLogic.test.tsindex 596bbcd1da1b..dcac13620933 100644--- a/products/tracing/frontend/tracingDataLogic.test.ts+++ b/products/tracing/frontend/tracingDataLogic.test.ts@@ -318,6 +318,19 @@ describe('tracingDataLogic', () => {expect(sparklineSpy).toHaveBeenCalledTimes(2)sparklineSpy.mockRestore()})++ it('re-fetches the sparkline on an explicit refresh with an unchanged scope', async () => {+ const sparklineSpy = jest.spyOn(api.tracing, 'sparkline').mockResolvedValue({ results: [] })+ logic = mountWithSpans([])+ await logic.asyncActions.fetchSparkline()+ // The refresh button asks for newer data without touching the filters, so the+ // memoized scope must not stop it from hitting the endpoint again.+ await expectLogic(logic, () => {+ logic.actions.refreshQuery()+ }).toDispatchActions(['fetchSparklineSuccess'])+ expect(sparklineSpy).toHaveBeenCalledTimes(2)+ sparklineSpy.mockRestore()+ })})describe('loading state across superseded queries', () => {diff --git a/products/tracing/frontend/tracingDataLogic.ts b/products/tracing/frontend/tracingDataLogic.tsindex a50e56b56c99..c0f3b02b1b05 100644--- a/products/tracing/frontend/tracingDataLogic.ts+++ b/products/tracing/frontend/tracingDataLogic.ts@@ -535,6 +535,9 @@ export interface tracingDataLogicActions {ts?: string | null}}+ refreshQuery: () => {+ value: true+ }runQuery: () => {value: true}@@ -681,6 +684,10 @@ export const tracingDataLogic = kea<tracingDataLogicType>([// A completed 2D brush on the latency heatmap — maps to a date range + duration chips.applyHeatmapBrush: (selection: HeatmapBrushSelection) => ({ selection }),runQuery: true,+ // An explicit user refresh. Same fetches as runQuery, but the scope-skip caches below+ // are dropped first, so the charts and the count re-hit the API even though nothing+ // about the query changed.+ refreshQuery: true,fetchNextPage: true,loadMoreTraceSpans: true,setTracePagination: (hasMore: boolean, nextOffset: number | null) => ({ hasMore, nextOffset }),@@ -1382,7 +1389,7 @@ export const tracingDataLogic = kea<tracingDataLogicType>([],}),- listeners(({ actions, values }) => ({+ listeners(({ actions, values, cache }) => ({handleFilterChange: ({ filterType, extraProps }) => {posthog.capture('tracing filter changed', { filter_type: filterType, ...extraProps })actions.runQuery()@@ -1445,6 +1452,12 @@ export const tracingDataLogic = kea<tracingDataLogicType>([// while the user moves windows around within it. The compare-flame refetch (viewer UI// state) lives in tracingViewerLogic.updateComparisonWindows: () => actions.fetchAggregation(),+ refreshQuery: () => {+ cache.sparklineScope = undefined+ cache.matchingCountsScope = undefined+ cache.latencyHeatmapScope = undefined+ actions.runQuery()+ },runQuery: () => {actions.clearSpans()// The time sparkline is always fetched — it keeps the chart warm when the user flips back