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.

3.9 KB
Raw Blame
import { useValues } from 'kea'

import { getColorVar } from 'lib/colors'
import { AppMetricsFilters } from 'lib/components/AppMetrics/AppMetricsFilters'
import { appMetricsLogic } from 'lib/components/AppMetrics/appMetricsLogic'
import { AppMetricsTrends } from 'lib/components/AppMetrics/AppMetricsTrends'
import { AppMetricSummary } from 'lib/components/AppMetrics/AppMetricSummary'

const HOGFUNCTION_METRIC_KEYS = [
    'succeeded',
    'failed',
    'inputs_failed',
    'filtered',
    'dropped',
    'budget_skipped',
    'disabled_permanently',
    'quota_limited',
] as const

export const HOGFUNCTION_METRICS_INFO: Record<string, { name: string; description: string; color: string }> = {
    succeeded: {
        name: 'Success',
        description: 'Total number of events processed successfully',
        color: getColorVar('success'),
    },
    failed: {
        name: 'Failure',
        description: 'Total number of events that had errors during processing',
        color: getColorVar('danger'),
    },
    inputs_failed: {
        name: 'Input errors',
        description:
            'Total number of events dropped because their input mapping could not be built (for example, a property mapping threw an error)',
        color: getColorVar('warning'),
    },
    filtered: {
        name: 'Filtered',
        description: 'Total number of events that were filtered out',
        color: getColorVar('muted'),
    },
    dropped: {
        name: 'Dropped',
        description: 'Total number of events or log records dropped by the transformation',
        color: getColorVar('muted'),
    },
    budget_skipped: {
        name: 'Budget skipped',
        description: 'Total number of log records passed through untransformed because the time budget ran out',
        color: getColorVar('warning'),
    },
    disabled_permanently: {
        name: 'Disabled',
        description:
            'Total number of events that were skipped due to the destination being permanently disabled (due to prolonged issues with the destination)',
        color: getColorVar('danger'),
    },
    quota_limited: {
        name: 'Quota Limited',
        description: 'Total number of invocations blocked due to quota limits',
        color: getColorVar('danger'),
    },
}

export function HogFunctionMetrics({ id }: { id: string }): JSX.Element {
    const logic = appMetricsLogic({
        logicKey: `hog-function-metrics-${id}`,
        loadOnMount: true,
        loadOnChanges: true,
        forceParams: {
            appSource: 'hog_function',
            appSourceId: id,
            metricName: [...HOGFUNCTION_METRIC_KEYS],
            breakdownBy: 'metric_name',
        },
    })

    const { appMetricsTrends, appMetricsTrendsLoading, getSingleTrendSeries } = useValues(logic)

    return (
        <div className="flex flex-col gap-2">
            <div className="flex flex-row gap-2 flex-wrap justify-end">
                <AppMetricsFilters logicKey={`hog-function-metrics-${id}`} />
            </div>

            <div className="flex flex-row gap-2 flex-wrap justify-center">
                {HOGFUNCTION_METRIC_KEYS.map((key) => (
                    <AppMetricSummary
                        key={key}
                        name={HOGFUNCTION_METRICS_INFO[key].name}
                        description={HOGFUNCTION_METRICS_INFO[key].description}
                        loading={appMetricsTrendsLoading}
                        timeSeries={getSingleTrendSeries(key)}
                        previousPeriodTimeSeries={getSingleTrendSeries(key, true)}
                        color={HOGFUNCTION_METRICS_INFO[key].color}
                        colorIfZero={getColorVar('muted')}
                        hideIfZero={!['succeeded', 'failed', 'inputs_failed', 'filtered'].includes(key)}
                    />
                ))}
            </div>
            <AppMetricsTrends appMetricsTrends={appMetricsTrends} loading={appMetricsTrendsLoading} />
        </div>
    )
}