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(logs): add LogsAlertNotificationDetail scene and related updates (#59951)

Jon McCallum70307e9d0113
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index ceaafcef600f..12370a6a66ee 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -649,6 +649,7 @@ export const LOGS_ALERT_FIRING_SUB_TEMPLATE_ID = 'logs-alert-firing'
export const LOGS_ALERT_FIRING_EVENT_ID = '$logs_alert_firing'
export const LOGS_ALERT_RESOLVED_EVENT_ID = '$logs_alert_resolved'
export const LOGS_ALERT_AUTO_DISABLED_EVENT_ID = '$logs_alert_auto_disabled'
+export const LOGS_ALERT_ERRORED_EVENT_ID = '$logs_alert_errored'
export const COHORT_PERSONS_QUERY_LIMIT = 10000
diff --git a/frontend/src/products.tsx b/frontend/src/products.tsx
index ffb0720a8099..ac0f1922e011 100644
--- a/frontend/src/products.tsx
+++ b/frontend/src/products.tsx
@@ -120,6 +120,8 @@ export const productScenes: Record<string, () => Promise<any>> = {
LiveDebugger: () => import('../../products/live_debugger/frontend/LiveDebugger'),
Logs: () => import('../../products/logs/frontend/LogsScene'),
LogsAlertDetail: () => import('../../products/logs/frontend/scenes/LogsAlertDetailScene/LogsAlertDetailScene'),
+ LogsAlertNotificationDetail: () =>
+ import('../../products/logs/frontend/scenes/LogsAlertNotificationDetailScene/LogsAlertNotificationDetailScene'),
LogsSamplingNew: () => import('../../products/logs/frontend/scenes/LogsSamplingNewScene/LogsSamplingNewScene'),
LogsSamplingDetail: () =>
import('../../products/logs/frontend/scenes/LogsSamplingDetailScene/LogsSamplingDetailScene'),
@@ -243,6 +245,7 @@ export const productRoutes: Record<string, [string, string]> = {
'/live-debugger': ['LiveDebugger', 'liveDebugger'],
'/logs': ['Logs', 'logs'],
'/logs/alerts/:id': ['LogsAlertDetail', 'logsAlertDetail'],
+ '/logs/alerts/:id/notifications/:hogFunctionId': ['LogsAlertNotificationDetail', 'logsAlertNotificationDetail'],
'/logs/drop-rules/new': ['LogsSamplingNew', 'logsSamplingNew'],
'/logs/drop-rules/:id': ['LogsSamplingDetail', 'logsSamplingDetail'],
'/managed_migrations': ['ManagedMigration', 'managedMigration'],
@@ -657,6 +660,12 @@ export const productConfiguration: Record<string, any> = {
description: 'Monitor and analyze your logs to understand and fix issues.',
},
LogsAlertDetail: { projectBased: true, name: 'Alert', activityScope: ActivityScope.LOG, layout: 'app-container' },
+ LogsAlertNotificationDetail: {
+ projectBased: true,
+ name: 'Destination',
+ activityScope: ActivityScope.LOG,
+ layout: 'app-container',
+ },
LogsSamplingNew: {
projectBased: true,
name: 'New drop rule',
@@ -1051,6 +1060,8 @@ export const productUrls = {
logs: (): string => '/logs',
logsAlertDetail: (id: string, tab?: string): string =>
tab ? `/logs/alerts/${id}?tab=${tab}` : `/logs/alerts/${id}`,
+ logsAlertNotificationDetail: (alertId: string, hogFunctionId: string): string =>
+ `/logs/alerts/${alertId}/notifications/${hogFunctionId}`,
logsSamplingNew: (): string => '/logs/drop-rules/new',
logsSamplingDetail: (id: string): string => `/logs/drop-rules/${id}`,
managedMigration: (): string => '/managed_migrations',
@@ -1800,7 +1811,7 @@ export const getTreeItemsProducts = (): FileSystemImport[] => [
iconColor: ['var(--color-product-logs-light)'] as FileSystemIconColor,
href: urls.logs(),
sceneKey: 'Logs',
- sceneKeys: ['Logs', 'LogsAlertDetail', 'LogsSamplingNew', 'LogsSamplingDetail'],
+ sceneKeys: ['Logs', 'LogsAlertDetail', 'LogsAlertNotificationDetail', 'LogsSamplingNew', 'LogsSamplingDetail'],
},
{
path: 'MCP analytics',
diff --git a/frontend/src/scenes/hog-functions/HogFunctionScene.tsx b/frontend/src/scenes/hog-functions/HogFunctionScene.tsx
index 97cf1226e3a7..4d5bbd49be9c 100644
--- a/frontend/src/scenes/hog-functions/HogFunctionScene.tsx
+++ b/frontend/src/scenes/hog-functions/HogFunctionScene.tsx
@@ -157,6 +157,27 @@ export const hogFunctionSceneLogic = kea<hogFunctionSceneLogicType>([
iconType: 'data_pipeline',
}
+ const firstEventId = configuration?.filters?.events?.[0]?.id
+ const isLogsAlert = typeof firstEventId === 'string' && firstEventId.startsWith('$logs_alert_')
+
+ if (type === 'internal_destination' && isLogsAlert && alertId) {
+ return [
+ {
+ key: Scene.Logs,
+ name: 'Logs',
+ path: `${urls.logs()}?activeTab=alerts`,
+ iconType: 'logs',
+ },
+ {
+ key: Scene.LogsAlertDetail,
+ name: 'Alert',
+ path: returnTo ?? urls.logsAlertDetail(alertId, 'notifications'),
+ iconType: 'logs',
+ },
+ finalCrumb,
+ ]
+ }
+
if (type === 'internal_destination' && alertId) {
// returnTo contains the full path back to the alert edit view
// Strip the alert_id param for the insight breadcrumb
diff --git a/frontend/src/scenes/hog-functions/filters/HogFunctionFiltersInternal.tsx b/frontend/src/scenes/hog-functions/filters/HogFunctionFiltersInternal.tsx
index d289dc11c068..db08552e0103 100644
--- a/frontend/src/scenes/hog-functions/filters/HogFunctionFiltersInternal.tsx
+++ b/frontend/src/scenes/hog-functions/filters/HogFunctionFiltersInternal.tsx
@@ -6,6 +6,8 @@ import { LemonSelect } from '@posthog/lemon-ui'
import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { LemonField } from 'lib/lemon-ui/LemonField'
+import { Link } from 'lib/lemon-ui/Link'
+import { urls } from 'scenes/urls'
import { AnyPropertyFilter, CyclotronJobFiltersType, HogFunctionConfigurationContextId } from '~/types'
@@ -124,8 +126,13 @@ const getSimpleFilterValue = (value?: CyclotronJobFiltersType): string | undefin
return value?.events?.[0]?.id
}
-const setSimpleFilterValue = (options: FilterOption[], value: string): CyclotronJobFiltersType => {
- return {
+const setSimpleFilterValue = (
+ options: FilterOption[],
+ value: string,
+ previous: CyclotronJobFiltersType | undefined,
+ contextId: HogFunctionConfigurationContextId
+): CyclotronJobFiltersType => {
+ const next: CyclotronJobFiltersType = {
events: [
{
name: options.find((option) => option.value === value)?.label,
@@ -134,6 +141,12 @@ const setSimpleFilterValue = (options: FilterOption[], value: string): Cyclotron
},
],
}
+ // Preserve properties bound by Logs alerting (alert_id) — the trigger event id changes between
+ // firing/resolved/auto-disabled/errored, but the binding to the parent alert must survive.
+ if (contextId === 'logs-alerting' && previous?.properties && previous.properties.length > 0) {
+ next.properties = previous.properties
+ }
+ return next
}
export function HogFunctionFiltersInternal(): JSX.Element {
@@ -169,9 +182,10 @@ export function HogFunctionFiltersInternal(): JSX.Element {
<LemonSelect
options={options}
value={getSimpleFilterValue(value)}
- onChange={(value) => onChange(setSimpleFilterValue(options, value))}
+ onChange={(next) => onChange(setSimpleFilterValue(options, next, value, contextId))}
placeholder="Select a filter"
/>
+ {contextId === 'logs-alerting' ? <LogsAlertBindingHint filters={value} /> : null}
{taxonomicGroupTypes.length > 0 ? (
<PropertyFilters
key={contextId}
@@ -194,3 +208,27 @@ export function HogFunctionFiltersInternal(): JSX.Element {
</div>
)
}
+
+function LogsAlertBindingHint({ filters }: { filters: CyclotronJobFiltersType | undefined }): JSX.Element | null {
+ const alertIdProp = filters?.properties?.find((p) => 'key' in p && p.key === 'alert_id')
+ const rawValue = alertIdProp && 'value' in alertIdProp ? alertIdProp.value : undefined
+ const alertId =
+ typeof rawValue === 'string'
+ ? rawValue
+ : Array.isArray(rawValue) && typeof rawValue[0] === 'string'
+ ? rawValue[0]
+ : null
+
+ if (!alertId) {
+ return null
+ }
+
+ return (
+ <div className="text-xs text-secondary flex items-center gap-1 flex-wrap">
+ <span>Bound to alert</span>
+ <Link to={urls.logsAlertDetail(alertId)}>
+ <code className="text-xs">{alertId}</code>
+ </Link>
+ </div>
+ )
+}
diff --git a/frontend/src/scenes/sceneTypes.ts b/frontend/src/scenes/sceneTypes.ts
index 22ccbf3db763..03329d3e9683 100644
--- a/frontend/src/scenes/sceneTypes.ts
+++ b/frontend/src/scenes/sceneTypes.ts
@@ -198,6 +198,7 @@ export enum Scene {
AIObservabilityUsers = 'AIObservabilityUsers',
Logs = 'Logs',
LogsAlertDetail = 'LogsAlertDetail',
+ LogsAlertNotificationDetail = 'LogsAlertNotificationDetail',
LogsSamplingNew = 'LogsSamplingNew',
LogsSamplingDetail = 'LogsSamplingDetail',
ManagedMigration = 'ManagedMigration',
diff --git a/products/logs/backend/alert_destinations.py b/products/logs/backend/alert_destinations.py
index fa90fa9c4d50..d12af0958f1a 100644
--- a/products/logs/backend/alert_destinations.py
+++ b/products/logs/backend/alert_destinations.py
@@ -125,6 +125,15 @@ EVENT_KIND_CONFIG: dict[EventKind, EventKindSpec] = {
EVENT_KINDS: tuple[EventKind, ...] = tuple(EVENT_KIND_CONFIG.keys())
+# HogFunction.name is `models.CharField(max_length=400)` — clip rendered names to fit.
+_HOG_FUNCTION_NAME_MAX_LEN = 400
+
+
+def _clip_name(name: str) -> str:
+ if len(name) <= _HOG_FUNCTION_NAME_MAX_LEN:
+ return name
+ return name[: _HOG_FUNCTION_NAME_MAX_LEN - 1] + "…"
+
_SEVERITY_SERVICE_CONTEXT = (
"{if(length(event.properties.severity_levels) > 0 or length(event.properties.service_names) > 0,"
@@ -195,7 +204,7 @@ def build_slack_config(
"type": "internal_destination",
"enabled": True,
"filters": _filter_for(alert, kind),
- "name": f"Logs alert — {alert.name} ({spec.display_kind}) → Slack #{channel_display}",
+ "name": _clip_name(f"Logs alert — {alert.name} ({spec.display_kind}) → Slack #{channel_display}"),
"description": spec.destination_description(alert.name),
"template_id": "template-slack",
"inputs": {
@@ -218,7 +227,7 @@ def build_webhook_config(
"type": "internal_destination",
"enabled": True,
"filters": _filter_for(alert, kind),
- "name": f"Logs alert — {alert.name} ({spec.display_kind}) → Webhook {webhook_url}",
+ "name": _clip_name(f"Logs alert — {alert.name} ({spec.display_kind}) → Webhook {webhook_url}"),
"description": spec.destination_description(alert.name),
"template_id": "template-webhook",
"inputs": {
diff --git a/products/logs/frontend/components/LogsAlerting/LogsAlertNotifications.tsx b/products/logs/frontend/components/LogsAlerting/LogsAlertNotifications.tsx
index 2e5267ec0b88..7652b6545d15 100644
--- a/products/logs/frontend/components/LogsAlerting/LogsAlertNotifications.tsx
+++ b/products/logs/frontend/components/LogsAlerting/LogsAlertNotifications.tsx
@@ -1,40 +1,22 @@
import { useActions, useValues } from 'kea'
import { useEffect } from 'react'
-import { IconExternal, IconTrash } from '@posthog/icons'
+import { IconTrash } from '@posthog/icons'
import { LemonButton, LemonInput, LemonSelect, LemonSkeleton, LemonTag } from '@posthog/lemon-ui'
import { SlackChannelPicker, SlackNotConfiguredBanner } from 'lib/integrations/SlackIntegrationHelpers'
import { slackIntegrationLogic } from 'lib/integrations/slackIntegrationLogic'
import { urls } from 'scenes/urls'
-import { SlackChannelType } from '~/types'
-
import { LOGS_ALERT_NOTIFICATION_TYPE_OPTIONS, logsAlertNotificationLogic } from './logsAlertNotificationLogic'
import {
- LogsAlertDestinationGroup,
+ getHogFunctionEventKind,
LOGS_ALERT_NOTIFICATION_TYPE_SLACK,
LOGS_ALERT_NOTIFICATION_TYPE_WEBHOOK,
PendingLogsAlertNotification,
+ resolveGroupLabel,
} from './logsAlertUtils'
-function slackChannelLabel(channelValue: string, slackChannels: SlackChannelType[]): string {
- const channelId = channelValue.split('|')[0]
- const name = slackChannels.find((c) => c.id === channelId)?.name
- return name ? `Slack #${name}` : 'Slack'
-}
-
-function resolveGroupLabel(group: LogsAlertDestinationGroup, slackChannels: SlackChannelType[]): string {
- if (group.type === LOGS_ALERT_NOTIFICATION_TYPE_SLACK) {
- const hf = group.hogFunctions[0]
- const channelValue = hf.inputs?.channel?.value
- if (typeof channelValue === 'string') {
- return slackChannelLabel(channelValue, slackChannels)
- }
- }
- return group.label
-}
-
export function LogsAlertNotifications({ alertId }: { alertId?: string }): JSX.Element {
const {
existingHogFunctionsLoading,
@@ -108,42 +90,52 @@ export function LogsAlertNotifications({ alertId }: { alertId?: string }): JSX.E
<LemonSkeleton className="h-8" repeat={2} />
) : destinationGroups.length > 0 ? (
<div className="space-y-2">
- {destinationGroups.map((group) => (
- <div
- key={group.key}
- className="flex items-center justify-between border rounded p-2 gap-2"
- >
- <div className="flex-1 min-w-0">
- <div className="flex items-center gap-2 flex-wrap">
- <span className="text-sm font-medium truncate">
- {resolveGroupLabel(group, slackChannels)}
- </span>
- <LemonTag type={group.enabled ? 'success' : 'default'} size="small">
- {group.enabled ? 'Active' : 'Paused'}
- </LemonTag>
+ {destinationGroups.map((group) => {
+ const detailHogFunctionId =
+ group.hogFunctions.find((hf) => getHogFunctionEventKind(hf) === 'firing')?.id ??
+ group.hogFunctions[0]?.id
+ const detailUrl =
+ alertId && detailHogFunctionId
+ ? urls.logsAlertNotificationDetail(alertId, detailHogFunctionId)
+ : undefined
+ return (
+ <div
+ key={group.key}
+ className="flex items-center justify-between border rounded p-2 gap-2"
+ >
+ <div className="flex-1 min-w-0">
+ <div className="flex items-center gap-2 flex-wrap">
+ <span className="text-sm font-medium truncate">
+ {resolveGroupLabel(group, slackChannels)}
+ </span>
+ <LemonTag type={group.enabled ? 'success' : 'default'} size="small">
+ {group.enabled ? 'Active' : 'Paused'}
+ </LemonTag>
+ </div>
</div>
- </div>
- <div className="flex items-center gap-1 shrink-0">
- {group.hogFunctions.length === 1 && (
+ <div className="flex items-center gap-1 shrink-0">
<LemonButton
- icon={<IconExternal />}
size="xsmall"
- to={urls.hogFunction(group.hogFunctions[0].id)}
- targetBlank
- hideExternalLinkIcon
- tooltip="Open destination"
+ type="secondary"
+ to={detailUrl}
+ disabledReason={
+ detailUrl ? undefined : 'Save the alert to view details'
+ }
+ data-attr="logs-alert-destination-view"
+ >
+ View
+ </LemonButton>
+ <LemonButton
+ icon={<IconTrash />}
+ size="xsmall"
+ status="danger"
+ onClick={() => deleteExistingDestination(group)}
+ tooltip="Delete notification"
/>
- )}
- <LemonButton
- icon={<IconTrash />}
- size="xsmall"
- status="danger"
- onClick={() => deleteExistingDestination(group)}
- tooltip="Delete notification"
- />
+ </div>
</div>
- </div>
- ))}
+ )
+ })}
</div>
) : null}
</div>
diff --git a/products/logs/frontend/components/LogsAlerting/logsAlertUtils.ts b/products/logs/frontend/components/LogsAlerting/logsAlertUtils.ts
index e7e4fb909742..6d641956ba88 100644
--- a/products/logs/frontend/components/LogsAlerting/logsAlertUtils.ts
+++ b/products/logs/frontend/components/LogsAlerting/logsAlertUtils.ts
@@ -1,10 +1,62 @@
import { LemonDialog, lemonToast } from '@posthog/lemon-ui'
+import {
+ LOGS_ALERT_AUTO_DISABLED_EVENT_ID,
+ LOGS_ALERT_ERRORED_EVENT_ID,
+ LOGS_ALERT_FIRING_EVENT_ID,
+ LOGS_ALERT_RESOLVED_EVENT_ID,
+} from 'lib/constants'
+
import { FilterLogicalOperator, UniversalFiltersGroup } from '~/types'
-import { CyclotronJobFiltersType, HogFunctionType, PropertyFilterType, PropertyOperator } from '~/types'
+import {
+ CyclotronJobFiltersType,
+ HogFunctionType,
+ PropertyFilterType,
+ PropertyOperator,
+ SlackChannelType,
+} from '~/types'
import { LogsAlertConfigurationApi } from 'products/logs/frontend/generated/api.schemas'
+export type LogsAlertEventKind = 'firing' | 'resolved' | 'broken' | 'errored'
+
+export const LOGS_ALERT_EVENT_KIND_ORDER: LogsAlertEventKind[] = ['firing', 'resolved', 'broken', 'errored']
+
+export const LOGS_ALERT_EVENT_KIND_META: Record<LogsAlertEventKind, { label: string; description: string }> = {
+ firing: {
+ label: 'Firing',
+ description: 'Sent when the alert starts firing.',
+ },
+ resolved: {
+ label: 'Resolved',
+ description: 'Sent when a firing alert returns to normal.',
+ },
+ broken: {
+ label: 'Auto-disabled',
+ description: 'Sent if the alert is auto-disabled after repeated check failures.',
+ },
+ errored: {
+ label: 'Errored',
+ description: "Sent when an alert check can't evaluate.",
+ },
+}
+
+export function getHogFunctionEventKind(hf: HogFunctionType): LogsAlertEventKind | null {
+ const eventId = hf.filters?.events?.[0]?.id
+ switch (eventId) {
+ case LOGS_ALERT_FIRING_EVENT_ID:
+ return 'firing'
+ case LOGS_ALERT_RESOLVED_EVENT_ID:
+ return 'resolved'
+ case LOGS_ALERT_AUTO_DISABLED_EVENT_ID:
+ return 'broken'
+ case LOGS_ALERT_ERRORED_EVENT_ID:
+ return 'errored'
+ default:
+ return null
+ }
+}
+
export type PreEnableFilters = {
severityLevels: string[]
serviceNames: string[]
@@ -158,6 +210,23 @@ export type LogsAlertDestinationGroup = {
enabled: boolean
}
+export function slackChannelLabel(channelValue: string, slackChannels: SlackChannelType[]): string {
+ const channelId = channelValue.split('|')[0]
+ const name = slackChannels.find((c) => c.id === channelId)?.name
+ return name ? `Slack #${name}` : 'Slack'
+}
+
+export function resolveGroupLabel(group: LogsAlertDestinationGroup, slackChannels: SlackChannelType[]): string {
+ if (group.type === LOGS_ALERT_NOTIFICATION_TYPE_SLACK) {
+ const hf = group.hogFunctions[0]
+ const channelValue = hf?.inputs?.channel?.value
+ if (typeof channelValue === 'string') {
+ return slackChannelLabel(channelValue, slackChannels)
+ }
+ }
+ return group.label
+}
+
export function groupLogsAlertDestinations(
hogFunctions: HogFunctionType[],
resolveSlackLabel: (channelValue: string) => string | null
diff --git a/products/logs/frontend/scenes/LogsAlertNotificationDetailScene/LogsAlertNotificationDetailScene.tsx b/products/logs/frontend/scenes/LogsAlertNotificationDetailScene/LogsAlertNotificationDetailScene.tsx
new file mode 100644
index 000000000000..c376f244ebbb
--- /dev/null
+++ b/products/logs/frontend/scenes/LogsAlertNotificationDetailScene/LogsAlertNotificationDetailScene.tsx
@@ -0,0 +1,219 @@
+import { useActions, useValues } from 'kea'
+import { useEffect } from 'react'
+
+import { IconExternal, IconTrash } from '@posthog/icons'
+import { LemonButton, LemonDialog, LemonSkeleton, LemonSwitch, LemonTag } from '@posthog/lemon-ui'
+
+import { slackIntegrationLogic } from 'lib/integrations/slackIntegrationLogic'
+import { SceneExport } from 'scenes/sceneTypes'
+import { urls } from 'scenes/urls'
+
+import { SceneContent } from '~/layout/scenes/components/SceneContent'
+import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
+import { HogFunctionType } from '~/types'
+
+import {
+ getHogFunctionEventKind,
+ LOGS_ALERT_EVENT_KIND_META,
+ LOGS_ALERT_EVENT_KIND_ORDER,
+ LogsAlertEventKind,
+ resolveGroupLabel,
+} from 'products/logs/frontend/components/LogsAlerting/logsAlertUtils'
+
+import {
+ LogsAlertNotificationDetailSceneLogicProps,
+ logsAlertNotificationDetailSceneLogic,
+} from './logsAlertNotificationDetailSceneLogic'
+
+export const scene: SceneExport<LogsAlertNotificationDetailSceneLogicProps> = {
+ component: LogsAlertNotificationDetailScene,
+ logic: logsAlertNotificationDetailSceneLogic,
+ paramsToProps: ({ params: { id, hogFunctionId } }) => ({ alertId: id, hogFunctionId }),
+}
+
+export function LogsAlertNotificationDetailScene(): JSX.Element {
+ const {
+ alert,
+ alertLoading,
+ destinationGroup,
+ hogFunctionsLoading,
+ hasLoaded,
+ hogFunctionsError,
+ isDeleting,
+ togglingHogFunctionIds,
+ alertId,
+ hogFunctionId,
+ firstSlackIntegration,
+ } = useValues(logsAlertNotificationDetailSceneLogic)
+ const { deleteDestination, loadHogFunctions, setHogFunctionEnabled } = useActions(
+ logsAlertNotificationDetailSceneLogic
+ )
+
+ const slackLogic = slackIntegrationLogic({ id: firstSlackIntegration?.id ?? 0 })
+ const { slackChannels } = useValues(slackLogic)
+ const { loadAllSlackChannels } = useActions(slackLogic)
+
+ useEffect(() => {
+ if (firstSlackIntegration) {
+ loadAllSlackChannels()
+ }
+ }, [firstSlackIntegration?.id, loadAllSlackChannels])
+
+ const loading = alertLoading || hogFunctionsLoading
+ const displayLabel = destinationGroup ? resolveGroupLabel(destinationGroup, slackChannels) : 'Destination'
+ const editorReturnTo = encodeURIComponent(urls.logsAlertNotificationDetail(alertId, hogFunctionId))
+
+ if (hogFunctionsError) {
+ return (
+ <SceneContent>
+ <SceneTitleSection
+ name="Couldn't load destination"
+ resourceType={{ type: 'logs' }}
+ actions={
+ <div className="flex items-center gap-2">
+ <LemonButton type="secondary" to={urls.logsAlertDetail(alertId, 'notifications')}>
+ Back to alert
+ </LemonButton>
+ <LemonButton type="primary" onClick={() => loadHogFunctions()}>
+ Retry
+ </LemonButton>
+ </div>
+ }
+ />
+ <div className="p-8 text-muted text-center">
+ Failed to load destination details: {hogFunctionsError}
+ </div>
+ </SceneContent>
+ )
+ }
+
+ if (hasLoaded && !destinationGroup) {
+ return (
+ <SceneContent>
+ <SceneTitleSection
+ name="Destination not found"
+ resourceType={{ type: 'logs' }}
+ actions={
+ <LemonButton type="secondary" to={urls.logsAlertDetail(alertId, 'notifications')}>
+ Back to alert
+ </LemonButton>
+ }
+ />
+ <div className="p-8 text-muted text-center">
+ This notification destination no longer exists for this alert.
+ </div>
+ </SceneContent>
+ )
+ }
+
+ const kindToFn = new Map<LogsAlertEventKind, HogFunctionType>()
+ for (const hf of destinationGroup?.hogFunctions ?? []) {
+ const kind = getHogFunctionEventKind(hf)
+ if (kind) {
+ kindToFn.set(kind, hf)
+ }
+ }
+
+ return (
+ <SceneContent>
+ <SceneTitleSection
+ name={destinationGroup ? displayLabel : 'Destination'}
+ description={alert ? `Notifications fired for alert "${alert.name}".` : undefined}
+ resourceType={{ type: 'logs' }}
+ isLoading={loading && !destinationGroup}
+ actions={
+ destinationGroup ? (
+ <div className="flex items-center gap-2">
+ <LemonTag type={destinationGroup.enabled ? 'success' : 'default'}>
+ {destinationGroup.enabled ? 'Active' : 'Paused'}
+ </LemonTag>
+ <LemonButton
+ size="small"
+ type="secondary"
+ status="danger"
+ icon={<IconTrash />}
+ disabledReason={isDeleting ? 'Removing…' : undefined}
+ onClick={() => {
+ LemonDialog.open({
+ title: `Remove ${displayLabel}?`,
+ description:
+ 'This will delete all notification functions for this destination. The underlying hog functions will be soft-deleted.',
+ primaryButton: {
+ children: 'Remove',
+ type: 'primary',
+ status: 'danger',
+ onClick: () => deleteDestination(displayLabel),
+ 'data-attr': 'logs-alert-destination-delete-confirm',
+ },
+ secondaryButton: { children: 'Cancel' },
+ })
+ }}
+ data-attr="logs-alert-destination-delete"
+ >
+ Remove destination
+ </LemonButton>
+ </div>
+ ) : undefined
+ }
+ />
+ <div className="flex flex-col gap-4 p-4 max-w-3xl">
+ <p className="text-sm text-muted m-0">
+ These hog functions only run for this alert. Open one to edit the message body, headers, filters, or
+ destination details for the matching lifecycle event.
+ </p>
+
+ {loading ? (
+ <LemonSkeleton className="h-16" repeat={4} />
+ ) : (
+ <div className="flex flex-col gap-2">
+ {LOGS_ALERT_EVENT_KIND_ORDER.map((kind) => {
+ const fn = kindToFn.get(kind)
+ const meta = LOGS_ALERT_EVENT_KIND_META[kind]
+ const isToggling = !!fn && togglingHogFunctionIds.includes(fn.id)
+ return (
+ <div key={kind} className="flex items-center justify-between border rounded p-3 gap-3">
+ <div className="flex-1 min-w-0">
+ <div className="flex items-center gap-2 flex-wrap">
+ <span className="text-sm font-semibold">{meta.label}</span>
+ {!fn && (
+ <LemonTag type="warning" size="small">
+ Missing
+ </LemonTag>
+ )}
+ </div>
+ {fn ? <div className="text-xs text-muted mt-1 truncate">{fn.name}</div> : null}
+ <div className="text-xs text-muted mt-1">{meta.description}</div>
+ </div>
+ <div className="flex items-center gap-2 shrink-0">
+ {fn ? (
+ <LemonSwitch
+ checked={fn.enabled}
+ disabledReason={isToggling ? 'Saving…' : undefined}
+ onChange={(checked) => setHogFunctionEnabled(fn.id, checked)}
+ label={fn.enabled ? 'Active' : 'Paused'}
+ data-attr={`logs-alert-destination-toggle-${kind}`}
+ />
+ ) : null}
+ <LemonButton
+ size="small"
+ type="secondary"
+ icon={<IconExternal />}
+ to={
+ fn ? `${urls.hogFunction(fn.id)}?returnTo=${editorReturnTo}` : undefined
+ }
+ tooltip={fn ? 'Open hog function editor' : undefined}
+ disabledReason={fn ? undefined : 'No hog function for this event kind'}
+ data-attr={`logs-alert-destination-open-${kind}`}
+ >
+ Open editor
+ </LemonButton>
+ </div>
+ </div>
+ )
+ })}
+ </div>
+ )}
+ </div>
+ </SceneContent>
+ )
+}
diff --git a/products/logs/frontend/scenes/LogsAlertNotificationDetailScene/logsAlertNotificationDetailSceneLogic.ts b/products/logs/frontend/scenes/LogsAlertNotificationDetailScene/logsAlertNotificationDetailSceneLogic.ts
new file mode 100644
index 000000000000..d16c4e11fba4
--- /dev/null
+++ b/products/logs/frontend/scenes/LogsAlertNotificationDetailScene/logsAlertNotificationDetailSceneLogic.ts
@@ -0,0 +1,225 @@
+import { actions, afterMount, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
+import { loaders } from 'kea-loaders'
+import { router } from 'kea-router'
+import { subscriptions } from 'kea-subscriptions'
+import posthog from 'posthog-js'
+
+import { lemonToast } from '@posthog/lemon-ui'
+
+import api from 'lib/api'
+import { integrationsLogic } from 'lib/integrations/integrationsLogic'
+import { Scene } from 'scenes/sceneTypes'
+import { teamLogic } from 'scenes/teamLogic'
+import { urls } from 'scenes/urls'
+
+import { Breadcrumb, HogFunctionType, IntegrationType } from '~/types'
+
+import {
+ buildLogsAlertFilterConfig,
+ groupLogsAlertDestinations,
+ LogsAlertDestinationGroup,
+} from 'products/logs/frontend/components/LogsAlerting/logsAlertUtils'
+import { logsAlertsDestinationsDeleteCreate, logsAlertsRetrieve } from 'products/logs/frontend/generated/api'
+import { LogsAlertConfigurationApi } from 'products/logs/frontend/generated/api.schemas'
+
+import type { logsAlertNotificationDetailSceneLogicType } from './logsAlertNotificationDetailSceneLogicType'
+
+export interface LogsAlertNotificationDetailSceneLogicProps {
+ alertId: string
+ hogFunctionId: string
+}
+
+export const logsAlertNotificationDetailSceneLogic = kea<logsAlertNotificationDetailSceneLogicType>([
+ path((key) => [
+ 'products',
+ 'logs',
+ 'frontend',
+ 'scenes',
+ 'LogsAlertNotificationDetailScene',
+ 'logsAlertNotificationDetailSceneLogic',
+ key,
+ ]),
+ props({} as LogsAlertNotificationDetailSceneLogicProps),
+ key((props) => `${props.alertId}:${props.hogFunctionId}`),
+
+ connect({
+ values: [teamLogic, ['currentTeamId'], integrationsLogic, ['slackIntegrations']],
+ }),
+
+ actions({
+ deleteDestination: (displayLabel: string) => ({ displayLabel }),
+ deleteDestinationDone: true,
+ setHogFunctionEnabled: (hogFunctionId: string, enabled: boolean) => ({ hogFunctionId, enabled }),
+ }),
+
+ reducers({
+ hasLoaded: [
+ false,
+ {
+ loadHogFunctionsSuccess: () => true,
+ },
+ ],
+ hogFunctionsError: [
+ null as string | null,
+ {
+ loadHogFunctions: () => null,
+ loadHogFunctionsSuccess: () => null,
+ loadHogFunctionsFailure: (_, { error }: { error: string }) => error || 'Failed to load destinations',
+ },
+ ],
+ isDeleting: [
+ false,
+ {
+ deleteDestination: () => true,
+ deleteDestinationDone: () => false,
+ },
+ ],
+ togglingHogFunctionIds: [
+ [] as string[],
+ {
+ setHogFunctionEnabled: (state, { hogFunctionId }) =>
+ state.includes(hogFunctionId) ? state : [...state, hogFunctionId],
+ loadHogFunctionsSuccess: () => [],
+ loadHogFunctionsFailure: () => [],
+ },
+ ],
+ }),
+
+ loaders(({ values, props }) => ({
+ alert: [
+ null as LogsAlertConfigurationApi | null,
+ {
+ loadAlert: async () => {
+ if (!values.currentTeamId) {
+ return null
+ }
+ return logsAlertsRetrieve(String(values.currentTeamId), props.alertId)
+ },
+ },
+ ],
+ hogFunctions: [
+ [] as HogFunctionType[],
+ {
+ loadHogFunctions: async () => {
+ if (!values.currentTeamId) {
+ return []
+ }
+ const response = await api.hogFunctions.list({
+ types: ['internal_destination'],
+ filter_groups: [buildLogsAlertFilterConfig(props.alertId)],
+ full: true,
+ })
+ return response.results
+ },
+ },
+ ],
+ })),
+
+ selectors({
+ alertId: [() => [(_, props) => props.alertId], (alertId: string): string => alertId],
+ hogFunctionId: [() => [(_, props) => props.hogFunctionId], (id: string): string => id],
+ firstSlackIntegration: [
+ (s) => [s.slackIntegrations],
+ (slackIntegrations: IntegrationType[] | undefined): IntegrationType | undefined => slackIntegrations?.[0],
+ ],
+ destinationGroup: [
+ (s) => [s.hogFunctions, s.hogFunctionId],
+ (hogFunctions: HogFunctionType[], hogFunctionId: string): LogsAlertDestinationGroup | null => {
+ const groups = groupLogsAlertDestinations(hogFunctions, () => null)
+ return groups.find((g) => g.hogFunctions.some((hf) => hf.id === hogFunctionId)) ?? null
+ },
+ ],
+ breadcrumbs: [
+ (s) => [s.alert, s.destinationGroup, s.alertId],
+ (
+ alert: LogsAlertConfigurationApi | null,
+ group: LogsAlertDestinationGroup | null,
+ alertId: string
+ ): Breadcrumb[] => [
+ {
+ key: Scene.Logs,
+ name: 'Logs',
+ path: `${urls.logs()}?activeTab=alerts`,
+ iconType: 'logs',
+ },
+ {
+ key: Scene.LogsAlertDetail,
+ name: alert?.name ?? 'Alert',
+ path: urls.logsAlertDetail(alertId, 'notifications'),
+ iconType: 'logs',
+ },
+ {
+ key: Scene.LogsAlertNotificationDetail,
+ name: group?.label ?? 'Destination',
+ iconType: 'logs',
+ },
+ ],
+ ],
+ }),
+
+ listeners(({ actions, values, props }) => ({
+ deleteDestination: async ({ displayLabel }) => {
+ const group = values.destinationGroup
+ if (!group || !values.currentTeamId) {
+ actions.deleteDestinationDone()
+ return
+ }
+ try {
+ await logsAlertsDestinationsDeleteCreate(String(values.currentTeamId), props.alertId, {
+ hog_function_ids: group.hogFunctions.map((hf) => hf.id),
+ })
+ lemonToast.success(`Removed ${displayLabel}`)
+ router.actions.push(urls.logsAlertDetail(props.alertId, 'notifications'))
+ } catch (error: unknown) {
+ posthog.captureException(error, { tag: 'logs-alert-destination-delete' })
+ const detail =
+ (error as { detail?: string; message?: string })?.detail ?? (error as { message?: string })?.message
+ lemonToast.error(
+ detail ? `Failed to remove ${displayLabel}: ${detail}` : `Failed to remove ${displayLabel}`
+ )
+ } finally {
+ actions.deleteDestinationDone()
+ }
+ },
+ setHogFunctionEnabled: async ({ hogFunctionId, enabled }) => {
+ try {
+ await api.hogFunctions.update(hogFunctionId, { enabled })
+ } catch (error: unknown) {
+ posthog.captureException(error, { tag: 'logs-alert-hog-function-toggle' })
+ const detail =
+ (error as { detail?: string; message?: string })?.detail ?? (error as { message?: string })?.message
+ lemonToast.error(
+ detail
+ ? `Failed to ${enabled ? 'enable' : 'pause'} notification: ${detail}`
+ : `Failed to ${enabled ? 'enable' : 'pause'} notification`
+ )
+ }
+ // Refresh whether the update succeeded or failed — the success path picks up the new state,
+ // the failure path reverts the UI to the server's truth. `togglingHogFunctionIds` clears
+ // on loadHogFunctions{Success,Failure}, so the LemonSwitch stays disabled until the
+ // refreshed list lands (prevents the double-click race against stale local state).
+ actions.loadHogFunctions()
+ },
+ })),
+
+ subscriptions(({ values, actions }) => ({
+ currentTeamId: (currentTeamId: number | null) => {
+ if (!currentTeamId) {
+ return
+ }
+ if (!values.alert && !values.alertLoading) {
+ actions.loadAlert()
+ }
+ if (!values.hasLoaded && !values.hogFunctionsLoading) {
+ actions.loadHogFunctions()
+ }
+ },
+ })),
+
+ afterMount(({ actions, values }) => {
+ if (values.currentTeamId) {
+ actions.loadAlert()
+ actions.loadHogFunctions()
+ }
+ }),
+])
diff --git a/products/logs/manifest.tsx b/products/logs/manifest.tsx
index e007a7914a0d..be4bdc2443bb 100644
--- a/products/logs/manifest.tsx
+++ b/products/logs/manifest.tsx
@@ -25,6 +25,13 @@ export const manifest: ProductManifest = {
activityScope: ActivityScope.LOG,
layout: 'app-container',
},
+ LogsAlertNotificationDetail: {
+ import: () => import('./frontend/scenes/LogsAlertNotificationDetailScene/LogsAlertNotificationDetailScene'),
+ projectBased: true,
+ name: 'Destination',
+ activityScope: ActivityScope.LOG,
+ layout: 'app-container',
+ },
LogsSamplingNew: {
import: () => import('./frontend/scenes/LogsSamplingNewScene/LogsSamplingNewScene'),
projectBased: true,
@@ -43,6 +50,7 @@ export const manifest: ProductManifest = {
routes: {
'/logs': ['Logs', 'logs'],
'/logs/alerts/:id': ['LogsAlertDetail', 'logsAlertDetail'],
+ '/logs/alerts/:id/notifications/:hogFunctionId': ['LogsAlertNotificationDetail', 'logsAlertNotificationDetail'],
'/logs/drop-rules/new': ['LogsSamplingNew', 'logsSamplingNew'],
'/logs/drop-rules/:id': ['LogsSamplingDetail', 'logsSamplingDetail'],
},
@@ -56,6 +64,8 @@ export const manifest: ProductManifest = {
logs: (): string => '/logs',
logsAlertDetail: (id: string, tab?: string): string =>
tab ? `/logs/alerts/${id}?tab=${tab}` : `/logs/alerts/${id}`,
+ logsAlertNotificationDetail: (alertId: string, hogFunctionId: string): string =>
+ `/logs/alerts/${alertId}/notifications/${hogFunctionId}`,
logsSamplingNew: (): string => '/logs/drop-rules/new',
logsSamplingDetail: (id: string): string => `/logs/drop-rules/${id}`,
},