Skip to content

: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.

feat(alerts): tag alert query runs with interval and config type (#68647)

Christiaan Hendriksenee0f9d49df48
diff --git a/posthog/clickhouse/query_tagging.py b/posthog/clickhouse/query_tagging.py
index 68b6c9d32f54..4b8638d47290 100644
--- a/posthog/clickhouse/query_tagging.py
+++ b/posthog/clickhouse/query_tagging.py
@@ -406,6 +406,11 @@ class QueryTags(BaseModel):
scene: Optional[str] = None
alert_config_id: Optional[uuid.UUID] = None
+ # Cadence and query shape of the alert that triggered this run, tagged at evaluation
+ # so query_log cost can be grouped by frequency (real_time / every_15_minutes / ...)
+ # and by config type (TrendsAlertConfig vs HogQLAlertConfig) without joining to Postgres.
+ alert_calculation_interval: Optional[str] = None
+ alert_config_type: Optional[str] = None
batch_export_id: Optional[uuid.UUID] = None
cache_key: Optional[str] = None
celery_task_id: Optional[uuid.UUID] = None
diff --git a/posthog/temporal/alerts/activities.py b/posthog/temporal/alerts/activities.py
index 160a67ebfc78..87f95134e57f 100644
--- a/posthog/temporal/alerts/activities.py
+++ b/posthog/temporal/alerts/activities.py
@@ -219,7 +219,15 @@ async def evaluate_alert(inputs: EvaluateAlertActivityInputs) -> EvaluateAlertRe
)
# CH workload management keys off these tags to isolate alert queries from other tenants.
- tag_queries(alert_config_id=str(alert.id), product=Product.PRODUCT_ANALYTICS, feature=Feature.ALERTING)
+ # calculation_interval / config_type also let query_log cost be grouped by alert cadence
+ # (real_time vs every_15_minutes vs ...) and query shape (trends vs HogQL) without a join.
+ tag_queries(
+ alert_config_id=str(alert.id),
+ product=Product.PRODUCT_ANALYTICS,
+ feature=Feature.ALERTING,
+ alert_calculation_interval=alert.calculation_interval,
+ alert_config_type=(alert.config or {}).get("type"),
+ )
# Snapshot before add_alert_check mutates alert.state — needed to detect the
# NOT_FIRING/ERRORED -> FIRING transition that triggers an investigation.