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): prototype group-by lens behind feature flag (#68610)

Jon McCallume69e0991e2ed
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
index f820353e8c72..7f4e2dd6bd9d 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
@@ -969,11 +969,17 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
{ key: 'severity_level', name: 'severity_level', propertyFilterType: 'log' },
{ key: 'trace_id', name: 'trace_id', propertyFilterType: 'log' },
{ key: 'span_id', name: 'span_id', propertyFilterType: 'log' },
- ],
+ ].filter((o) => !excludedProperties[TaxonomicFilterGroupType.Logs]?.includes(o.key)),
localItemsSearch: (items: any[], q: string): any[] => {
if (!q) {
return items
}
+ const matches = items.filter((item) => item.name?.toLowerCase().includes(q.toLowerCase()))
+ // The free-text message-search item only makes sense where picking
+ // `message` does — consumers that exclude it get plain key search.
+ if (excludedProperties[TaxonomicFilterGroupType.Logs]?.includes('message')) {
+ return matches
+ }
return [
{
key: 'message',
@@ -981,7 +987,7 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
value: q,
propertyFilterType: 'log',
},
- ].concat(items.filter((item) => item.name?.toLowerCase().includes(q.toLowerCase())))
+ ].concat(matches)
},
getName: (option: { key: string; name: string }) => option.name,
getValue: (option: { key: string; name: string }) => option.key,
diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx b/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx
index 885b0c0ca1a7..e3b018981669 100644
--- a/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx
@@ -501,11 +501,17 @@ export function buildTaxonomicGroups(ctx: BuildTaxonomicGroupsContext): Taxonomi
{ key: 'severity_level', name: 'severity_level', propertyFilterType: 'log' },
{ key: 'trace_id', name: 'trace_id', propertyFilterType: 'log' },
{ key: 'span_id', name: 'span_id', propertyFilterType: 'log' },
- ],
+ ].filter((o) => !excludedProperties[TaxonomicFilterGroupType.Logs]?.includes(o.key)),
localItemsSearch: (items: any[], q: string): any[] => {
if (!q) {
return items
}
+ const matches = items.filter((item) => item.name?.toLowerCase().includes(q.toLowerCase()))
+ // Mirrors the legacy Logs group in taxonomicFilterLogic: the free-text message-search
+ // item only makes sense where picking `message` does.
+ if (excludedProperties[TaxonomicFilterGroupType.Logs]?.includes('message')) {
+ return matches
+ }
return [
{
key: 'message',
@@ -513,7 +519,7 @@ export function buildTaxonomicGroups(ctx: BuildTaxonomicGroupsContext): Taxonomi
value: q,
propertyFilterType: 'log',
},
- ].concat(items.filter((item) => item.name?.toLowerCase().includes(q.toLowerCase())))
+ ].concat(matches)
},
getName: (option: { key: string; name: string }) => option.name,
getValue: (option: { key: string; name: string }) => option.key,
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 7ed42428312c..6f933adaa98d 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -351,6 +351,7 @@ export const FEATURE_FLAGS = {
LOGS: 'logs', // owner: #team-logs
LOGS_ALERTING: 'logs-alerting', // owner: #team-logs
LOGS_FACET_RAIL: 'logs-facet-rail', // owner: #team-logs
+ LOGS_GROUP_BY: 'logs-group-by', // owner: #team-logs
LOGS_PATTERNS_VIEW: 'logs-patterns-view', // owner: #team-logs
LOGS_SAVED_VIEWS: 'logs-saved-views', // owner: #team-logs
LOGS_SERVICES_VIEW: 'logs-services-view', // owner: #team-logs
diff --git a/products/logs/frontend/components/LogsGroupBy/LogsGroupByResults.tsx b/products/logs/frontend/components/LogsGroupBy/LogsGroupByResults.tsx
new file mode 100644
index 000000000000..fb08345f2510
--- /dev/null
+++ b/products/logs/frontend/components/LogsGroupBy/LogsGroupByResults.tsx
@@ -0,0 +1,98 @@
+import { LemonBanner, LemonTable } from '@posthog/lemon-ui'
+
+import { TZLabel } from 'lib/components/TZLabel'
+import { dayjs } from 'lib/dayjs'
+import { humanFriendlyNumber } from 'lib/utils/numbers'
+
+/**
+ * PROTOTYPE — visual exploration of the "group by" lens; the rows are mocked.
+ * Behind the `logs-group-by` flag; nothing here queries the backend for results (the attribute
+ * picker in the display bar searches real keys). The goal is to judge the UX shape before
+ * building a real query runner.
+ *
+ * Column choice is deliberate — each column maps to a triage job:
+ * - value: which entity is this (identity, the pivot for drill-in)
+ * - logs: which groups are noisiest (default sort)
+ * - errors: which groups are failing (the "show me what's broken" sort)
+ * - last seen: is it still happening
+ * Anything that doesn't serve triage or drill-in (timeline art, duration, first seen) is out.
+ */
+
+interface MockGroupRow {
+ value: string
+ count: number
+ errorCount: number
+ lastSeenMinutesAgo: number
+}
+
+const MOCK_VALUES: Record<string, string[]> = {
+ transaction_id: ['txn_9f3ab21c', 'txn_04e77d90', 'txn_b81c33fa', 'txn_5a2e01dd', 'txn_c9f04e12', 'txn_77ab90e3'],
+ person_id: ['person_018f3a', 'person_02d417', 'person_0a99c1', 'person_11e402', 'person_1c07b9', 'person_23f8d0'],
+ session_id: ['sess_a1b2c3', 'sess_d4e5f6', 'sess_071829', 'sess_3a4b5c', 'sess_9d8e7f', 'sess_616263'],
+ 'service.name': ['api', 'worker', 'ingestion', 'capture', 'feature-flags', 'billing'],
+}
+
+// Deterministic pseudo-variety so each attribute renders distinct-looking (but stable) rows.
+function mockRowsFor(groupBy: string): MockGroupRow[] {
+ const values = MOCK_VALUES[groupBy] ?? [`${groupBy}_a`, `${groupBy}_b`, `${groupBy}_c`, `${groupBy}_d`]
+ return values.map((value, i) => ({
+ value,
+ count: [4183, 1962, 870, 412, 96, 23][i] ?? 10,
+ errorCount: [37, 0, 214, 0, 3, 0][i] ?? 0,
+ lastSeenMinutesAgo: [2, 45, 1, 118, 7, 31][i] ?? 60,
+ }))
+}
+
+export function LogsGroupByResults({ groupBy }: { groupBy: string }): JSX.Element {
+ const rows = mockRowsFor(groupBy)
+ const totalLogs = rows.reduce((sum, r) => sum + r.count, 0)
+
+ return (
+ <div className="flex-1 min-h-0 overflow-auto" data-attr="logs-group-by-results">
+ <LemonBanner type="warning" className="m-2">
+ Prototype — grouped results are mocked. This visualizes the group-by lens; no real query runs.
+ </LemonBanner>
+ <div className="px-2 pb-1 text-muted text-xs">
+ {humanFriendlyNumber(rows.length)} groups found (based on {humanFriendlyNumber(totalLogs)} logs)
+ </div>
+ <LemonTable
+ columns={[
+ {
+ title: groupBy,
+ key: 'value',
+ render: (_, row) => <span className="font-mono text-xs">{row.value}</span>,
+ },
+ {
+ title: 'Logs',
+ key: 'count',
+ align: 'right',
+ render: (_, row) => humanFriendlyNumber(row.count),
+ sorter: (a, b) => a.count - b.count,
+ },
+ {
+ title: 'Errors',
+ key: 'errorCount',
+ align: 'right',
+ render: (_, row) =>
+ row.errorCount > 0 ? (
+ <span className="text-danger font-semibold">{humanFriendlyNumber(row.errorCount)}</span>
+ ) : (
+ <span className="text-muted">0</span>
+ ),
+ sorter: (a, b) => a.errorCount - b.errorCount,
+ },
+ {
+ title: 'Last seen',
+ key: 'lastSeen',
+ render: (_, row) => <TZLabel time={dayjs().subtract(row.lastSeenMinutesAgo, 'minute')} />,
+ sorter: (a, b) => a.lastSeenMinutesAgo - b.lastSeenMinutesAgo,
+ },
+ ]}
+ dataSource={rows}
+ defaultSorting={{ columnKey: 'count', order: -1 }}
+ rowKey="value"
+ size="small"
+ />
+ </div>
+ )
+}
diff --git a/products/logs/frontend/components/LogsViewer/LogsDisplayBar.tsx b/products/logs/frontend/components/LogsViewer/LogsDisplayBar.tsx
index ace4678db3c1..18ca0b4d511a 100644
--- a/products/logs/frontend/components/LogsViewer/LogsDisplayBar.tsx
+++ b/products/logs/frontend/components/LogsViewer/LogsDisplayBar.tsx
@@ -3,6 +3,8 @@ import { useActions, useValues } from 'kea'
import { IconChevronLeft, IconChevronRight } from '@posthog/icons'
import { LemonButton, LemonSegmentedButton } from '@posthog/lemon-ui'
+import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
+import { TaxonomicStringPopover } from 'lib/components/TaxonomicPopover/TaxonomicPopover'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { humanFriendlyNumber } from 'lib/utils/numbers'
@@ -33,11 +35,14 @@ export const LogsDisplayBar = ({
showFacetRailToggle = false,
totalLogsCount,
}: LogsDisplayBarProps): JSX.Element => {
- const { facetRailCollapsed, viewMode } = useValues(logsViewerConfigLogic)
- const { setFacetRailCollapsed, setViewMode } = useActions(logsViewerConfigLogic)
+ const { facetRailCollapsed, viewMode, groupBy } = useValues(logsViewerConfigLogic)
+ const { setFacetRailCollapsed, setViewMode, setGroupBy } = useActions(logsViewerConfigLogic)
const showPatternsView = useFeatureFlag('LOGS_PATTERNS_VIEW')
+ const showGroupBy = useFeatureFlag('LOGS_GROUP_BY')
const inPatternsMode = showPatternsView && viewMode === 'patterns'
+ // Grouping applies to the Logs lens only; Patterns has its own aggregation.
+ const inGroupByMode = showGroupBy && !inPatternsMode && groupBy !== null
return (
<div className="flex items-center justify-between gap-2 flex-wrap">
@@ -63,16 +68,42 @@ export const LogsDisplayBar = ({
]}
/>
)}
+ {showGroupBy && !inPatternsMode && (
+ <TaxonomicStringPopover
+ size="small"
+ groupType={TaxonomicFilterGroupType.Logs}
+ groupTypes={[
+ TaxonomicFilterGroupType.Logs,
+ TaxonomicFilterGroupType.LogAttributes,
+ TaxonomicFilterGroupType.LogResourceAttributes,
+ ]}
+ // `message` is not a grouping key — high-cardinality free text is the
+ // Patterns lens's job. Excluding it also drops the message-search item.
+ excludedProperties={{ [TaxonomicFilterGroupType.Logs]: ['message'] }}
+ value={groupBy ?? undefined}
+ onChange={(value) => setGroupBy(value || null)}
+ allowClear
+ placeholder="Group by"
+ renderValue={(value) => (
+ <span>
+ Group by <span className="font-mono">{value}</span>
+ </span>
+ )}
+ selectingKeyOnly
+ data-attr="logs-group-by-picker"
+ />
+ )}
{inPatternsMode ? (
<PatternsCountIndicator id={id} />
) : (
+ !inGroupByMode &&
totalLogsCount !== undefined &&
totalLogsCount > 0 && (
<span className="text-muted text-xs">{humanFriendlyNumber(totalLogsCount)} logs</span>
)
)}
</div>
- {!inPatternsMode && <LogsViewerToolbar totalLogsCount={totalLogsCount} />}
+ {!inPatternsMode && !inGroupByMode && <LogsViewerToolbar totalLogsCount={totalLogsCount} />}
</div>
)
}
diff --git a/products/logs/frontend/components/LogsViewer/LogsViewer.tsx b/products/logs/frontend/components/LogsViewer/LogsViewer.tsx
index 2cd6cd94f8f2..ccdb81bbe37f 100644
--- a/products/logs/frontend/components/LogsViewer/LogsViewer.tsx
+++ b/products/logs/frontend/components/LogsViewer/LogsViewer.tsx
@@ -8,6 +8,7 @@ import { useKeyboardHotkeys } from 'lib/hooks/useKeyboardHotkeys'
import { SceneDivider } from '~/layout/scenes/components/SceneDivider'
import { UniversalFiltersGroup } from '~/types'
+import { LogsGroupByResults } from 'products/logs/frontend/components/LogsGroupBy/LogsGroupByResults'
import { LogsPatterns } from 'products/logs/frontend/components/LogsPatterns/LogsPatterns'
import { logsViewerConfigLogic } from 'products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic'
import { LogsViewerFilters } from 'products/logs/frontend/components/LogsViewer/config/types'
@@ -106,7 +107,7 @@ function LogsViewerContent({
clearSelection,
togglePrettifyLog,
} = useActions(logsViewerLogic)
- const { orderBy, sparklineBreakdownBy, sparklineCollapsed, facetRailCollapsed, viewMode } =
+ const { orderBy, sparklineBreakdownBy, sparklineCollapsed, facetRailCollapsed, viewMode, groupBy } =
useValues(logsViewerConfigLogic)
const { setOrderBy, setSparklineBreakdownBy, toggleSparklineCollapsed } = useActions(logsViewerConfigLogic)
const {
@@ -122,6 +123,7 @@ function LogsViewerContent({
const { setDateRange, zoomDateRange } = useActions(logsViewerFiltersLogic)
const showFacetRail = useFeatureFlag('LOGS_FACET_RAIL')
const showPatternsView = useFeatureFlag('LOGS_PATTERNS_VIEW')
+ const showGroupBy = useFeatureFlag('LOGS_GROUP_BY')
const { cellScrollLefts } = useValues(virtualizedLogsListLogic({ id }))
const { setCellScrollLeft } = useActions(virtualizedLogsListLogic({ id }))
const messageScrollLeft = cellScrollLefts['message'] ?? 0
@@ -353,7 +355,16 @@ function LogsViewerContent({
// Gate on the flag too, so the patterns query stays unreachable when the flag is off regardless
// of the (non-persisted) viewMode state.
const inPatternsMode = showPatternsView && viewMode === 'patterns'
- const resultsRegion = inPatternsMode ? <LogsPatterns id={id} /> : logList
+ // Group-by (prototype, logs-group-by flag): an active grouping swaps the Logs lens's results
+ // for the grouped table. Double-gated like Patterns so it's unreachable with the flag off.
+ const inGroupByMode = showGroupBy && !inPatternsMode && groupBy !== null
+ const resultsRegion = inPatternsMode ? (
+ <LogsPatterns id={id} />
+ ) : inGroupByMode && groupBy ? (
+ <LogsGroupByResults groupBy={groupBy} />
+ ) : (
+ logList
+ )
// Both layouts share the same results column; only the results bar above it differs (the facet-rail
// layout adds the rail toggle). The bar owns the Logs⇄Patterns switch and hides its Logs-only tools
diff --git a/products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic.ts b/products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic.ts
index 34e3ce5fc813..ad9b587a9dda 100644
--- a/products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic.ts
+++ b/products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic.ts
@@ -45,6 +45,7 @@ export const logsViewerConfigLogic = kea<logsViewerConfigLogicType>([
toggleSparklineCollapsed: true,
setFacetRailCollapsed: (facetRailCollapsed: boolean) => ({ facetRailCollapsed }),
setViewMode: (viewMode: LogsViewerViewMode) => ({ viewMode }),
+ setGroupBy: (groupBy: string | null) => ({ groupBy }),
}),
reducers({
@@ -92,6 +93,14 @@ export const logsViewerConfigLogic = kea<logsViewerConfigLogicType>([
setViewMode: (_, { viewMode }) => viewMode,
},
],
+ // The attribute to group results by (behind the logs-group-by flag); null = ungrouped.
+ // Not persisted — grouping is an explicit, per-visit exploration like Patterns.
+ groupBy: [
+ null as string | null,
+ {
+ setGroupBy: (_, { groupBy }) => groupBy,
+ },
+ ],
}),
selectors({