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.

929 B
Raw Blame
import { CyclotronJobInvocationHogFunction, CyclotronJobInvocationResult } from '~/cdp/types'

type HogFlowBillingMetricData = {
    invocation: CyclotronJobInvocationHogFunction
    billingMetricType: 'fetch' | 'email' | 'sms' | 'push'
}

/**
 * In workflows, we bill per-function-invocation so that pricing is equivalent to Hog Functions.
 *
 * For certain native functions like email sending, we instead bill per email sent as these
 * have a slight upcharge associated with them.
 */
export const trackHogFlowBillableInvocation = (
    result: CyclotronJobInvocationResult,
    data: HogFlowBillingMetricData
) => {
    result.metrics.push({
        team_id: data.invocation.teamId,
        app_source_id: data.invocation.functionId,
        instance_id: data.invocation.state.actionId || data.invocation.id,
        metric_kind: data.billingMetricType,
        metric_name: 'billable_invocation',
        count: 1,
    })
}