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(web-analytics): per-tile lifecycle logs in eager precompute warming (#61888)

Lucas Ricoy42fd0c5199a9
diff --git a/products/web_analytics/dags/eager_web_analytics_precompute.py b/products/web_analytics/dags/eager_web_analytics_precompute.py
index a66a4d3d2f8a..a4aaaba7397a 100644
--- a/products/web_analytics/dags/eager_web_analytics_precompute.py
+++ b/products/web_analytics/dags/eager_web_analytics_precompute.py
@@ -171,10 +171,17 @@ def _warm_baseline_for_team(context: dagster.OpExecutionContext, team: Team) ->
warmed = 0
failed = 0
- for query in queries:
+ total = len(queries)
+ for idx, query in enumerate(queries, start=1):
kind = str(query.get("kind"))
breakdown_value = query.get("breakdownBy")
label = f"{kind}:{breakdown_value}" if breakdown_value else kind
+ # Per-tile start line so the run is followable live in the Dagster UI —
+ # each tile can take up to the query timeout, so seeing which one is in
+ # flight (and how far through the matrix) matters when a run drags.
+ context.log.info(f"eager_baseline_warming_tile_start [{idx}/{total}] team={team.pk} query={label}")
+ logger.info("eager_baseline_warming_tile_start", team_id=team.pk, query=label, tile=idx, total=total)
+ tile_started = time.monotonic()
try:
# Tag BEFORE constructing the runner. `tag_queries` writes to
# a contextvar; any I/O the runner does at construction time
@@ -189,14 +196,36 @@ def _warm_baseline_for_team(context: dagster.OpExecutionContext, team: Team) ->
runner.run(analytics_props={"source": EventSource.CACHE_WARMING})
EAGER_PRECOMPUTE_BASELINE_WARMED.labels(query_kind=label).inc()
warmed += 1
+ tile_ms = round((time.monotonic() - tile_started) * 1000)
+ context.log.info(
+ f"eager_baseline_warming_tile_done [{idx}/{total}] team={team.pk} query={label} "
+ f"status=warmed duration_ms={tile_ms}"
+ )
+ logger.info(
+ "eager_baseline_warming_tile_done",
+ team_id=team.pk,
+ query=label,
+ tile=idx,
+ total=total,
+ status="warmed",
+ duration_ms=tile_ms,
+ )
except Exception as exc:
+ tile_ms = round((time.monotonic() - tile_started) * 1000)
EAGER_PRECOMPUTE_BASELINE_FAILED.labels(query_kind=label, error_type=type(exc).__name__).inc()
- context.log.exception(f"eager_baseline_warming_query_failed team={team.pk} query={label}")
+ context.log.exception(
+ f"eager_baseline_warming_query_failed [{idx}/{total}] team={team.pk} query={label} "
+ f"duration_ms={tile_ms}"
+ )
logger.exception(
"eager_baseline_warming_query_failed",
team_id=team.pk,
query=label,
query_kind=label,
+ tile=idx,
+ total=total,
+ status="failed",
+ duration_ms=tile_ms,
error_type=type(exc).__name__,
)
failed += 1
diff --git a/products/web_analytics/dags/tests/test_eager_web_analytics_precompute.py b/products/web_analytics/dags/tests/test_eager_web_analytics_precompute.py
index 11092c492aaa..1ba72d7d17fc 100644
--- a/products/web_analytics/dags/tests/test_eager_web_analytics_precompute.py
+++ b/products/web_analytics/dags/tests/test_eager_web_analytics_precompute.py
@@ -216,6 +216,16 @@ class TestEagerBaselineLogging(APIBaseTest):
assert start[0]["teams"] == 1
assert start[0]["gate_reason"] == "ok"
+ # Per-tile lifecycle: one start + one done line per tile, so the full
+ # matrix is followable in the Dagster UI / Loki.
+ tile_start = self._events(cap_logs, "eager_baseline_warming_tile_start")
+ assert len(tile_start) == _QUERIES_PER_TEAM
+ assert {t["tile"] for t in tile_start} == set(range(1, _QUERIES_PER_TEAM + 1))
+
+ tile_done = self._events(cap_logs, "eager_baseline_warming_tile_done")
+ assert len(tile_done) == _QUERIES_PER_TEAM
+ assert all(t["status"] == "warmed" and "duration_ms" in t for t in tile_done)
+
team_logs = self._events(cap_logs, "eager_baseline_warming_team")
assert len(team_logs) == 1
assert team_logs[0]["team_id"] == self.team.pk
@@ -248,6 +258,11 @@ class TestEagerBaselineLogging(APIBaseTest):
assert len(failed) == _QUERIES_PER_TEAM
assert all(f["error_type"] == "RuntimeError" for f in failed)
assert all(f["team_id"] == self.team.pk for f in failed)
+ assert all(f["status"] == "failed" and "duration_ms" in f for f in failed)
+
+ # Every tile still emits a start even when its query fails.
+ assert len(self._events(cap_logs, "eager_baseline_warming_tile_start")) == _QUERIES_PER_TEAM
+ assert self._events(cap_logs, "eager_baseline_warming_tile_done") == []
class TestJobConfiguration: