: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(flags): show $feature_flag_called in destination and workflow pickers (#121713)
Phil Haack4ea91cc3ec15
diff --git a/frontend/src/lib/components/TaxonomicFilter/types.ts b/frontend/src/lib/components/TaxonomicFilter/types.tsindex 038b63e2f9fd..a55c95d5889c 100644--- a/frontend/src/lib/components/TaxonomicFilter/types.ts+++ b/frontend/src/lib/components/TaxonomicFilter/types.ts@@ -145,8 +145,9 @@ export interface TaxonomicFilterProps {excludedProperties?: ExcludedProperties/*** Keep offering events whose data is moving out of the `events` table. Set it where the surface- * still needs such an event: it reads live capture, or it measures experiment exposure. Leave it- * unset everywhere else, so a picker stops saving queries that return nothing once the data moves.+ * still needs such an event: it reads live capture, it matches events as they arrive (destinations+ * and workflows), or it measures experiment exposure. Leave it unset everywhere else, so a picker+ * stops saving queries that return nothing once the data moves.*/includeHiddenEvents?: boolean/** use to indicate if a result in a group is selected */diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/hiddenEvents.ts b/frontend/src/lib/components/TaxonomicFilter/utils/hiddenEvents.tsindex b2063cdbf1fd..cdaceb3bd68e 100644--- a/frontend/src/lib/components/TaxonomicFilter/utils/hiddenEvents.ts+++ b/frontend/src/lib/components/TaxonomicFilter/utils/hiddenEvents.ts@@ -31,8 +31,7 @@ const HIDDEN_EVENT_NAMES = EVENTS_HIDDEN_IN_QUERY_BUILDERS.map(({ name }) => nam* Names the Events group adds to its own exclusions.** Empty when the team's `flag_evaluations_mode` is Events or missing, or when the picker passes- * `includeHiddenEvents`. Surfaces that browse captured events (the activity explorer, live events, a- * group's event feed, ingestion triggers) and the experiment pickers pass it.+ * `includeHiddenEvents`. `TaxonomicFilterProps.includeHiddenEvents` says which pickers pass it.** For an organization on mode 1, the team API reports Events while the* `FLAG_EVALUATIONS_READS_FORCE_EVENTS` instance setting is on, so its pickers show these events again.diff --git a/frontend/src/scenes/hog-functions/filters/HogFunctionFilters.test.tsx b/frontend/src/scenes/hog-functions/filters/HogFunctionFilters.test.tsxnew file mode 100644index 000000000000..cd88eaf43d49--- /dev/null+++ b/frontend/src/scenes/hog-functions/filters/HogFunctionFilters.test.tsx@@ -0,0 +1,107 @@+import { MOCK_DEFAULT_TEAM } from '~/lib/api.mock'++import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'+import { BindLogic } from 'kea'+import { Form } from 'kea-forms'++import { teamLogic } from 'scenes/teamLogic'++import { FlagEvaluationsModeEnumApi } from '~/generated/core/api.schemas'+import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'+import { mockEventDefinitions, mockGetEventDefinitionsFrom } from '~/test/mocks'+import { CyclotronJobFiltersType, HogFunctionConfigurationType, HogFunctionTemplateType } from '~/types'++import { hogFunctionConfigurationLogic } from '../configuration/hogFunctionConfigurationLogic'+import { HogFunctionMappings } from '../mapping/HogFunctionMappings'+import { HogFunctionFilters } from './HogFunctionFilters'++// react-virtualized renders no rows without real DOM measurements.+jest.mock('lib/components/AutoSizer', () => ({+ AutoSizer: ({ renderProp }: { renderProp: (size: { height: number; width: number }) => React.ReactNode }) =>+ renderProp({ height: 400, width: 400 }),+}))++const LOGIC_PROPS = { templateId: 'template-webhook' }++const PAGEVIEW_FILTERS: CyclotronJobFiltersType = {+ events: [{ id: '$pageview', name: '$pageview', type: 'events', order: 0 }],+}++const TEMPLATE: HogFunctionTemplateType = {+ free: true,+ status: 'stable',+ id: 'template-webhook',+ type: 'destination',+ name: 'HTTP Webhook',+ description: 'Sends a webhook',+ code: 'print(event)',+ code_language: 'hog',+ inputs_schema: [],+ filters: PAGEVIEW_FILTERS,+ icon_url: '/static/posthog-icon.svg',+}++describe('destination event matchers', () => {+ beforeEach(() => {+ // Recent picks persist in localStorage. Without this, a pick in one case shows up in the next.+ localStorage.clear()+ initKeaTests()+ teamLogic.actions.loadCurrentTeamSuccess({+ ...MOCK_DEFAULT_TEAM,+ flag_evaluations_mode: FlagEvaluationsModeEnumApi.Number2,+ })+ })++ afterEach(cleanup)++ it.each([+ {+ matcher: 'the destination filters',+ template: TEMPLATE,+ matchedEvents: (configuration: HogFunctionConfigurationType) => configuration.filters?.events,+ },+ {+ matcher: 'a mapping',+ template: {+ ...TEMPLATE,+ filters: null,+ mapping_templates: [{ name: 'Track', include_by_default: true, filters: PAGEVIEW_FILTERS }],+ },+ matchedEvents: (configuration: HogFunctionConfigurationType) =>+ configuration.mappings?.[0]?.filters?.events,+ },+ ])(+ 'lets a team on flag evaluations mode 2 match Feature flag called in $matcher',+ async ({ template, matchedEvents }) => {+ useMocks({+ get: {+ '/api/projects/:team/hog_function_templates/:id': template,+ '/api/projects/:team/event_definitions': mockGetEventDefinitionsFrom([+ { ...mockEventDefinitions[0], id: 'flag-called', name: '$feature_flag_called' },+ ]),+ },+ })+ const logic = hogFunctionConfigurationLogic(LOGIC_PROPS)+ logic.mount()+ // HogFunctionConfiguration renders both. Each template leaves exactly one of them with an event matcher.+ render(+ <BindLogic logic={hogFunctionConfigurationLogic} props={LOGIC_PROPS}>+ <Form logic={hogFunctionConfigurationLogic} props={LOGIC_PROPS} formKey="configuration">+ <HogFunctionFilters />+ <HogFunctionMappings />+ </Form>+ </BindLogic>+ )++ fireEvent.click(await screen.findByTestId('trend-element-subject-0'))+ fireEvent.click(await screen.findByText('Feature flag called'))++ await waitFor(() => {+ expect(matchedEvents(logic.values.configuration)?.map((event) => event.id)).toEqual([+ '$feature_flag_called',+ ])+ })+ }+ )+})diff --git a/frontend/src/scenes/hog-functions/filters/HogFunctionFilters.tsx b/frontend/src/scenes/hog-functions/filters/HogFunctionFilters.tsxindex cf96684f43e3..da625d145caa 100644--- a/frontend/src/scenes/hog-functions/filters/HogFunctionFilters.tsx+++ b/frontend/src/scenes/hog-functions/filters/HogFunctionFilters.tsx@@ -382,9 +382,12 @@ export function HogFunctionFilters({: 'Add event matcher'}excludedProperties={excludedProperties}- // Transformations run before ingestion stops writing $feature_flag_called- // to `events`, so they receive the event at every flag evaluations mode.- includeHiddenEvents={isTransformation}+ // Every function type here receives $feature_flag_called at every flag+ // evaluations mode. Transformations run during ingestion, before the step+ // that drops the call from `events`. Site destinations run in the browser.+ // Destinations also consume `realtime_only_events_json`, which carries the+ // call when ingestion does not write it to `events`.+ includeHiddenEventsallowNonCapturedEvents/>{selectedFullRefreshView ? (diff --git a/frontend/src/scenes/hog-functions/mapping/HogFunctionMappings.tsx b/frontend/src/scenes/hog-functions/mapping/HogFunctionMappings.tsxindex 6de8453d1951..a8ad6300ac20 100644--- a/frontend/src/scenes/hog-functions/mapping/HogFunctionMappings.tsx+++ b/frontend/src/scenes/hog-functions/mapping/HogFunctionMappings.tsx@@ -130,6 +130,7 @@ export function HogFunctionMapping({type: 'secondary',}}buttonCopy="Add event matcher"+ includeHiddenEvents/></>)}diff --git a/frontend/src/test/mocks.ts b/frontend/src/test/mocks.tsindex 80d6276adf27..952e8aa007b4 100644--- a/frontend/src/test/mocks.ts+++ b/frontend/src/test/mocks.ts@@ -269,16 +269,18 @@ export const mockSlackChannels: SlackChannelType[] = [},]-export const mockGetEventDefinitions = ({ request }: MockResolverInfo): [number, Record<string, any>] => {- const searchParams = new URL(request.url).searchParams- const search = searchParams.get('search') ?? ''- // The real endpoint filters excluded_properties server-side- const excluded: string[] = JSON.parse(searchParams.get('excluded_properties') ?? '[]')- const results = mockEventDefinitions.filter(- (e) => (!search || e.name.includes(search)) && !excluded.includes(e.name)- )- return [200, { results, count: results.length }]-}+export const mockGetEventDefinitionsFrom =+ (definitions: EventDefinition[]) =>+ ({ request }: MockResolverInfo): [number, Record<string, any>] => {+ const searchParams = new URL(request.url).searchParams+ const search = searchParams.get('search') ?? ''+ // The real endpoint filters excluded_properties server-side+ const excluded: string[] = JSON.parse(searchParams.get('excluded_properties') ?? '[]')+ const results = definitions.filter((e) => (!search || e.name.includes(search)) && !excluded.includes(e.name))+ return [200, { results, count: results.length }]+ }++export const mockGetEventDefinitions = mockGetEventDefinitionsFrom(mockEventDefinitions)export const mockGetPropertyDefinitions = ({ request }: MockResolverInfo): [number, Record<string, any>] => {const search = new URL(request.url).searchParams.get('search') ?? ''diff --git a/products/workflows/frontend/Workflows/hogflows/filters/HogFlowFilters.tsx b/products/workflows/frontend/Workflows/hogflows/filters/HogFlowFilters.tsxindex 020b1fe6296a..0dd780d66354 100644--- a/products/workflows/frontend/Workflows/hogflows/filters/HogFlowFilters.tsx+++ b/products/workflows/frontend/Workflows/hogflows/filters/HogFlowFilters.tsx@@ -124,6 +124,7 @@ export function HogFlowEventFilters({type: 'secondary',}}buttonCopy={buttonCopy ?? 'Add filter'}+ includeHiddenEventsallowNonCapturedEventshogQLGlobals={sampleGlobals}operatorAllowlist={WORKFLOW_OPERATOR_ALLOWLIST}diff --git a/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.test.tsx b/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.test.tsxindex 6c7c7218b6c4..7fd7a2b56d78 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.test.tsx+++ b/products/workflows/frontend/Workflows/hogflows/steps/StepTrigger.test.tsx@@ -1,3 +1,5 @@+import { MOCK_DEFAULT_TEAM } from '~/lib/api.mock'+import '@testing-library/jest-dom'import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'@@ -5,19 +7,34 @@ import { Node } from '@xyflow/react'import { BindLogic } from 'kea'import { recentTaxonomicFiltersLogic } from 'lib/components/TaxonomicFilter/recentTaxonomicFiltersLogic'+import { teamLogic } from 'scenes/teamLogic'+import { FlagEvaluationsModeEnumApi } from '~/generated/core/api.schemas'import { useMocks } from '~/mocks/jest'import { actionsModel } from '~/models/actionsModel'import { groupsModel } from '~/models/groupsModel'import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'import { initKeaTests } from '~/test/init'-import { mockActionDefinition, mockGetEventDefinitions, mockGetPropertyDefinitions } from '~/test/mocks'+import {+ mockActionDefinition,+ mockEventDefinitions,+ mockGetEventDefinitions,+ mockGetEventDefinitionsFrom,+ mockGetPropertyDefinitions,+} from '~/test/mocks'import { WorkflowLogicProps, workflowLogic } from '../../workflowLogic'import { HogFlowAction } from '../types'import { StepTriggerConfiguration } from './StepTrigger'+// react-virtualized renders no rows without real DOM measurements.+jest.mock('lib/components/AutoSizer', () => ({+ AutoSizer: ({ renderProp }: { renderProp: (size: { height: number; width: number }) => React.ReactNode }) =>+ renderProp({ height: 400, width: 400 }),+}))+type TriggerAction = Extract<HogFlowAction, { type: 'trigger' }>+type EventTriggerConfig = Extract<TriggerAction['config'], { type: 'event' }>const LOGIC_PROPS: WorkflowLogicProps = { id: 'new' }@@ -38,6 +55,8 @@ describe('StepTriggerConfiguration', () => {'/api/environments/:team/query': { results: [] },},})+ // Recent picks persist in localStorage. Without this, a pick in one case shows up in the next.+ localStorage.clear()initKeaTests()actionsModel.mount()groupsModel.mount()@@ -78,9 +97,31 @@ describe('StepTriggerConfiguration', () => {await waitFor(() => {const trigger = workflowLogic(LOGIC_PROPS).values.workflow.trigger as TriggerAction['config']expect(trigger.type).toEqual('event')- expect((trigger as Extract<TriggerAction['config'], { type: 'event' }>).filters?.properties).toEqual(- properties- )+ expect((trigger as EventTriggerConfig).filters?.properties).toEqual(properties)+ })+ })++ it('lets a team on flag evaluations mode 2 pick Feature flag called as a trigger event', async () => {+ teamLogic.actions.loadCurrentTeamSuccess({+ ...MOCK_DEFAULT_TEAM,+ flag_evaluations_mode: FlagEvaluationsModeEnumApi.Number2,+ })+ useMocks({+ get: {+ '/api/projects/:team/event_definitions': mockGetEventDefinitionsFrom([+ { ...mockEventDefinitions[0], id: 'flag-called', name: '$feature_flag_called' },+ ]),+ },+ })+ renderTrigger([])++ fireEvent.click(screen.getByText('Add trigger event'))+ fireEvent.click(await screen.findByTestId('trend-element-subject-0'))+ fireEvent.click(await screen.findByText('Feature flag called'))++ await waitFor(() => {+ const trigger = workflowLogic(LOGIC_PROPS).values.workflow.trigger as EventTriggerConfig+ expect(trigger.filters?.events?.map((event) => event.id)).toEqual(['$feature_flag_called'])})})