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.

feat(data-warehouse): add logs/retry debug and sectioned webhook tab (#60704)

Tom Owersc8e5aba00dcb
diff --git a/frontend/src/scenes/hog-functions/logs/HogFunctionLogs.tsx b/frontend/src/scenes/hog-functions/logs/HogFunctionLogs.tsx
index 7ed7449df2e2..6a0029084c47 100644
--- a/frontend/src/scenes/hog-functions/logs/HogFunctionLogs.tsx
+++ b/frontend/src/scenes/hog-functions/logs/HogFunctionLogs.tsx
@@ -3,7 +3,7 @@ import { router } from 'kea-router'
import { useMemo } from 'react'
import { IconEllipsis } from '@posthog/icons'
-import { LemonButton, LemonCheckbox, LemonDialog, LemonMenu, LemonTag, Link } from '@posthog/lemon-ui'
+import { LemonButton, LemonCheckbox, LemonDialog, LemonMenu, LemonTag } from '@posthog/lemon-ui'
import { LemonTableColumns } from 'lib/lemon-ui/LemonTable'
import { capitalizeFirstLetter } from 'lib/utils'
@@ -14,30 +14,7 @@ import { hogFunctionTestLogic } from '../configuration/hogFunctionTestLogic'
import { hogFunctionLogsLogic } from './hogFunctionLogsLogic'
import { LogsViewer } from './LogsViewer'
import { GroupedLogEntry, LogsViewerLogicProps } from './logsViewerLogic'
-
-const EVENT_LINK_REGEX = /Event: '(.+)'/g
-
-export const renderHogFunctionMessage = (message: string): JSX.Element => {
- const parts = message.split(EVENT_LINK_REGEX)
- const elements: (string | JSX.Element)[] = []
-
- for (let i = 0; i < parts.length; i++) {
- if (i % 2 === 0) {
- // Even indices are regular text parts
- if (parts[i]) {
- elements.push(parts[i])
- }
- } else {
- elements.push(
- <Link className="rounded p-1 -m-1 bg-border text-bg-primary" to={parts[i]} targetBlankIcon>
- View event
- </Link>
- )
- }
- }
-
- return <>{elements}</>
-}
+import { renderHogFunctionMessage } from './renderHogFunctionMessage'
export function HogFunctionLogs(): JSX.Element | null {
const { logicProps } = useValues(hogFunctionConfigurationLogic)
diff --git a/frontend/src/scenes/hog-functions/logs/renderHogFunctionMessage.tsx b/frontend/src/scenes/hog-functions/logs/renderHogFunctionMessage.tsx
new file mode 100644
index 000000000000..72b127188fdf
--- /dev/null
+++ b/frontend/src/scenes/hog-functions/logs/renderHogFunctionMessage.tsx
@@ -0,0 +1,25 @@
+import { Link } from '@posthog/lemon-ui'
+
+const EVENT_LINK_REGEX = /Event: '(.+)'/g
+
+export const renderHogFunctionMessage = (message: string): JSX.Element => {
+ const parts = message.split(EVENT_LINK_REGEX)
+ const elements: (string | JSX.Element)[] = []
+
+ for (let i = 0; i < parts.length; i++) {
+ if (i % 2 === 0) {
+ // Even indices are regular text parts
+ if (parts[i]) {
+ elements.push(parts[i])
+ }
+ } else {
+ elements.push(
+ <Link className="rounded p-1 -m-1 bg-border text-bg-primary" to={parts[i]} targetBlankIcon>
+ View event
+ </Link>
+ )
+ }
+ }
+
+ return <>{elements}</>
+}
diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/WebhookLogsSection.tsx b/products/data_warehouse/frontend/scenes/SourceScene/tabs/WebhookLogsSection.tsx
new file mode 100644
index 000000000000..f516431b5ee1
--- /dev/null
+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/WebhookLogsSection.tsx
@@ -0,0 +1,165 @@
+import { useActions, useValues } from 'kea'
+import { useMemo } from 'react'
+
+import { IconEllipsis } from '@posthog/icons'
+import { LemonButton, LemonCheckbox, LemonDialog, LemonMenu, LemonTag } from '@posthog/lemon-ui'
+
+import { LemonCard } from 'lib/lemon-ui/LemonCard'
+import { LemonTableColumns } from 'lib/lemon-ui/LemonTable'
+import { capitalizeFirstLetter } from 'lib/utils'
+import { hogFunctionLogsLogic } from 'scenes/hog-functions/logs/hogFunctionLogsLogic'
+import { LogsViewer } from 'scenes/hog-functions/logs/LogsViewer'
+import { GroupedLogEntry, LogsViewerLogicProps } from 'scenes/hog-functions/logs/logsViewerLogic'
+import { renderHogFunctionMessage } from 'scenes/hog-functions/logs/renderHogFunctionMessage'
+import { urls } from 'scenes/urls'
+
+export function WebhookLogsSection({ hogFunctionId }: { hogFunctionId: string }): JSX.Element {
+ const logsLogicProps: LogsViewerLogicProps = {
+ sourceType: 'hog_function',
+ sourceId: hogFunctionId,
+ }
+ const logic = hogFunctionLogsLogic(logsLogicProps)
+
+ const { selectingMany, selectedForRetry, retryRunning } = useValues(logic)
+ const { setSelectingMany, retrySelectedInvocations, selectAllForRetry } = useActions(logic)
+
+ return (
+ <LemonCard hoverEffect={false} className="space-y-3">
+ <div className="flex items-center justify-between gap-2">
+ <div>
+ <h3 className="text-lg font-semibold mb-0">Logs</h3>
+ <p className="text-muted text-xs mb-0">
+ Inspect received webhook requests and retry failed events.
+ </p>
+ </div>
+ {selectingMany ? (
+ <div className="flex gap-2 items-center">
+ <LemonButton size="small" type="secondary" onClick={() => setSelectingMany(false)}>
+ Cancel
+ </LemonButton>
+ <LemonButton size="small" type="secondary" onClick={() => selectAllForRetry()}>
+ Select all
+ </LemonButton>
+ <LemonButton
+ size="small"
+ type="primary"
+ onClick={() => {
+ LemonDialog.open({
+ title: 'Retry events',
+ content: `Are you sure you want to retry the selected events? Please don't close the window until the retries have completed.`,
+ secondaryButton: { children: 'Cancel' },
+ primaryButton: {
+ children: 'Retry selected events',
+ onClick: () => retrySelectedInvocations(),
+ },
+ })
+ }}
+ loading={retryRunning}
+ disabledReason={
+ retryRunning
+ ? 'Please wait for the current retries to complete.'
+ : Object.values(selectedForRetry).length === 0
+ ? 'No events selected'
+ : undefined
+ }
+ >
+ Retry selected
+ </LemonButton>
+ </div>
+ ) : null}
+ </div>
+ <LogsViewer
+ {...logsLogicProps}
+ instanceLabel="request"
+ renderColumns={(columns) => {
+ const newColumns: LemonTableColumns<GroupedLogEntry> = [
+ {
+ title: 'Status',
+ key: 'status',
+ width: 0,
+ render: (_, record) => <WebhookLogStatus record={record} hogFunctionId={hogFunctionId} />,
+ },
+ ...columns.filter((column) => column.key !== 'logLevel'),
+ ]
+ return newColumns
+ }}
+ renderMessage={renderHogFunctionMessage}
+ />
+ </LemonCard>
+ )
+}
+
+type WebhookLogStatusType = 'success' | 'failure' | 'running'
+
+function WebhookLogStatus({ record, hogFunctionId }: { record: GroupedLogEntry; hogFunctionId: string }): JSX.Element {
+ const logicProps: LogsViewerLogicProps = {
+ sourceType: 'hog_function',
+ sourceId: hogFunctionId,
+ }
+ const logic = hogFunctionLogsLogic(logicProps)
+ const { retries, selectingMany, selectedForRetry, eventIdByInvocationId } = useValues(logic)
+ const { retryInvocations, setSelectingMany, setSelectedForRetry } = useActions(logic)
+
+ const thisRetry = retries[record.instanceId]
+
+ const status = useMemo<WebhookLogStatusType>((): WebhookLogStatusType => {
+ if (thisRetry === 'pending') {
+ return 'running'
+ }
+ if (
+ record.entries.some(
+ (e) => e.message.includes('Function completed') || e.message.includes('Execution successful')
+ )
+ ) {
+ return 'success'
+ }
+ if (record.entries.some((e) => e.level === 'ERROR')) {
+ return 'failure'
+ }
+ return 'running'
+ }, [record, thisRetry])
+
+ const eventId = eventIdByInvocationId?.[record.instanceId]
+
+ return (
+ <div className="flex items-center gap-2">
+ {selectingMany ? (
+ <LemonCheckbox
+ checked={selectedForRetry[record.instanceId] ?? false}
+ onChange={(checked) => setSelectedForRetry({ [record.instanceId]: checked })}
+ />
+ ) : null}
+ <LemonTag type={status === 'success' ? 'success' : status === 'failure' ? 'danger' : 'warning'}>
+ {capitalizeFirstLetter(status)}
+ </LemonTag>
+ <LemonMenu
+ items={[
+ eventId
+ ? {
+ label: 'View event',
+ to: urls.event(eventId, ''),
+ }
+ : null,
+ {
+ label: 'Retry event',
+ disabledReason: !eventId ? 'Could not find the source event' : undefined,
+ onClick: () => retryInvocations([record]),
+ },
+ {
+ label: 'Select for retry',
+ onClick: () => {
+ setSelectingMany(true)
+ setSelectedForRetry({ [record.instanceId]: true })
+ },
+ },
+ ]}
+ >
+ <LemonButton
+ size="xsmall"
+ icon={<IconEllipsis className="rotate-90" />}
+ loading={thisRetry === 'pending'}
+ />
+ </LemonMenu>
+ </div>
+ )
+}
diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/WebhookTab.tsx b/products/data_warehouse/frontend/scenes/SourceScene/tabs/WebhookTab.tsx
index 3cb2afeda8aa..af424979ad46 100644
--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/WebhookTab.tsx
+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/WebhookTab.tsx
@@ -1,7 +1,7 @@
import { useActions, useValues } from 'kea'
import { Form } from 'kea-forms'
-import { LemonBanner, LemonButton, LemonSkeleton, LemonTable, LemonTag } from '@posthog/lemon-ui'
+import { LemonBanner, LemonButton, LemonCollapse, LemonSkeleton, LemonTable, LemonTag } from '@posthog/lemon-ui'
import { getColorVar } from 'lib/colors'
import { AppMetricsFilters } from 'lib/components/AppMetrics/AppMetricsFilters'
@@ -21,7 +21,14 @@ import {
WebhookUrlDisplay,
} from '../../../shared/components/forms/WebhookSetupForm'
import type { WebhookCreateResult } from '../../../shared/components/forms/WebhookSetupForm'
-import { webhookTabLogic } from './webhookTabLogic'
+import { WebhookLogsSection } from './WebhookLogsSection'
+import { WEBHOOK_SECTIONS, WebhookSection, webhookTabLogic } from './webhookTabLogic'
+
+const SECTION_LABELS: Record<WebhookSection, string> = {
+ overview: 'Overview',
+ configuration: 'Configuration',
+ activity: 'Activity',
+}
const WEBHOOK_METRIC_KEYS = ['succeeded', 'failed'] as const
@@ -51,8 +58,11 @@ export function WebhookTab({ id, tabId }: { id: string; tabId?: string }): JSX.E
sourceConfig,
canDeleteWebhook,
webhookDeleting,
+ currentSection,
} = useValues(webhookTabLogic({ id, tabId }))
- const { createWebhook, loadWebhookInfo, deleteWebhook } = useActions(webhookTabLogic({ id, tabId }))
+ const { createWebhook, loadWebhookInfo, deleteWebhook, setCurrentSection } = useActions(
+ webhookTabLogic({ id, tabId })
+ )
if (webhookInfoLoading && !webhookInfo) {
return (
@@ -85,33 +95,99 @@ export function WebhookTab({ id, tabId }: { id: string; tabId?: string }): JSX.E
const externalMissing =
webhookInfo.external_status && !webhookInfo.external_status.exists && !webhookInfo.external_status.error
+ const hogFunctionId = webhookInfo.hog_function?.id
+ const hasConfiguration = !!sourceConfig && (sourceConfig.webhookFields?.length ?? 0) > 0
+ const visibleSections = WEBHOOK_SECTIONS.filter(
+ (key) => (key !== 'configuration' || hasConfiguration) && (key !== 'activity' || !!hogFunctionId)
+ )
+ const activeSection = visibleSections.includes(currentSection) ? currentSection : 'overview'
+
+ let body: JSX.Element
+ switch (activeSection) {
+ case 'configuration':
+ body = <WebhookConfigurationSection sourceConfig={sourceConfig!} formLogicProps={logicProps} />
+ break
+ case 'activity':
+ body = (
+ <>
+ {hogFunctionId && <WebhookMetricsSection hogFunctionId={hogFunctionId} />}
+ {hogFunctionId && <WebhookLogsSection hogFunctionId={hogFunctionId} />}
+ </>
+ )
+ break
+ default:
+ body = (
+ <>
+ <WebhookStatusSection
+ webhookInfo={webhookInfo}
+ webhookInfoLoading={webhookInfoLoading}
+ internalStateLabel={internalStateLabel}
+ externalStateLabel={externalStateLabel}
+ onRefresh={loadWebhookInfo}
+ />
+ {externalMissing && (
+ <WebhookRecreateSection
+ id={id}
+ sourceName={sourceConfig?.label ?? source?.source_type ?? 'source'}
+ sourceConfig={sourceConfig}
+ webhookCreating={webhookCreating}
+ createWebhookResult={createWebhookResult}
+ onCreateWebhook={createWebhook}
+ tabId={tabId}
+ />
+ )}
+ <WebhookDetailsSection webhookInfo={webhookInfo} />
+ {mappedTables.length > 0 && <MappedTablesSection mappedTables={mappedTables} />}
+ <WebhookDeleteSection
+ canDelete={canDeleteWebhook}
+ deleting={webhookDeleting}
+ onDelete={deleteWebhook}
+ />
+ </>
+ )
+ }
+
return (
- <div className="space-y-4">
- <WebhookStatusSection
- webhookInfo={webhookInfo}
- webhookInfoLoading={webhookInfoLoading}
- internalStateLabel={internalStateLabel}
- externalStateLabel={externalStateLabel}
- onRefresh={loadWebhookInfo}
- />
- {externalMissing && (
- <WebhookRecreateSection
- id={id}
- sourceName={sourceConfig?.label ?? source?.source_type ?? 'source'}
- sourceConfig={sourceConfig}
- webhookCreating={webhookCreating}
- createWebhookResult={createWebhookResult}
- onCreateWebhook={createWebhook}
- tabId={tabId}
- />
- )}
- <WebhookDetailsSection webhookInfo={webhookInfo} />
- {sourceConfig && (sourceConfig.webhookFields?.length ?? 0) > 0 && (
- <WebhookConfigurationSection sourceConfig={sourceConfig} formLogicProps={logicProps} />
- )}
- {webhookInfo.hog_function?.id && <WebhookMetricsSection hogFunctionId={webhookInfo.hog_function.id} />}
- {mappedTables.length > 0 && <MappedTablesSection mappedTables={mappedTables} />}
- <WebhookDeleteSection canDelete={canDeleteWebhook} deleting={webhookDeleting} onDelete={deleteWebhook} />
+ <WebhookSectionLayout
+ sections={visibleSections}
+ section={activeSection}
+ onSectionChange={setCurrentSection}
+ body={body}
+ />
+ )
+}
+
+function WebhookSectionLayout({
+ sections,
+ section,
+ onSectionChange,
+ body,
+}: {
+ sections: readonly WebhookSection[]
+ section: WebhookSection
+ onSectionChange: (section: WebhookSection) => void
+ body: JSX.Element
+}): JSX.Element {
+ return (
+ <div className="flex items-start gap-6">
+ <nav className="sticky top-[var(--scene-title-section-height,50px)] flex flex-col w-56 flex-shrink-0">
+ <ul className="flex flex-col gap-y-px">
+ {sections.map((key) => (
+ <li key={key}>
+ <LemonButton
+ fullWidth
+ size="small"
+ active={section === key}
+ onClick={() => onSectionChange(key)}
+ data-attr={`webhook-section-${key}`}
+ >
+ {SECTION_LABELS[key]}
+ </LemonButton>
+ </li>
+ ))}
+ </ul>
+ </nav>
+ <div className="flex-1 min-w-0 space-y-4">{body}</div>
</div>
)
}
@@ -259,19 +335,26 @@ function WebhookDetailsSection({ webhookInfo }: { webhookInfo: WebhookInfo }): J
{webhookInfo.webhook_url && <WebhookUrlDisplay url={webhookInfo.webhook_url} />}
{externalStatus?.enabled_events && externalStatus.enabled_events.length > 0 && (
- <div>
- <p className="text-xs font-semibold text-muted uppercase mb-1">
- Listening to {externalStatus.enabled_events.length} event
- {externalStatus.enabled_events.length !== 1 ? 's' : ''}
- </p>
- <div className="flex flex-wrap gap-1 mt-1">
- {externalStatus.enabled_events.map((event) => (
- <LemonTag key={event} type="muted" className="text-xs">
- {event}
- </LemonTag>
- ))}
- </div>
- </div>
+ <LemonCollapse
+ size="small"
+ panels={[
+ {
+ key: 'enabled-events',
+ header: `Listening to ${externalStatus.enabled_events.length} event${
+ externalStatus.enabled_events.length !== 1 ? 's' : ''
+ }`,
+ content: (
+ <div className="flex flex-wrap gap-1">
+ {externalStatus.enabled_events.map((event) => (
+ <LemonTag key={event} type="muted" className="text-xs">
+ {event}
+ </LemonTag>
+ ))}
+ </div>
+ ),
+ },
+ ]}
+ />
)}
</LemonCard>
)
diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/webhookTabLogic.ts b/products/data_warehouse/frontend/scenes/SourceScene/tabs/webhookTabLogic.ts
index bc2720cb3ede..fcf3cd62a26d 100644
--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/webhookTabLogic.ts
+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/webhookTabLogic.ts
@@ -1,6 +1,7 @@
import { actions, afterMount, kea, key, listeners, path, props, reducers, selectors } from 'kea'
import { forms } from 'kea-forms'
import { loaders } from 'kea-loaders'
+import { actionToUrl, router, urlToAction } from 'kea-router'
import { lemonToast } from '@posthog/lemon-ui'
@@ -19,6 +20,10 @@ export interface WebhookTabLogicProps {
tabId?: string
}
+export const WEBHOOK_SECTIONS = ['overview', 'configuration', 'activity'] as const
+export type WebhookSection = (typeof WEBHOOK_SECTIONS)[number]
+export const DEFAULT_WEBHOOK_SECTION: WebhookSection = 'overview'
+
export const webhookTabLogic = kea<webhookTabLogicType>([
props({} as WebhookTabLogicProps),
key(({ id }: WebhookTabLogicProps) => id),
@@ -32,8 +37,17 @@ export const webhookTabLogic = kea<webhookTabLogicType>([
submitWebhookFields: true,
deleteWebhook: true,
setWebhookDeleting: (deleting: boolean) => ({ deleting }),
+ setCurrentSection: (section: WebhookSection) => ({ section }),
+ _setCurrentSection: (section: WebhookSection) => ({ section }),
}),
reducers({
+ currentSection: [
+ DEFAULT_WEBHOOK_SECTION as WebhookSection,
+ {
+ setCurrentSection: (_, { section }) => section,
+ _setCurrentSection: (_, { section }) => section,
+ },
+ ],
webhookCreating: [
false,
{
@@ -187,6 +201,27 @@ export const webhookTabLogic = kea<webhookTabLogicType>([
},
},
})),
+ actionToUrl(({ values }) => ({
+ setCurrentSection: () => {
+ return [
+ router.values.location.pathname,
+ { ...router.values.searchParams, section: values.currentSection },
+ router.values.hashParams,
+ ]
+ },
+ })),
+ urlToAction(({ actions, values }) => ({
+ '*': (_, searchParams): void => {
+ // Reset to default when no/invalid ?section= so the UI matches the deep link.
+ const possibleSection = searchParams.section as WebhookSection | undefined
+ const nextSection: WebhookSection = WEBHOOK_SECTIONS.includes(possibleSection as WebhookSection)
+ ? (possibleSection as WebhookSection)
+ : DEFAULT_WEBHOOK_SECTION
+ if (nextSection !== values.currentSection) {
+ actions._setCurrentSection(nextSection)
+ }
+ },
+ })),
listeners(({ actions, props, values }) => ({
loadWebhookInfoSuccess: ({ webhookInfo }) => {
// Server returns each input either as `{secret: true}` (masked) or `{value: ...}`