: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(annotations): filter the change feed by kind (#116610)
Daniel Viscae56a0e39199b
diff --git a/products/annotations/backend/api/test/test_change_feed.py b/products/annotations/backend/api/test/test_change_feed.pyindex 1ae8d2ed4619..fc5216dc4e70 100644--- a/products/annotations/backend/api/test/test_change_feed.py+++ b/products/annotations/backend/api/test/test_change_feed.py@@ -58,7 +58,7 @@ class TestChangeFeed(APIBaseTest):scope=Annotation.Scope.PROJECT,)- def _list(self, headers: dict[str, str] | None = None, **params: str) -> dict:+ def _list(self, headers: dict[str, str] | None = None, **params: str | list[str]) -> dict:response = self.client.get(f"/api/projects/{self.team.id}/change_feed/", params, headers=headers or {})assert response.status_code == 200, response.json()return response.json()@@ -130,10 +130,35 @@ class TestChangeFeed(APIBaseTest):assert [change["kind"] for change in feed["results"]] == expected_kinds- def test_rejects_a_window_that_ends_before_it_starts(self) -> None:- response = self.client.get(- f"/api/projects/{self.team.id}/change_feed/",- {"date_from": NOW.isoformat(), "date_to": (NOW - timedelta(hours=1)).isoformat()},- )+ @parameterized.expand(+ [+ ("repeated_keys", ["feature_flag", "experiment"]),+ ("json_encoded_array", '["feature_flag", "experiment"]'),+ ("comma_separated", "feature_flag,experiment"),+ ]+ )+ @time_machine.travel(NOW, tick=False)+ def test_kinds_returns_only_those_kinds(self, _name: str, kinds: list[str] | str) -> None:+ self._log_activity(at=NOW - timedelta(hours=2))+ self._log_activity(at=NOW - timedelta(minutes=100), scope="Experiment", item_id="7", name="Checkout test")+ with time_machine.travel(NOW - timedelta(hours=1), tick=False):+ create_release(team_id=self.team.id, hash_id="checkout-1.4.0", version="1.4.0", project="checkout")+ self._create_annotation(at=NOW - timedelta(minutes=30))++ feed = self._list(kinds=kinds)++ assert [change["kind"] for change in feed["results"]] == ["experiment", "feature_flag"]++ @parameterized.expand(+ [+ (+ "window_ends_before_it_starts",+ {"date_from": NOW.isoformat(), "date_to": (NOW - timedelta(hours=1)).isoformat()},+ ),+ ("unknown_kind", {"kinds": "deploy"}),+ ]+ )+ def test_rejects_invalid_query(self, _name: str, params: dict[str, str]) -> None:+ response = self.client.get(f"/api/projects/{self.team.id}/change_feed/", params)assert response.status_code == 400diff --git a/products/annotations/backend/presentation/serializers.py b/products/annotations/backend/presentation/serializers.pyindex 44bad4d0025a..00ebd3920f7c 100644--- a/products/annotations/backend/presentation/serializers.py+++ b/products/annotations/backend/presentation/serializers.py@@ -5,6 +5,8 @@ from django.utils import timezonefrom drf_spectacular.utils import extend_schema_serializerfrom rest_framework import serializers+from posthog.api.fields import JSONTolerantListField, RepeatedOrCommaSeparatedListField+from products.annotations.backend.facade.change_feed import ChangeKindDEFAULT_WINDOW = timedelta(hours=24)@@ -12,6 +14,14 @@ DEFAULT_LIMIT = 100MAX_LIMIT = 500+class ChangeKindsField(RepeatedOrCommaSeparatedListField, JSONTolerantListField):+ """Repeated keys, one comma-joined value (the generated frontend client) or one JSON array (the MCP client).++ The base order matters: JSONTolerantListField reads a JSON array before+ RepeatedOrCommaSeparatedListField splits on commas.+ """++class ChangeFeedQuerySerializer(serializers.Serializer):date_from = serializers.DateTimeField(required=False,@@ -28,6 +38,15 @@ class ChangeFeedQuerySerializer(serializers.Serializer):max_value=MAX_LIMIT,help_text=f"Maximum number of changes to return, newest first. Defaults to {DEFAULT_LIMIT}, at most {MAX_LIMIT}.",)+ kinds = ChangeKindsField(+ child=serializers.ChoiceField(choices=ChangeKind.choices),+ required=False,+ default=[],+ help_text=(+ "Return only these kinds of change. Omit to return every kind. "+ "Use `feature_flag` and `experiment` to see configuration edits without releases and annotations."+ ),+ )def validate(self, attrs: dict) -> dict:date_to = attrs.get("date_to") or timezone.now()diff --git a/products/annotations/backend/presentation/views.py b/products/annotations/backend/presentation/views.pyindex 5e089f0b92ec..6cfce5fef4fd 100644--- a/products/annotations/backend/presentation/views.py+++ b/products/annotations/backend/presentation/views.py@@ -68,12 +68,15 @@ class ChangeFeedViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):)def list(self, request: Request, **kwargs) -> Response:query = request.validated_query_data+ visibility = self._visibility(request)+ if query["kinds"]:+ visibility = {kind: rules for kind, rules in visibility.items() if kind in query["kinds"]}feed = api.list_changes(team_id=self.team_id,organization_id=self.team.organization_id,user_is_staff=cast(User, request.user).is_staff,window=ChangeWindow(start=query["date_from"], end=query["date_to"]),- visibility=self._visibility(request),+ visibility=visibility,limit=query["limit"],)return Response(ChangeFeedSerializer(feed).data)diff --git a/products/annotations/frontend/generated/api.schemas.ts b/products/annotations/frontend/generated/api.schemas.tsindex 6e5be9211564..cb00ce88237f 100644--- a/products/annotations/frontend/generated/api.schemas.ts+++ b/products/annotations/frontend/generated/api.schemas.ts@@ -307,6 +307,10 @@ export type ChangeFeedListParams = {* End of the time window (inclusive), ISO 8601. Defaults to now.*/date_to?: string+ /**+ * Return only these kinds of change. Omit to return every kind. Use `feature_flag` and `experiment` to see configuration edits without releases and annotations.+ */+ kinds?: ChangeFeedListKindsItem[]/*** Maximum number of changes to return, newest first. Defaults to 100, at most 500.* @minimum 1@@ -314,3 +318,18 @@ export type ChangeFeedListParams = {*/limit?: number}++/**+ * * `feature_flag` - Feature flag+ * * `experiment` - Experiment+ * * `release` - Release+ * * `annotation` - Annotation+ */+export type ChangeFeedListKindsItem = (typeof ChangeFeedListKindsItem)[keyof typeof ChangeFeedListKindsItem]++export const ChangeFeedListKindsItem = {+ FeatureFlag: 'feature_flag',+ Experiment: 'experiment',+ Release: 'release',+ Annotation: 'annotation',+} as constdiff --git a/products/annotations/mcp/tools.yaml b/products/annotations/mcp/tools.yamlindex f6b3f871b2fa..052a13b9928e 100644--- a/products/annotations/mcp/tools.yaml+++ b/products/annotations/mcp/tools.yaml@@ -128,5 +128,6 @@ tools:List the changes that can affect production in a time window, newest first: feature flag and experimentedits, error tracking releases, and annotations. Use this first when you investigate an error spike, alatency regression, or a metric drop, to find what changed just before it. Set `date_from` and `date_to`- (ISO 8601) around the incident. The default is the last 24 hours. When `has_more` is true, narrow the- window. Changes the user has no access to are left out.+ (ISO 8601) around the incident. The default is the last 24 hours. Deploy annotations and releases can fill+ the page, so set `kinds` to `["feature_flag", "experiment"]` to see only configuration edits. When+ `has_more` is true, narrow the window or set `kinds`. Changes the user has no access to are left out.diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 1d46d724d407..64a29d2efb96 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -2484,7 +2484,7 @@}},"change-feed-list": {- "description": "List the changes that can affect production in a time window, newest first: feature flag and experiment edits, error tracking releases, and annotations. Use this first when you investigate an error spike, a latency regression, or a metric drop, to find what changed just before it. Set `date_from` and `date_to` (ISO 8601) around the incident. The default is the last 24 hours. When `has_more` is true, narrow the window. Changes the user has no access to are left out.",+ "description": "List the changes that can affect production in a time window, newest first: feature flag and experiment edits, error tracking releases, and annotations. Use this first when you investigate an error spike, a latency regression, or a metric drop, to find what changed just before it. Set `date_from` and `date_to` (ISO 8601) around the incident. The default is the last 24 hours. Deploy annotations and releases can fill the page, so set `kinds` to `[\"feature_flag\", \"experiment\"]` to see only configuration edits. When `has_more` is true, narrow the window or set `kinds`. Changes the user has no access to are left out.","category": "Annotations","feature": "annotations","summary": "List recent production changes",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 161c0a554739..2abb6cce0fe6 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -2499,7 +2499,7 @@}},"change-feed-list": {- "description": "List the changes that can affect production in a time window, newest first: feature flag and experiment edits, error tracking releases, and annotations. Use this first when you investigate an error spike, a latency regression, or a metric drop, to find what changed just before it. Set `date_from` and `date_to` (ISO 8601) around the incident. The default is the last 24 hours. When `has_more` is true, narrow the window. Changes the user has no access to are left out.",+ "description": "List the changes that can affect production in a time window, newest first: feature flag and experiment edits, error tracking releases, and annotations. Use this first when you investigate an error spike, a latency regression, or a metric drop, to find what changed just before it. Set `date_from` and `date_to` (ISO 8601) around the incident. The default is the last 24 hours. Deploy annotations and releases can fill the page, so set `kinds` to `[\"feature_flag\", \"experiment\"]` to see only configuration edits. When `has_more` is true, narrow the window or set `kinds`. Changes the user has no access to are left out.","category": "Annotations","feature": "annotations","summary": "List recent production changes",diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 50516cc175d7..df052660b7b4 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -122833,6 +122833,10 @@ export namespace Schemas {* End of the time window (inclusive), ISO 8601. Defaults to now.*/date_to?: string;+ /**+ * Return only these kinds of change. Omit to return every kind. Use `feature_flag` and `experiment` to see configuration edits without releases and annotations.+ */+ kinds?: ChangeFeedListKindsItem[];/*** Maximum number of changes to return, newest first. Defaults to 100, at most 500.* @minimum 1@@ -122841,6 +122845,22 @@ export namespace Schemas {limit?: number;};+ /**+ * * `feature_flag` - Feature flag+ * * `experiment` - Experiment+ * * `release` - Release+ * * `annotation` - Annotation+ */+ export type ChangeFeedListKindsItem = typeof ChangeFeedListKindsItem[keyof typeof ChangeFeedListKindsItem];+++ export const ChangeFeedListKindsItem = {+ FeatureFlag: 'feature_flag',+ Experiment: 'experiment',+ Release: 'release',+ Annotation: 'annotation',+ } as const;+export type ChangeRequestsListParams = {action_key?: string;/**diff --git a/services/mcp/src/generated/annotations/api.ts b/services/mcp/src/generated/annotations/api.tsindex bbf29f23e5f0..a46ea30d76f4 100644--- a/services/mcp/src/generated/annotations/api.ts+++ b/services/mcp/src/generated/annotations/api.ts@@ -194,6 +194,7 @@ export const ChangeFeedListParams = () => zod.object({),})+export const changeFeedListQueryKindsDefault = []export const changeFeedListQueryLimitDefault = 100export const changeFeedListQueryLimitMax = 500@@ -206,6 +207,18 @@ export const ChangeFeedListQueryParams = () => zod.object({.datetime({ offset: true }).optional().describe('End of the time window (inclusive), ISO 8601. Defaults to now.'),+ kinds: zod+ .array(+ zod+ .enum(['feature_flag', 'experiment', 'release', 'annotation'])+ .describe(+ '\* `feature_flag` - Feature flag\n\* `experiment` - Experiment\n\* `release` - Release\n\* `annotation` - Annotation'+ )+ )+ .default(changeFeedListQueryKindsDefault)+ .describe(+ 'Return only these kinds of change. Omit to return every kind. Use `feature_flag` and `experiment` to see configuration edits without releases and annotations.'+ ),limit: zod.number().min(1)diff --git a/services/mcp/src/tools/generated/annotations.ts b/services/mcp/src/tools/generated/annotations.tsindex 46e9512c1fcc..d879d26033fe 100644--- a/services/mcp/src/tools/generated/annotations.ts+++ b/services/mcp/src/tools/generated/annotations.ts@@ -195,6 +195,7 @@ const changeFeedList = (): ToolBase<ReturnType<typeof ChangeFeedListSchema>, Schquery: {date_from: params.date_from,date_to: params.date_to,+ kinds: params.kinds,limit: params.limit,},})diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/change-feed-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/change-feed-list.jsonindex 6abc4d25dfc7..2b41d9fe95ee 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/change-feed-list.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/change-feed-list.json@@ -13,6 +13,16 @@"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$","type": "string"},+ "kinds": {+ "default": [],+ "description": "Return only these kinds of change. Omit to return every kind. Use `feature_flag` and `experiment` to see configuration edits without releases and annotations.",+ "items": {+ "description": "* `feature_flag` - Feature flag\n* `experiment` - Experiment\n* `release` - Release\n* `annotation` - Annotation",+ "enum": ["feature_flag", "experiment", "release", "annotation"],+ "type": "string"+ },+ "type": "array"+ },"limit": {"default": 100,"description": "Maximum number of changes to return, newest first. Defaults to 100, at most 500.",