: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(error-tracking): align summary stats and insight charts on same filters (#56637)
posthog[bot]5569bf4e1aeb
diff --git a/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx b/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsxindex 09ccd0b72f95..5aab39478ddc 100644--- a/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx+++ b/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx@@ -83,6 +83,7 @@ function DashboardInsightRefreshHintOrLoading({key={queryId}insightProps={insightProps}renderEmptyStateAsSkeleton={context?.renderEmptyStateAsSkeleton}+ suppressSlowQuerySuggestions={context?.suppressSlowQuerySuggestions}/>)}@@ -175,6 +176,7 @@ export function InsightVizDisplay({key={queryId}insightProps={insightProps}renderEmptyStateAsSkeleton={context?.renderEmptyStateAsSkeleton}+ suppressSlowQuerySuggestions={context?.suppressSlowQuerySuggestions}/>)}diff --git a/frontend/src/queries/types.ts b/frontend/src/queries/types.tsindex 2b862c6f6980..52cbde35a952 100644--- a/frontend/src/queries/types.ts+++ b/frontend/src/queries/types.ts@@ -71,6 +71,12 @@ export interface QueryContext<Q extends QuerySchema = QuerySchema> {onDateRangeZoom?: (dateFrom: string, dateTo: string) => void/** Wired by the web analytics scene so a pre-computed tile's badge can offer "always query live data". */onDisableWebAnalyticsPrecompute?: () => void+ /**+ * Suppress the generic "Need to speed things up?" optimization tips while a query is loading.+ * Use this when the embedded chart is built from a fixed query that the viewer cannot edit+ * (e.g. the Error tracking insights tab) and the suggestions would not be actionable.+ */+ suppressSlowQuerySuggestions?: boolean}export type QueryContextColumnTitleComponent = ComponentType<{diff --git a/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx b/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsxindex a3a23451f5b3..df0c0e41896f 100644--- a/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx+++ b/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx@@ -428,10 +428,12 @@ export function InsightLoadingState({queryId,insightProps,renderEmptyStateAsSkeleton = false,+ suppressSlowQuerySuggestions = false,}: {queryId?: string | nullinsightProps: InsightLogicPropsrenderEmptyStateAsSkeleton?: boolean+ suppressSlowQuerySuggestions?: boolean}): JSX.Element {const { insightPollResponse, insightLoadingTimeSeconds } = useValues(insightDataLogic(insightProps))const { currentTeam } = useValues(teamLogic)@@ -446,7 +448,9 @@ export function InsightLoadingState({loadingTimeSeconds={insightLoadingTimeSeconds}renderEmptyStateAsSkeleton={renderEmptyStateAsSkeleton}suggestion={- personsOnEventsMode === 'person_id_override_properties_joined' ? (+ suppressSlowQuerySuggestions ? (+ <></>+ ) : personsOnEventsMode === 'person_id_override_properties_joined' ? (<div className="text-xs">You can speed this query up by changing the{' '}<Link to="/settings/project#persons-on-events">person properties mode</Link> setting.diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/ChartCard.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/ChartCard.tsxindex b10e5a21cd3a..533c6d667138 100644--- a/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/ChartCard.tsx+++ b/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/ChartCard.tsx@@ -42,7 +42,12 @@ export function ChartCard({</LemonButton></div><div className="ErrorTracking__insights flex-1 min-h-0 p-2">- <Query query={query} readOnly={true} context={{ insightProps }} inSharedMode={true} />+ <Query+ query={query}+ readOnly={true}+ context={{ insightProps, suppressSlowQuerySuggestions: true }}+ inSharedMode={true}+ /></div></div>)diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/errorTrackingInsightsLogic.ts b/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/errorTrackingInsightsLogic.tsindex 86b9fc45ab53..ca0aac927867 100644--- a/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/errorTrackingInsightsLogic.ts+++ b/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/errorTrackingInsightsLogic.ts@@ -6,7 +6,14 @@ import posthog from 'posthog-js'import api from 'lib/api'import { isUniversalGroupFilterLike } from 'lib/components/UniversalFilters/utils'-import { HogQLQueryResponse, InsightVizNode, NodeKind, ProductKey, TrendsQuery } from '~/queries/schema/schema-general'+import {+ DateRange,+ HogQLQueryResponse,+ InsightVizNode,+ NodeKind,+ ProductKey,+ TrendsQuery,+} from '~/queries/schema/schema-general'import {AnyPropertyFilter,FilterLogicalOperator,@@ -85,27 +92,42 @@ export const errorTrackingInsightsLogic = kea<errorTrackingInsightsLogicType>([} as UniversalFiltersGroup},],+ // Flat property list shared by the HogQL summary query and the embedded TrendsQuery charts.+ // Both paths must use the same shape — passing a wrapped group to one path and a flat list+ // to the other can cause the summary stats and charts to disagree on which events match.+ effectiveProperties: [+ (s) => [s.insightsFilterGroup],+ (insightsFilterGroup): AnyPropertyFilter[] => {+ const inner = insightsFilterGroup.values[0] as UniversalFiltersGroup | undefined+ return (inner?.values ?? []) as AnyPropertyFilter[]+ },+ ],+ // Single source of truth for the date range used by both the summary stats query and the charts.+ effectiveDateRange: [+ (s) => [s.dateRange],+ (dateRange): DateRange => ({+ date_from: dateRange.date_from ?? '-7d',+ date_to: dateRange.date_to ?? null,+ }),+ ],insightQueryFilters: [- (s) => [s.insightsFilterGroup, s.filterTestAccounts],- (insightsFilterGroup, filterTestAccounts): InsightQueryFilters => ({- filterGroup: insightsFilterGroup,+ (s) => [s.effectiveProperties, s.filterTestAccounts],+ (properties, filterTestAccounts): InsightQueryFilters => ({+ properties,filterTestAccounts,}),],exceptionVolumeQuery: [- (s) => [s.dateRange, s.insightQueryFilters],- (dateRange, filters): InsightVizNode<TrendsQuery> =>- buildExceptionVolumeQuery(dateRange.date_from ?? '-7d', dateRange.date_to ?? null, filters),+ (s) => [s.effectiveDateRange, s.insightQueryFilters],+ (dateRange, filters): InsightVizNode<TrendsQuery> => buildExceptionVolumeQuery(dateRange, filters),],affectedUsersQuery: [- (s) => [s.dateRange, s.insightQueryFilters],- (dateRange, filters): InsightVizNode<TrendsQuery> =>- buildAffectedUsersQuery(dateRange.date_from ?? '-7d', dateRange.date_to ?? null, filters),+ (s) => [s.effectiveDateRange, s.insightQueryFilters],+ (dateRange, filters): InsightVizNode<TrendsQuery> => buildAffectedUsersQuery(dateRange, filters),],crashFreeSessionsQuery: [- (s) => [s.dateRange, s.insightQueryFilters],- (dateRange, filters): InsightVizNode<TrendsQuery> =>- buildCrashFreeSessionsQuery(dateRange.date_from ?? '-7d', dateRange.date_to ?? null, filters),+ (s) => [s.effectiveDateRange, s.insightQueryFilters],+ (dateRange, filters): InsightVizNode<TrendsQuery> => buildCrashFreeSessionsQuery(dateRange, filters),],}),@@ -127,10 +149,9 @@ export const errorTrackingInsightsLogic = kea<errorTrackingInsightsLogicType>([WHERE {filters}`,filters: {- dateRange: values.dateRange,+ dateRange: values.effectiveDateRange,filterTestAccounts: values.filterTestAccounts,- properties: (values.insightsFilterGroup.values[0] as UniversalFiltersGroup)- .values as AnyPropertyFilter[],+ properties: values.effectiveProperties,},tags: { productKey: ProductKey.ERROR_TRACKING },})diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/queries.test.ts b/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/queries.test.tsindex 5eb66150620f..036c4be5a31c 100644--- a/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/queries.test.ts+++ b/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/queries.test.ts@@ -1,25 +1,22 @@import { ProductKey } from '~/queries/schema/schema-general'-import { FilterLogicalOperator } from '~/types'import { buildAffectedUsersQuery, buildCrashFreeSessionsQuery, buildExceptionVolumeQuery } from './queries'describe('error tracking insights queries', () => {it('tags chart queries as error tracking', () => {const filters = {- filterGroup: {- type: FilterLogicalOperator.And,- values: [{ type: FilterLogicalOperator.And, values: [] }],- },+ properties: [],filterTestAccounts: false,}+ const dateRange = { date_from: '-7d', date_to: null }- expect(buildExceptionVolumeQuery('-7d', null, filters).source.tags).toEqual({+ expect(buildExceptionVolumeQuery(dateRange, filters).source.tags).toEqual({productKey: ProductKey.ERROR_TRACKING,})- expect(buildAffectedUsersQuery('-7d', null, filters).source.tags).toEqual({+ expect(buildAffectedUsersQuery(dateRange, filters).source.tags).toEqual({productKey: ProductKey.ERROR_TRACKING,})- expect(buildCrashFreeSessionsQuery('-7d', null, filters).source.tags).toEqual({+ expect(buildCrashFreeSessionsQuery(dateRange, filters).source.tags).toEqual({productKey: ProductKey.ERROR_TRACKING,})})diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/queries.ts b/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/queries.tsindex 8fbb096f495b..5f45b5e49bd9 100644--- a/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/queries.ts+++ b/products/error_tracking/frontend/scenes/ErrorTrackingScene/tabs/insights/queries.ts@@ -2,19 +2,19 @@ import { dayjs } from 'lib/dayjs'import { dateStringToDayJs } from 'lib/utils/dateFilters'import { urls } from 'scenes/urls'-import { InsightVizNode, NodeKind, ProductKey, TrendsQuery } from '~/queries/schema/schema-general'-import { BaseMathType, ChartDisplayType, IntervalType, PropertyGroupFilter, UniversalFiltersGroup } from '~/types'+import { DateRange, InsightVizNode, NodeKind, ProductKey, TrendsQuery } from '~/queries/schema/schema-general'+import { AnyPropertyFilter, BaseMathType, ChartDisplayType, IntervalType } from '~/types'export interface InsightQueryFilters {- filterGroup: UniversalFiltersGroup+ properties: AnyPropertyFilter[]filterTestAccounts: boolean}const MAX_HOURS_FOR_HOURLY_INTERVAL = 25-export function getInterval(dateFrom: string | null, dateTo: string | null): IntervalType {- const from = dateStringToDayJs(dateFrom)- const to = dateStringToDayJs(dateTo) ?? dayjs()+export function getInterval(dateFrom: string | null | undefined, dateTo: string | null | undefined): IntervalType {+ const from = dateStringToDayJs(dateFrom ?? null)+ const to = dateStringToDayJs(dateTo ?? null) ?? dayjs()if (from && to.diff(from, 'hour') < MAX_HOURS_FOR_HOURLY_INTERVAL) {return 'hour'}@@ -22,11 +22,10 @@ export function getInterval(dateFrom: string | null, dateTo: string | null): Int}export function buildExceptionVolumeQuery(- dateFrom: string,- dateTo: string | null,- { filterGroup, filterTestAccounts }: InsightQueryFilters+ dateRange: DateRange,+ { properties, filterTestAccounts }: InsightQueryFilters): InsightVizNode<TrendsQuery> {- const interval = getInterval(dateFrom, dateTo)+ const interval = getInterval(dateRange.date_from, dateRange.date_to)return {kind: NodeKind.InsightVizNode,source: {@@ -39,10 +38,10 @@ export function buildExceptionVolumeQuery(},],interval,- dateRange: { date_from: dateFrom, date_to: dateTo },+ dateRange,trendsFilter: { display: ChartDisplayType.ActionsBar },filterTestAccounts,- properties: filterGroup as PropertyGroupFilter,+ properties,tags: { productKey: ProductKey.ERROR_TRACKING },},showHeader: false,@@ -51,11 +50,10 @@ export function buildExceptionVolumeQuery(}export function buildAffectedUsersQuery(- dateFrom: string,- dateTo: string | null,- { filterGroup, filterTestAccounts }: InsightQueryFilters+ dateRange: DateRange,+ { properties, filterTestAccounts }: InsightQueryFilters): InsightVizNode<TrendsQuery> {- const interval = getInterval(dateFrom, dateTo)+ const interval = getInterval(dateRange.date_from, dateRange.date_to)return {kind: NodeKind.InsightVizNode,source: {@@ -69,10 +67,10 @@ export function buildAffectedUsersQuery(},],interval,- dateRange: { date_from: dateFrom, date_to: dateTo },+ dateRange,trendsFilter: { display: ChartDisplayType.ActionsLineGraph },filterTestAccounts,- properties: filterGroup as PropertyGroupFilter,+ properties,tags: { productKey: ProductKey.ERROR_TRACKING },},showHeader: false,@@ -81,11 +79,10 @@ export function buildAffectedUsersQuery(}export function buildCrashFreeSessionsQuery(- dateFrom: string,- dateTo: string | null,- { filterGroup, filterTestAccounts }: InsightQueryFilters+ dateRange: DateRange,+ { properties, filterTestAccounts }: InsightQueryFilters): InsightVizNode<TrendsQuery> {- const interval = getInterval(dateFrom, dateTo)+ const interval = getInterval(dateRange.date_from, dateRange.date_to)return {kind: NodeKind.InsightVizNode,source: {@@ -105,14 +102,14 @@ export function buildCrashFreeSessionsQuery(},],interval,- dateRange: { date_from: dateFrom, date_to: dateTo },+ dateRange,trendsFilter: {display: ChartDisplayType.ActionsLineGraph,formulaNodes: [{ formula: '(A - B) / A * 100', custom_name: 'Crash-free sessions %' }],aggregationAxisPostfix: '%',},filterTestAccounts,- properties: filterGroup as PropertyGroupFilter,+ properties,tags: { productKey: ProductKey.ERROR_TRACKING },},showHeader: false,