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.

fix(logs): surface save errors and drop metrics for log transformations (#76030)

Daniel Viscaf160fa9acd34
diff --git a/frontend/src/scenes/hog-functions/HogFunctionScene.tsx b/frontend/src/scenes/hog-functions/HogFunctionScene.tsx
index 982edd5d9d82..0176b8572973 100644
--- a/frontend/src/scenes/hog-functions/HogFunctionScene.tsx
+++ b/frontend/src/scenes/hog-functions/HogFunctionScene.tsx
@@ -5,6 +5,7 @@ import {
connect,
kea,
key,
+ listeners,
path,
props,
reducers,
@@ -91,6 +92,13 @@ export interface hogFunctionSceneLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface hogFunctionSceneLogicActions {
+ loadHogFunctionSuccess: (
+ hogFunction: HogFunctionType | null,
+ payload?: any
+ ) => {
+ hogFunction: HogFunctionType | null
+ payload?: any
+ } // hogFunctionConfigurationLogic
setCurrentTab: (tab: HogFunctionSceneTab) => {
tab: 'backfills' | 'configuration' | 'history' | 'invocations' | 'metrics' | 'runs'
}
@@ -132,6 +140,7 @@ export const hogFunctionSceneLogic = kea<hogFunctionSceneLogicType>([
path((key) => ['scenes', 'hog-functions', 'hogFunctionSceneLogic', key]),
connect((props: HogFunctionConfigurationLogicProps) => ({
values: [hogFunctionConfigurationLogic(props), ['configuration', 'type', 'loading', 'loaded']],
+ actions: [hogFunctionConfigurationLogic(props), ['loadHogFunctionSuccess']],
})),
actions({
setCurrentTab: (tab: HogFunctionSceneTab) => ({ tab }),
@@ -371,11 +380,24 @@ export const hogFunctionSceneLogic = kea<hogFunctionSceneLogicType>([
]
},
})),
+ listeners(({ actions, values }) => ({
+ // `type` loads after the URL fires, so a deep link to a tab this type never
+ // renders (e.g. ?tab=invocations on a log transformation) must be corrected
+ // here too, or LemonTabs shows no active content.
+ loadHogFunctionSuccess: () => {
+ if (values.type === 'transformation_log' && values.currentTab === 'invocations') {
+ actions.setCurrentTab('configuration')
+ }
+ },
+ })),
urlToAction(({ actions, values }) => {
const reactToTabChange = (_: any, search: Record<string, string>): void => {
const possibleTab = (search.tab ?? 'configuration') as HogFunctionSceneTab
- const tab = HOG_FUNCTION_SCENE_TABS.includes(possibleTab) ? possibleTab : 'configuration'
+ let tab = HOG_FUNCTION_SCENE_TABS.includes(possibleTab) ? possibleTab : 'configuration'
+ if (tab === 'invocations' && values.type === 'transformation_log') {
+ tab = 'configuration'
+ }
if (tab !== values.currentTab) {
actions.setCurrentTab(tab)
}
@@ -501,7 +523,9 @@ export function HogFunctionScene(): JSX.Element {
key: 'metrics',
content: <HogFunctionMetrics id={id} />,
},
- type === 'site_app' || type === 'site_destination'
+ // Log transformations aggregate outcomes per Kafka message and never write
+ // per-invocation results, so the Invocations tab would always be empty for them.
+ type === 'site_app' || type === 'site_destination' || type === 'transformation_log'
? null
: {
label: 'Invocations',
diff --git a/frontend/src/scenes/hog-functions/configuration/HogFunctionTest.tsx b/frontend/src/scenes/hog-functions/configuration/HogFunctionTest.tsx
index d4d7369f2f30..1279e36ef72c 100644
--- a/frontend/src/scenes/hog-functions/configuration/HogFunctionTest.tsx
+++ b/frontend/src/scenes/hog-functions/configuration/HogFunctionTest.tsx
@@ -447,8 +447,9 @@ export function HogFunctionTest(): JSX.Element {
</>
) : (
<LemonBanner type="warning">
- The event was dropped by the transformation. If this is expected then
- great news! If not, you should double check the configuration.
+ The {type === 'transformation_log' ? 'record' : 'event'} was dropped by
+ the transformation. If this is expected then great news! If not, you
+ should double check the configuration.
</LemonBanner>
)}
</>
diff --git a/frontend/src/scenes/hog-functions/configuration/hogFunctionConfigurationLogic.test.ts b/frontend/src/scenes/hog-functions/configuration/hogFunctionConfigurationLogic.test.ts
index 4ea0cd546423..8925de9a2af6 100644
--- a/frontend/src/scenes/hog-functions/configuration/hogFunctionConfigurationLogic.test.ts
+++ b/frontend/src/scenes/hog-functions/configuration/hogFunctionConfigurationLogic.test.ts
@@ -1,5 +1,7 @@
import { expectLogic } from 'kea-test-utils'
+import { lemonToast } from '@posthog/lemon-ui'
+
import api from 'lib/api'
import { initKeaTests } from '~/test/init'
@@ -214,5 +216,23 @@ describe('hogFunctionConfigurationLogic', () => {
expect(globals.record?.body).toContain('GET /api/users')
expect(globals.event).toBeUndefined()
})
+
+ it('surfaces validation errors on `type` as a toast, since no form field renders them', async () => {
+ // The feature-flag gate and the enabled-function cap both reject with attr `type`;
+ // without the toast the Save button fails with no visible feedback at all.
+ const toastSpy = jest.spyOn(lemonToast, 'error').mockImplementation(() => 'id')
+ const detail = 'Log transformations are not enabled for this team.'
+ mockApi.create.mockRejectedValue({
+ status: 400,
+ data: { type: 'validation_error', code: 'invalid_input', attr: 'type', detail },
+ })
+ await expectLogic(logic).toDispatchActions(['loadTemplate', 'loadTemplateSuccess'])
+
+ await expectLogic(logic, () => {
+ logic.actions.submitConfiguration()
+ }).toDispatchActions(['upsertHogFunctionFailure'])
+
+ expect(toastSpy).toHaveBeenCalledWith(detail)
+ })
})
})
diff --git a/frontend/src/scenes/hog-functions/configuration/hogFunctionConfigurationLogic.tsx b/frontend/src/scenes/hog-functions/configuration/hogFunctionConfigurationLogic.tsx
index 9ba2f457c527..efb4e114eded 100644
--- a/frontend/src/scenes/hog-functions/configuration/hogFunctionConfigurationLogic.tsx
+++ b/frontend/src/scenes/hog-functions/configuration/hogFunctionConfigurationLogic.tsx
@@ -1957,7 +1957,12 @@ export const hogFunctionConfigurationLogic = kea<hogFunctionConfigurationLogicTy
upsertHogFunctionFailure: ({ errorObject }) => {
const maybeValidationError = errorObject.data
- if (maybeValidationError?.type === 'validation_error') {
+ if (maybeValidationError?.type === 'validation_error' && maybeValidationError.attr) {
+ // Errors on `type` (the feature gate and the enabled-function cap reject there)
+ // have no rendered form field, so a toast is the only way the user sees them.
+ if (maybeValidationError.attr === 'type') {
+ lemonToast.error(maybeValidationError.detail)
+ }
setTimeout(() => {
// TRICKY: We want to run on the next tick otherwise the errors don't show (possibly because of the async wait in the submit)
if (maybeValidationError.attr.includes('inputs__')) {
@@ -1974,7 +1979,7 @@ export const hogFunctionConfigurationLogic = kea<hogFunctionConfigurationLogicTy
}, 1)
} else {
console.error(errorObject)
- lemonToast.error('Error submitting configuration')
+ lemonToast.error(maybeValidationError?.detail ?? 'Error submitting configuration')
}
},
diff --git a/frontend/src/scenes/hog-functions/hogFunctionSceneLogic.test.ts b/frontend/src/scenes/hog-functions/hogFunctionSceneLogic.test.ts
new file mode 100644
index 000000000000..74036488ec6f
--- /dev/null
+++ b/frontend/src/scenes/hog-functions/hogFunctionSceneLogic.test.ts
@@ -0,0 +1,57 @@
+import { router } from 'kea-router'
+import { expectLogic } from 'kea-test-utils'
+
+import api from 'lib/api'
+import { urls } from 'scenes/urls'
+
+import { initKeaTests } from '~/test/init'
+import { HogFunctionType } from '~/types'
+
+jest.mock('lib/api', () => ({
+ ...jest.requireActual('lib/api'),
+ hogFunctions: {
+ get: jest.fn(),
+ getTemplate: jest.fn(),
+ update: jest.fn(),
+ create: jest.fn(),
+ },
+}))
+
+const mockApi = api.hogFunctions as jest.Mocked<typeof api.hogFunctions>
+
+const LOG_TRANSFORMATION: HogFunctionType = {
+ id: 'fn-1',
+ type: 'transformation_log',
+ name: 'Scrub PII',
+ description: '',
+ created_at: '2026-01-01',
+ created_by: null,
+ updated_at: '2026-01-01',
+ enabled: true,
+ hog: 'return record',
+ inputs_schema: [],
+ inputs: {},
+ filters: null,
+ icon_url: null,
+ template: null,
+ status: { state: 1, tokens: 0 } as any,
+} as unknown as HogFunctionType
+
+describe('hogFunctionSceneLogic', () => {
+ it('falls back from a deep-linked tab the loaded type never renders', async () => {
+ // `type` arrives after the URL fires, so ?tab=invocations on a log
+ // transformation used to stick and LemonTabs rendered no active content.
+ initKeaTests()
+ // Required lazily: the scene's component import chain reads the app context
+ // at module scope, which initKeaTests only provides at test time.
+ const { hogFunctionSceneLogic } = require('./HogFunctionScene')
+ mockApi.get.mockResolvedValue(LOG_TRANSFORMATION)
+
+ router.actions.push(urls.hogFunction('fn-1'), { tab: 'invocations' })
+ const logic = hogFunctionSceneLogic({ id: 'fn-1' })
+ logic.mount()
+
+ await expectLogic(logic).toDispatchActions(['loadHogFunctionSuccess'])
+ expect(logic.values.currentTab).toBe('configuration')
+ })
+})
diff --git a/frontend/src/scenes/hog-functions/list/HogFunctionsList.tsx b/frontend/src/scenes/hog-functions/list/HogFunctionsList.tsx
index 9643437e3089..c35093dca807 100644
--- a/frontend/src/scenes/hog-functions/list/HogFunctionsList.tsx
+++ b/frontend/src/scenes/hog-functions/list/HogFunctionsList.tsx
@@ -218,7 +218,12 @@ export function HogFunctionList({
forceParams={{
appSource: 'hog_function',
appSourceId: hogFunction.id,
- metricKind: ['success', 'failure'],
+ // Log transformations report drops and budget skips under
+ // metric_kind 'other' — without it their sparkline reads as idle.
+ metricKind:
+ hogFunction.type === 'transformation_log'
+ ? ['success', 'failure', 'other']
+ : ['success', 'failure'],
breakdownBy: 'metric_kind',
interval: 'day',
dateFrom: '-7d',
diff --git a/frontend/src/scenes/hog-functions/metrics/HogFunctionMetrics.tsx b/frontend/src/scenes/hog-functions/metrics/HogFunctionMetrics.tsx
index 7fd91051071e..0c0bbeb39f5b 100644
--- a/frontend/src/scenes/hog-functions/metrics/HogFunctionMetrics.tsx
+++ b/frontend/src/scenes/hog-functions/metrics/HogFunctionMetrics.tsx
@@ -6,7 +6,15 @@ 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', 'filtered', 'disabled_permanently', 'quota_limited'] as const
+const HOGFUNCTION_METRIC_KEYS = [
+ 'succeeded',
+ '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: {
@@ -24,6 +32,16 @@ export const HOGFUNCTION_METRICS_INFO: Record<string, { name: string; descriptio
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: