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(early-access-features): show who created each feature (#72993)

Phil Haack8046c9fc352d
diff --git a/frontend/src/lib/lemon-ui/LemonTable/columnUtils.tsx b/frontend/src/lib/lemon-ui/LemonTable/columnUtils.tsx
index 17072c5f99ae..a3294c8720a6 100644
--- a/frontend/src/lib/lemon-ui/LemonTable/columnUtils.tsx
+++ b/frontend/src/lib/lemon-ui/LemonTable/columnUtils.tsx
@@ -55,7 +55,11 @@ export function createdByColumn<T extends { created_by?: UserBasicType | null }>
const { created_by } = item
return (
<div className="flex flex-row items-center flex-nowrap">
- {created_by && <ProfilePicture user={created_by} size="md" showName />}
+ {created_by ? (
+ <ProfilePicture user={created_by} size="md" showName />
+ ) : (
+ <span className="text-secondary">—</span>
+ )}
</div>
)
},
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 1d0876445b90..3b2961934bcd 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -4445,6 +4445,8 @@ export interface EarlyAccessFeatureType {
/** Custom JSON payload for the early access feature */
payload?: Record<string, any>
created_at: string
+ /** The user who created this feature. Null for features created before creator tracking was added. */
+ created_by?: UserBasicType | null
_create_in_folder?: string | null
/** The effective access level the user has for this early access feature. */
user_access_level?: AccessControlLevel
diff --git a/posthog/models/resource_transfer/test/__snapshots__/test_visitor_field_snapshots.ambr b/posthog/models/resource_transfer/test/__snapshots__/test_visitor_field_snapshots.ambr
index 3e4c4282f72f..28966ae9f717 100644
--- a/posthog/models/resource_transfer/test/__snapshots__/test_visitor_field_snapshots.ambr
+++ b/posthog/models/resource_transfer/test/__snapshots__/test_visitor_field_snapshots.ambr
@@ -368,6 +368,7 @@
# ---
# name: TestVisitorFieldSnapshots.test_relation_fields_EarlyAccessFeature
list([
+ 'created_by',
'feature_flag',
'team',
])
@@ -662,6 +663,7 @@
'__str__',
'_meta',
'created_at',
+ 'created_by_id',
'feature_flag_id',
'get_file_system_representation',
'get_file_system_unfiled',
diff --git a/products/early_access_features/backend/api.py b/products/early_access_features/backend/api.py
index d5554f4673d4..31a49452d00b 100644
--- a/products/early_access_features/backend/api.py
+++ b/products/early_access_features/backend/api.py
@@ -113,6 +113,11 @@ class EarlyAccessFeatureSerializer(UserAccessControlSerializerMixin, serializers
help_text="URL to external documentation for this feature. Shown to users in the opt-in UI.",
)
payload = serializers.SerializerMethodField()
+ created_by = UserBasicSerializer(
+ read_only=True,
+ allow_null=True,
+ help_text="The user who created this early access feature. Null for features created before creator tracking was added.",
+ )
class Meta:
model = EarlyAccessFeature
@@ -125,9 +130,10 @@ class EarlyAccessFeatureSerializer(UserAccessControlSerializerMixin, serializers
"documentation_url",
"payload",
"created_at",
+ "created_by",
"user_access_level",
]
- read_only_fields = ["id", "feature_flag", "created_at"]
+ read_only_fields = ["id", "feature_flag", "created_at", "created_by"]
@extend_schema_field(serializers.DictField(help_text="Feature flag payload for this early access feature"))
def get_payload(self, obj):
@@ -262,12 +268,13 @@ class EarlyAccessFeatureSerializerCreateOnly(EarlyAccessFeatureSerializer):
"documentation_url",
"payload",
"created_at",
+ "created_by",
"feature_flag_id",
"feature_flag",
"_create_in_folder",
"user_access_level",
]
- read_only_fields = ["id", "feature_flag", "created_at"]
+ read_only_fields = ["id", "feature_flag", "created_at", "created_by"]
def validate(self, data):
feature_flag_id = data.get("feature_flag_id", None)
@@ -299,6 +306,9 @@ class EarlyAccessFeatureSerializerCreateOnly(EarlyAccessFeatureSerializer):
def create(self, validated_data):
validated_data["team_id"] = self.context["team_id"]
+ request = self.context["request"]
+ validated_data["created_by"] = request.user if request.user.is_authenticated else None
+
feature_flag_id = validated_data.get("feature_flag_id", None)
default_condition = [
@@ -367,7 +377,7 @@ class EarlyAccessFeatureSerializerCreateOnly(EarlyAccessFeatureSerializer):
class EarlyAccessFeatureViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, viewsets.ModelViewSet):
scope_object = "early_access_feature"
- queryset = EarlyAccessFeature.objects.select_related("feature_flag").all()
+ queryset = EarlyAccessFeature.objects.select_related("feature_flag", "created_by").all()
def get_serializer_class(self) -> type[serializers.Serializer]:
if self.request.method == "POST":
diff --git a/products/early_access_features/backend/migrations/0007_earlyaccessfeature_created_by.py b/products/early_access_features/backend/migrations/0007_earlyaccessfeature_created_by.py
new file mode 100644
index 000000000000..3dc5e1509a25
--- /dev/null
+++ b/products/early_access_features/backend/migrations/0007_earlyaccessfeature_created_by.py
@@ -0,0 +1,28 @@
+# Generated manually
+
+import django.db.models.deletion
+from django.conf import settings
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("early_access_features", "0006_migrate_feature_flags_models"),
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="earlyaccessfeature",
+ name="created_by",
+ field=models.ForeignKey(
+ blank=True,
+ # db_constraint disabled to avoid locking the hot posthog_user table when adding this FK.
+ db_constraint=False,
+ null=True,
+ on_delete=django.db.models.deletion.SET_NULL,
+ related_name="early_access_features",
+ to=settings.AUTH_USER_MODEL,
+ ),
+ ),
+ ]
diff --git a/products/early_access_features/backend/migrations/0008_backfill_earlyaccessfeature_created_by.py b/products/early_access_features/backend/migrations/0008_backfill_earlyaccessfeature_created_by.py
new file mode 100644
index 000000000000..f196db29c40f
--- /dev/null
+++ b/products/early_access_features/backend/migrations/0008_backfill_earlyaccessfeature_created_by.py
@@ -0,0 +1,28 @@
+# Generated manually
+
+from django.db import migrations
+from django.db.models import OuterRef, Subquery
+
+
+def backfill_created_by(apps, schema_editor):
+ # Existing features predate creator tracking. The feature flag auto-created alongside each
+ # feature was created by the same user in the same request, so its created_by is a reliable
+ # best-effort source for the feature's creator.
+ EarlyAccessFeature = apps.get_model("early_access_features", "EarlyAccessFeature")
+ FeatureFlag = apps.get_model("feature_flags", "FeatureFlag")
+
+ flag_creator = FeatureFlag.objects.filter(id=OuterRef("feature_flag_id")).values("created_by_id")[:1]
+ EarlyAccessFeature.objects.filter(created_by__isnull=True, feature_flag__isnull=False).update(
+ created_by_id=Subquery(flag_creator)
+ )
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("early_access_features", "0007_earlyaccessfeature_created_by"),
+ ("feature_flags", "0002_migrate_feature_flags_models"),
+ ]
+
+ operations = [
+ migrations.RunPython(backfill_created_by, migrations.RunPython.noop, elidable=True),
+ ]
diff --git a/products/early_access_features/backend/migrations/max_migration.txt b/products/early_access_features/backend/migrations/max_migration.txt
index 83c91681da3a..932308544374 100644
--- a/products/early_access_features/backend/migrations/max_migration.txt
+++ b/products/early_access_features/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0006_migrate_feature_flags_models
+0008_backfill_earlyaccessfeature_created_by
diff --git a/products/early_access_features/backend/models.py b/products/early_access_features/backend/models.py
index 3f6c19645bad..2c432c7667c3 100644
--- a/products/early_access_features/backend/models.py
+++ b/products/early_access_features/backend/models.py
@@ -43,6 +43,15 @@ class EarlyAccessFeature(FileSystemSyncMixin, RootTeamMixin, UUIDTModel):
related_name="features",
related_query_name="feature",
)
+ created_by = models.ForeignKey(
+ "posthog.User",
+ on_delete=models.SET_NULL,
+ null=True,
+ blank=True,
+ related_name="early_access_features",
+ # db_constraint disabled to avoid locking the hot posthog_user table when adding this FK.
+ db_constraint=False,
+ )
name = models.CharField(max_length=200)
description = models.TextField(blank=True)
stage = models.CharField(max_length=40, choices=Stage)
@@ -69,7 +78,7 @@ class EarlyAccessFeature(FileSystemSyncMixin, RootTeamMixin, UUIDTModel):
href=f"/early_access_features/{self.id}",
meta={
"created_at": str(self.created_at),
- "created_by": None,
+ "created_by": self.created_by_id,
},
should_delete=False,
)
diff --git a/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr b/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr
index 3ef79c13e987..20daa692bccf 100644
--- a/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr
+++ b/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr
@@ -150,6 +150,7 @@
SELECT "posthog_earlyaccessfeature"."id",
"posthog_earlyaccessfeature"."team_id",
"posthog_earlyaccessfeature"."feature_flag_id",
+ "posthog_earlyaccessfeature"."created_by_id",
"posthog_earlyaccessfeature"."name",
"posthog_earlyaccessfeature"."description",
"posthog_earlyaccessfeature"."stage",
@@ -611,6 +612,7 @@
SELECT "posthog_earlyaccessfeature"."id",
"posthog_earlyaccessfeature"."team_id",
"posthog_earlyaccessfeature"."feature_flag_id",
+ "posthog_earlyaccessfeature"."created_by_id",
"posthog_earlyaccessfeature"."name",
"posthog_earlyaccessfeature"."description",
"posthog_earlyaccessfeature"."stage",
@@ -891,6 +893,7 @@
SELECT "posthog_earlyaccessfeature"."id",
"posthog_earlyaccessfeature"."team_id",
"posthog_earlyaccessfeature"."feature_flag_id",
+ "posthog_earlyaccessfeature"."created_by_id",
"posthog_earlyaccessfeature"."name",
"posthog_earlyaccessfeature"."description",
"posthog_earlyaccessfeature"."stage",
@@ -1069,6 +1072,7 @@
SELECT "posthog_earlyaccessfeature"."id",
"posthog_earlyaccessfeature"."team_id",
"posthog_earlyaccessfeature"."feature_flag_id",
+ "posthog_earlyaccessfeature"."created_by_id",
"posthog_earlyaccessfeature"."name",
"posthog_earlyaccessfeature"."description",
"posthog_earlyaccessfeature"."stage",
diff --git a/products/early_access_features/backend/test/test_early_access_feature.py b/products/early_access_features/backend/test/test_early_access_feature.py
index b73885916ffe..ab77b141f150 100644
--- a/products/early_access_features/backend/test/test_early_access_feature.py
+++ b/products/early_access_features/backend/test/test_early_access_feature.py
@@ -94,6 +94,8 @@ class TestEarlyAccessFeature(APIBaseTest):
assert len(response_data["feature_flag"]["filters"]["groups"]) == 1
assert response_data["feature_flag"]["filters"]["groups"][0]["rollout_percentage"] == 0
assert isinstance(response_data["created_at"], str)
+ assert response_data["created_by"]["id"] == self.user.id
+ assert EarlyAccessFeature.objects.get(id=response_data["id"]).created_by_id == self.user.id
def test_can_create_early_access_feature_in_alpha_stage(self):
response = self.client.post(
@@ -659,6 +661,7 @@ class TestEarlyAccessFeature(APIBaseTest):
"results": [
{
"created_at": ANY,
+ "created_by": None,
"description": "A revolution in usability research: now you can count clicks!",
"documentation_url": "",
"feature_flag": None,
diff --git a/products/early_access_features/backend/test/test_migration_backfill.py b/products/early_access_features/backend/test/test_migration_backfill.py
new file mode 100644
index 000000000000..a1bd43d0dd37
--- /dev/null
+++ b/products/early_access_features/backend/test/test_migration_backfill.py
@@ -0,0 +1,32 @@
+import importlib
+
+from posthog.test.base import APIBaseTest
+
+from django.apps import apps
+
+from products.early_access_features.backend.models import EarlyAccessFeature
+from products.feature_flags.backend.models.feature_flag import FeatureFlag
+
+m8 = importlib.import_module(
+ "products.early_access_features.backend.migrations.0008_backfill_earlyaccessfeature_created_by"
+)
+
+
+class TestEarlyAccessFeatureCreatedByBackfill(APIBaseTest):
+ def test_backfills_from_flag_creator_and_leaves_others_untouched(self) -> None:
+ other_user = self._create_user("[email protected]")
+ flag = FeatureFlag.objects.create(team=self.team, key="flag-with-creator", created_by=other_user)
+ unset = EarlyAccessFeature.objects.create(team=self.team, name="unset", stage="beta", feature_flag=flag)
+ already_set = EarlyAccessFeature.objects.create(
+ team=self.team, name="already-set", stage="beta", feature_flag=flag, created_by=self.user
+ )
+ flagless = EarlyAccessFeature.objects.create(team=self.team, name="flagless", stage="beta")
+
+ m8.backfill_created_by(apps, None)
+
+ unset.refresh_from_db()
+ already_set.refresh_from_db()
+ flagless.refresh_from_db()
+ assert unset.created_by_id == other_user.id
+ assert already_set.created_by_id == self.user.id
+ assert flagless.created_by_id is None
diff --git a/products/early_access_features/frontend/EarlyAccessFeatures.stories.tsx b/products/early_access_features/frontend/EarlyAccessFeatures.stories.tsx
index cf6915ec302e..41e3d5c4d681 100644
--- a/products/early_access_features/frontend/EarlyAccessFeatures.stories.tsx
+++ b/products/early_access_features/frontend/EarlyAccessFeatures.stories.tsx
@@ -56,6 +56,13 @@ const EARLY_ACCESS_FEATURE_RESULT = [
stage: 'alpha',
documentation_url: '',
created_at: '2023-04-27T10:04:37.977401Z',
+ created_by: {
+ id: 1,
+ uuid: '0187c22c-06d9-0000-34fe-000000000000',
+ distinct_id: 'abc',
+ first_name: 'Ada',
+ email: '[email protected]',
+ },
},
{
id: '0187c279-bcae-0000-34f5-4f121921f005',
diff --git a/products/early_access_features/frontend/EarlyAccessFeatures.tsx b/products/early_access_features/frontend/EarlyAccessFeatures.tsx
index 1bb730e4aeff..11ad93ebdca8 100644
--- a/products/early_access_features/frontend/EarlyAccessFeatures.tsx
+++ b/products/early_access_features/frontend/EarlyAccessFeatures.tsx
@@ -6,7 +6,9 @@ import { LemonButton, LemonInput, LemonTable, LemonTag } from '@posthog/lemon-ui
import { ProductIntroduction } from 'lib/components/ProductIntroduction/ProductIntroduction'
import { Shortcut } from 'lib/components/Shortcuts/Shortcut'
import { keyBinds } from 'lib/components/Shortcuts/shortcuts'
+import { createdAtColumn, createdByColumn } from 'lib/lemon-ui/LemonTable/columnUtils'
import { LemonTableLink } from 'lib/lemon-ui/LemonTable/LemonTableLink'
+import { LemonTableColumn } from 'lib/lemon-ui/LemonTable/types'
import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
import { sceneConfigurations } from 'scenes/scenes'
import { Scene, SceneExport } from 'scenes/sceneTypes'
@@ -136,6 +138,14 @@ export function EarlyAccessFeatures(): JSX.Element {
},
sorter: (a, b) => STAGES_IN_ORDER[a.stage] - STAGES_IN_ORDER[b.stage],
},
+ createdByColumn<EarlyAccessFeatureType>() as LemonTableColumn<
+ EarlyAccessFeatureType,
+ keyof EarlyAccessFeatureType | undefined
+ >,
+ createdAtColumn<EarlyAccessFeatureType>() as LemonTableColumn<
+ EarlyAccessFeatureType,
+ keyof EarlyAccessFeatureType | undefined
+ >,
]}
dataSource={filteredEarlyAccessFeatures}
emptyState={
diff --git a/products/early_access_features/frontend/generated/api.schemas.ts b/products/early_access_features/frontend/generated/api.schemas.ts
index 76b5e93a120d..20a4428d5bc3 100644
--- a/products/early_access_features/frontend/generated/api.schemas.ts
+++ b/products/early_access_features/frontend/generated/api.schemas.ts
@@ -89,6 +89,55 @@ export const StageEnumApi = {
Archived: 'archived',
} as const
+/**
+ * * `engineering` - Engineering
+ * * `data` - Data
+ * * `product` - Product Management
+ * * `founder` - Founder
+ * * `leadership` - Leadership
+ * * `marketing` - Marketing
+ * * `sales` - Sales / Success
+ * * `other` - Other
+ */
+export type RoleAtOrganizationEnumApi = (typeof RoleAtOrganizationEnumApi)[keyof typeof RoleAtOrganizationEnumApi]
+
+export const RoleAtOrganizationEnumApi = {
+ Engineering: 'engineering',
+ Data: 'data',
+ Product: 'product',
+ Founder: 'founder',
+ Leadership: 'leadership',
+ Marketing: 'marketing',
+ Sales: 'sales',
+ Other: 'other',
+} as const
+
+/**
+ * @nullable
+ */
+export type UserBasicApiHedgehogConfig = { [key: string]: unknown } | null
+
+export interface UserBasicApi {
+ readonly id: number
+ readonly uuid: string
+ /**
+ * @maxLength 200
+ * @nullable
+ */
+ distinct_id?: string | null
+ /** @maxLength 150 */
+ first_name?: string
+ /** @maxLength 150 */
+ last_name?: string
+ /** @maxLength 254 */
+ email: string
+ /** @nullable */
+ is_email_verified?: boolean | null
+ /** @nullable */
+ readonly hedgehog_config: UserBasicApiHedgehogConfig
+ role_at_organization?: RoleAtOrganizationEnumApi | BlankEnumApi | null
+}
+
/**
* Feature flag payload for this early access feature
*/
@@ -124,6 +173,8 @@ export interface EarlyAccessFeatureApi {
/** Feature flag payload for this early access feature */
readonly payload: EarlyAccessFeatureApiPayload
readonly created_at: string
+ /** The user who created this early access feature. Null for features created before creator tracking was added. */
+ readonly created_by: UserBasicApi | null
/**
* The effective access level the user has for this object
* @nullable
@@ -169,6 +220,8 @@ export interface EarlyAccessFeatureSerializerCreateOnlyApi {
/** Arbitrary JSON metadata associated with this feature. */
payload?: unknown
readonly created_at: string
+ /** The user who created this early access feature. Null for features created before creator tracking was added. */
+ readonly created_by: UserBasicApi | null
/** Optional ID of an existing feature flag to link. If omitted, a new flag is auto-created from the feature name. The flag must not already be linked to another feature, must not be group-based, and must not be multivariate. */
feature_flag_id?: number
readonly feature_flag: MinimalFeatureFlagApi
@@ -215,6 +268,8 @@ export interface PatchedEarlyAccessFeatureApi {
/** Feature flag payload for this early access feature */
readonly payload?: PatchedEarlyAccessFeatureApiPayload
readonly created_at?: string
+ /** The user who created this early access feature. Null for features created before creator tracking was added. */
+ readonly created_by?: UserBasicApi | null
/**
* The effective access level the user has for this object
* @nullable
diff --git a/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr b/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr
index ab5f8bd98b24..f960f57ddd8a 100644
--- a/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr
+++ b/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr
@@ -2032,6 +2032,7 @@
SELECT "posthog_earlyaccessfeature"."id",
"posthog_earlyaccessfeature"."team_id",
"posthog_earlyaccessfeature"."feature_flag_id",
+ "posthog_earlyaccessfeature"."created_by_id",
"posthog_earlyaccessfeature"."name",
"posthog_earlyaccessfeature"."description",
"posthog_earlyaccessfeature"."stage",
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 268e93098fa5..3b0a9bfaeca5 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -22358,6 +22358,8 @@ export namespace Schemas {
/** Feature flag payload for this early access feature */
readonly payload: EarlyAccessFeaturePayload;
readonly created_at: string;
+ /** The user who created this early access feature. Null for features created before creator tracking was added. */
+ readonly created_by: UserBasic | null;
/**
* The effective access level the user has for this object
* @nullable
@@ -22394,6 +22396,8 @@ export namespace Schemas {
/** Arbitrary JSON metadata associated with this feature. */
payload?: unknown;
readonly created_at: string;
+ /** The user who created this early access feature. Null for features created before creator tracking was added. */
+ readonly created_by: UserBasic | null;
/** Optional ID of an existing feature flag to link. If omitted, a new flag is auto-created from the feature name. The flag must not already be linked to another feature, must not be group-based, and must not be multivariate. */
feature_flag_id?: number;
readonly feature_flag: MinimalFeatureFlag;
@@ -47475,6 +47479,8 @@ export namespace Schemas {
/** Feature flag payload for this early access feature */
readonly payload?: PatchedEarlyAccessFeaturePayload;
readonly created_at?: string;
+ /** The user who created this early access feature. Null for features created before creator tracking was added. */
+ readonly created_by?: UserBasic | null;
/**
* The effective access level the user has for this object
* @nullable