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.

fix(warehouse-sources): cap sentry tag values at the issues snapshot (#88057)

Daniel RC1e4fc87933ad
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/sentry.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/sentry.py
index 0643ee5420cd..1b84e0c1bb88 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/sentry.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/sentry.py
@@ -455,6 +455,7 @@ def _iter_issue_tag_values_rows(
resumable_source_manager: Optional[ResumableSourceManager[SentryResumeConfig]] = None,
incremental_last_seen_max: Any = None,
issues_table: Optional["ParentTableRef"] = None,
+ issues_snapshot_at: datetime | None = None,
) -> Iterator[dict[str, Any]]:
cutoff_last_seen = _parse_datetime_value(incremental_last_seen_max)
use_warehouse_parent = issues_table is not None
@@ -654,11 +655,16 @@ def _iter_issue_tag_values_rows(
should_stop = False
for row in rows:
- if cutoff_last_seen is not None:
- row_last_seen = _parse_datetime_value(row.get("lastSeen"))
- if row_last_seen is not None and row_last_seen <= cutoff_last_seen:
+ row_last_seen = _parse_datetime_value(row.get("lastSeen"))
+ if cutoff_last_seen is not None and row_last_seen is not None:
+ if row_last_seen <= cutoff_last_seen:
should_stop = True
break
+ if issues_snapshot_at is not None and row_last_seen is not None:
+ if row_last_seen > issues_snapshot_at:
+ # Newer than the issues snapshot this run fanned out over. Values are
+ # returned newest-first, so skip past it rather than stopping.
+ continue
row["issue_id"] = issue_id
row["tag_key"] = tag_key
@@ -1273,6 +1279,7 @@ def sentry_source(
headers = _auth_headers(auth_token)
incremental_last_seen_max = db_incremental_field_last_value if should_use_incremental_field else None
issues_table: ParentTableRef | None = None
+ issues_snapshot_at: datetime | None = None
# Warehouse reuse only with a watermark: the per-row cutoff then bounds the fan-out to
# issues newer than the last run, the regime whose volume matched the API path in
# production. Without one (a full refresh), the only available floor is our window
@@ -1284,20 +1291,34 @@ def sentry_source(
# noqa reason: keeps deltalake/pyarrow off the import path of this module (imported
# by the API process for schema discovery) — the reader stack loads only when syncing.
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.warehouse_parent import ( # noqa: PLC0415
+ parent_snapshot_covers_through,
try_resolve_parent_table,
)
- # Resolved here, in sync source-build context, never inside the iterator: its body
- # runs on the pipeline's executor threads, where ad-hoc ORM reads hit the
- # pooler-drop failure mode resolve_parent_table_ref documents.
- issues_table = try_resolve_parent_table(
- team_id=team_id,
- source_id=source_id,
- parent_name="issues",
- required_columns=_ISSUES_PARENT_COLUMNS,
- schema_name="issue_tag_values",
- row_filter=_issues_parent_row_filter(_parse_datetime_value(incremental_last_seen_max)),
- )
+ # How far the issues snapshot is guaranteed complete. The tag values fanned out below
+ # are fetched live, so emitting one past this point would carry the watermark over
+ # issues the snapshot has not shown yet, and the next floor would skip them for good.
+ # Read before the table is pinned, never after: a sync completing between the two
+ # reads would otherwise cap on the newer job while the fan-out reads the older
+ # snapshot. No completed sync means nothing to cap against, so take the API path.
+ issues_snapshot_at = parent_snapshot_covers_through(team_id, source_id, "issues")
+ if issues_snapshot_at is not None:
+ # Resolved here, in sync source-build context, never inside the iterator: its body
+ # runs on the pipeline's executor threads, where ad-hoc ORM reads hit the
+ # pooler-drop failure mode resolve_parent_table_ref documents.
+ issues_table = try_resolve_parent_table(
+ team_id=team_id,
+ source_id=source_id,
+ parent_name="issues",
+ required_columns=_ISSUES_PARENT_COLUMNS,
+ schema_name="issue_tag_values",
+ row_filter=_issues_parent_row_filter(_parse_datetime_value(incremental_last_seen_max)),
+ )
+ if issues_table is None:
+ # The table turned out to be unreadable, so this run reads the live issues
+ # API. That listing has no snapshot behind it, so capping against one would
+ # drop fresh tag values the API path had no reason to hold back.
+ issues_snapshot_at = None
if resumable_source_manager is not None and resumable_source_manager.can_resume():
# The pipeline reads this same Redis state to pick replace-vs-append for chunk 0,
# so state the iterator will refuse has to go now, before it decides. Same
@@ -1313,6 +1334,7 @@ def sentry_source(
resumable_source_manager=resumable_source_manager,
incremental_last_seen_max=incremental_last_seen_max,
issues_table=issues_table,
+ issues_snapshot_at=issues_snapshot_at,
),
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/tests/test_sentry.py b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/tests/test_sentry.py
index 129f7b3824b5..c98ccf7d4bf6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/tests/test_sentry.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/sentry/tests/test_sentry.py
@@ -876,6 +876,16 @@ class TestSentrySourceResumable:
class TestIssueTagValuesResumable:
+ @pytest.fixture(autouse=True)
+ def _fresh_issues_snapshot(self):
+ # These cases predate the snapshot cap and assert on the rows the fan-out emits, so pin
+ # the parent snapshot ahead of every fixture timestamp to leave that set unchanged.
+ with patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.warehouse_parent.parent_snapshot_covers_through",
+ return_value=datetime(2999, 1, 1, tzinfo=UTC),
+ ):
+ yield
+
"""Resume behaviour for the two-level issue_tag_values fan-out loop."""
@patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry.make_tracked_session")
@@ -1881,6 +1891,16 @@ class TestSentryCustomIteratorEndpoints:
class TestWarehouseParentReuse:
+ @pytest.fixture(autouse=True)
+ def _fresh_issues_snapshot(self):
+ # These cases predate the snapshot cap and assert on the rows the fan-out emits, so pin
+ # the parent snapshot ahead of every fixture timestamp to leave that set unchanged.
+ with patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.warehouse_parent.parent_snapshot_covers_through",
+ return_value=datetime(2999, 1, 1, tzinfo=UTC),
+ ):
+ yield
+
@parameterized.expand(
[
("issue_events", []),
@@ -1976,6 +1996,98 @@ class TestWarehouseParentReuse:
row_filter=_issues_parent_row_filter(datetime(2020, 1, 1, tzinfo=UTC)),
)
+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry.make_tracked_session")
+ @patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.warehouse_parent.parent_snapshot_covers_through",
+ return_value=datetime(2026, 3, 4, 0, 0, 0, tzinfo=UTC),
+ )
+ @patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.warehouse_parent.try_resolve_parent_table",
+ return_value=None,
+ )
+ def test_api_fallback_keeps_values_newer_than_the_stale_snapshot(
+ self, _mock_resolve, _mock_snapshot, mock_get
+ ) -> None:
+ cutoff = datetime(2026, 3, 3, 0, 0, 0, tzinfo=UTC)
+
+ def side_effect(url, headers=None, params=None, timeout=None):
+ if url.endswith("/organizations/acme/issues/"):
+ return _response([{"id": "200", "lastSeen": "2026-03-06T00:00:00Z"}])
+ if url.endswith("/organizations/acme/issues/200/tags/"):
+ return _response([{"key": "browser"}])
+ if url.endswith("/organizations/acme/issues/200/tags/browser/values/"):
+ return _response([{"value": "Firefox", "lastSeen": "2026-03-06T00:00:00Z"}])
+ return _response([])
+
+ mock_get.return_value.get.side_effect = side_effect
+
+ resp = sentry_source(
+ auth_token="token",
+ organization_slug="acme",
+ api_base_url="https://sentry.io",
+ endpoint="issue_tag_values",
+ team_id=123,
+ job_id="job-id",
+ source_id="source-1",
+ use_warehouse_parent=True,
+ should_use_incremental_field=True,
+ db_incremental_field_last_value=cutoff,
+ incremental_field="lastSeen",
+ )
+
+ # The live listing has no snapshot behind it, so the stale cap must not apply.
+ assert [row["value"] for row in cast(Any, resp.items())] == ["Firefox"]
+
+ @patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry.make_tracked_session")
+ @patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.warehouse_parent.parent_snapshot_covers_through",
+ return_value=datetime(2026, 3, 4, 0, 0, 0, tzinfo=UTC),
+ )
+ @patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.warehouse_parent.resolve_parent_table_ref",
+ return_value=ParentTableRef(uri="s3://bucket/team_123_sentry_x/issues", version=3),
+ )
+ @patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.warehouse_parent.iter_parent_pages_from_warehouse"
+ )
+ def test_issue_tag_values_drops_values_newer_than_the_issues_snapshot(
+ self, mock_reader, _mock_resolve, _mock_snapshot, mock_get
+ ) -> None:
+ cutoff = datetime(2026, 3, 3, 0, 0, 0, tzinfo=UTC)
+ mock_reader.return_value = iter([[{"id": "200", "lastSeen": "2026-03-05T00:00:00Z"}]])
+
+ def side_effect(url, headers=None, params=None, timeout=None):
+ if url.endswith("/organizations/acme/issues/200/tags/"):
+ return _response([{"key": "browser"}])
+ if url.endswith("/organizations/acme/issues/200/tags/browser/values/"):
+ return _response(
+ [
+ {"value": "Firefox", "lastSeen": "2026-03-06T00:00:00Z"},
+ {"value": "Chrome", "lastSeen": "2026-03-03T12:00:00Z"},
+ ]
+ )
+ return _response([])
+
+ mock_get.return_value.get.side_effect = side_effect
+
+ resp = sentry_source(
+ auth_token="token",
+ organization_slug="acme",
+ api_base_url="https://sentry.io",
+ endpoint="issue_tag_values",
+ team_id=123,
+ job_id="job-id",
+ source_id="source-1",
+ use_warehouse_parent=True,
+ should_use_incremental_field=True,
+ db_incremental_field_last_value=cutoff,
+ incremental_field="lastSeen",
+ )
+
+ # Firefox is newer than the snapshot, so emitting it would carry the watermark past
+ # issues the snapshot has not shown yet. Chrome sits inside the snapshot and still ships.
+ assert [row["value"] for row in cast(Any, resp.items())] == ["Chrome"]
+
@patch("products.warehouse_sources.backend.temporal.data_imports.sources.sentry.sentry.make_tracked_session")
@patch(
"products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.warehouse_parent.resolve_parent_table_ref",