: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
feat(data-warehouse): add Vercel team activity events table (#78207)
Tom Owers1085b7168272
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/canonical_descriptions.pyindex c93d0e1482d3..0f8c92339fce 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/canonical_descriptions.py@@ -23,6 +23,23 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"inspectorUrl": "URL of the deployment's inspector page in the Vercel dashboard.",},},+ "events": {+ "description": "A Vercel team activity event: one action taken on the team, such as a deployment being created, a project renamed, or an environment variable changed. Where the other tables hold current state, this one holds the transitions between states.",+ "docs_url": "https://vercel.com/docs/rest-api/reference/endpoints/user/list-user-events",+ "columns": {+ "id": "Unique identifier for the event.",+ "type": "The type of action the event records, such as deployment-created or env-variable-edit.",+ "text": "Human-readable summary of the event.",+ "createdAt": "Time the event was generated, as a Unix timestamp in milliseconds.",+ "entities": "Spans within the event text marking the entities it refers to, as JSON.",+ "categories": "Categories grouping this event with related types. An event can belong to more than one.",+ "payload": "Event-specific detail about the entity acted on, as JSON. The shape varies by event type.",+ "principalId": "Identifier of the principal that generated the event, usually a user but sometimes an app or integration.",+ "userId": "Identifier of the user that generated the event, empty when the principal was not a user.",+ "user": "Metadata about the user that generated the event, as JSON.",+ "via": "Chain of principals the authority was delegated through, as JSON, when a user acted through an app.",+ },+ },"projects": {"description": "A Vercel project: a codebase connected to Vercel with its build, environment, and deployment configuration.","docs_url": "https://vercel.com/docs/rest-api/reference/endpoints/projects/retrieve-a-list-of-projects",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.pyindex 939cd8e2956c..aa4f4aaa944b 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@@ -36,6 +36,13 @@ class VercelEndpointConfig:# `from`/`to` date window instead of the cursor-paginated list envelope every other endpoint# uses. Routed through its own transport path in vercel.py.is_focus_billing: bool = False+ # Field holding the row's creation timestamp (Unix ms) for endpoints that return rows but no+ # `pagination` envelope. The transport pages those by feeding the oldest value on a page back+ # as the next `until`. None means the endpoint carries the envelope and pages from+ # `pagination.next`.+ cursor_from_field: Optional[str] = None+ # Static query params this endpoint needs on every request, merged over the shared ones.+ extra_params: dict[str, str] = field(default_factory=dict)# Charges get restated after they first post (usage finalization, plus adjustments, credits, and tax@@ -71,6 +78,40 @@ VERCEL_ENDPOINTS: dict[str, VercelEndpointConfig] = {},],),+ # Team activity stream: every action taken on the team, across ~600 event types (deployments,+ # projects, env vars, domains, aliases, certs, flags, firewall config, access groups). The+ # resource tables above hold current state; this one holds the transitions between them, which+ # is what deployment frequency, change-failure rate, and config audit trails are built from.+ "events": VercelEndpointConfig(+ name="events",+ path="/v3/events",+ response_data_key="events",+ primary_key="id",+ # /v3/events documents `since`/`until` (Unix ms) as a server-side filter on event creation+ # 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",+ supports_incremental=True,+ supports_append=True,+ # Unlike the resource endpoints this one returns no `pagination` envelope, so pages are+ # walked from the oldest `createdAt` on each page.+ cursor_from_field="createdAt",+ # Without this the response carries only the event's summary text, not the entity it acted+ # on. The payload shape varies per event type; the pipeline serializes it to a JSON string+ # column, so the variation doesn't drift the Arrow schema.+ extra_params={"withPayload": "true"},+ # Deliberately left unpartitioned. `createdAt` is Unix *milliseconds*, and the datetime+ # partition mode feeds an int straight to `datetime.fromtimestamp()`, which reads it as+ # seconds and raises for any ms value. Same reason `deployments.created` is unpartitioned.+ incremental_fields=[+ {+ "label": "createdAt",+ "type": IncrementalFieldType.Integer,+ "field": "createdAt",+ "field_type": IncrementalFieldType.Integer,+ },+ ],+ ),# The endpoints below are full refresh only: Vercel's public docs describe the `pagination`# cursor for them but do not document a server-side creation-time filter, and we have no API# credentials to curl-verify one. Marking them incremental would re-page the whole resourcediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/source.pyindex e4cff3190741..c92d37849ee9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/source.py@@ -30,6 +30,7 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType@SourceRegistry.registerclass VercelSource(ResumableSource[VercelSourceConfig, VercelResumeConfig]):api_docs_url = "https://vercel.com/docs/rest-api"+ lists_tables_without_credentials = True # static endpoint catalog — safe for public docs@propertydef source_type(self) -> ExternalDataSourceType: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.pyindex 36007593fc5d..ee491af52fe8 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@@ -15,6 +15,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.vercel.verVercelResumeConfig,_billing_window_start,_build_params,+ _cursor_from_page,_floor_to_day,_focus_charge_id,_iso8601_utc,@@ -81,6 +82,16 @@ class TestBuildParams:("since_and_until", "deployments", None, 123, 456, {"limit": PAGE_SIZE, "since": 123, "until": 456}),# projects has no since_param, so a cursor value must not become a query filter.("no_since_param_drops_since", "projects", None, 123, None, {"limit": PAGE_SIZE}),+ # Without withPayload the response carries only each event's summary text, so the+ # payload column lands empty and the table loses the detail it exists for.+ (+ "events_requests_the_payload",+ "events",+ "team_1",+ None,+ None,+ {"limit": PAGE_SIZE, "teamId": "team_1", "withPayload": "true"},+ ),])def test_build_params(@@ -113,6 +124,22 @@ class TestShouldStopDesc:assert _should_stop_desc(items, field_name, cutoff) is expected+class TestCursorFromPage:+ @parameterized.expand(+ [+ # The oldest value bounds the next page. Taking the newest would re-request page one.+ ("oldest_wins", [{"createdAt": 300}, {"createdAt": 100}, {"createdAt": 200}], 100),+ ("single_row", [{"createdAt": 42}], 42),+ ("ignores_rows_missing_the_field", [{"createdAt": 300}, {"other": 1}], 300),+ ("ignores_non_integer_values", [{"createdAt": "300"}, {"createdAt": 200}], 200),+ ("no_usable_values", [{"other": 1}], None),+ ("empty_page", [], None),+ ]+ )+ def test_cursor_from_page(self, _name: str, items: list[dict[str, Any]], expected: int | None) -> None:+ assert _cursor_from_page(items, "createdAt") == expected++class TestValidateCredentials:@parameterized.expand([(200, True), (401, False), (403, False), (500, False)])def test_status_mapping(self, status: int, expected_ok: bool) -> None:@@ -226,6 +253,53 @@ class TestGetRows:assert rows == []assert len(calls) == 1+ def test_events_pages_without_a_pagination_envelope(self, monkeypatch: Any) -> None:+ # /v3/events returns rows but no `pagination` object. Without the derived cursor the walk+ # ends after page one and the table silently caps at a single page of history forever.+ responses: list[dict] = [+ {"events": [{"id": "e1", "createdAt": 300}, {"id": "e2", "createdAt": 200}]},+ {"events": [{"id": "e3", "createdAt": 100}]},+ {"events": []},+ ]+ rows, calls = _collect("events", _FakeResumableManager(), monkeypatch, responses)++ 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]++ 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+ # to end there rather than re-request the same page forever.+ responses = [+ {"events": [{"id": "e1", "createdAt": 500}, {"id": "e2", "createdAt": 500}]},+ {"events": [{"id": "e3", "createdAt": 500}]},+ ]+ rows, calls = _collect("events", _FakeResumableManager(), monkeypatch, responses)++ assert [r["id"] for r in rows] == ["e1", "e2", "e3"]+ assert len(calls) == 2++ def test_events_incremental_sends_since_and_stops_at_watermark(self, monkeypatch: Any) -> None:+ responses = [+ {"events": [{"id": "e1", "createdAt": 300}, {"id": "e2", "createdAt": 200}]},+ {"events": [{"id": "e3", "createdAt": 120}]},+ {"events": [{"id": "e4", "createdAt": 50}]},+ ]+ rows, calls = _collect(+ "events",+ _FakeResumableManager(),+ monkeypatch,+ responses,+ should_use_incremental_field=True,+ db_incremental_field_last_value=150,+ )++ assert [r["id"] for r in rows] == ["e1", "e2", "e3"]+ assert "since=150" in calls[0]+ assert len(calls) == 2+def test_mid_page_yield_checkpoints_current_page_not_next(self, monkeypatch: Any) -> None:# Regression: a mid-page yield must checkpoint the cursor for the CURRENT page, not the# next one. Page two crosses the batcher's 2000-row chunk, so the batch yields while the@@ -250,7 +324,14 @@ class TestGetRows:class TestVercelSource:@parameterized.expand(- [("deployments", "uid"), ("projects", "id"), ("teams", "id"), ("domains", "id"), ("aliases", "uid")]+ [+ ("deployments", "uid"),+ ("events", "id"),+ ("projects", "id"),+ ("teams", "id"),+ ("domains", "id"),+ ("aliases", "uid"),+ ])def test_source_response_primary_key_and_sort(self, endpoint: str, expected_pk: str) -> None:response = vercel_source(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel_source.pyindex 5c4e264c1dd4..6718797cefef 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/vercel/tests/test_vercel_source.py@@ -65,7 +65,15 @@ class TestVercelSource:def test_get_schemas_sync_capabilities_per_endpoint(self) -> None:schemas = {s.name: s for s in self.source.get_schemas(self.config, team_id=1)}- assert set(schemas) == {"deployments", "projects", "teams", "domains", "aliases", "billing_charges"}+ assert set(schemas) == {+ "deployments",+ "events",+ "projects",+ "teams",+ "domains",+ "aliases",+ "billing_charges",+ }deployments = schemas["deployments"]assert deployments.supports_incremental is True@@ -73,6 +81,14 @@ class TestVercelSource:assert [f["field"] for f in deployments.incremental_fields] == ["created"]assert deployments.incremental_fields[0]["field_type"] == IncrementalFieldType.Integer+ # The activity stream cursors on the event's own creation time, which never changes, and+ # supports append because events are immutable once emitted.+ events = schemas["events"]+ assert events.supports_incremental is True+ assert events.supports_append is True+ assert [f["field"] for f in events.incremental_fields] == ["createdAt"]+ assert events.incremental_fields[0]["field_type"] == IncrementalFieldType.Integer+# Billing supports incremental merge but not append (append would duplicate restated charges),# cursors on the charge period, and carries a lookback so restatements get re-read and merged.billing = schemas["billing_charges"]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.pyindex ef4cabf44534..a2581b90adb4 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@@ -75,7 +75,7 @@ def _build_params(since_value: Any,until: int | None,) -> dict[str, Any]:- params: dict[str, Any] = {"limit": PAGE_SIZE}+ params: dict[str, Any] = {"limit": PAGE_SIZE, **config.extra_params}if config.team_scoped and team_id:params["teamId"] = team_id@@ -127,6 +127,19 @@ def _should_stop_desc(items: list[dict[str, Any]], field_name: str | None, cutofreturn any(item.get(field_name) is not None and item[field_name] <= cutoff for item in items)+def _cursor_from_page(items: list[dict[str, Any]], field_name: str) -> int | None:+ """Next `until` cursor for an endpoint that returns rows but no `pagination` envelope.++ Rows arrive newest-first, so the oldest timestamp on this page bounds the next one. The value is+ fed back unmodified rather than decremented: `until` is inclusive, so the boundary row is+ re-fetched and merge dedupes it on the primary key, whereas stepping back a millisecond would+ drop any row sharing that exact timestamp. A page whose rows all share one timestamp can't+ advance the cursor; the caller's non-advancing-cursor guard ends the walk there.+ """+ timestamps = [item[field_name] for item in items if isinstance(item.get(field_name), int)]+ return min(timestamps) if timestamps else None++def validate_credentials(access_token: str) -> tuple[bool, str | None]:"""Confirm the access token is genuine via GET /v2/user — the cheapest authenticated probe,available to any valid Vercel token regardless of team scope or resource permissions."""@@ -193,6 +206,8 @@ def get_rows(breaknext_until = (data.get("pagination") or {}).get("next")+ if next_until is None and config.cursor_from_field:+ next_until = _cursor_from_page(items, config.cursor_from_field)stop_after_page = _should_stop_desc(items, field_name, cutoff)for item in items: