: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(experiments): Log freeze and unfreeze exposure in History (#78938)
Juraj Majerik916584d3cace
diff --git a/frontend/src/scenes/experiments/experimentActivityDescriber.test.tsx b/frontend/src/scenes/experiments/experimentActivityDescriber.test.tsxindex 28a2bc69bac6..6fd1bd54ae79 100644--- a/frontend/src/scenes/experiments/experimentActivityDescriber.test.tsx+++ b/frontend/src/scenes/experiments/experimentActivityDescriber.test.tsx@@ -65,6 +65,20 @@ describe('experimentActivityDescriber', () => {})})+ describe('exposure freeze rows', () => {+ it.each([+ { activity: 'exposure_frozen', expectedFragment: 'froze exposure for', notExpected: 'unfroze' },+ { activity: 'exposure_unfrozen', expectedFragment: 'unfroze exposure for', notExpected: 'unknown action' },+ ])('$activity: "$expectedFragment experiment name"', ({ activity, expectedFragment, notExpected }) => {+ const result = experimentActivityDescriber(baseLogItem({ activity }))+ const text = textOf(result)+ expect(text).toContain('Alice Adams')+ expect(text).toContain(expectedFragment)+ expect(text).toContain('Checkout funnel')+ expect(text).not.toContain(notExpected)+ })+ })+describe('metric reorder rows on the experiment scope', () => {it.each([{diff --git a/frontend/src/scenes/experiments/experimentActivityDescriber.tsx b/frontend/src/scenes/experiments/experimentActivityDescriber.tsxindex 7c5342a22cc0..c6eb7e7aff8c 100644--- a/frontend/src/scenes/experiments/experimentActivityDescriber.tsx+++ b/frontend/src/scenes/experiments/experimentActivityDescriber.tsx@@ -265,6 +265,28 @@ export const experimentActivityDescriber = (logItem: ActivityLogItem): Humanized),}})+ .with({ activity: 'exposure_frozen' }, ({ item_id, detail }) => {+ return {+ description: (+ <SentenceList+ prefix={<strong className="ph-no-capture">{userNameForLogItem(logItem)}</strong>}+ listParts={['froze exposure for']}+ suffix={nameOrLinkToExperiment(detail.name, item_id)}+ />+ ),+ }+ })+ .with({ activity: 'exposure_unfrozen' }, ({ item_id, detail }) => {+ return {+ description: (+ <SentenceList+ prefix={<strong className="ph-no-capture">{userNameForLogItem(logItem)}</strong>}+ listParts={['unfroze exposure for']}+ suffix={nameOrLinkToExperiment(detail.name, item_id)}+ />+ ),+ }+ }).with({ activity: 'updated' }, ({ item_id, detail: updateLogDetail }) => {/*** This is the catch all for all experiment updatesdiff --git a/products/experiments/backend/experiment_service.py b/products/experiments/backend/experiment_service.pyindex 1e69895c349d..f2ab7ddba5b2 100644--- a/products/experiments/backend/experiment_service.py+++ b/products/experiments/backend/experiment_service.py@@ -43,6 +43,8 @@ from posthog.exceptions import (ClickHouseQueryMemoryLimitExceeded,ClickHouseQueryTimeOut,)+from posthog.models.activity_logging.activity_log import Detail, log_activity+from posthog.models.activity_logging.model_activity import is_impersonated_sessionfrom posthog.models.activity_logging.utils import get_changed_fields_localfrom posthog.models.filters.filter import Filterfrom posthog.models.person.util import get_person_ids_and_uuids_by_uuids@@ -2277,6 +2279,19 @@ class ExperimentService:# end_date intentionally left null — metrics keep flowing.+ # The flag write above logs under the FeatureFlag scope only; without this entry the+ # experiment's History tab shows nothing for the freeze.+ log_activity(+ organization_id=self.team.organization_id,+ team_id=self.team.pk,+ user=self.user,+ was_impersonated=is_impersonated_session(request),+ item_id=experiment.pk,+ scope="Experiment",+ activity="exposure_frozen",+ detail=Detail(name=experiment.name),+ )+self._report_lifecycle_event(experiment, "experiment exposure frozen", request=request)# flag_save_ms includes the transaction commit, so it carries the on-commit flag cache@@ -2535,6 +2550,17 @@ class ExperimentService:self._delete_orphaned_snapshot_cohorts(cohort_ids)cohort_cleanup_done_at = time.monotonic()+ log_activity(+ organization_id=self.team.organization_id,+ team_id=self.team.pk,+ user=self.user,+ was_impersonated=is_impersonated_session(request),+ item_id=experiment.pk,+ scope="Experiment",+ activity="exposure_unfrozen",+ detail=Detail(name=experiment.name),+ )+self._report_lifecycle_event(experiment, "experiment exposure unfrozen", request=request)# flag_save_ms carries the on-commit flag cache rebuilds; cohort_cleanup_ms carries thediff --git a/products/experiments/backend/test/test_experiment_service.py b/products/experiments/backend/test/test_experiment_service.pyindex f79d3316a50b..a8e975ba2cb7 100644--- a/products/experiments/backend/test/test_experiment_service.py+++ b/products/experiments/backend/test/test_experiment_service.py@@ -3669,6 +3669,12 @@ class TestExperimentService(APIBaseTest):assert frozen.is_running is Trueassert frozen.is_exposure_frozen is True+ # The freeze shows up in the experiment's History tab, not only under the flag's scope.+ log = ActivityLog.objects.get(scope="Experiment", item_id=str(experiment.pk), activity="exposure_frozen")+ assert log.user == self.user+ assert log.detail is not None+ assert log.detail["name"] == "Freeze Exposure"+def test_freeze_exposure_multi_group_flag(self):experiment = self._create_running_experiment(name="Freeze Multi", feature_flag_key="freeze-multi-flag")flag = experiment.feature_flag@@ -4187,6 +4193,12 @@ class TestExperimentService(APIBaseTest):cohort.refresh_from_db()assert cohort.deleted is True+ # The unfreeze shows up in the experiment's History tab, not only under the flag's scope.+ log = ActivityLog.objects.get(scope="Experiment", item_id=str(experiment.pk), activity="exposure_unfrozen")+ assert log.user == self.user+ assert log.detail is not None+ assert log.detail["name"] == "Unfreeze Test"+def test_unfreeze_exposure_keeps_user_edits_made_while_frozen(self) -> None:experiment = self._create_running_experiment(name="Unfreeze Edits", feature_flag_key="unfreeze-edits-flag")