: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
fix(logs): polish session id attribute keys setting (#70698)
Jon McCallum8611bae24d2a
diff --git a/frontend/src/scenes/settings/environment/LogsSessionIdAttributeKeys.tsx b/frontend/src/scenes/settings/environment/LogsSessionIdAttributeKeys.tsxindex d168f728b383..c9bf0cd9d243 100644--- a/frontend/src/scenes/settings/environment/LogsSessionIdAttributeKeys.tsx+++ b/frontend/src/scenes/settings/environment/LogsSessionIdAttributeKeys.tsx@@ -41,10 +41,10 @@ export function LogsSessionIdAttributeKeys(): JSX.Element {mode="multiple"allowCustomValuesvalue={value}- onChange={(values: string[]) => setValue(values || [])}+ onChange={setValue}placeholder={DEFAULT_LOGS_SESSION_ID_ATTRIBUTE_KEYS.join(', ')}loading={logsConfigLoading}- disabled={!!restrictedReason}+ disabled={logsConfigLoading || !!restrictedReason}data-attr="logs-session-id-attribute-keys-select"className="max-w-md"/>diff --git a/posthog/api/team.py b/posthog/api/team.pyindex c90ddb3532d8..5554c319c10f 100644--- a/posthog/api/team.py+++ b/posthog/api/team.py@@ -115,7 +115,9 @@ class TeamLogsConfigSerializer(serializers.ModelSerializer):),)logs_session_id_attribute_keys = serializers.ListField(- child=serializers.CharField(max_length=200, allow_blank=False),+ # trim_whitespace is the DRF default, but the uniqueness validator below+ # depends on it — spell it out so it can't drift silently.+ child=serializers.CharField(max_length=200, allow_blank=False, trim_whitespace=True),allow_empty=False,max_length=10,help_text=(@@ -132,12 +134,11 @@ class TeamLogsConfigSerializer(serializers.ModelSerializer):fields = ["logs_distinct_id_attribute_key", "logs_session_id_attribute_keys"]def validate_logs_session_id_attribute_keys(self, value: list[str]) -> list[str]:- keys = [key.strip() for key in value]- if any(not key for key in keys):- raise serializers.ValidationError("Attribute keys cannot be blank.")- if len(set(keys)) != len(keys):+ # The child CharField already trims whitespace and rejects blanks; only+ # cross-item uniqueness needs checking here.+ if len(set(value)) != len(value):raise serializers.ValidationError("Attribute keys must be unique.")- return keys+ return valuedef handle_logs_config(request: request.Request, team: Team) -> response.Response:diff --git a/posthog/api/test/test_team_logs_config.py b/posthog/api/test/test_team_logs_config.pyindex f3da6eb5ea07..317bab633163 100644--- a/posthog/api/test/test_team_logs_config.py+++ b/posthog/api/test/test_team_logs_config.py@@ -9,15 +9,19 @@ from posthog.api.team import TeamLogsConfigSerializerfrom posthog.models import OrganizationMembership, Teamfrom posthog.models.team.extensions import get_or_create_team_extension-from products.logs.backend.models import TeamLogsConfig+from products.logs.backend.models import (+ DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEY,+ DEFAULT_LOGS_SESSION_ID_ATTRIBUTE_KEYS,+ TeamLogsConfig,+)# Both routes resolve to the same handler — /api/projects/ is canonical, /api/environments/# remains as the back-compat alias. See `handle_logs_config` in posthog/api/team.py.URL_PREFIXES = [("projects", "api/projects"), ("environments", "api/environments")]DEFAULT_CONFIG = {- "logs_distinct_id_attribute_key": "posthogDistinctId",- "logs_session_id_attribute_keys": ["posthogSessionId"],+ "logs_distinct_id_attribute_key": DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEY,+ "logs_session_id_attribute_keys": DEFAULT_LOGS_SESSION_ID_ATTRIBUTE_KEYS,}