Skip to content

: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.

fix(tracing): stop toasting when the matching count fails (#129922)

Frank Hamandfcf766a94da7
diff --git a/frontend/src/initKea.ts b/frontend/src/initKea.ts
index 325472369263..289ce575bdc3 100644
--- a/frontend/src/initKea.ts
+++ b/frontend/src/initKea.ts
@@ -117,6 +117,7 @@ const ERROR_FILTER_ALLOW_LIST_BY_LOGIC_PATH: Record<string, string> = {
loadReportDiff: 'scenes.inbox.logics.inboxReportDetailLogic',
loadMembers: 'products.replay_vision.frontend.replay_scanners.highlightFeedGroupLogic', // The feed card shows its own retry
loadTraceSpans: 'products.tracing.frontend.components.TraceDialog.traceDialogLogic', // The dialog shows its own retry
+ fetchMatchingCounts: 'products.tracing.frontend.tracingDataLogic', // The matching-count label is hidden when the count fails
loadPreview: 'products.metrics.frontend.components.metricVariableEditorLogic', // The variable editor shows the error under the preview
loadSiteProfiles: 'products.webAnalytics.contentAutopilot.contentAutopilotLogic',
loadProposals: 'products.webAnalytics.contentAutopilot.contentAutopilotLogic',
diff --git a/products/tracing/frontend/tracingDataLogic.test.ts b/products/tracing/frontend/tracingDataLogic.test.ts
index 6f046e1da1ac..8cf6e28abc71 100644
--- a/products/tracing/frontend/tracingDataLogic.test.ts
+++ b/products/tracing/frontend/tracingDataLogic.test.ts
@@ -329,13 +329,20 @@ describe('tracingDataLogic', () => {
countSpy.mockRestore()
})
- it('toasts on a real count failure', async () => {
+ it('hides the count instead of toasting on a real count failure', async () => {
silenceKeaLoadersErrors()
const toastSpy = jest.spyOn(lemonToast, 'error').mockReturnValue(undefined as any)
- jest.spyOn(api.tracing, 'count').mockRejectedValue(new Error('boom'))
+ const countSpy = jest.spyOn(api.tracing, 'count').mockResolvedValue({ count: 10, traceCount: 3 })
logic = mountWithSpans([])
- await logic.asyncActions.fetchMatchingCounts().catch(() => {})
- expect(toastSpy).toHaveBeenCalled()
+ await logic.asyncActions.fetchMatchingCounts()
+ expect(logic.values.totalMatchingFilters).toEqual(10)
+
+ countSpy.mockRejectedValue(new Error('boom'))
+ tracingFiltersLogic().actions.setServiceNames(['api'])
+ await expectLogic(logic).toDispatchActions(['fetchMatchingCountsFailure'])
+ expect(logic.values.totalMatchingFilters).toEqual(0)
+ expect(toastSpy).not.toHaveBeenCalled()
+ countSpy.mockRestore()
toastSpy.mockRestore()
})
})
diff --git a/products/tracing/frontend/tracingDataLogic.ts b/products/tracing/frontend/tracingDataLogic.ts
index 8616cab52a53..9d5ea9ae8419 100644
--- a/products/tracing/frontend/tracingDataLogic.ts
+++ b/products/tracing/frontend/tracingDataLogic.ts
@@ -161,6 +161,7 @@ export interface tracingDataLogicValues {
traceCount: number
}
matchingCountsAbortController: AbortController | null
+ matchingCountsFailed: boolean
matchingCountsLoading: boolean
nextCursor: string | null
rawDurationHistogram: DurationHistogramRow[]
@@ -628,6 +629,7 @@ export interface tracingDataLogicMeta {
count: number
traceCount: number
},
+ matchingCountsFailed: boolean,
filters: TracingFilters
) => number
durationHistogramData: (rawDurationHistogram: DurationHistogramRow[]) => TracingDurationHistogramData
@@ -828,6 +830,15 @@ export const tracingDataLogic = kea<tracingDataLogicType>([
fetchSpansFailure: (state, { error }) => (isUserInitiatedError(error) ? state : error),
},
],
+ // The count is a secondary label, so a failed count hides the label instead of raising a toast.
+ // Without this flag the label keeps the previous scope's count, which no longer matches the filters.
+ matchingCountsFailed: [
+ false as boolean,
+ {
+ fetchMatchingCountsSuccess: () => false,
+ fetchMatchingCountsFailure: (state, { error }) => (isUserInitiatedError(error) ? state : true),
+ },
+ ],
sparklineError: [
null as string | null,
{
@@ -1370,9 +1381,17 @@ export const tracingDataLogic = kea<tracingDataLogicType>([
// Total matching the filters, in the unit the list is showing: distinct traces in 'traces'
// mode, individual spans in 'spans' mode. Fed by the count endpoint, which returns both.
totalMatchingFilters: [
- (s) => [s.matchingCounts, s.filters],
- (matchingCounts: { count: number; traceCount: number }, filters: TracingFilters): number =>
- filters.viewMode === 'spans' ? matchingCounts.count : matchingCounts.traceCount,
+ (s) => [s.matchingCounts, s.matchingCountsFailed, s.filters],
+ (
+ matchingCounts: { count: number; traceCount: number },
+ matchingCountsFailed: boolean,
+ filters: TracingFilters
+ ): number => {
+ if (matchingCountsFailed) {
+ return 0
+ }
+ return filters.viewMode === 'spans' ? matchingCounts.count : matchingCounts.traceCount
+ },
],
durationHistogramData: [
(s) => [s.rawDurationHistogram],
@@ -1628,7 +1647,7 @@ export const tracingDataLogic = kea<tracingDataLogicType>([
},
fetchMatchingCountsFailure: ({ error }) => {
if (!isUserInitiatedError(error)) {
- lemonToast.error(`Failed to load the matching count: ${error}`)
+ posthog.capture('tracing query failed', { query_type: 'count', error_message: String(error) })
}
},
fetchAggregationFailure: ({ error }) => {