: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(hogql): read $sent_at and session duration from permanent properties (#111330)
Rory Shanksc3bb775e1d7d
diff --git a/posthog/clickhouse/events_json.py b/posthog/clickhouse/events_json.pyindex 10137ac29da9..8d0d65f5a60c 100644--- a/posthog/clickhouse/events_json.py+++ b/posthog/clickhouse/events_json.py@@ -30,12 +30,13 @@ TEMPORARY_EVENT_PROPERTY_ROOTS = frozenset("$session_recording_network_payload_capture","$session_recording_canvas_recording","$replay_script_config",- "$sent_at","$lib_rate_limit_remaining_tokens","$lib_custom_api_host",})TEMPORARY_EVENT_PROPERTY_ROOT_PREFIX = "$sdk_debug_"+# Customers read it over windows longer than the temporary retention, so it stays permanent.+PERMANENT_SDK_DEBUG_PROPERTIES = frozenset({"$sdk_debug_current_session_duration"})def is_temporary_event_property(key: str) -> bool:@@ -43,6 +44,8 @@ def is_temporary_event_property(key: str) -> bool:A dotted key such as `$set.foo` is one flat key, so it matches only the prefix rule, never a root name."""+ if key in PERMANENT_SDK_DEBUG_PROPERTIES:+ return Falsereturn key in TEMPORARY_EVENT_PROPERTY_ROOTS or key.startswith(TEMPORARY_EVENT_PROPERTY_ROOT_PREFIX)diff --git a/posthog/clickhouse/test/test_events_json.py b/posthog/clickhouse/test/test_events_json.pynew file mode 100644index 000000000000..cd11152114df--- /dev/null+++ b/posthog/clickhouse/test/test_events_json.py@@ -0,0 +1,20 @@+import pytest++from posthog.clickhouse.events_json import is_temporary_event_property+++ "key, expected",+ [+ ("$set", True),+ ("$lib_custom_api_host", True),+ ("$sdk_debug_replay_flushed_size", True),+ ("$sdk_debug_current_session_duration.value", True),+ ("$set.foo", False),+ ("$sent_at", False),+ ("$sdk_debug_current_session_duration", False),+ ("custom", False),+ ],+)+def test_is_temporary_event_property(key: str, expected: bool) -> None:+ assert is_temporary_event_property(key) is expecteddiff --git a/posthog/hogql/transforms/clickhouse_property_resolution.py b/posthog/hogql/transforms/clickhouse_property_resolution.pyindex 5ad9fd1262ee..63c72ada4882 100644--- a/posthog/hogql/transforms/clickhouse_property_resolution.py+++ b/posthog/hogql/transforms/clickhouse_property_resolution.py@@ -60,6 +60,7 @@ from posthog.hogql.visitor import CloningVisitor, clone_exprfrom posthog.clickhouse.events_json import (DISTRIBUTED_EVENTS_JSON_TABLE,EVENTS_PROPERTIES_JSON_SUBCOLUMNS,+ PERMANENT_SDK_DEBUG_PROPERTIES,TEMPORARY_EVENT_PROPERTY_ROOT_PREFIX,TEMPORARY_EVENT_PROPERTY_ROOTS,TEMPORARY_PROPERTIES_COLUMN,@@ -678,7 +679,24 @@ def _names_temporary_event_property(key: ast.Expr) -> ast.Expr:"or",[_call("has", [ast.Array(exprs=[_const(root) for root in sorted(TEMPORARY_EVENT_PROPERTY_ROOTS)]), name]),- _call("startsWith", [clone_expr(name), _const(TEMPORARY_EVENT_PROPERTY_ROOT_PREFIX)]),+ _call(+ "and",+ [+ _call("startsWith", [clone_expr(name), _const(TEMPORARY_EVENT_PROPERTY_ROOT_PREFIX)]),+ _call(+ "not",+ [+ _call(+ "has",+ [+ ast.Array(exprs=[_const(key) for key in sorted(PERMANENT_SDK_DEBUG_PROPERTIES)]),+ clone_expr(name),+ ],+ )+ ],+ ),+ ],+ ),],)