: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
chore(web-analytics): tag session property value queries (#104745)
Javier Bahamondesce90aaef9f59
diff --git a/posthog/api/session.py b/posthog/api/session.pyindex ac8236552541..f08c6dadf7fe 100644--- a/posthog/api/session.py+++ b/posthog/api/session.py@@ -4,7 +4,7 @@ from opentelemetry import tracefrom rest_framework import request, response, viewsetsfrom rest_framework.exceptions import ValidationError-from posthog.schema import SessionTableVersion+from posthog.schema import ProductKey, SessionTableVersionfrom posthog.hogql.database.schema.sessions_v1 import (get_lazy_session_table_properties_v1,@@ -23,6 +23,7 @@ from posthog.hogql.modifiers import create_default_modifiers_for_teamfrom posthog.api.property_value_metrics import PROPERTY_VALUES_DURATIONfrom posthog.api.routing import TeamAndOrgViewSetMixinfrom posthog.api.utils import action+from posthog.clickhouse.query_tagging import Feature, tag_queriesfrom posthog.errors import ExposedCHQueryErrorfrom posthog.rate_limit import ClickHouseBurstRateThrottle, ClickHouseSustainedRateThrottlefrom posthog.utils import convert_property_value, flatten@@ -56,6 +57,11 @@ class SessionViewSet(span.set_attribute("property_key", key)span.set_attribute("has_search_term", search_term is not None)+ # `/sessions/values` is hit from every taxonomic property-value picker that offers+ # session properties, so tag by the endpoint name rather than a scene, the same way+ # `/events/values` does.+ tag_queries(product=ProductKey.WEB_ANALYTICS, feature=Feature.SESSIONS_VALUES_API)+modifiers = create_default_modifiers_for_team(team)version = modifiers.sessionTableVersiondiff --git a/posthog/api/test/test_session.py b/posthog/api/test/test_session.pyindex 4ea2a044ee52..68ea53776497 100644--- a/posthog/api/test/test_session.py+++ b/posthog/api/test/test_session.py@@ -1,6 +1,8 @@+import jsonimport uuid+from collections.abc import Callable-from posthog.test.base import APIBaseTest+from posthog.test.base import APIBaseTest, patch_clickhouse_client_executefrom unittest.mock import patchfrom parameterized import parameterized@@ -187,9 +189,19 @@ class TestSessionsAPI(APIBaseTest):assert actual_values == expected_values@parameterized.expand([("v2",), ("v3",)])- def test_list_session_property_values(self, version):+ def test_list_session_property_values(self, version: str) -> None:_set_session_table_version(self.team, version)- response = self.client.get(f"/api/projects/{self.team.pk}/sessions/values/?key=$entry_utm_source")+ query_tags: list[tuple[str | None, str | None]] = []++ def capture_tags(execute: Callable[..., object], query: str, *args: object, **kwargs: object) -> object:+ settings = kwargs["settings"]+ assert isinstance(settings, dict)+ tags = json.loads(settings["log_comment"])+ query_tags.append((tags.get("product"), tags.get("feature")))+ return execute(query, *args, **kwargs)++ with patch_clickhouse_client_execute(capture_tags):+ response = self.client.get(f"/api/projects/{self.team.pk}/sessions/values/?key=$entry_utm_source")self.assertEqual(response.status_code, status.HTTP_200_OK)actual_values = {entry["name"] for entry in response.json()["results"]}expected_values = {@@ -197,6 +209,8 @@ class TestSessionsAPI(APIBaseTest):"youtube",}assert actual_values == expected_values+ assert query_tags+ assert set(query_tags) == {("web_analytics", "sessions_values_api")}@parameterized.expand([("v2",), ("v3",)])def test_search_session_property_values(self, version):diff --git a/posthog/clickhouse/query_tagging.py b/posthog/clickhouse/query_tagging.pyindex 1b4529acac62..f0ee4234bb9e 100644--- a/posthog/clickhouse/query_tagging.py+++ b/posthog/clickhouse/query_tagging.py@@ -127,6 +127,7 @@ class Feature(StrEnum):# is hit from every taxonomic property-value picker across the app, so attribution by scene# would be misleading; tagging by endpoint name keeps the signal honest.EVENTS_VALUES_API = "events_values_api"+ SESSIONS_VALUES_API = "sessions_values_api"USAGE_REPORT = "usage_report"DATA_FRESHNESS = "data_freshness" # "when did this project last receive data" probesBILLING_ETL = "billing_etl"