: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
fix(workflows): include push dispatches in aggregate usage (#118809)
Alex Maysa642006c64fe
diff --git a/nodejs/src/cdp/services/hogflows/actions/hog_function.test.ts b/nodejs/src/cdp/services/hogflows/actions/hog_function.test.tsindex 302950f1f378..8c919e6ce7ed 100644--- a/nodejs/src/cdp/services/hogflows/actions/hog_function.test.ts+++ b/nodejs/src/cdp/services/hogflows/actions/hog_function.test.ts@@ -723,7 +723,7 @@ describe('HogFunctionHandler', () => {if (isTest && mockFunctions) {expect(usageReporter.reportBillableInvocation).not.toHaveBeenCalled()} else {- expect(usageReporter.reportBillableInvocation).toHaveBeenCalledTimes(1)+ expect(usageReporter.reportBillableInvocation).toHaveBeenCalledTimes(billingType === 'push' ? 2 : 1)expect(usageReporter.reportBillableInvocation).toHaveBeenCalledWith(expect.objectContaining({ teamId: team.id, usageKey }))@@ -767,9 +767,18 @@ describe('HogFunctionHandler', () => {expect(invocationResult.metrics.some((metric) => metric.metric_name === 'billable_invocation')).toBe(shouldBill)if (shouldBill) {- expect(usageReporter.reportBillableInvocation).toHaveBeenCalledWith(- expect.objectContaining({ teamId: team.id, usageKey: 'workflow_push_sent' })- )+ const recordId = `flow:${invocation.id}:${invocation.state.actionStepCount}:push`+ expect(usageReporter.reportBillableInvocation).toHaveBeenCalledWith({+ teamId: team.id,+ usageKey: 'workflow_push_sent',+ recordId,+ })+ expect(usageReporter.reportBillableInvocation).toHaveBeenCalledWith({+ teamId: team.id,+ usageKey: 'workflow_billable_invocations',+ recordId,+ })+ expect(usageReporter.reportBillableInvocation).toHaveBeenCalledTimes(2)} else {expect(usageReporter.reportBillableInvocation).not.toHaveBeenCalled()}diff --git a/nodejs/src/cdp/services/hogflows/actions/hog_function.ts b/nodejs/src/cdp/services/hogflows/actions/hog_function.tsindex f984540a2d85..14fac9309f12 100644--- a/nodejs/src/cdp/services/hogflows/actions/hog_function.ts+++ b/nodejs/src/cdp/services/hogflows/actions/hog_function.ts@@ -50,10 +50,10 @@ type FunctionActionType = 'function' | 'function_email' | 'function_sms'type HogFlowActionBillingType = 'fetch' | 'email' | 'push' | 'sms'const WORKFLOW_USAGE_KEYS = {- fetch: 'workflow_billable_invocations',- email: 'workflow_emails_sent',- push: 'workflow_push_sent',- sms: 'workflow_sms_sent',+ fetch: ['workflow_billable_invocations'],+ email: ['workflow_emails_sent'],+ push: ['workflow_push_sent', 'workflow_billable_invocations'],+ sms: ['workflow_sms_sent'],} as consttype Action = Extract<HogFlowAction, { type: FunctionActionType }>@@ -260,11 +260,13 @@ export class HogFunctionHandler implements ActionHandler {if (!hogExecutorOptions?.isTest || !hogExecutorOptions.functions) {// actionStepCount holds across a retry of this step but changes on a loop revisit.- this.usageReporter?.reportBillableInvocation({- teamId: invocation.teamId,- usageKey: WORKFLOW_USAGE_KEYS[this.hogFlowActionBillingType],- recordId: `flow:${invocation.id}:${invocation.state.actionStepCount}:${this.hogFlowActionBillingType}`,- })+ for (const usageKey of WORKFLOW_USAGE_KEYS[this.hogFlowActionBillingType]) {+ this.usageReporter?.reportBillableInvocation({+ teamId: invocation.teamId,+ usageKey,+ recordId: `flow:${invocation.id}:${invocation.state.actionStepCount}:${this.hogFlowActionBillingType}`,+ })+ }}}diff --git a/posthog/usage_counters.py b/posthog/usage_counters.pyindex 0a818fa86832..11212a5a9f5d 100644--- a/posthog/usage_counters.py+++ b/posthog/usage_counters.py@@ -150,8 +150,8 @@ _REPLAY_UNDERCOUNT = ("When that message fails, the session writes no usage record, even when later messages record.")_WORKFLOW_PUSH_UNDERCOUNT = (- "The legacy count bills fetch and push dispatches as workflow invocations. "- "Push dispatches write `workflow_push_sent` records, so `workflow_billable_invocations` holds only fetches."+ "Workflow invocation records from before push reporting omit push dispatches. "+ "The legacy count includes both fetch and push dispatches.")_EVENT_DATE_ATTRIBUTION = ("Event usage records use capture time; legacy queries use source event time. "