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.

fix(logs): use the resource attribute filter type for custom column cells (#113920)

posthog[bot]54613c00173b
diff --git a/products/logs/frontend/components/LogsViewer/config/LogsColumnConfigurator.tsx b/products/logs/frontend/components/LogsViewer/config/LogsColumnConfigurator.tsx
index c111e92c0810..136e1e8c2bbb 100644
--- a/products/logs/frontend/components/LogsViewer/config/LogsColumnConfigurator.tsx
+++ b/products/logs/frontend/components/LogsViewer/config/LogsColumnConfigurator.tsx
@@ -42,6 +42,7 @@ function taxonomicSelectionToColumn(group: TaxonomicFilterGroup, value: string):
return { type: 'custom', expression: value }
}
const prefix = TAXONOMIC_GROUP_TO_PREFIX[group.type]
+ // customColumnFilterType matches this exact `<prefix>.<key>` form, so a change here needs a change there
return prefix ? { type: 'custom', name: value, expression: `${prefix}.${value}` } : null
}
diff --git a/products/logs/frontend/components/LogsViewer/config/columns.test.ts b/products/logs/frontend/components/LogsViewer/config/columns.test.ts
index 643d12a1c511..d07af402fd5d 100644
--- a/products/logs/frontend/components/LogsViewer/config/columns.test.ts
+++ b/products/logs/frontend/components/LogsViewer/config/columns.test.ts
@@ -1,8 +1,12 @@
+import { PropertyFilterType } from '~/types'
+
import { AttributeColumnConfig } from 'products/logs/frontend/types'
import {
+ attributeLookupExpression,
columnLabel,
columnsToCustomColumns,
+ customColumnFilterType,
LogsColumnConfig,
migrateAttributeColumns,
normalizeColumns,
@@ -89,6 +93,66 @@ describe('logs column config', () => {
})
})
+ describe('customColumnFilterType', () => {
+ const key = 'k8s.pod'
+ it.each<
+ [
+ string,
+ string,
+ string,
+ Record<string, unknown> | undefined,
+ Record<string, unknown> | undefined,
+ PropertyFilterType,
+ ]
+ >([
+ [
+ 'fallback, resource only',
+ key,
+ attributeLookupExpression(key),
+ {},
+ { [key]: 'r' },
+ PropertyFilterType.LogResourceAttribute,
+ ],
+ [
+ 'fallback, empty value in attributes',
+ key,
+ attributeLookupExpression(key),
+ { [key]: '' },
+ { [key]: 'r' },
+ PropertyFilterType.LogAttribute,
+ ],
+ [
+ 'fallback, inherited key in neither map',
+ 'constructor',
+ attributeLookupExpression('constructor'),
+ undefined,
+ {},
+ PropertyFilterType.LogAttribute,
+ ],
+ ['attributes shorthand', key, `attributes.${key}`, {}, { [key]: 'r' }, PropertyFilterType.LogAttribute],
+ [
+ 'resource_attributes shorthand with trailing space',
+ key,
+ `resource_attributes.${key} `,
+ { [key]: 'a' },
+ { [key]: 'r' },
+ PropertyFilterType.LogResourceAttribute,
+ ],
+ [
+ 'other HogQL',
+ key,
+ `upper(resource_attributes['${key}'])`,
+ {},
+ { [key]: 'r' },
+ PropertyFilterType.LogAttribute,
+ ],
+ ])('%s', (_, name, expression, attributes, resourceAttributes, expected) => {
+ expect(
+ customColumnFilterType({ id: 'c', type: 'custom', name, expression }, attributes, resourceAttributes)
+ ).toEqual(expected)
+ })
+ })
+
describe('normalizeColumns', () => {
it('pins message columns last, preserving relative order of the rest', () => {
const columns: LogsColumnConfig[] = [
diff --git a/products/logs/frontend/components/LogsViewer/config/columns.ts b/products/logs/frontend/components/LogsViewer/config/columns.ts
index 372a226f4aaa..54fc720dd6b1 100644
--- a/products/logs/frontend/components/LogsViewer/config/columns.ts
+++ b/products/logs/frontend/components/LogsViewer/config/columns.ts
@@ -1,6 +1,7 @@
import { uuid } from 'lib/utils/dom'
import { LogsQuery } from '~/queries/schema/schema-general'
+import { PropertyFilterType } from '~/types'
import { AttributeColumnConfig, ParsedLogMessage } from 'products/logs/frontend/types'
@@ -134,6 +135,32 @@ export function attributeLookupExpression(key: string): string {
return `if(mapContains(attributes, '${escaped}'), attributes['${escaped}'], resource_attributes['${escaped}'])`
}
+/** Only app-written attribute expressions tie `column.name` to a map key, so others keep the log attribute filter. */
+export function customColumnFilterType(
+ column: LogsColumnConfig,
+ attributes: Record<string, unknown> | undefined,
+ resourceAttributes: Record<string, unknown> | undefined
+): PropertyFilterType.LogAttribute | PropertyFilterType.LogResourceAttribute {
+ const key = column.name
+ const expression = column.expression?.trim()
+ if (!key) {
+ return PropertyFilterType.LogAttribute
+ }
+ if (expression === `resource_attributes.${key}`) {
+ return PropertyFilterType.LogResourceAttribute
+ }
+ // Same check as the expression's mapContains, so the filter targets the map the cell read
+ if (
+ expression === attributeLookupExpression(key) &&
+ !(attributes && Object.hasOwn(attributes, key)) &&
+ resourceAttributes &&
+ Object.hasOwn(resourceAttributes, key)
+ ) {
+ return PropertyFilterType.LogResourceAttribute
+ }
+ return PropertyFilterType.LogAttribute
+}
+
/** Migrate the legacy persisted `attributeColumnsConfig` map to typed custom columns. */
export function migrateAttributeColumns(config: Record<string, AttributeColumnConfig>): LogsColumnConfig[] {
return Object.entries(config)
diff --git a/products/logs/frontend/components/VirtualizedLogsList/cells/AttributeCell.tsx b/products/logs/frontend/components/VirtualizedLogsList/cells/AttributeCell.tsx
index de7544687097..c5d1e18b0ce6 100644
--- a/products/logs/frontend/components/VirtualizedLogsList/cells/AttributeCell.tsx
+++ b/products/logs/frontend/components/VirtualizedLogsList/cells/AttributeCell.tsx
@@ -32,11 +32,7 @@ export interface AttributeCellProps {
* together.
*/
cellKey?: string
- /**
- * Which property the popover's filter actions target. Defaults to a log attribute; the Person
- * and Session columns pass a resource-attribute filter when that is where the row's value came
- * from, so the filter matches the row it was added from.
- */
+ /** Popover filter type, default log attribute. Pass resource attribute for values read from resource attributes. */
filterType?: PropertyFilterType
}
diff --git a/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx b/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx
index c0a4fa1ec651..19a9f55bf8e3 100644
--- a/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx
+++ b/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx
@@ -17,6 +17,7 @@ import {
LogsColumnConfig,
LogsColumnType,
columnLabel,
+ customColumnFilterType,
} from 'products/logs/frontend/components/LogsViewer/config/columns'
import { logsViewerLogic } from 'products/logs/frontend/components/LogsViewer/logsViewerLogic'
import { AttributeCell } from 'products/logs/frontend/components/VirtualizedLogsList/cells/AttributeCell'
@@ -402,6 +403,12 @@ export function createConfiguredColumn(params: {
<AttributeCell
attributeKey={semanticKey}
value={getBuiltInValue ? getBuiltInValue(log) : customColumnValue(log, alias)}
+ // Raw map: the stringified copy drops a `__proto__` key that the server still reads
+ filterType={
+ config.type === 'custom'
+ ? customColumnFilterType(config, log.originalLog.attributes, log.resource_attributes)
+ : undefined
+ }
width={totalWidth}
timestamp={log.timestamp}
/>