: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(ingestion): let teams be excluded from the personless default (#98053)
Phil Haackddcc71252b5b
diff --git a/nodejs/src/ingestion/common/persons/flag-called-personless.test.ts b/nodejs/src/ingestion/common/persons/flag-called-personless.test.tsindex 862f7c50325f..4074448cd6b3 100644--- a/nodejs/src/ingestion/common/persons/flag-called-personless.test.ts+++ b/nodejs/src/ingestion/common/persons/flag-called-personless.test.ts@@ -1,6 +1,10 @@import { PluginEvent } from '~/plugin-scaffold'-import { eventHasGroups, isFlagCalledPersonlessCandidate } from './flag-called-personless'+import {+ buildFlagCalledPersonlessMatcher,+ eventHasGroups,+ isFlagCalledPersonlessCandidate,+} from './flag-called-personless'describe('flag-called-personless', () => {const enabledForAll = (): boolean => true@@ -25,6 +29,20 @@ describe('flag-called-personless', () => {})})+ describe('buildFlagCalledPersonlessMatcher', () => {+ it.each<[string, string, number, boolean]>([+ ['', '', 1, false],+ ['*', '', 1, true],+ ['*', '1', 1, false],+ ['*', '1', 2, true],+ ['1,2', '2', 1, true],+ ['1,2', '2', 2, false],+ ['*', '*', 1, false],+ ])('allowlist %j, excluded %j, team %i -> %s', (allowlist, excluded, teamId, expected) => {+ expect(buildFlagCalledPersonlessMatcher(allowlist, excluded)(teamId)).toBe(expected)+ })+ })+describe('isFlagCalledPersonlessCandidate', () => {it('is a candidate for a flag-called event on an enabled team', () => {expect(isFlagCalledPersonlessCandidate(event(), 1, false, enabledForAll)).toBe(true)diff --git a/nodejs/src/ingestion/common/persons/flag-called-personless.ts b/nodejs/src/ingestion/common/persons/flag-called-personless.tsindex e73ef32f2da2..188cbeb971a4 100644--- a/nodejs/src/ingestion/common/persons/flag-called-personless.ts+++ b/nodejs/src/ingestion/common/persons/flag-called-personless.ts@@ -1,19 +1,35 @@-import { buildIntegerMatcher } from '~/common/config/config'-import { DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS } from '~/ingestion/config'+import { parseTeamsList } from '~/common/utils/env-utils'+import { logger } from '~/common/utils/logger'+import { buildTeamGate } from '~/ingestion/common/team-gate'+import {+ DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,+ DEFAULT_FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS,+} from '~/ingestion/config'import { PluginEvent } from '~/plugin-scaffold'+import { ValueMatcher } from '~/types'export const FEATURE_FLAG_CALLED_EVENT = '$feature_flag_called'/**- * Builds the team matcher for the $feature_flag_called personless default. The per-event step- * and the batch step both gate on team eligibility and must agree, so they share this one- * construction site — a divergent trim/star/default here would desync the two phases (the- * batch step would insert rows the per-event step never claims, or vice versa).+ * Builds the team matcher for the $feature_flag_called personless default (see #60581).+ *+ * The exclusion list holds a team back from an allowlist of '*', which is what lets the+ * default go fleet-wide at all. A team whose running experiment breaks down by a person+ * property that its flag-called events carry loses that breakdown once those events go+ * personless, so it is named here instead of enumerating every other team.*/export function buildFlagCalledPersonlessMatcher(- flagCalledPersonlessDefaultTeams: string = DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS-): (teamId: number) => boolean {- return buildIntegerMatcher(flagCalledPersonlessDefaultTeams.trim(), true)+ flagCalledPersonlessDefaultTeams: string = DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,+ flagCalledPersonlessExcludedTeams: string = DEFAULT_FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS+): ValueMatcher<number> {+ const excludedTeams = parseTeamsList(flagCalledPersonlessExcludedTeams)+ if (excludedTeams === '*') {+ // An operator's '*' exclusion means "off": the escape hatch fails toward leaving+ // person processing alone.+ logger.warn('FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS is "*", disabling the personless default')+ return () => false+ }+ return buildTeamGate(parseTeamsList(flagCalledPersonlessDefaultTeams), excludedTeams)}/**@@ -33,10 +49,9 @@ export function eventHasGroups(properties: PluginEvent['properties']): boolean {* Whether a $feature_flag_called event should default to personless so server-side flag* evaluation does not create orphan person profiles (see #60581).*- * `processPersonExplicitlyTrue` must be supplied by the caller because the per-event step- * runs after normalizeProcessPerson has stripped $process_person_profile, while the batch- * step reads it from the raw event — each reads the signal from the source valid in its- * pipeline phase.+ * `processPersonExplicitlyTrue` must be supplied by the caller. normalizeProcessPerson+ * rewrites $process_person_profile before this runs, so the event no longer shows whether+ * the client set it to true.*/export function isFlagCalledPersonlessCandidate(event: Pick<PluginEvent, 'event' | 'properties'>,diff --git a/nodejs/src/ingestion/common/steps/event-processing/event-pipeline-options.ts b/nodejs/src/ingestion/common/steps/event-processing/event-pipeline-options.tsindex 3ceea0be697b..777b22848e71 100644--- a/nodejs/src/ingestion/common/steps/event-processing/event-pipeline-options.ts+++ b/nodejs/src/ingestion/common/steps/event-processing/event-pipeline-options.ts@@ -9,6 +9,8 @@ export interface EventPipelineRunnerOptions {PERSON_PROPERTIES_UPDATE_ALL: boolean/** Teams whose $feature_flag_called events default to personless: '*' for all, '' to disable, or comma-separated team IDs */FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS: string+ /** Teams held back from the personless default even when the allowlist is '*': '' for none, '*' to disable the default for every team, or comma-separated team IDs */+ FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS: string/** Teams whose multivariate $feature_flag_called events are duplicated as $experiment_exposure: '*' for all, '' to disable, or comma-separated team IDs */EXPERIMENT_EXPOSURE_DUPLICATION_TEAMS: string}diff --git a/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.test.ts b/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.test.tsindex 53955a90b347..4ddc0d21d65f 100644--- a/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.test.ts+++ b/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.test.ts@@ -221,6 +221,20 @@ describe('createProcessPersonlessStep', () => {expect(fetchForCheckingSpy).not.toHaveBeenCalled()})+ it('keeps the event personful when the team is excluded', async () => {+ const fetchForCheckingSpy = jest.spyOn(personsStore, 'fetchForChecking')++ const step = createProcessPersonlessStep('*', `${teamId}`)+ const result = await step(createInput({ processPerson: true, normalizedEvent: flagCalledEvent() }))++ expect(result.type).toBe(PipelineResultType.OK)+ if (isOkResult(result)) {+ expect(result.value.processPerson).toBe(true)+ expect(result.value.personlessPerson).toBeUndefined()+ }+ expect(fetchForCheckingSpy).not.toHaveBeenCalled()+ })+it('applies the default when the team is in the configured team list', async () => {const step = createProcessPersonlessStep(`${teamId}`)const result = await step(createInput({ processPerson: true, normalizedEvent: flagCalledEvent() }))diff --git a/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.ts b/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.tsindex 87ead7c71170..27e5cbb48b79 100644--- a/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.ts+++ b/nodejs/src/ingestion/common/steps/event-processing/process-personless-step.ts@@ -7,7 +7,10 @@ import {} from '~/ingestion/common/persons/flag-called-personless'import { uuidFromDistinctId } from '~/ingestion/common/persons/person-uuid'import { PersonsStoreForBatch } from '~/ingestion/common/persons/persons-store-for-batch'-import { DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS } from '~/ingestion/config'+import {+ DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,+ DEFAULT_FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS,+} from '~/ingestion/config'import { PipelineResult, ok } from '~/ingestion/framework/results'import { ProcessingStep } from '~/ingestion/framework/steps'import { PluginEvent } from '~/plugin-scaffold'@@ -41,9 +44,13 @@ export type ProcessPersonlessOutput = {* 3. Returns person (real or fake) with potential force_upgrade flag*/export function createProcessPersonlessStep<TInput extends ProcessPersonlessInput>(- flagCalledPersonlessDefaultTeams: string = DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS+ flagCalledPersonlessDefaultTeams: string = DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,+ flagCalledPersonlessExcludedTeams: string = DEFAULT_FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS): ProcessingStep<TInput, TInput & ProcessPersonlessOutput> {- const flagCalledDefaultEnabledForTeam = buildFlagCalledPersonlessMatcher(flagCalledPersonlessDefaultTeams)+ const flagCalledDefaultEnabledForTeam = buildFlagCalledPersonlessMatcher(+ flagCalledPersonlessDefaultTeams,+ flagCalledPersonlessExcludedTeams+ )return async function processPersonlessStep(input: TInputdiff --git a/nodejs/src/ingestion/config.ts b/nodejs/src/ingestion/config.tsindex b1f8926279c1..3dcaaa371bdb 100644--- a/nodejs/src/ingestion/config.ts+++ b/nodejs/src/ingestion/config.ts@@ -26,6 +26,9 @@ import {/** Default for FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS: '' disables the personless default so it is opt-in per team via config. */export const DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS = ''+/** Default for FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS: '' excludes nobody, so the allowlist alone decides. */+export const DEFAULT_FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS = ''+// =============================================================================// Infrastructure sub-config types// These group CommonConfig keys by infrastructure concern for use in server@@ -248,6 +251,8 @@ export type IngestionConsumerConfig = {KAFKA_BATCH_START_LOGGING_ENABLED: boolean/** Teams whose $feature_flag_called events default to personless: '*' for all, '' to disable, or comma-separated team IDs */FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS: string+ /** Teams held back from the personless default even when the allowlist is '*': '' for none, '*' to disable the default for every team, or comma-separated team IDs */+ FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS: string/** Teams whose multivariate $feature_flag_called events are duplicated as $experiment_exposure: '*' for all, '' to disable, or comma-separated team IDs */EXPERIMENT_EXPOSURE_DUPLICATION_TEAMS: string@@ -412,6 +417,7 @@ export function getDefaultIngestionConsumerConfig(): IngestionConsumerConfig {EVENT_SCHEMA_ENFORCEMENT_ENABLED: true,KAFKA_BATCH_START_LOGGING_ENABLED: false,FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS: DEFAULT_FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,+ FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS: DEFAULT_FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS,EXPERIMENT_EXPOSURE_DUPLICATION_TEAMS: '',// $feature_flag_called fork into the flag_evaluations ClickHouse table.diff --git a/nodejs/src/ingestion/ingestion-consumer.ts b/nodejs/src/ingestion/ingestion-consumer.tsindex 41c071e8e606..407b0fc56519 100644--- a/nodejs/src/ingestion/ingestion-consumer.ts+++ b/nodejs/src/ingestion/ingestion-consumer.ts@@ -316,6 +316,7 @@ export class IngestionConsumer {PERSON_JSONB_SIZE_ESTIMATE_ENABLE: this.config.PERSON_JSONB_SIZE_ESTIMATE_ENABLE,PERSON_PROPERTIES_UPDATE_ALL: this.config.PERSON_PROPERTIES_UPDATE_ALL,FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS: this.config.FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,+ FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS: this.config.FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS,EXPERIMENT_EXPOSURE_DUPLICATION_TEAMS: this.config.EXPERIMENT_EXPOSURE_DUPLICATION_TEAMS,},concurrentBatches: this.config.INGESTION_WORKER_CONCURRENT_BATCHES,diff --git a/nodejs/src/ingestion/pipelines/analytics/event-subpipeline.ts b/nodejs/src/ingestion/pipelines/analytics/event-subpipeline.tsindex 1b4cd4980973..521ca1713e32 100644--- a/nodejs/src/ingestion/pipelines/analytics/event-subpipeline.ts+++ b/nodejs/src/ingestion/pipelines/analytics/event-subpipeline.ts@@ -124,9 +124,13 @@ export function createEventSubpipeline<TInput extends EventSubpipelineInput & Wi{ retry: { tries: 5, sleepMs: 100, name: 'hog_transform_event' } }).pipe(createNormalizeEventStep())- .pipe(createProcessPersonlessStep(options.FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS), {- retry: { tries: 5, sleepMs: 100, name: 'process_personless' },- })+ .pipe(+ createProcessPersonlessStep(+ options.FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,+ options.FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS+ ),+ { retry: { tries: 5, sleepMs: 100, name: 'process_personless' } }+ ).pipe(topHog(createProcessPersonsStep(options, outputs), [timer('process_persons_time', (input) => ({diff --git a/nodejs/src/servers/ingestion-api-server.ts b/nodejs/src/servers/ingestion-api-server.tsindex a889955d4291..13c3cd834cb8 100644--- a/nodejs/src/servers/ingestion-api-server.ts+++ b/nodejs/src/servers/ingestion-api-server.ts@@ -434,6 +434,7 @@ export class IngestionApiServer implements NodeServer {PERSON_JSONB_SIZE_ESTIMATE_ENABLE: this.config.PERSON_JSONB_SIZE_ESTIMATE_ENABLE,PERSON_PROPERTIES_UPDATE_ALL: this.config.PERSON_PROPERTIES_UPDATE_ALL,FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS: this.config.FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS,+ FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS: this.config.FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS,EXPERIMENT_EXPOSURE_DUPLICATION_TEAMS: this.config.EXPERIMENT_EXPOSURE_DUPLICATION_TEAMS,},concurrentBatches: this.config.INGESTION_WORKER_CONCURRENT_BATCHES,diff --git a/nodejs/tests/ingestion/common/steps/event-processing/process-persons-step.integration.test.ts b/nodejs/tests/ingestion/common/steps/event-processing/process-persons-step.integration.test.tsindex 239daca83e9d..c01e92b620f1 100644--- a/nodejs/tests/ingestion/common/steps/event-processing/process-persons-step.integration.test.ts+++ b/nodejs/tests/ingestion/common/steps/event-processing/process-persons-step.integration.test.ts@@ -57,6 +57,7 @@ describe('createProcessPersonsStep', () => {PERSON_JSONB_SIZE_ESTIMATE_ENABLE: 0,PERSON_PROPERTIES_UPDATE_ALL: false,FLAG_CALLED_PERSONLESS_DEFAULT_TEAMS: '*',+ FLAG_CALLED_PERSONLESS_EXCLUDED_TEAMS: '',EXPERIMENT_EXPOSURE_DUPLICATION_TEAMS: '',}