: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
feat(logs): admin-gated settings UI for the person pivot attribute (#61301)
Daniel Visca6407322eca7f
diff --git a/frontend/src/scenes/persons/PersonLogsTab.tsx b/frontend/src/scenes/persons/PersonLogsTab.tsxindex dfab6b64de5f..a75aeb6a844e 100644--- a/frontend/src/scenes/persons/PersonLogsTab.tsx+++ b/frontend/src/scenes/persons/PersonLogsTab.tsx@@ -1,6 +1,11 @@import { useValues } from 'kea'import { useMemo } from 'react'+import { IconGear } from '@posthog/icons'+import { LemonButton } from '@posthog/lemon-ui'++import { urls } from 'scenes/urls'+import { FilterLogicalOperator, LogPropertyFilter, PersonType, PropertyFilterType, PropertyOperator } from '~/types'import { LogsViewer } from 'products/logs/frontend/components/LogsViewer/LogsViewer'@@ -33,14 +38,22 @@ export function PersonLogsTab({ person }: { person: PersonType }): JSX.Element {return (<div className="flex flex-col h-[calc(100vh-16rem)] min-h-[25rem]">- <p className="text-muted text-xs mb-2">- Scoped to this person via the <code>{distinctIdAttributeKey}</code> log attribute.- {isCustomizedKey && (- <>- {' '}- Customised from default <code>{DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEY}</code>.- </>- )}+ <p className="text-muted text-xs mb-2 flex items-center gap-1 flex-wrap">+ <span>+ Scoped to this person via the <code>{distinctIdAttributeKey}</code> log attribute.+ {isCustomizedKey && (+ <>+ {' '}+ Customised from default <code>{DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEY}</code>.+ </>+ )}+ </span>+ <LemonButton+ size="xsmall"+ icon={<IconGear />}+ tooltip="Change the log attribute used to link logs to a person"+ to={urls.settings('environment-logs', 'logs-distinct-id-attribute-key')}+ /></p><LogsViewerid={`person-${person.uuid ?? person.id}`}diff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsxindex 2e10e327a735..9e5891e82f76 100644--- a/frontend/src/scenes/settings/SettingsMap.tsx+++ b/frontend/src/scenes/settings/SettingsMap.tsx@@ -95,6 +95,7 @@ import {LogsPiiScrubSettings,LogsRetentionSettings,} from './environment/LogsCaptureSettings'+import { LogsDistinctIdAttributeKey } from './environment/LogsDistinctIdAttributeKey'import { ManagedReverseProxy } from './environment/ManagedReverseProxy'import { MarketingAnalyticsSettingsWrapper } from './environment/MarketingAnalyticsSettingsWrapper'import MCPServerSettings from './environment/MCPServerSettings'@@ -715,6 +716,23 @@ export const SETTINGS_MAP: SettingSection[] = [flag: 'LOGS_SETTINGS_PII_SCRUB',keywords: ['pii', 'privacy', 'gdpr', 'redact', 'mask', 'scrub', 'sensitive'],},+ {+ id: 'logs-distinct-id-attribute-key',+ title: 'Link to person',+ description: (+ <>+ The log attribute PostHog reads to identify which person a log belongs to. Matched against the+ person's distinct IDs to surface logs on their profile. Defaults to{' '}+ <code>posthogDistinctId</code> — the key the JavaScript and React Native SDKs auto-attach.+ Override only if your backend pipeline emits the person identifier under a different key.+ </>+ ),+ searchDescription:+ "The log attribute PostHog reads to identify which person a log belongs to. Matched against the person's distinct IDs to surface logs on their profile. Defaults to posthogDistinctId — the key the JavaScript and React Native SDKs auto-attach. Override only if your backend pipeline emits the person identifier under a different key.",+ component: <LogsDistinctIdAttributeKey />,+ flag: 'LOGS_SETTINGS',+ keywords: ['log', 'person', 'distinct', 'attribute', 'pivot', 'profile', 'link'],+ },{id: 'logs-retention',title: 'Retention',diff --git a/frontend/src/scenes/settings/environment/LogsDistinctIdAttributeKey.tsx b/frontend/src/scenes/settings/environment/LogsDistinctIdAttributeKey.tsxnew file mode 100644index 000000000000..cd716d365921--- /dev/null+++ b/frontend/src/scenes/settings/environment/LogsDistinctIdAttributeKey.tsx@@ -0,0 +1,59 @@+import { useActions, useValues } from 'kea'+import { useEffect, useState } from 'react'++import { LemonButton, LemonInput } from '@posthog/lemon-ui'++import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'+import { TeamMembershipLevel } from 'lib/constants'+import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'++import { DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEY, logsConfigLogic } from 'products/logs/frontend/logsConfigLogic'++export function LogsDistinctIdAttributeKey(): JSX.Element {+ const { logsConfig, logsConfigLoading } = useValues(logsConfigLogic)+ const { updateLogsConfig } = useActions(logsConfigLogic)+ const restrictedReason = useRestrictedArea({+ scope: RestrictionScope.Project,+ minimumAccessLevel: TeamMembershipLevel.Admin,+ })++ const [value, setValue] = useState<string>('')++ useEffect(() => {+ if (logsConfig) {+ setValue(logsConfig.logs_distinct_id_attribute_key)+ }+ }, [logsConfig])++ if (!logsConfig && logsConfigLoading) {+ return <LemonSkeleton className="w-1/2 h-4" />+ }++ const trimmed = value.trim()+ const isDirty = trimmed !== (logsConfig?.logs_distinct_id_attribute_key ?? '')+ const isEmpty = trimmed.length === 0++ return (+ <div className="deprecated-space-y-4">+ <LemonInput+ value={value}+ onChange={setValue}+ placeholder={DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEY}+ maxLength={200}+ disabledReason={restrictedReason}+ className="max-w-md"+ />+ <LemonButton+ type="primary"+ onClick={() => updateLogsConfig({ logs_distinct_id_attribute_key: trimmed })}+ disabledReason={+ restrictedReason ||+ (isEmpty ? 'Attribute key is required' : !isDirty ? 'No changes to save' : undefined)+ }+ loading={logsConfigLoading}+ >+ Save+ </LemonButton>+ </div>+ )+}diff --git a/frontend/src/scenes/settings/types.ts b/frontend/src/scenes/settings/types.tsindex c100b21baf15..659546d945f9 100644--- a/frontend/src/scenes/settings/types.ts+++ b/frontend/src/scenes/settings/types.ts@@ -171,6 +171,7 @@ export type SettingId =| 'js-snippet-version'| 'logs'| 'logs-alerting'+ | 'logs-distinct-id-attribute-key'| 'logs-drop-rules'| 'logs-json-parse'| 'logs-pii-scrub'diff --git a/products/logs/frontend/logsConfigLogic.ts b/products/logs/frontend/logsConfigLogic.tsindex 9929060fa4a0..fa1a8f098a6e 100644--- a/products/logs/frontend/logsConfigLogic.ts+++ b/products/logs/frontend/logsConfigLogic.ts@@ -27,6 +27,10 @@ export const logsConfigLogic = kea<logsConfigLogicType>([// nosemgrep: prefer-codegen-apireturn await api.get(`api/projects/${values.currentTeamId}/logs_config/`)},+ updateLogsConfig: async (patch: Partial<LogsConfig>): Promise<LogsConfig> => {+ // nosemgrep: prefer-codegen-api+ return await api.update(`api/projects/${values.currentTeamId}/logs_config/`, patch)+ },},],})),