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(vercel): encode events pagination timestamps as ISO 8601 (#78491)

Tom Owersde5f36120672
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/settings.py
index aa4f4aaa944b..83b7dfbab0cb 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/settings.py
@@ -18,6 +18,11 @@ class VercelEndpointConfig:
# Query param that lower-bounds results by creation time (Unix ms). Only set where Vercel
# documents a genuine server-side time filter — None means full refresh for this endpoint.
since_param: Optional[str] = None
+ # Whether `since`/`until` must be sent as ISO 8601 UTC strings rather than raw Unix-ms
+ # integers. Vercel's OpenAPI spec types since/until as numbers (e.g. 1540095775941) for
+ # deployments, domains, aliases, and teams, but as strings (e.g. "2019-12-08T10:00:38.976Z")
+ # for events — sending events a raw ms integer gets rejected with a 400.
+ since_until_as_iso: bool = False
# Team-owned resources require ?teamId=<id> on each request. Endpoints that list resources
# visible to the token itself (e.g. /v2/teams) are not team-scoped.
team_scoped: bool = True
@@ -91,6 +96,7 @@ VERCEL_ENDPOINTS: dict[str, VercelEndpointConfig] = {
# time, so this is genuinely incremental rather than a client-side skip. `createdAt` is
# immutable, making it both the incremental cursor and the pagination cursor.
since_param="since",
+ since_until_as_iso=True,
supports_incremental=True,
supports_append=True,
# Unlike the resource endpoints this one returns no `pagination` envelope, so pages are
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel.py
index ee491af52fe8..80d063da0be7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel.py
@@ -19,6 +19,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.vercel.ver
_floor_to_day,
_focus_charge_id,
_iso8601_utc,
+ _ms_to_iso8601,
_should_stop_desc,
get_billing_rows,
get_rows,
@@ -92,6 +93,22 @@ class TestBuildParams:
None,
{"limit": PAGE_SIZE, "teamId": "team_1", "withPayload": "true"},
),
+ # events' since/until must be ISO 8601 strings, not raw Unix-ms integers — Vercel's
+ # OpenAPI spec types them as strings and 400s a raw ms value (unlike deployments above,
+ # which documents since/until as numbers).
+ (
+ "events_since_and_until_as_iso",
+ "events",
+ None,
+ 123,
+ 456,
+ {
+ "limit": PAGE_SIZE,
+ "withPayload": "true",
+ "since": "1970-01-01T00:00:00.123Z",
+ "until": "1970-01-01T00:00:00.456Z",
+ },
+ ),
]
)
def test_build_params(
@@ -265,9 +282,10 @@ class TestGetRows:
assert [r["id"] for r in rows] == ["e1", "e2", "e3"]
assert "until=" not in calls[0]
- # The oldest row on each page bounds the next, so page two asks for until=200, not 300.
- assert "until=200" in calls[1]
- assert "until=100" in calls[2]
+ # The oldest row on each page bounds the next, so page two asks for until=200, not 300 —
+ # encoded as the ISO string events requires, not the raw ms integer.
+ assert "until=1970-01-01T00%3A00%3A00.200Z" in calls[1]
+ assert "until=1970-01-01T00%3A00%3A00.100Z" in calls[2]
def test_events_stop_when_a_whole_page_shares_one_timestamp(self, monkeypatch: Any) -> None:
# The derived cursor can't advance past a page whose rows share a timestamp; the walk has
@@ -297,7 +315,7 @@ class TestGetRows:
)
assert [r["id"] for r in rows] == ["e1", "e2", "e3"]
- assert "since=150" in calls[0]
+ assert "since=1970-01-01T00%3A00%3A00.150Z" in calls[0]
assert len(calls) == 2
def test_mid_page_yield_checkpoints_current_page_not_next(self, monkeypatch: Any) -> None:
@@ -380,6 +398,20 @@ class TestIso8601Utc:
assert formatted == "2025-01-02T03:04:05.000Z"
+class TestMsToIso8601:
+ @parameterized.expand(
+ [
+ ("whole_second", 1700000000000, "2023-11-14T22:13:20.000Z"),
+ # Millisecond digits must survive, not just the second — a truncated cursor would
+ # under-report `until` and re-request rows the previous page already yielded.
+ ("preserves_millis", 1699999999123, "2023-11-14T22:13:19.123Z"),
+ ("epoch", 0, "1970-01-01T00:00:00.000Z"),
+ ]
+ )
+ def test_ms_to_iso8601(self, _name: str, ms: int, expected: str) -> None:
+ assert _ms_to_iso8601(ms) == expected
+
+
class TestFocusChargeId:
def test_stable_when_only_amounts_change(self) -> None:
# A restated charge (same dimensions, different measures) must keep its id so merge updates
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/vercel.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/vercel.py
index a2581b90adb4..6ae1c2c697ec 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/vercel.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/vercel.py
@@ -69,6 +69,13 @@ def _get_headers(access_token: str) -> dict[str, str]:
}
+def _ms_to_iso8601(ms: int) -> str:
+ """Convert a Unix-ms cursor value to the ISO 8601 UTC string format some Vercel endpoints
+ (e.g. events) expect for `since`/`until` — see `VercelEndpointConfig.since_until_as_iso`."""
+ seconds, millis = divmod(ms, 1000)
+ return datetime.fromtimestamp(seconds, tz=UTC).strftime("%Y-%m-%dT%H:%M:%S.") + f"{millis:03d}Z"
+
+
def _build_params(
config: VercelEndpointConfig,
team_id: str | None,
@@ -81,10 +88,10 @@ def _build_params(
params["teamId"] = team_id
if config.since_param and since_value is not None:
- params[config.since_param] = since_value
+ params[config.since_param] = _ms_to_iso8601(since_value) if config.since_until_as_iso else since_value
if until is not None:
- params["until"] = until
+ params["until"] = _ms_to_iso8601(until) if config.since_until_as_iso else until
return params