: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
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import type { LogsGroupBySourceEnumApi } from 'products/logs/frontend/generated/api.schemas'
// Maps the picker's taxonomic group onto the group-by endpoint's source vocabulary.
export const TAXONOMIC_GROUP_TO_SOURCE: Partial<Record<TaxonomicFilterGroupType, LogsGroupBySourceEnumApi>> = {
[TaxonomicFilterGroupType.Logs]: 'column',
[TaxonomicFilterGroupType.LogAttributes]: 'log',
[TaxonomicFilterGroupType.LogResourceAttributes]: 'resource',
}
// Top-level log fields that the endpoint groups by `source: 'column'` (backend `GROUPABLE_COLUMNS`
// in `products/logs/backend/group_by_query_runner.py`). The same keys also surface in the Recent
// tab, where they were recorded under `LogAttributes` (the search bar stores them as filter type
// `log`). Trusting that group would send `source: 'log'`, so the aggregation reads a non-existent
// attribute map entry and returns nothing. Pin them to `column` by key so a recent groups by the
// real column, matching a fresh pick from the `Logs` group.
// This mirrors the backend dict by hand; `groupBySource.test.ts` fails if the two drift apart.
export const GROUPABLE_COLUMN_KEYS = new Set<string>([
'severity_level',
'trace_id',
'span_id',
'service_name',
'pattern',
])
export function resolveGroupBySource(key: string, groupType: TaxonomicFilterGroupType): LogsGroupBySourceEnumApi {
if (GROUPABLE_COLUMN_KEYS.has(key)) {
return 'column'
}
return TAXONOMIC_GROUP_TO_SOURCE[groupType] ?? 'log'
}