: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 background queries with query_type (#115655)
Jordan Mryyan303a96fe894b
diff --git a/posthog/temporal/health_checks/activities.py b/posthog/temporal/health_checks/activities.pyindex 918a07b8247a..edec3e3c12ea 100644--- a/posthog/temporal/health_checks/activities.py+++ b/posthog/temporal/health_checks/activities.py@@ -92,6 +92,7 @@ def _run_health_check_batch_sync(product=get_product(kind),feature=Feature.HEALTH_CHECK,name=kind,+ query_type=f"health_check_{kind}",)detect_fn = get_detect_fn(kind)diff --git a/products/web_analytics/dags/cache_warming.py b/products/web_analytics/dags/cache_warming.pyindex 2e2b0ff7389f..c810afad4994 100644--- a/products/web_analytics/dags/cache_warming.py+++ b/products/web_analytics/dags/cache_warming.py@@ -27,7 +27,7 @@ from posthog.hogql.constants import LimitContextfrom posthog.clickhouse.client import sync_executefrom posthog.clickhouse.client.connection import Workload-from posthog.clickhouse.query_tagging import Feature, Product, reset_query_tags, tag_queries+from posthog.clickhouse.query_tagging import Feature, Product, reset_query_tags, tag_queries, tags_contextfrom posthog.dags.common import JobOwnersfrom posthog.event_usage import EventSourcefrom posthog.exceptions import ClickHouseAtCapacity@@ -889,22 +889,27 @@ def publish_volume_floor_op(context: dagster.OpExecutionContext) -> bool:# the candidates it needs: existing members stay until they fall below# the exit floor instead of flapping around the entry threshold.exit_floor = max(1, floor // 2)- tag_queries(feature=Feature.CACHE_WARMUP, trigger="webAnalyticsQueryWarming", product=Product.WEB_ANALYTICS)- rows = sync_execute(- """- SELECT team_id, count() AS ev7d- FROM events- WHERE timestamp > now() - INTERVAL 7 DAY AND timestamp < now()- GROUP BY team_id- HAVING ev7d >= %(exit_floor)s- """,- {"exit_floor": exit_floor},- workload=Workload.OFFLINE,- # Bound the fleet scan like the shape-selection query: a marks-only- # count still reads the timestamp column across every team, so cap it- # rather than let a plan regression drain offline capacity to timeout.- settings={"max_bytes_to_read": _SELECTION_MAX_BYTES_TO_READ, "max_execution_time": 300},- )+ with tags_context(+ feature=Feature.CACHE_WARMUP,+ trigger="webAnalyticsQueryWarming",+ product=Product.WEB_ANALYTICS,+ query_type="web_cache_warming_volume_floor",+ ):+ rows = sync_execute(+ """+ SELECT team_id, count() AS ev7d+ FROM events+ WHERE timestamp > now() - INTERVAL 7 DAY AND timestamp < now()+ GROUP BY team_id+ HAVING ev7d >= %(exit_floor)s+ """,+ {"exit_floor": exit_floor},+ workload=Workload.OFFLINE,+ # Bound the fleet scan like the shape-selection query: a marks-only+ # count still reads the timestamp column across every team, so cap it+ # rather than let a plan regression drain offline capacity to timeout.+ settings={"max_bytes_to_read": _SELECTION_MAX_BYTES_TO_READ, "max_execution_time": 300},+ )above_floor = [int(r[0]) for r in rows if int(r[1]) >= floor]above_exit_floor = [int(r[0]) for r in rows]if not above_floor:diff --git a/products/web_analytics/dags/web_preaggregated.py b/products/web_analytics/dags/web_preaggregated.pyindex caa6260c0f78..1dfe0dd3e0d5 100644--- a/products/web_analytics/dags/web_preaggregated.py+++ b/products/web_analytics/dags/web_preaggregated.py@@ -48,7 +48,11 @@ REPLACE_TEMPLATES_BY_STAGING_TABLE_NAME = {def count_selected_teams() -> int:- with tags_context(product=ProductKey.WEB_ANALYTICS, feature=Feature.PREAGGREGATION):+ with tags_context(+ product=ProductKey.WEB_ANALYTICS,+ feature=Feature.PREAGGREGATION,+ query_type="web_pre_aggregated_selected_teams_count",+ ):rows = sync_execute(f"SELECT count() FROM ({WEB_PRE_AGGREGATED_SELECTED_TEAMS_SQL()})")return rows[0][0]@@ -99,7 +103,11 @@ def pre_aggregate_web_analytics_data(context.log.info(f"Populating staging table with hourly data from {date_start} to {date_end}")context.log.info(f"Processing team_ids: {team_ids or 'all teams in the team selection table'}")context.log.info(insert_query)- with tags_context(product=ProductKey.WEB_ANALYTICS, feature=Feature.PREAGGREGATION):+ with tags_context(+ product=ProductKey.WEB_ANALYTICS,+ feature=Feature.PREAGGREGATION,+ query_type=f"{staging_table_name}_insert",+ ):sync_execute(insert_query)# 3. Sync replicas before partition swapping to ensure consistency