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.

chore(experiments): tracking for health-check parity and launch findings (#114297)

Marcel Poelker657ab0602990
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts
index 267c92388e1a..0788694bf66b 100644
--- a/frontend/src/lib/utils/eventUsageLogic.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.ts
@@ -76,6 +76,7 @@ import {
import { captureBIWorksheetAction } from 'products/business_intelligence/frontend/biEditorAnalytics'
import { getExperimentStatus } from 'products/experiments/frontend/experimentStatus'
+import type { ExperimentViewedHealthProperties } from 'products/experiments/frontend/health/experimentHealthFindingEvents'
import type { ExperimentMetricUnion } from '../../queries/schema/schema-general'
import type { FunnelCorrelationResultsType, Realm, UserType } from '../../types'
@@ -1251,10 +1252,12 @@ export interface eventUsageLogicActions {
}
reportExperimentViewed: (
experiment: Experiment,
- duration: number | null
+ duration: number | null,
+ healthProperties: ExperimentViewedHealthProperties
) => {
duration: number | null
experiment: Experiment
+ healthProperties: ExperimentViewedHealthProperties
}
reportExperimentWatchCardSelected: (
experimentId: ExperimentIdType,
@@ -1959,7 +1962,11 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
hasSearch: boolean
archived: boolean
}) => listView,
- reportExperimentViewed: (experiment: Experiment, duration: number | null) => ({ experiment, duration }),
+ reportExperimentViewed: (
+ experiment: Experiment,
+ duration: number | null,
+ healthProperties: ExperimentViewedHealthProperties
+ ) => ({ experiment, duration, healthProperties }),
reportExperimentMetricBreakdownAdded: (
experiment: Experiment,
metricUuid: string,
@@ -2612,12 +2619,13 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
archived,
})
},
- reportExperimentViewed: ({ experiment, duration }) => {
+ reportExperimentViewed: ({ experiment, duration, healthProperties }) => {
posthog.capture('experiment viewed', {
...getEventPropertiesForExperiment(experiment),
experiment_id: experiment.id,
experiment_status: getExperimentStatus(experiment),
duration,
+ ...healthProperties,
})
},
reportExperimentMetricBreakdownAdded: ({ experiment, metricUuid, breakdown, isPrimary }) => {
diff --git a/frontend/src/scenes/experiments/experimentLogic.test.ts b/frontend/src/scenes/experiments/experimentLogic.test.ts
index 2e9d0b052568..a2d94637f33f 100644
--- a/frontend/src/scenes/experiments/experimentLogic.test.ts
+++ b/frontend/src/scenes/experiments/experimentLogic.test.ts
@@ -376,44 +376,92 @@ describe('experimentLogic', () => {
total_exposures: { control: 600, test: 350, $multiple: 50 },
sample_ratio_mismatch: { expected: { control: 475, test: 475 }, p_value: 0.0001 },
bias_risk: { multiple_variant_percentage: 5 },
+ health_findings: [{ code: 'srm' }, { code: 'bias_risk_multiple_excluded' }],
}
+ const noServerVerdicts = { srm_server: null, zero_exposures_server: null, bias_risk_server: null }
it.each([
{
desc: 'no exposure answer',
exposures: null,
handling: undefined,
- expected: { exposures_total: null, exposures_multiple: null, has_srm: null, has_bias_risk: null },
+ health: undefined,
+ expected: {
+ health_ui: 'warnings',
+ exposures_total: null,
+ exposures_multiple: null,
+ has_srm: null,
+ has_bias_risk: null,
+ ...noServerVerdicts,
+ },
},
{
- desc: 'an answer without exposures',
+ desc: 'an answer without exposures, cached before the server ran its checks',
exposures: { timeseries: [], total_exposures: {} },
handling: undefined,
- expected: { exposures_total: 0, exposures_multiple: 0, has_srm: false, has_bias_risk: false },
+ health: undefined,
+ expected: {
+ exposures_total: 0,
+ exposures_multiple: 0,
+ has_srm: false,
+ has_bias_risk: false,
+ ...noServerVerdicts,
+ },
},
{
desc: 'an uneven split with users in several variants',
exposures: unevenExposures,
handling: 'exclude' as const,
- expected: { exposures_total: 1000, exposures_multiple: 50, has_srm: true, has_bias_risk: true },
+ health: undefined,
+ expected: {
+ exposures_total: 1000,
+ exposures_multiple: 50,
+ has_srm: true,
+ has_bias_risk: true,
+ srm_server: true,
+ zero_exposures_server: false,
+ bias_risk_server: true,
+ },
},
{
desc: 'first-seen handling, which hides the users in several variants',
exposures: {
timeseries: [{ variant: 'control' }, { variant: 'test' }],
total_exposures: { control: 600, test: 400 },
+ health_findings: [],
},
handling: 'first_seen' as const,
- expected: { exposures_total: 1000, exposures_multiple: null, has_srm: false, has_bias_risk: false },
+ health: undefined,
+ expected: {
+ exposures_total: 1000,
+ exposures_multiple: null,
+ has_srm: false,
+ has_bias_risk: false,
+ srm_server: false,
+ zero_exposures_server: false,
+ bias_risk_server: false,
+ },
+ },
+ {
+ desc: 'a reader with health findings on a legacy experiment, and an answer where the server finds no exposure',
+ exposures: {
+ timeseries: [{ variant: 'control' }, { variant: 'test' }],
+ total_exposures: { control: 0, test: 0 },
+ health_findings: [{ code: 'zero_exposures' }],
+ },
+ handling: undefined,
+ health: { findings: [] },
+ expected: { health_ui: 'warnings', exposures_total: 0, zero_exposures_server: true },
},
])(
'reports the exposure state with the completed refresh: $desc',
- async ({ exposures, handling, expected }) => {
+ async ({ exposures, handling, health, expected }) => {
const captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)
// The fixture holds legacy metrics, so the refresh keeps the exposures that are set here.
logic.actions.setExperiment({
...experiment,
exposure_criteria: { ...experiment.exposure_criteria, multiple_variant_handling: handling },
+ health,
})
if (exposures) {
logic.actions.loadExposuresSuccess(exposures)
@@ -2796,6 +2844,8 @@ describe('experimentLogic', () => {
})
const running = { start_date: '2020-01-01', end_date: undefined }
+ // The fixture holds legacy metrics, and a legacy experiment never shows the health panel.
+ const newEngineMetrics = { metrics: [], metrics_secondary: [], saved_metrics: [] }
it.each<{ desc: string; overrides: Partial<Experiment>; expected: ExperimentWarning | null }>([
{
@@ -2982,6 +3032,63 @@ describe('experimentLogic', () => {
expect(logic.values.experimentWarning).toEqual(expected)
})
+ it.each<{ desc: string; overrides: Partial<Experiment>; expected: Record<string, unknown> }>([
+ {
+ desc: 'a server finding the local rules miss',
+ overrides: {
+ ...running,
+ ...newEngineMetrics,
+ feature_flag: flag(true, multivariantFilters),
+ health: { findings: [healthFinding('flag_off_while_running', 'running_but_flag_disabled')] },
+ },
+ expected: {
+ health_ui: 'panel',
+ health_finding_codes: ['flag_off_while_running'],
+ health_finding_count: 1,
+ flag_state_browser: null,
+ flag_state_server: 'running_but_flag_disabled',
+ no_metric_server: false,
+ },
+ },
+ {
+ desc: 'a server subcode the page does not know',
+ overrides: {
+ ...running,
+ feature_flag: flag(true, multivariantFilters),
+ health: { findings: [healthFinding('flag_off_while_running', 'running_but_flag_archived')] },
+ },
+ expected: { flag_state_browser: null, flag_state_server: 'running_but_flag_archived' },
+ },
+ {
+ desc: 'a reader with health findings on a legacy experiment, which shows the separate warnings',
+ overrides: { ...running, feature_flag: flag(true, multivariantFilters), health: { findings: [] } },
+ expected: { health_ui: 'warnings', health_finding_count: 0 },
+ },
+ {
+ desc: 'a reader without health findings',
+ overrides: { ...running, feature_flag: flag(false, multivariantFilters), health: null },
+ expected: {
+ health_ui: 'warnings',
+ health_finding_codes: null,
+ health_finding_count: null,
+ flag_state_browser: 'running_but_flag_disabled',
+ flag_state_server: null,
+ no_metric_server: null,
+ },
+ },
+ ])(
+ 'reports the local rules and the server checks with the experiment view: $desc',
+ ({ overrides, expected }) => {
+ const captureSpy = jest.spyOn(posthog, 'capture').mockReturnValue(undefined as any)
+
+ logic.actions.loadExperimentSuccess(createExperiment(overrides))
+
+ const viewedEvents = captureSpy.mock.calls.filter(([event]) => event === 'experiment viewed')
+ expect(viewedEvents).toHaveLength(1)
+ expect(viewedEvents[0][1]).toMatchObject(expected)
+ }
+ )
+
it('applies the local rules after a local flag write makes the server findings stale', () => {
logic.actions.setExperiment(
createExperiment({
@@ -3035,6 +3142,7 @@ describe('experimentLogic', () => {
experiment_days_since_start: null,
finding_code: 'flag_live_before_launch',
finding_variant: 'not_started_but_multiple_variants_rolled_out',
+ health_ui: 'warnings',
surface: 'experiment_page',
source: 'web',
},
@@ -3054,6 +3162,10 @@ describe('experimentLogic', () => {
id: 7,
status: ExperimentStatus.Running,
start_date: dayjs().subtract(3, 'day').toISOString(),
+ metrics: [],
+ metrics_secondary: [],
+ saved_metrics: [],
+ health: { findings: [] },
})
logic.actions.reportHealthFindingActedOn({ code: 'bias_risk_multiple_excluded' }, 'use_first_seen_variant')
@@ -3068,6 +3180,7 @@ describe('experimentLogic', () => {
experiment_days_since_start: 3,
finding_code: 'bias_risk_multiple_excluded',
finding_variant: null,
+ health_ui: 'panel',
surface: 'experiment_page',
source: 'web',
action_kind: 'use_first_seen_variant',
@@ -3091,6 +3204,7 @@ describe('experimentLogic', () => {
experiment_days_since_start: 3,
finding_code: 'zero_exposures',
finding_variant: null,
+ health_ui: 'warnings',
surface: 'experiment_page',
source: 'web',
}
diff --git a/frontend/src/scenes/experiments/experimentLogic.tsx b/frontend/src/scenes/experiments/experimentLogic.tsx
index 1a1f5d5dfe82..996df8c16a20 100644
--- a/frontend/src/scenes/experiments/experimentLogic.tsx
+++ b/frontend/src/scenes/experiments/experimentLogic.tsx
@@ -90,9 +90,12 @@ import {
type ExperimentHealthFinding,
type ExperimentHealthFindingActionKind,
type ExperimentHealthFindingOpenKind,
+ type ExperimentViewedHealthProperties,
captureExperimentHealthFindingActedOn,
captureExperimentHealthFindingOpened,
captureExperimentHealthFindingShown,
+ experimentHealthUi,
+ experimentHealthStateEventProperties,
experimentWarningFromHealth,
exposureHealthEventProperties,
} from 'products/experiments/frontend/health/experimentHealthFindingEvents'
@@ -714,10 +717,12 @@ export interface experimentLogicActions {
} // eventUsageLogic
reportExperimentViewed: (
experiment: Experiment,
- duration: number | null
+ duration: number | null,
+ healthProperties: ExperimentViewedHealthProperties
) => {
duration: number | null
experiment: Experiment
+ healthProperties: ExperimentViewedHealthProperties
} // eventUsageLogic
updateExperiments: (experiment: Experiment) => Experiment // experimentsLogic
setFeatureFlags: (
@@ -2329,7 +2334,16 @@ export const experimentLogic = kea<experimentLogicType>([
loadExperimentSuccess: async ({ experiment, payload }) => {
const duration = experiment?.start_date ? dayjs().diff(experiment.start_date, 'second') : null
// eslint-disable-next-line no-unused-expressions
- experiment && actions.reportExperimentViewed(experiment, duration)
+ experiment &&
+ actions.reportExperimentViewed(
+ experiment,
+ duration,
+ experimentHealthStateEventProperties(
+ experiment,
+ values.browserExperimentWarning,
+ values.browserNoMetricsWarning
+ )
+ )
// Load metrics for launched experiments (will set up auto-refresh after load completes).
// refreshExperimentResults branches on the recalculation feature flag internally.
@@ -2636,6 +2650,7 @@ export const experimentLogic = kea<experimentLogicType>([
experiment_status: values.experiment?.status ?? null,
total_metrics_count: primaryCount + secondaryCount,
execution_mode: getExperimentExecutionMode(values.featureFlags),
+ health_ui: experimentHealthUi(values.experiment),
...exposureHealthEventProperties(
values.exposures,
values.exposureCriteria?.multiple_variant_handling
diff --git a/products/experiments/backend/experiment_service.py b/products/experiments/backend/experiment_service.py
index a3a9ff41eda3..9f98cd97f0b6 100644
--- a/products/experiments/backend/experiment_service.py
+++ b/products/experiments/backend/experiment_service.py
@@ -51,6 +51,11 @@ from products.cohorts.backend.models.cohort import Cohort
from products.event_definitions.backend.models import EventDefinition, effective_project_id_expr
from products.experiments.backend.facade.launch_signals import experiment_launched
from products.experiments.backend.flag_cleanup import build_cleanup_prompt, cleanup_plan
+from products.experiments.backend.health.context import load_health_context
+from products.experiments.backend.health.registry import (
+ EXPERIMENT_HEALTH_CHECKS,
+ evaluate as evaluate_health,
+)
from products.experiments.backend.hogql_queries import CONTROL_VARIANT_KEY, get_baseline_variant_key
from products.experiments.backend.hogql_queries.experiment_metric_fingerprint import compute_metric_fingerprint
from products.experiments.backend.hogql_queries.exposure_query_logic import (
@@ -1365,6 +1370,8 @@ class ExperimentService:
# Every path saves the launch before it reports it, so an analytics failure must not fail the request.
try:
flag_age = timezone.now() - experiment.feature_flag.created_at
+ # Every launch reports the findings it leaves open, also for a launcher who has no health findings.
+ findings = evaluate_health(load_health_context(experiment), EXPERIMENT_HEALTH_CHECKS)
self._report_lifecycle_event(
experiment,
"experiment launched",
@@ -1374,6 +1381,8 @@ class ExperimentService:
"launch_date": experiment.start_date.isoformat() if experiment.start_date else None,
"launch_path": launch_path,
"flag_age_seconds": int(flag_age.total_seconds()),
+ "health_finding_codes": [finding.code.value for finding in findings],
+ "health_finding_count": len(findings),
},
)
except Exception:
diff --git a/products/experiments/backend/test/test_experiment_service.py b/products/experiments/backend/test/test_experiment_service.py
index 08b65f87f220..545ed34314c3 100644
--- a/products/experiments/backend/test/test_experiment_service.py
+++ b/products/experiments/backend/test/test_experiment_service.py
@@ -3803,7 +3803,7 @@ class TestExperimentService(APIBaseTest):
"launch_endpoint",
lambda self: self._create_launchable_experiment(name="Path L", feature_flag_key="path-launch-flag"),
lambda service, experiment, request: service.launch_experiment(experiment, request=request),
- [("launch_endpoint", 0)],
+ [("launch_endpoint", 0, [])],
),
(
"launch_endpoint_on_older_flag",
@@ -3811,7 +3811,7 @@ class TestExperimentService(APIBaseTest):
timedelta(days=3, hours=2), name="Path O", feature_flag_key="path-older-flag"
),
lambda service, experiment, request: service.launch_experiment(experiment, request=request),
- [("launch_endpoint", 266400)],
+ [("launch_endpoint", 266400, [])],
),
(
"create_with_start_date",
@@ -3822,7 +3822,7 @@ class TestExperimentService(APIBaseTest):
start_date=timezone.now(),
event_source=EventSource.API,
),
- [("create_request", 0)],
+ [("create_request", 0, ["no_metric"])],
),
(
"create_draft",
@@ -3838,7 +3838,7 @@ class TestExperimentService(APIBaseTest):
lambda service, experiment, request: service.update_experiment(
experiment, {"start_date": timezone.now()}, event_source=EventSource.API
),
- [("update_start_date", 0)],
+ [("update_start_date", 0, [])],
),
(
"update_moves_start_date_of_running",
@@ -3862,7 +3862,9 @@ class TestExperimentService(APIBaseTest):
launched = [
call.args[2] for call in mock_report_user_action.call_args_list if call.args[1] == "experiment launched"
]
- assert [(event["launch_path"], event["flag_age_seconds"]) for event in launched] == expected
+ assert [
+ (event["launch_path"], event["flag_age_seconds"], event["health_finding_codes"]) for event in launched
+ ] == expected
@parameterized.expand(
[
diff --git a/products/experiments/frontend/health/experimentHealthFindingEvents.ts b/products/experiments/frontend/health/experimentHealthFindingEvents.ts
index 63622714ef96..26b7869e55ec 100644
--- a/products/experiments/frontend/health/experimentHealthFindingEvents.ts
+++ b/products/experiments/frontend/health/experimentHealthFindingEvents.ts
@@ -1,13 +1,14 @@
import { dayjs } from 'lib/dayjs'
import posthog from 'lib/posthog-typed'
import type { ExperimentWarning, ExperimentWarningKey } from 'scenes/experiments/experimentLogic'
+import { isLegacyExperiment } from 'scenes/experiments/utils'
import type { ExperimentExposureCriteria, ExperimentExposureQueryResponse } from '~/queries/schema/schema-general'
import type { Experiment } from '~/types'
import { EXPERIMENT_VARIANT_MULTIPLE } from '../constants'
import { getExperimentStatus } from '../experimentStatus'
-import type { ExperimentHealthApi } from '../generated/api.schemas'
+import type { ExperimentHealthApi, ExperimentHealthFindingApi } from '../generated/api.schemas'
import { getTotalExposures, hasSampleRatioMismatch } from './exposureHealth'
// pinned: `finding_code` property values. Insights group and filter on them, so a rename breaks those insights.
@@ -51,6 +52,16 @@ export const FLAG_STATE_FINDING_CODES: ReadonlySet<ExperimentHealthFindingCode>
Object.values(EXPERIMENT_WARNING_FINDING_CODES)
)
+// pinned: `health_ui` property values. Insights compare the health panel with the separate warnings on them.
+export type ExperimentHealthUi = 'panel' | 'warnings'
+
+export function experimentHealthUi(experiment: Experiment): ExperimentHealthUi {
+ // The page shows the health panel only when the server sent health findings, which it does for readers
+ // with the experiment-health-findings flag. A legacy experiment opens the legacy view, which shows the
+ // separate warnings even then.
+ return experiment.health && !isLegacyExperiment(experiment) ? 'panel' : 'warnings'
+}
+
export function healthFindingForExperimentWarning(warningKey: ExperimentWarningKey): ExperimentHealthFinding {
return { code: EXPERIMENT_WARNING_FINDING_CODES[warningKey], variant: warningKey }
}
@@ -87,6 +98,7 @@ function healthFindingEventProperties(
experiment_days_since_start: experiment.start_date ? dayjs().diff(experiment.start_date, 'day') : null,
finding_code: finding.code,
finding_variant: finding.variant ?? null,
+ health_ui: experimentHealthUi(experiment),
surface: 'experiment_page',
// The value the backend reports for a request from the web app, so one breakdown covers both.
source: 'web',
@@ -124,9 +136,46 @@ export function captureExperimentHealthFindingActedOn(
})
}
+export interface ExperimentViewedHealthProperties {
+ health_ui: ExperimentHealthUi
+ health_finding_codes: ExperimentHealthFindingApi['code'][] | null
+ health_finding_count: number | null
+ flag_state_browser: string | null
+ flag_state_server: string | null
+ no_metric_browser: boolean
+ no_metric_server: boolean | null
+}
+
+/**
+ * The health state of one experiment load, for `experiment viewed`. A `_browser` value is the result of the
+ * page's own rule, and a `_server` value is the result of the server's check, so every load compares the two.
+ * The server values are null when the server sent no health findings.
+ */
+export function experimentHealthStateEventProperties(
+ experiment: Experiment,
+ browserWarning: ExperimentWarning | null,
+ browserNoMetricsWarning: boolean
+): ExperimentViewedHealthProperties {
+ const { health } = experiment
+ const flagStateFinding = health?.findings.find((finding) => FLAG_STATE_FINDING_CODES.has(finding.code))
+ return {
+ health_ui: experimentHealthUi(experiment),
+ health_finding_codes: health ? health.findings.map((finding) => finding.code) : null,
+ health_finding_count: health ? health.findings.length : null,
+ flag_state_browser: browserWarning?.key ?? null,
+ // The server sends the warning key as the subcode. A finding without one still differs from no finding.
+ flag_state_server: flagStateFinding ? (flagStateFinding.subcode ?? flagStateFinding.code) : null,
+ no_metric_browser: browserNoMetricsWarning,
+ no_metric_server: health ? health.findings.some((finding) => finding.code === 'no_metric') : null,
+ }
+}
+
/**
* The exposure warnings render on one tab only, so a "shown" event cannot give the exposure state of
* every load. `experiment results refresh completed` follows the exposure load on every tab.
+ * `has_srm`, `has_bias_risk` and a zero `exposures_total` are the page's own rules. The `_server` values are
+ * the server's checks on the same answer, null when the answer holds no server findings (a cached answer
+ * from before the server ran them).
*/
export function exposureHealthEventProperties(
exposures: ExperimentExposureQueryResponse | null | undefined,
@@ -136,10 +185,22 @@ export function exposureHealthEventProperties(
exposures_multiple: number | null
has_srm: boolean | null
has_bias_risk: boolean | null
+ srm_server: boolean | null
+ zero_exposures_server: boolean | null
+ bias_risk_server: boolean | null
} {
if (!exposures) {
- return { exposures_total: null, exposures_multiple: null, has_srm: null, has_bias_risk: null }
+ return {
+ exposures_total: null,
+ exposures_multiple: null,
+ has_srm: null,
+ has_bias_risk: null,
+ srm_server: null,
+ zero_exposures_server: null,
+ bias_risk_server: null,
+ }
}
+ const serverCodes = exposures.health_findings ? new Set(exposures.health_findings.map(({ code }) => code)) : null
return {
exposures_total: getTotalExposures(exposures),
// With "first seen" handling the exposure query gives each person their first variant and
@@ -150,5 +211,8 @@ export function exposureHealthEventProperties(
: Number(exposures.total_exposures?.[EXPERIMENT_VARIANT_MULTIPLE] || 0),
has_srm: hasSampleRatioMismatch(exposures),
has_bias_risk: exposures.bias_risk != null,
+ srm_server: serverCodes ? serverCodes.has('srm') : null,
+ zero_exposures_server: serverCodes ? serverCodes.has('zero_exposures') : null,
+ bias_risk_server: serverCodes ? serverCodes.has('bias_risk_multiple_excluded') : null,
}
}