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(warehouse-sources): Decagon admin logs table (#80186)

jake sciotto9145cf1a137a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/canonical_descriptions.py
index e2801c62c762..50a385146d0f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/canonical_descriptions.py
@@ -93,4 +93,23 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
),
},
},
+ "admin_logs": {
+ "description": (
+ "An entry in Decagon's admin log: a configuration change with who made it, when, "
+ "and the before and after state. An immutable audit trail."
+ ),
+ "docs_url": "https://docs.decagon.ai/api-reference/getting-started",
+ "columns": {
+ "id": "Unique identifier for the log entry.",
+ "created_at": "Timestamp at which the change was made.",
+ "resource_type": "Type of the resource that was changed.",
+ "resource_id": "Identifier of the resource that was changed.",
+ "action": "Action performed on the resource.",
+ "user_id": "Identifier of the user who made the change.",
+ "team_id": "Identifier of the team the change belongs to.",
+ "status": "Status of the change.",
+ "details_before": "State of the resource before the change, as free-form JSON.",
+ "details_after": "State of the resource after the change, as free-form JSON.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/settings.py
index e683bde4f2b5..bcae2e3bf86e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/settings.py
@@ -193,6 +193,41 @@ DECAGON_ENDPOINTS: dict[str, DecagonEndpointConfig] = {
pagination="single",
extra_params={"get_counts": "true"},
),
+ # /admin_log/get is Decagon's audit trail of configuration changes: who changed what,
+ # when, and the before/after state. Immutable rows paged on limit/offset over a
+ # `total` count. Incremental sync filters server-side via `start`, preferred over
+ # walking the offset history at 1 request/second. The spec types start/end loosely
+ # rather than as the exports' epoch seconds, so the bound is sent as ISO 8601,
+ # matching the ISO created_at column it filters; if that guess is wrong the sync
+ # either fails loudly on a 4xx or degrades to a full walk, and the merge on id keeps
+ # the table correct either way. Append is not offered for the same reason: with the
+ # filter silently ignored, appends would re-add all history every sync.
+ "admin_logs": DecagonEndpointConfig(
+ name="admin_logs",
+ path="/admin_log/get",
+ data_key="admin_logs",
+ primary_keys=["id"],
+ incremental_fields=[
+ {
+ "label": "created_at",
+ "type": IncrementalFieldType.DateTime,
+ "field": "created_at",
+ "field_type": IncrementalFieldType.DateTime,
+ }
+ ],
+ pagination="offset",
+ page_size=100,
+ total_key="total",
+ partition_key="created_at",
+ incremental_param="start",
+ incremental_param_format="iso8601",
+ # Ordering is undocumented for this endpoint; desc is the safe declaration (see
+ # the field comment).
+ sort_mode="desc",
+ # Opt-in until what lands in details_before/details_after is confirmed against a
+ # live account; config diffs can carry sensitive settings content.
+ should_sync_default=False,
+ ),
}
ENDPOINTS = tuple(DECAGON_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/tests/test_decagon.py b/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/tests/test_decagon.py
index 292689d7aa6f..08f7af0527b2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/tests/test_decagon.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/tests/test_decagon.py
@@ -610,6 +610,42 @@ class TestTags:
assert response.partition_keys is None
+class TestAdminLogs:
+ def test_incremental_walk_sends_iso_start_and_pages_on_offset(self) -> None:
+ # `start` takes a different value format from the exports' epoch min_timestamp;
+ # sending an epoch here is the cross-endpoint confusion the spec warns about.
+ manager = _fresh_manager()
+ responses = [
+ _make_response({"admin_logs": [{"id": "a1"}, {"id": "a2"}], "total": 3}),
+ _make_response({"admin_logs": [{"id": "a3"}], "total": 3}),
+ ]
+ sent_params, batches = _drive_rows(
+ manager,
+ responses,
+ endpoint="admin_logs",
+ should_use_incremental_field=True,
+ db_incremental_field_last_value=datetime(2026, 1, 15, 12, 0, 5, tzinfo=UTC),
+ incremental_field="created_at",
+ )
+
+ assert sent_params == [
+ {"offset": "0", "limit": "100", "start": "2026-01-15T12:00:05+00:00"},
+ {"offset": "2", "limit": "100", "start": "2026-01-15T12:00:05+00:00"},
+ ]
+ assert [len(b) for b in batches] == [2, 1]
+
+ def test_response_merges_on_id_partitioned_by_created_at(self) -> None:
+ response = decagon_source(
+ api_key="key",
+ endpoint="admin_logs",
+ logger=MagicMock(),
+ resumable_source_manager=MagicMock(spec=ResumableSourceManager),
+ )
+ assert response.primary_keys == ["id"]
+ assert response.partition_keys == ["created_at"]
+ assert response.sort_mode == "desc"
+
+
class TestToEpochSeconds:
# The pipeline hands the DateTime watermark back as a datetime, a date, or an epoch
# number depending on how it round-tripped through storage; the request boundary must
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/tests/test_decagon_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/tests/test_decagon_source.py
index e1f232f12a89..0d2813ccd8af 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/tests/test_decagon_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/decagon/tests/test_decagon_source.py
@@ -85,6 +85,15 @@ class TestDecagonSource:
assert tags.supports_incremental is False
assert tags.supports_append is False
+ admin_logs = next(s for s in schemas if s.name == "admin_logs")
+ # Merge on id keeps the table correct even if the loosely typed `start` filter is
+ # ignored server-side; an append sync in that case would re-add all history every
+ # run, so it is not offered. Opt-in until the details columns are confirmed safe.
+ assert admin_logs.supports_incremental is True
+ assert admin_logs.supports_append is False
+ assert admin_logs.should_sync_default is False
+ assert [f["field"] for f in admin_logs.incremental_fields] == ["created_at"]
+
def test_get_schemas_filtered_by_names(self) -> None:
assert [s.name for s in self.source.get_schemas(self.config, self.team_id, names=["conversations"])] == [
"conversations"