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 Person and Session column types (#94989)

Jon McCallumd320a5806da6
diff --git a/products/logs/backend/presentation/views/views_api.py b/products/logs/backend/presentation/views/views_api.py
index 5444c58fb06c..31c7cecc8b5a 100644
--- a/products/logs/backend/presentation/views/views_api.py
+++ b/products/logs/backend/presentation/views/views_api.py
@@ -17,6 +17,8 @@ class LogsViewColumnType(models.TextChoices):
SOURCE = "source", "source"
TRACE_ID = "trace_id", "trace_id"
SPAN_ID = "span_id", "span_id"
+ PERSON = "person", "person"
+ SESSION = "session", "session"
PATTERN = "pattern", "pattern"
MESSAGE = "message", "message"
CUSTOM = "custom", "custom"
diff --git a/products/logs/frontend/components/LogsViewer/LogContextSelector/logContextUtils.ts b/products/logs/frontend/components/LogsViewer/LogContextSelector/logContextUtils.ts
index c4ba03d0e3b4..6979ad20a190 100644
--- a/products/logs/frontend/components/LogsViewer/LogContextSelector/logContextUtils.ts
+++ b/products/logs/frontend/components/LogsViewer/LogContextSelector/logContextUtils.ts
@@ -4,7 +4,7 @@ import { LogsViewerFilters } from 'products/logs/frontend/components/LogsViewer/
import { ParsedLogMessage } from 'products/logs/frontend/types'
import {
SESSION_LOGS_WINDOW_MINUTES,
- SessionIdMatch,
+ LogIdentityMatch,
buildDateRangeAround,
getSessionIdWithKey,
} from 'products/logs/frontend/utils'
@@ -26,7 +26,7 @@ function getServiceName(log: ParsedLogMessage): string | null {
return serviceName ? String(serviceName) : null
}
-function getSessionMatch(log: ParsedLogMessage, configuredKeys?: string[]): SessionIdMatch | null {
+function getSessionMatch(log: ParsedLogMessage, configuredKeys?: string[]): LogIdentityMatch | null {
return getSessionIdWithKey(log.attributes, log.resource_attributes, configuredKeys)
}
diff --git a/products/logs/frontend/components/LogsViewer/config/columns.test.ts b/products/logs/frontend/components/LogsViewer/config/columns.test.ts
index 4df7ba4fd78f..643d12a1c511 100644
--- a/products/logs/frontend/components/LogsViewer/config/columns.test.ts
+++ b/products/logs/frontend/components/LogsViewer/config/columns.test.ts
@@ -1,6 +1,12 @@
import { AttributeColumnConfig } from 'products/logs/frontend/types'
-import { columnsToCustomColumns, LogsColumnConfig, migrateAttributeColumns, normalizeColumns } from './columns'
+import {
+ columnLabel,
+ columnsToCustomColumns,
+ LogsColumnConfig,
+ migrateAttributeColumns,
+ normalizeColumns,
+} from './columns'
describe('logs column config', () => {
describe('columnsToCustomColumns', () => {
@@ -31,11 +37,29 @@ describe('logs column config', () => {
['client-side built-ins only', [{ id: 'timestamp', type: 'timestamp' }]],
['custom with blank expression', [{ id: 'x', type: 'custom', expression: ' ' }]],
['custom with no expression', [{ id: 'x', type: 'custom' }]],
+ // Person and Session resolve from the row's attribute maps in the cell, so they cost nothing on the wire
+ [
+ 'person and session',
+ [
+ { id: 'person', type: 'person' },
+ { id: 'session', type: 'session' },
+ ],
+ ],
])('returns undefined (not []) for %s, keeping query payloads cache-identical', (_, columns) => {
expect(columnsToCustomColumns(columns)).toBeUndefined()
})
})
+ describe('columnLabel', () => {
+ it.each<[LogsColumnConfig, string]>([
+ [{ id: 'person', type: 'person' }, 'Person'],
+ [{ id: 'session', type: 'session' }, 'Session'],
+ [{ id: 'person', type: 'person', name: 'User' }, 'User'],
+ ])('labels %j as %s', (column, expected) => {
+ expect(columnLabel(column)).toBe(expected)
+ })
+ })
+
describe('migrateAttributeColumns', () => {
it('orders by the legacy order field and preserves width', () => {
// Insertion order deliberately disagrees with the order field
diff --git a/products/logs/frontend/components/LogsViewer/config/columns.ts b/products/logs/frontend/components/LogsViewer/config/columns.ts
index 854c597f2861..372a226f4aaa 100644
--- a/products/logs/frontend/components/LogsViewer/config/columns.ts
+++ b/products/logs/frontend/components/LogsViewer/config/columns.ts
@@ -10,6 +10,8 @@ export type LogsColumnType =
| 'source'
| 'trace_id'
| 'span_id'
+ | 'person'
+ | 'session'
| 'pattern'
| 'message'
| 'custom'
@@ -31,7 +33,10 @@ export interface LogsColumnConfig {
interface BuiltInColumnDef {
label: string
- /** Reads the value off the row. Absent when the value only exists server-side (see `expression`). */
+ /**
+ * Reads the value off the row. Absent when the value only exists server-side (see `expression`),
+ * or when the cell resolves it itself (see `person` and `session` below).
+ */
getValue?: (log: ParsedLogMessage) => string
/** HogQL the server computes for this column, for values a log row does not carry. */
expression?: string
@@ -41,13 +46,17 @@ interface BuiltInColumnDef {
// they never hit the wire. `source` has no top-level row field; the service name rides in
// resource_attributes per OTel convention. `pattern` is the exception: it is a table column the
// row payload leaves out, so it rides the same wire mechanism as custom columns and is only
-// fetched while the column is on screen.
+// fetched while the column is on screen. `person` and `session` have no fixed field either: the
+// value sits under whichever attribute key the team's logs config names, so the cell resolves it
+// per row (see IdentityCell) rather than a `getValue` here.
export const LOGS_COLUMN_REGISTRY: Record<Exclude<LogsColumnType, 'custom'>, BuiltInColumnDef> = {
timestamp: { label: 'Timestamp', getValue: (log) => log.timestamp },
level: { label: 'Level', getValue: (log) => log.severity_text },
source: { label: 'Source', getValue: (log) => String(log.resource_attributes?.['service.name'] ?? '') },
trace_id: { label: 'Trace ID', getValue: (log) => log.trace_id },
span_id: { label: 'Span ID', getValue: (log) => log.span_id },
+ person: { label: 'Person' },
+ session: { label: 'Session' },
pattern: { label: 'Pattern', expression: 'pattern' },
message: { label: 'Message', getValue: (log) => log.body },
}
diff --git a/products/logs/frontend/components/VirtualizedLogsList/cells/AttributeCell.tsx b/products/logs/frontend/components/VirtualizedLogsList/cells/AttributeCell.tsx
index 72f745990c96..473e32dc0d1c 100644
--- a/products/logs/frontend/components/VirtualizedLogsList/cells/AttributeCell.tsx
+++ b/products/logs/frontend/components/VirtualizedLogsList/cells/AttributeCell.tsx
@@ -10,7 +10,7 @@ import ViewRecordingButton, {
import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
import { PersonDisplay } from 'scenes/persons/PersonDisplay'
-import { AccessControlLevel, AccessControlResourceType } from '~/types'
+import { AccessControlLevel, AccessControlResourceType, PropertyFilterType } from '~/types'
import { LogsViewerCellPopover } from 'products/logs/frontend/components/LogsViewer/LogsViewerCellPopover'
import { logsViewerLogic } from 'products/logs/frontend/components/LogsViewer/logsViewerLogic'
@@ -26,6 +26,18 @@ export interface AttributeCellProps {
width: number
/** The row's timestamp; lets the trace_id cell link with a time hint for the cold-load query. */
timestamp?: string
+ /**
+ * Overrides the horizontal-scroll sync key, which defaults to the attribute key. The Person and
+ * Session columns pass a per-column key, so rows resolving different attribute keys still scroll
+ * 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.
+ */
+ filterType?: PropertyFilterType
}
export const AttributeCell = memo(function AttributeCell({
@@ -33,9 +45,11 @@ export const AttributeCell = memo(function AttributeCell({
value,
width,
timestamp,
+ cellKey,
+ filterType,
}: AttributeCellProps): JSX.Element {
const { id, isAttributeColumn } = useValues(logsViewerLogic)
- const { configuredSessionIdKeys } = useValues(logsConfigLogic)
+ const { configuredDistinctIdKeys, configuredSessionIdKeys } = useValues(logsConfigLogic)
const { addFilter, toggleAttributeColumn } = useActions(logsViewerLogic)
const tracingDisabledReason = getAccessControlDisabledReason(
AccessControlResourceType.Tracing,
@@ -44,7 +58,7 @@ export const AttributeCell = memo(function AttributeCell({
const { scrollRef, handleScroll, startScrolling, stopScrolling } = useCellScroll({
id,
- cellKey: `attr:${attributeKey}`,
+ cellKey: cellKey ?? `attr:${attributeKey}`,
})
return (
@@ -52,12 +66,12 @@ export const AttributeCell = memo(function AttributeCell({
attributeKey={attributeKey}
value={value}
isColumn={isAttributeColumn(attributeKey)}
- onAddFilter={addFilter}
+ onAddFilter={(key, filterValue, operator) => addFilter(key, filterValue, operator, filterType)}
onToggleColumn={toggleAttributeColumn}
>
<div style={{ width, flexShrink: 0 }} className="relative flex items-center self-stretch group/attr pr-1">
<div ref={scrollRef} onScroll={handleScroll} className="flex-1 overflow-x-auto hide-scrollbar">
- {isDistinctIdKey(attributeKey) ? (
+ {isDistinctIdKey(attributeKey, configuredDistinctIdKeys) && value ? (
<span className="font-mono text-xs whitespace-nowrap pr-24" title={value}>
<PersonDisplay person={{ distinct_id: value }} noEllipsis inline />
</span>
diff --git a/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx b/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx
index 1cf23e8b0432..bdd4167de9c5 100644
--- a/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx
+++ b/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx
@@ -10,6 +10,7 @@ import { IconArrowDown, IconArrowUp } from 'lib/lemon-ui/icons'
import { cn } from 'lib/utils/css-classes'
import { LogMessage } from '~/queries/schema/schema-general'
+import { PropertyFilterType } from '~/types'
import {
LOGS_COLUMN_REGISTRY,
@@ -28,13 +29,21 @@ import {
MESSAGE_MIN_WIDTH,
MIN_ATTRIBUTE_COLUMN_WIDTH,
PATTERN_WIDTH,
+ PERSON_WIDTH,
RESIZER_HANDLE_WIDTH,
+ SESSION_WIDTH,
SEVERITY_WIDTH,
TIMESTAMP_WIDTH,
getMessageStyle,
} from 'products/logs/frontend/components/VirtualizedLogsList/layoutUtils'
import { VirtualizedTableColumn } from 'products/logs/frontend/components/VirtualizedLogsList/types'
+import {
+ DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEYS,
+ DEFAULT_LOGS_SESSION_ID_ATTRIBUTE_KEYS,
+ logsConfigLogic,
+} from 'products/logs/frontend/logsConfigLogic'
import { LogsOrderBy, ParsedLogMessage } from 'products/logs/frontend/types'
+import { getDistinctIdWithKey, getSessionIdWithKey } from 'products/logs/frontend/utils'
export const SEVERITY_BAR_COLORS: Record<LogMessage['severity_text'], string> = {
trace: 'bg-muted-alt',
@@ -112,6 +121,52 @@ function ControlsHeader({ dataSourceRef }: { dataSourceRef: RefObject<ParsedLogM
)
}
+type IdentityColumnType = Extract<LogsColumnType, 'person' | 'session'>
+
+const IDENTITY_FALLBACK_KEYS: Record<IdentityColumnType, string[]> = {
+ person: DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEYS,
+ session: DEFAULT_LOGS_SESSION_ID_ATTRIBUTE_KEYS,
+}
+
+/**
+ * Person and Session cells. Neither value has a fixed home on the row: it sits under whichever
+ * attribute key the team's logs settings name (falling back to the built-in conventions), so the
+ * key is resolved per row and handed to AttributeCell, which renders it with the same person link
+ * or recording button the matching attribute column shows.
+ */
+function IdentityCell({
+ log,
+ type,
+ width,
+}: {
+ log: ParsedLogMessage
+ type: IdentityColumnType
+ width: number
+}): JSX.Element {
+ const { configuredDistinctIdKeys, configuredSessionIdKeys } = useValues(logsConfigLogic)
+
+ const configuredKeys = type === 'person' ? configuredDistinctIdKeys : configuredSessionIdKeys
+ const resolve = type === 'person' ? getDistinctIdWithKey : getSessionIdWithKey
+ const match = resolve(log.attributes, log.resource_attributes, configuredKeys)
+
+ return (
+ <AttributeCell
+ // A row with no match still needs a key for the cell popover's filter actions: the first
+ // configured key, or the default the settings fall back to before logs_config resolves.
+ attributeKey={match?.key ?? configuredKeys?.[0] ?? IDENTITY_FALLBACK_KEYS[type][0]}
+ cellKey={`identity:${type}`}
+ value={match?.value ?? ''}
+ filterType={
+ match?.source === 'resource_attribute'
+ ? PropertyFilterType.LogResourceAttribute
+ : PropertyFilterType.LogAttribute
+ }
+ width={width}
+ timestamp={log.timestamp}
+ />
+ )
+}
+
function MessageColumnCell({
log,
wrapBody,
@@ -171,6 +226,8 @@ export interface ConfiguredColumnRendering {
const DEFAULT_COLUMN_WIDTHS: Partial<Record<LogsColumnType, number>> = {
timestamp: TIMESTAMP_WIDTH,
pattern: PATTERN_WIDTH,
+ person: PERSON_WIDTH,
+ session: SESSION_WIDTH,
}
/** Read a server-computed column value off the raw row by its canonical alias. */
@@ -305,6 +362,8 @@ export function createConfiguredColumn(params: {
const width = config.width ?? DEFAULT_COLUMN_WIDTHS[config.type] ?? DEFAULT_ATTRIBUTE_COLUMN_WIDTH
const totalWidth = width + RESIZER_HANDLE_WIDTH
+ const identityType: IdentityColumnType | null =
+ config.type === 'person' || config.type === 'session' ? config.type : null
const semanticKey = config.type === 'custom' ? (config.name ?? config.expression ?? '') : config.type
// Columns the server computes (custom, and built-ins like `pattern`) read their value off the
// aliased result; the rest read it straight off the row.
@@ -318,14 +377,18 @@ export function createConfiguredColumn(params: {
</span>
</div>
)
- : (log: ParsedLogMessage): JSX.Element => (
- <AttributeCell
- attributeKey={semanticKey}
- value={getBuiltInValue ? getBuiltInValue(log) : customColumnValue(log, alias)}
- width={totalWidth}
- timestamp={log.timestamp}
- />
- )
+ : identityType
+ ? (log: ParsedLogMessage): JSX.Element => (
+ <IdentityCell log={log} type={identityType} width={totalWidth} />
+ )
+ : (log: ParsedLogMessage): JSX.Element => (
+ <AttributeCell
+ attributeKey={semanticKey}
+ value={getBuiltInValue ? getBuiltInValue(log) : customColumnValue(log, alias)}
+ width={totalWidth}
+ timestamp={log.timestamp}
+ />
+ )
return {
key: `col:${config.id}`,
diff --git a/products/logs/frontend/components/VirtualizedLogsList/layoutUtils.ts b/products/logs/frontend/components/VirtualizedLogsList/layoutUtils.ts
index b7c0a416b379..e1cf354104f8 100644
--- a/products/logs/frontend/components/VirtualizedLogsList/layoutUtils.ts
+++ b/products/logs/frontend/components/VirtualizedLogsList/layoutUtils.ts
@@ -18,6 +18,10 @@ export const TIMESTAMP_WIDTH = 180
// A pattern is a whole message line with its variable parts masked, so it starts much wider
// than an attribute value.
export const PATTERN_WIDTH = 400
+// A person link shows a display name or a distinct id; a session cell shows a full session
+// UUID. Both start wider than a plain attribute value.
+export const PERSON_WIDTH = 200
+export const SESSION_WIDTH = 280
export const MESSAGE_MIN_WIDTH = 300
export const LOG_ROW_FAB_WIDTH = 150
export const ROW_GAP = 8
diff --git a/products/logs/frontend/generated/api.schemas.ts b/products/logs/frontend/generated/api.schemas.ts
index 7e70331e8c22..06ebd4c12de8 100644
--- a/products/logs/frontend/generated/api.schemas.ts
+++ b/products/logs/frontend/generated/api.schemas.ts
@@ -2459,6 +2459,8 @@ export interface _LogsValuesResponseApi {
* * `source` - source
* * `trace_id` - trace_id
* * `span_id` - span_id
+ * * `person` - person
+ * * `session` - session
* * `pattern` - pattern
* * `message` - message
* * `custom` - custom
@@ -2471,6 +2473,8 @@ export const LogsViewColumnTypeEnumApi = {
Source: 'source',
TraceId: 'trace_id',
SpanId: 'span_id',
+ Person: 'person',
+ Session: 'session',
Pattern: 'pattern',
Message: 'message',
Custom: 'custom',
@@ -2486,6 +2490,8 @@ export interface LogsViewColumnApi {
* * `source` - source
* * `trace_id` - trace_id
* * `span_id` - span_id
+ * * `person` - person
+ * * `session` - session
* * `pattern` - pattern
* * `message` - message
* * `custom` - custom */
diff --git a/products/logs/frontend/generated/api.zod.ts b/products/logs/frontend/generated/api.zod.ts
index d22570d40388..185545c6db3d 100644
--- a/products/logs/frontend/generated/api.zod.ts
+++ b/products/logs/frontend/generated/api.zod.ts
@@ -1967,12 +1967,23 @@ export const LogsViewsCreateBody = /* @__PURE__ */ zod.object({
'Client-generated stable identity for list operations (React keys, reorder). Never interpreted by the server.'
),
type: zod
- .enum(['timestamp', 'level', 'source', 'trace_id', 'span_id', 'pattern', 'message', 'custom'])
+ .enum([
+ 'timestamp',
+ 'level',
+ 'source',
+ 'trace_id',
+ 'span_id',
+ 'person',
+ 'session',
+ 'pattern',
+ 'message',
+ 'custom',
+ ])
.describe(
- '\* `timestamp` - timestamp\n\* `level` - level\n\* `source` - source\n\* `trace_id` - trace_id\n\* `span_id` - span_id\n\* `pattern` - pattern\n\* `message` - message\n\* `custom` - custom'
+ '\* `timestamp` - timestamp\n\* `level` - level\n\* `source` - source\n\* `trace_id` - trace_id\n\* `span_id` - span_id\n\* `person` - person\n\* `session` - session\n\* `pattern` - pattern\n\* `message` - message\n\* `custom` - custom'
)
.describe(
- 'Column type. Most built-in types resolve client-side from log row fields; `pattern` and `custom` columns are computed server-side, the latter from `expression`.\n\n\* `timestamp` - timestamp\n\* `level` - level\n\* `source` - source\n\* `trace_id` - trace_id\n\* `span_id` - span_id\n\* `pattern` - pattern\n\* `message` - message\n\* `custom` - custom'
+ 'Column type. Most built-in types resolve client-side from log row fields; `pattern` and `custom` columns are computed server-side, the latter from `expression`.\n\n\* `timestamp` - timestamp\n\* `level` - level\n\* `source` - source\n\* `trace_id` - trace_id\n\* `span_id` - span_id\n\* `person` - person\n\* `session` - session\n\* `pattern` - pattern\n\* `message` - message\n\* `custom` - custom'
),
name: zod
.string()
@@ -2024,12 +2035,23 @@ export const LogsViewsUpdateBody = /* @__PURE__ */ zod.object({
'Client-generated stable identity for list operations (React keys, reorder). Never interpreted by the server.'
),
type: zod
- .enum(['timestamp', 'level', 'source', 'trace_id', 'span_id', 'pattern', 'message', 'custom'])
+ .enum([
+ 'timestamp',
+ 'level',
+ 'source',
+ 'trace_id',
+ 'span_id',
+ 'person',
+ 'session',
+ 'pattern',
+ 'message',
+ 'custom',
+ ])
.describe(
- '\* `timestamp` - timestamp\n\* `level` - level\n\* `source` - source\n\* `trace_id` - trace_id\n\* `span_id` - span_id\n\* `pattern` - pattern\n\* `message` - message\n\* `custom` - custom'
+ '\* `timestamp` - timestamp\n\* `level` - level\n\* `source` - source\n\* `trace_id` - trace_id\n\* `span_id` - span_id\n\* `person` - person\n\* `session` - session\n\* `pattern` - pattern\n\* `message` - message\n\* `custom` - custom'
)
.describe(
- 'Column type. Most built-in types resolve client-side from log row fields; `pattern` and `custom` columns are computed server-side, the latter from `expression`.\n\n\* `timestamp` - timestamp\n\* `level` - level\n\* `source` - source\n\* `trace_id` - trace_id\n\* `span_id` - span_id\n\* `pattern` - pattern\n\* `message` - message\n\* `custom` - custom'
+ 'Column type. Most built-in types resolve client-side from log row fields; `pattern` and `custom` columns are computed server-side, the latter from `expression`.\n\n\* `timestamp` - timestamp\n\* `level` - level\n\* `source` - source\n\* `trace_id` - trace_id\n\* `span_id` - span_id\n\* `person` - person\n\* `session` - session\n\* `pattern` - pattern\n\* `message` - message\n\* `custom` - custom'
),
name: zod
.string()
@@ -2081,12 +2103,23 @@ export const LogsViewsPartialUpdateBody = /* @__PURE__ */ zod.object({
'Client-generated stable identity for list operations (React keys, reorder). Never interpreted by the server.'
),
type: zod
- .enum(['timestamp', 'level', 'source', 'trace_id', 'span_id', 'pattern', 'message', 'custom'])
+ .enum([
+ 'timestamp',
+ 'level',
+ 'source',
+ 'trace_id',
+ 'span_id',
+ 'person',
+ 'session',
+ 'pattern',
+ 'message',
+ 'custom',
+ ])
.describe(
- '\* `timestamp` - timestamp\n\* `level` - level\n\* `source` - source\n\* `trace_id` - trace_id\n\* `span_id` - span_id\n\* `pattern` - pattern\n\* `message` - message\n\* `custom` - custom'
+ '\* `timestamp` - timestamp\n\* `level` - level\n\* `source` - source\n\* `trace_id` - trace_id\n\* `span_id` - span_id\n\* `person` - person\n\* `session` - session\n\* `pattern` - pattern\n\* `message` - message\n\* `custom` - custom'
)
.describe(
- 'Column type. Most built-in types resolve client-side from log row fields; `pattern` and `custom` columns are computed server-side, the latter from `expression`.\n\n\* `timestamp` - timestamp\n\* `level` - level\n\* `source` - source\n\* `trace_id` - trace_id\n\* `span_id` - span_id\n\* `pattern` - pattern\n\* `message` - message\n\* `custom` - custom'
+ 'Column type. Most built-in types resolve client-side from log row fields; `pattern` and `custom` columns are computed server-side, the latter from `expression`.\n\n\* `timestamp` - timestamp\n\* `level` - level\n\* `source` - source\n\* `trace_id` - trace_id\n\* `span_id` - span_id\n\* `person` - person\n\* `session` - session\n\* `pattern` - pattern\n\* `message` - message\n\* `custom` - custom'
),
name: zod
.string()
diff --git a/products/logs/frontend/utils.test.ts b/products/logs/frontend/utils.test.ts
index 079d9163e815..d0ed05e1719d 100644
--- a/products/logs/frontend/utils.test.ts
+++ b/products/logs/frontend/utils.test.ts
@@ -5,6 +5,7 @@ import { DEFAULT_LOGS_SESSION_ID_ATTRIBUTE_KEYS } from 'products/logs/frontend/l
import {
buildLogsSessionFilters,
formatFilterGroupValues,
+ getDistinctIdWithKey,
getFiltersSummaryLines,
getSessionIdFromLogAttributes,
isDistinctIdKey,
@@ -57,6 +58,31 @@ describe('logs utils', () => {
})
})
+ describe('getDistinctIdWithKey', () => {
+ it('prefers a configured key over a convention, and attributes over resource_attributes', () => {
+ expect(
+ getDistinctIdWithKey({ distinct_id: 'convention', 'user.id': 'configured' }, undefined, ['user.id'])
+ ).toEqual({ key: 'user.id', value: 'configured', source: 'attribute' })
+ expect(getDistinctIdWithKey({}, { 'user.id': 'configured' }, ['user.id'])).toEqual({
+ key: 'user.id',
+ value: 'configured',
+ source: 'resource_attribute',
+ })
+ })
+
+ it('falls back to the built-in conventions when no configured key carries a value', () => {
+ expect(getDistinctIdWithKey({ posthogDistinctId: 'abc' }, undefined, ['user.id'])).toEqual({
+ key: 'posthogDistinctId',
+ value: 'abc',
+ source: 'attribute',
+ })
+ })
+
+ it('returns null when the log carries no distinct id', () => {
+ expect(getDistinctIdWithKey({ unrelated: 'x' }, { 'service.name': 'api' }, ['user.id'])).toBeNull()
+ })
+ })
+
describe.each([
// Exact matches
['session.id', true],
diff --git a/products/logs/frontend/utils.tsx b/products/logs/frontend/utils.tsx
index d394a5d3f789..8f77675fbf41 100644
--- a/products/logs/frontend/utils.tsx
+++ b/products/logs/frontend/utils.tsx
@@ -162,17 +162,18 @@ export function isSessionIdKey(key: string, configuredKeys?: string[]): boolean
return (configuredKeys ?? []).includes(key) || matchesKey(key, SESSION_ID_KEYS)
}
-export interface SessionIdMatch {
+export interface LogIdentityMatch {
key: string
value: string
source: 'attribute' | 'resource_attribute'
}
-export function getSessionIdWithKey(
+function getIdentityMatch(
attributes: Record<string, unknown> | undefined,
resourceAttributes: Record<string, unknown> | undefined,
- configuredKeys?: string[]
-): SessionIdMatch | null {
+ configuredKeys: string[] | undefined,
+ isConventionKey: (key: string) => boolean
+): LogIdentityMatch | null {
// Configured keys win over the built-in conventions, in list order: for each key,
// attributes are checked before resource_attributes, and the first value found wins.
for (const key of configuredKeys ?? []) {
@@ -185,21 +186,38 @@ export function getSessionIdWithKey(
return { key, value: String(resourceAttributeValue), source: 'resource_attribute' }
}
}
- // Built-in convention fallback only — the configured-key pass already ran above,
- // so isSessionIdKey is deliberately called without configuredKeys here.
+ // Built-in convention fallback only — the configured-key pass already ran above, so
+ // isConventionKey is deliberately called without the configured keys here.
for (const [key, value] of Object.entries(attributes || {})) {
- if (isSessionIdKey(key) && value) {
+ if (isConventionKey(key) && value) {
return { key, value: String(value), source: 'attribute' }
}
}
for (const [key, value] of Object.entries(resourceAttributes || {})) {
- if (isSessionIdKey(key) && value) {
+ if (isConventionKey(key) && value) {
return { key, value: String(value), source: 'resource_attribute' }
}
}
return null
}
+export function getSessionIdWithKey(
+ attributes: Record<string, unknown> | undefined,
+ resourceAttributes: Record<string, unknown> | undefined,
+ configuredKeys?: string[]
+): LogIdentityMatch | null {
+ return getIdentityMatch(attributes, resourceAttributes, configuredKeys, (key) => isSessionIdKey(key))
+}
+
+/** The distinct-id counterpart of `getSessionIdWithKey`, resolved the same way. */
+export function getDistinctIdWithKey(
+ attributes: Record<string, unknown> | undefined,
+ resourceAttributes: Record<string, unknown> | undefined,
+ configuredKeys?: string[]
+): LogIdentityMatch | null {
+ return getIdentityMatch(attributes, resourceAttributes, configuredKeys, (key) => isDistinctIdKey(key))
+}
+
export function getSessionIdFromLogAttributes(
attributes: Record<string, unknown> | undefined,
resourceAttributes: Record<string, unknown> | undefined,
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 86a8b8e249fd..b25b37d1c524 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -49297,6 +49297,8 @@ export namespace Schemas {
* * `source` - source
* * `trace_id` - trace_id
* * `span_id` - span_id
+ * * `person` - person
+ * * `session` - session
* * `pattern` - pattern
* * `message` - message
* * `custom` - custom
@@ -49310,6 +49312,8 @@ export namespace Schemas {
Source: 'source',
TraceId: 'trace_id',
SpanId: 'span_id',
+ Person: 'person',
+ Session: 'session',
Pattern: 'pattern',
Message: 'message',
Custom: 'custom',
@@ -49325,6 +49329,8 @@ export namespace Schemas {
* * `source` - source
* * `trace_id` - trace_id
* * `span_id` - span_id
+ * * `person` - person
+ * * `session` - session
* * `pattern` - pattern
* * `message` - message
* * `custom` - custom */