: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
feat(logs): show per-value counts in the facet rail (#64653)
Jon McCallum9a7e56449ade
diff --git a/products/logs/frontend/components/LogsViewer/FacetRail/Facet.tsx b/products/logs/frontend/components/LogsViewer/FacetRail/Facet.tsxindex 377a0101febb..3246dad420f7 100644--- a/products/logs/frontend/components/LogsViewer/FacetRail/Facet.tsx+++ b/products/logs/frontend/components/LogsViewer/FacetRail/Facet.tsx@@ -5,6 +5,7 @@ import { IconChevronDown, IconChevronRight } from '@posthog/icons'import { LemonButton, LemonCheckbox, LemonInput } from '@posthog/lemon-ui'import { cn } from 'lib/utils/css-classes'+import { humanFriendlyLargeNumber } from 'lib/utils/numbers'const ROW_HEIGHT = 33@@ -13,6 +14,8 @@ export interface FacetOption {label: string/** Tailwind bg class for a leading color swatch (e.g. severity colors). */color?: string+ /** Number of matching log records; rendered right-aligned. Omitted when unavailable. */+ count?: number}interface FacetProps {@@ -169,9 +172,12 @@ function FacetValueButton({onClick={() => onToggle(option.value)}data-attr={`logs-facet-${slug}-${option.value}`}>- <span className="flex items-center gap-2 min-w-0">+ <span className="flex items-center gap-2 min-w-0 w-full">{option.color && <span className={cn('w-1 h-3.5 rounded-full shrink-0', option.color)} />}- <span className="truncate">{option.label}</span>+ <span className="truncate flex-1">{option.label}</span>+ {option.count != null && (+ <span className="shrink-0 text-muted tabular-nums">{humanFriendlyLargeNumber(option.count)}</span>+ )}</span></LemonButton>)diff --git a/products/logs/frontend/components/LogsViewer/FacetRail/FacetRail.tsx b/products/logs/frontend/components/LogsViewer/FacetRail/FacetRail.tsxindex a3e5366339c5..f235457b63c5 100644--- a/products/logs/frontend/components/LogsViewer/FacetRail/FacetRail.tsx+++ b/products/logs/frontend/components/LogsViewer/FacetRail/FacetRail.tsx@@ -7,6 +7,7 @@ import { ResizerLogicProps, resizerLogic } from 'lib/components/Resizer/resizerLimport { LogSeverityLevel } from '~/queries/schema/schema-general'import { logsViewerConfigLogic } from 'products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic'+import { logsViewerDataLogic } from 'products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic'import { logsViewerFiltersLogic } from 'products/logs/frontend/components/LogsViewer/Filters/logsViewerFiltersLogic'import { serviceFilterLogic } from 'products/logs/frontend/components/LogsViewer/Filters/serviceFilterLogic'import { SEVERITY_BAR_COLORS } from 'products/logs/frontend/components/VirtualizedLogsList/columnDefinitions'@@ -38,9 +39,12 @@ export function FacetRail({ id }: FacetRailProps): JSX.Element {const railRef = useRef<HTMLDivElement>(null)const { setFacetRailCollapsed } = useActions(logsViewerConfigLogic)const { severityLevels, serviceNames, utcDateRange } = useValues(logsViewerFiltersLogic)+ const { severityTotals } = useValues(logsViewerDataLogic)const { collapsedFacets } = useValues(facetRailLogic({ id }))const { toggleSeverityLevel, toggleServiceName, toggleFacetCollapsed } = useActions(facetRailLogic({ id }))+ const levelOptions = SEVERITY_OPTIONS.map((option) => ({ ...option, count: severityTotals?.[option.value] }))+const onToggleClosed = useCallback((shouldBeClosed: boolean) => setFacetRailCollapsed(shouldBeClosed),[setFacetRailCollapsed]@@ -76,7 +80,7 @@ export function FacetRail({ id }: FacetRailProps): JSX.Element {</div><Facettitle="Level"- options={SEVERITY_OPTIONS}+ options={levelOptions}selected={severityLevels ?? []}onToggle={(value) => toggleSeverityLevel(value as LogSeverityLevel)}collapsed={collapsedFacets.includes('level')}@@ -107,10 +111,10 @@ function ServiceFacet({collapsed: booleanonToggleCollapsed: () => void}): JSX.Element {- const { serviceNames, allServiceNamesLoading, search } = useValues(serviceFilterLogic)+ const { serviceValues, allServiceNamesLoading, search } = useValues(serviceFilterLogic)const { setSearch } = useActions(serviceFilterLogic)- const options: FacetOption[] = serviceNames.map((name) => ({ value: name, label: name }))+ const options: FacetOption[] = serviceValues.map((s) => ({ value: s.name, label: s.name, count: s.count }))return (<Facetdiff --git a/products/logs/frontend/components/LogsViewer/Filters/serviceFilterLogic.ts b/products/logs/frontend/components/LogsViewer/Filters/serviceFilterLogic.tsindex d4629afe9a04..e744f82cfe70 100644--- a/products/logs/frontend/components/LogsViewer/Filters/serviceFilterLogic.ts+++ b/products/logs/frontend/components/LogsViewer/Filters/serviceFilterLogic.ts@@ -13,6 +13,11 @@ export interface ServiceFilterLogicProps {dateRange?: DateRange}+export interface ServiceValue {+ name: string+ count?: number+}+export const serviceFilterLogic = kea<serviceFilterLogicType>([path(['products', 'logs', 'frontend', 'components', 'LogsViewer', 'Filters', 'serviceFilterLogic']),props({} as ServiceFilterLogicProps),@@ -32,7 +37,7 @@ export const serviceFilterLogic = kea<serviceFilterLogicType>([loaders(({ values, props: logicProps }) => ({allServiceNames: [- [] as string[],+ [] as ServiceValue[],{loadServiceNames: async () => {const url = combineUrl(`api/environments/${values.currentTeamId}/logs/values`, {@@ -44,14 +49,17 @@ export const serviceFilterLogic = kea<serviceFilterLogicType>([}).url// nosemgrep: prefer-codegen-apiconst response = await api.get(url)- return ((response.results ?? []) as { name: string }[]).map((r) => r.name)+ return (response.results ?? []) as ServiceValue[]},},],})),selectors({- serviceNames: [(s) => [s.allServiceNames], (allServiceNames): string[] => allServiceNames],+ // Names only — kept for the legacy ServiceFilter dropdown (flag off).+ serviceNames: [(s) => [s.allServiceNames], (allServiceNames): string[] => allServiceNames.map((r) => r.name)],+ // Name + count — used by the facet rail to show per-value counts.+ serviceValues: [(s) => [s.allServiceNames], (allServiceNames): ServiceValue[] => allServiceNames],}),listeners(({ actions }) => ({diff --git a/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.ts b/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.tsindex a29c16bef59a..fc847fbcdb0f 100644--- a/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.ts+++ b/products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic.ts@@ -481,6 +481,26 @@ export const logsViewerDataLogic = kea<logsViewerDataLogicType>([(s) => [s.sparkline],(sparkline): number => sparkline?.reduce((sum: number, item: any) => sum + item.count, 0) ?? 0,],+ // Per-severity totals for the facet rail's Level counts, summed from the already-loaded+ // sparkline. Only available when the sparkline is broken down by severity (the default);+ // returns null otherwise so the Level facet just omits counts rather than showing wrong ones.+ severityTotals: [+ (s) => [s.sparkline, s.sparklineBreakdownBy],+ (+ sparkline: any[] | null,+ sparklineBreakdownBy: LogsSparklineBreakdownBy+ ): Record<string, number> | null => {+ if (!sparkline || sparklineBreakdownBy !== 'severity') {+ return null+ }+ return sparkline.reduce((acc: Record<string, number>, row: any) => {+ if (row.severity) {+ acc[row.severity] = (acc[row.severity] ?? 0) + row.count+ }+ return acc+ }, {})+ },+ ],logsRemainingToLoad: [(s) => [s.totalLogsMatchingFilters, s.logs],(totalLogsMatchingFilters, logs): number => totalLogsMatchingFilters - logs.length,