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.

feat(logs): add level and service facets to the filter rail (#65117)

Jon McCallum963943addef5
diff --git a/products/logs/frontend/components/LogsViewer/FacetRail/Facet.tsx b/products/logs/frontend/components/LogsViewer/FacetRail/Facet.tsx
new file mode 100644
index 000000000000..377a0101febb
--- /dev/null
+++ b/products/logs/frontend/components/LogsViewer/FacetRail/Facet.tsx
@@ -0,0 +1,178 @@
+import { CSSProperties, useMemo } from 'react'
+import { List } from 'react-window'
+
+import { IconChevronDown, IconChevronRight } from '@posthog/icons'
+import { LemonButton, LemonCheckbox, LemonInput } from '@posthog/lemon-ui'
+
+import { cn } from 'lib/utils/css-classes'
+
+const ROW_HEIGHT = 33
+
+export interface FacetOption {
+ value: string
+ label: string
+ /** Tailwind bg class for a leading color swatch (e.g. severity colors). */
+ color?: string
+}
+
+interface FacetProps {
+ title: string
+ options: FacetOption[]
+ selected: string[]
+ onToggle: (value: string) => void
+ loading?: boolean
+ emptyLabel?: string
+ /** When provided, renders a search box above the values (state owned by the caller). */
+ searchValue?: string
+ onSearchChange?: (value: string) => void
+ searchPlaceholder?: string
+ collapsed?: boolean
+ onToggleCollapsed?: () => void
+ /** When set, values render in a fixed-height virtualized list capped at this many pixels. */
+ maxHeight?: number
+}
+
+/** A single rail facet: a collapsible field title and its selectable values (multi-select = OR). No counts yet. */
+export function Facet({
+ title,
+ options,
+ selected,
+ onToggle,
+ loading = false,
+ emptyLabel = 'No values',
+ searchValue,
+ onSearchChange,
+ searchPlaceholder = 'Search…',
+ collapsed = false,
+ onToggleCollapsed,
+ maxHeight,
+}: FacetProps): JSX.Element {
+ const slug = title.toLowerCase().replace(/\s+/g, '-')
+
+ const rowProps = useMemo<FacetValueRowProps>(
+ () => ({ options, selected, slug, onToggle }),
+ [options, selected, slug, onToggle]
+ )
+
+ return (
+ <div className="mb-3">
+ <button
+ type="button"
+ onClick={onToggleCollapsed}
+ disabled={!onToggleCollapsed}
+ className="flex items-center gap-1 w-full px-1 mb-1 text-[10px] font-semibold uppercase tracking-wide text-secondary hover:text-default"
+ data-attr={`logs-facet-${slug}-header`}
+ >
+ {collapsed ? <IconChevronRight /> : <IconChevronDown />}
+ <span>{title}</span>
+ </button>
+ {!collapsed && onSearchChange && (
+ <div className="px-1 pb-1">
+ <LemonInput
+ type="search"
+ size="small"
+ fullWidth
+ placeholder={searchPlaceholder}
+ value={searchValue ?? ''}
+ onChange={onSearchChange}
+ />
+ </div>
+ )}
+ {!collapsed &&
+ (loading && options.length === 0 ? (
+ <div className="px-1 text-xs text-muted">Loading…</div>
+ ) : options.length === 0 ? (
+ <div className="px-1 text-xs text-muted">{emptyLabel}</div>
+ ) : (
+ // Dim the list while a refetch is in flight (e.g. typing in search) so there's
+ // feedback that results are updating, rather than the list silently changing.
+ <div className={cn(loading && 'opacity-60 transition-opacity')}>
+ {maxHeight ? (
+ <List<FacetValueRowProps>
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{ width: '100%', height: Math.min(options.length * ROW_HEIGHT, maxHeight) }}
+ rowCount={options.length}
+ rowHeight={ROW_HEIGHT}
+ overscanCount={5}
+ rowComponent={FacetValueRow}
+ rowProps={rowProps}
+ />
+ ) : (
+ <div className="space-y-px">
+ {options.map((option) => (
+ <FacetValueButton
+ key={option.value}
+ option={option}
+ selected={selected.includes(option.value)}
+ slug={slug}
+ onToggle={onToggle}
+ />
+ ))}
+ </div>
+ )}
+ </div>
+ ))}
+ </div>
+ )
+}
+
+interface FacetValueRowProps {
+ options: FacetOption[]
+ selected: string[]
+ slug: string
+ onToggle: (value: string) => void
+}
+
+function FacetValueRow({
+ index,
+ style,
+ options,
+ selected,
+ slug,
+ onToggle,
+}: {
+ ariaAttributes: Record<string, unknown>
+ index: number
+ style: CSSProperties
+} & FacetValueRowProps): JSX.Element {
+ const option = options[index]
+ return (
+ // eslint-disable-next-line react/forbid-dom-props
+ <div style={style}>
+ <FacetValueButton
+ option={option}
+ selected={selected.includes(option.value)}
+ slug={slug}
+ onToggle={onToggle}
+ />
+ </div>
+ )
+}
+
+function FacetValueButton({
+ option,
+ selected,
+ slug,
+ onToggle,
+}: {
+ option: FacetOption
+ selected: boolean
+ slug: string
+ onToggle: (value: string) => void
+}): JSX.Element {
+ return (
+ <LemonButton
+ type="tertiary"
+ size="small"
+ fullWidth
+ icon={<LemonCheckbox checked={selected} className="pointer-events-none" />}
+ onClick={() => onToggle(option.value)}
+ data-attr={`logs-facet-${slug}-${option.value}`}
+ >
+ <span className="flex items-center gap-2 min-w-0">
+ {option.color && <span className={cn('w-1 h-3.5 rounded-full shrink-0', option.color)} />}
+ <span className="truncate">{option.label}</span>
+ </span>
+ </LemonButton>
+ )
+}
diff --git a/products/logs/frontend/components/LogsViewer/FacetRail/FacetRail.tsx b/products/logs/frontend/components/LogsViewer/FacetRail/FacetRail.tsx
index 34f132170474..a3e5366339c5 100644
--- a/products/logs/frontend/components/LogsViewer/FacetRail/FacetRail.tsx
+++ b/products/logs/frontend/components/LogsViewer/FacetRail/FacetRail.tsx
@@ -1,22 +1,45 @@
-import { useActions, useValues } from 'kea'
+import { BindLogic, useActions, useValues } from 'kea'
import { useCallback, useMemo, useRef } from 'react'
import { Resizer } from 'lib/components/Resizer/Resizer'
import { ResizerLogicProps, resizerLogic } from 'lib/components/Resizer/resizerLogic'
+import { LogSeverityLevel } from '~/queries/schema/schema-general'
+
import { logsViewerConfigLogic } from 'products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic'
+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'
+
+import { Facet, FacetOption } from './Facet'
+import { facetRailLogic } from './facetRailLogic'
const DEFAULT_WIDTH_PX = 240
const COLLAPSE_THRESHOLD_PX = 120
+// Colors mirror the severity bar in the log rows (SEVERITY_BAR_COLORS) so the rail matches the viewer.
+const SEVERITY_OPTIONS: FacetOption[] = (
+ [
+ ['trace', 'Trace'],
+ ['debug', 'Debug'],
+ ['info', 'Info'],
+ ['warn', 'Warn'],
+ ['error', 'Error'],
+ ['fatal', 'Fatal'],
+ ] as const
+).map(([value, label]) => ({ value, label, color: SEVERITY_BAR_COLORS[value] }))
+
export interface FacetRailProps {
id: string
}
-/** Resizable left-hand facet rail. Shell only — facets and filtering land in follow-up work. */
+/** Resizable left-hand facet rail. Level + Service today; more facets and counts land in follow-up work. */
export function FacetRail({ id }: FacetRailProps): JSX.Element {
const railRef = useRef<HTMLDivElement>(null)
const { setFacetRailCollapsed } = useActions(logsViewerConfigLogic)
+ const { severityLevels, serviceNames, utcDateRange } = useValues(logsViewerFiltersLogic)
+ const { collapsedFacets } = useValues(facetRailLogic({ id }))
+ const { toggleSeverityLevel, toggleServiceName, toggleFacetCollapsed } = useActions(facetRailLogic({ id }))
const onToggleClosed = useCallback(
(shouldBeClosed: boolean) => setFacetRailCollapsed(shouldBeClosed),
@@ -48,9 +71,61 @@ export function FacetRail({ id }: FacetRailProps): JSX.Element {
<span className="text-xs font-semibold text-secondary uppercase tracking-wide">Filters</span>
</div>
<div className="flex-1 min-h-0 overflow-y-auto p-2">
- <p className="text-xs text-muted m-0">Facets will appear here.</p>
+ <div className="px-1 pb-1 mb-2 text-[11px] font-semibold uppercase tracking-wider text-muted border-b border-primary">
+ Standard
+ </div>
+ <Facet
+ title="Level"
+ options={SEVERITY_OPTIONS}
+ selected={severityLevels ?? []}
+ onToggle={(value) => toggleSeverityLevel(value as LogSeverityLevel)}
+ collapsed={collapsedFacets.includes('level')}
+ onToggleCollapsed={() => toggleFacetCollapsed('level')}
+ />
+ <BindLogic logic={serviceFilterLogic} props={{ dateRange: utcDateRange }}>
+ <ServiceFacet
+ selected={serviceNames ?? []}
+ onToggle={toggleServiceName}
+ collapsed={collapsedFacets.includes('service')}
+ onToggleCollapsed={() => toggleFacetCollapsed('service')}
+ />
+ </BindLogic>
</div>
<Resizer {...resizerLogicProps} visible={false} offset="0.25rem" handleClassName="rounded my-1" />
</div>
)
}
+
+function ServiceFacet({
+ selected,
+ onToggle,
+ collapsed,
+ onToggleCollapsed,
+}: {
+ selected: string[]
+ onToggle: (name: string) => void
+ collapsed: boolean
+ onToggleCollapsed: () => void
+}): JSX.Element {
+ const { serviceNames, allServiceNamesLoading, search } = useValues(serviceFilterLogic)
+ const { setSearch } = useActions(serviceFilterLogic)
+
+ const options: FacetOption[] = serviceNames.map((name) => ({ value: name, label: name }))
+
+ return (
+ <Facet
+ title="Service"
+ options={options}
+ selected={selected}
+ onToggle={onToggle}
+ loading={allServiceNamesLoading}
+ emptyLabel="No services"
+ searchValue={search}
+ onSearchChange={setSearch}
+ searchPlaceholder="Search services…"
+ collapsed={collapsed}
+ onToggleCollapsed={onToggleCollapsed}
+ maxHeight={300}
+ />
+ )
+}
diff --git a/products/logs/frontend/components/LogsViewer/FacetRail/facetRailLogic.test.ts b/products/logs/frontend/components/LogsViewer/FacetRail/facetRailLogic.test.ts
new file mode 100644
index 000000000000..02eca0a10ac4
--- /dev/null
+++ b/products/logs/frontend/components/LogsViewer/FacetRail/facetRailLogic.test.ts
@@ -0,0 +1,82 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { initKeaTests } from '~/test/init'
+
+import { logsViewerFiltersLogic } from '../Filters/logsViewerFiltersLogic'
+import { facetRailLogic } from './facetRailLogic'
+
+describe('facetRailLogic', () => {
+ let filtersLogic: ReturnType<typeof logsViewerFiltersLogic.build>
+ let logic: ReturnType<typeof facetRailLogic.build>
+
+ beforeEach(() => {
+ initKeaTests()
+ filtersLogic = logsViewerFiltersLogic({ id: 'test' })
+ filtersLogic.mount()
+ logic = facetRailLogic({ id: 'test' })
+ logic.mount()
+ })
+
+ afterEach(() => {
+ logic.unmount()
+ filtersLogic.unmount()
+ })
+
+ describe('severity level toggling', () => {
+ it('adds, accumulates (OR), and removes levels on the shared filters logic', async () => {
+ await expectLogic(logic, () => logic.actions.toggleSeverityLevel('error')).toFinishAllListeners()
+ expect(filtersLogic.values.severityLevels).toEqual(['error'])
+
+ await expectLogic(logic, () => logic.actions.toggleSeverityLevel('warn')).toFinishAllListeners()
+ expect(filtersLogic.values.severityLevels).toEqual(['error', 'warn'])
+
+ await expectLogic(logic, () => logic.actions.toggleSeverityLevel('error')).toFinishAllListeners()
+ expect(filtersLogic.values.severityLevels).toEqual(['warn'])
+ })
+
+ it.each(['trace', 'info', 'error', 'fatal'] as const)(
+ 'toggling %s on then off round-trips to empty',
+ async (level) => {
+ await expectLogic(logic, () => logic.actions.toggleSeverityLevel(level)).toFinishAllListeners()
+ expect(filtersLogic.values.severityLevels).toEqual([level])
+
+ await expectLogic(logic, () => logic.actions.toggleSeverityLevel(level)).toFinishAllListeners()
+ expect(filtersLogic.values.severityLevels).toEqual([])
+ }
+ )
+ })
+
+ describe('facet collapse', () => {
+ it('adds a facet to the collapsed set, then removes it on the second toggle', async () => {
+ await expectLogic(logic, () => logic.actions.toggleFacetCollapsed('level')).toFinishAllListeners()
+ expect(logic.values.collapsedFacets).toContain('level')
+
+ await expectLogic(logic, () => logic.actions.toggleFacetCollapsed('service')).toFinishAllListeners()
+ expect(logic.values.collapsedFacets).toEqual(expect.arrayContaining(['level', 'service']))
+
+ await expectLogic(logic, () => logic.actions.toggleFacetCollapsed('level')).toFinishAllListeners()
+ expect(logic.values.collapsedFacets).not.toContain('level')
+ expect(logic.values.collapsedFacets).toContain('service')
+ })
+ })
+
+ describe('service name toggling', () => {
+ it('adds then removes a service on the shared filters logic', async () => {
+ await expectLogic(logic, () => logic.actions.toggleServiceName('api')).toFinishAllListeners()
+ expect(filtersLogic.values.serviceNames).toEqual(['api'])
+
+ await expectLogic(logic, () => logic.actions.toggleServiceName('api')).toFinishAllListeners()
+ expect(filtersLogic.values.serviceNames).toEqual([])
+ })
+ })
+
+ describe('shared state', () => {
+ it('toggles relative to selections already on the filters logic', async () => {
+ filtersLogic.actions.setSeverityLevels(['info'])
+ await expectLogic(filtersLogic).toFinishAllListeners()
+
+ await expectLogic(logic, () => logic.actions.toggleSeverityLevel('error')).toFinishAllListeners()
+ expect(filtersLogic.values.severityLevels).toEqual(['info', 'error'])
+ })
+ })
+})
diff --git a/products/logs/frontend/components/LogsViewer/FacetRail/facetRailLogic.ts b/products/logs/frontend/components/LogsViewer/FacetRail/facetRailLogic.ts
new file mode 100644
index 000000000000..a08bdffa6598
--- /dev/null
+++ b/products/logs/frontend/components/LogsViewer/FacetRail/facetRailLogic.ts
@@ -0,0 +1,56 @@
+import { actions, connect, kea, key, listeners, path, props, reducers } from 'kea'
+
+import { LogSeverityLevel } from '~/queries/schema/schema-general'
+
+import { logsViewerFiltersLogic } from 'products/logs/frontend/components/LogsViewer/Filters/logsViewerFiltersLogic'
+
+import type { facetRailLogicType } from './facetRailLogicType'
+
+export interface FacetRailLogicProps {
+ id: string
+}
+
+function toggleMembership<T>(values: readonly T[] | undefined | null, value: T): T[] {
+ const current = values ?? []
+ return current.includes(value) ? current.filter((v) => v !== value) : [...current, value]
+}
+
+// The rail is a lens over the existing filter model — facet toggles write straight back to
+// logsViewerFiltersLogic's reducers, so URL sync, saved views, and the chips bar stay in step.
+export const facetRailLogic = kea<facetRailLogicType>([
+ path(['products', 'logs', 'frontend', 'components', 'LogsViewer', 'FacetRail', 'facetRailLogic']),
+ props({ id: 'default' } as FacetRailLogicProps),
+ key((props) => props.id),
+
+ connect((props: FacetRailLogicProps) => ({
+ actions: [logsViewerFiltersLogic({ id: props.id }), ['setSeverityLevels', 'setServiceNames']],
+ })),
+
+ actions({
+ toggleSeverityLevel: (level: LogSeverityLevel) => ({ level }),
+ toggleServiceName: (name: string) => ({ name }),
+ toggleFacetCollapsed: (facetKey: string) => ({ facetKey }),
+ }),
+
+ reducers({
+ collapsedFacets: [
+ [] as string[],
+ { persist: true },
+ {
+ toggleFacetCollapsed: (state, { facetKey }) =>
+ state.includes(facetKey) ? state.filter((k) => k !== facetKey) : [...state, facetKey],
+ },
+ ],
+ }),
+
+ listeners(({ props, actions }) => ({
+ toggleSeverityLevel: ({ level }) => {
+ const { severityLevels } = logsViewerFiltersLogic({ id: props.id }).values
+ actions.setSeverityLevels(toggleMembership(severityLevels, level))
+ },
+ toggleServiceName: ({ name }) => {
+ const { serviceNames } = logsViewerFiltersLogic({ id: props.id }).values
+ actions.setServiceNames(toggleMembership(serviceNames, name))
+ },
+ })),
+])
diff --git a/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx b/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx
index b610f7a0a3e7..55dc8f0e9b70 100644
--- a/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx
+++ b/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx
@@ -27,7 +27,7 @@ import {
import { VirtualizedTableColumn } from 'products/logs/frontend/components/VirtualizedLogsList/types'
import { LogsOrderBy, ParsedLogMessage } from 'products/logs/frontend/types'
-const SEVERITY_BAR_COLORS: Record<LogMessage['severity_text'], string> = {
+export const SEVERITY_BAR_COLORS: Record<LogMessage['severity_text'], string> = {
trace: 'bg-muted-alt',
debug: 'bg-muted',
info: 'bg-brand-blue',