Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7721,9 +7721,9 @@ snapshots:
scenes-app-settings-environment--settings-environment-error-tracking--light:
hash: v1.k794b7964.5ac167271f00184ce6159d0072ce163542658b08419f6e70b5cf6a6ca201a718.X6dKpM6uGw_g_FAwdQ5PukTVcKWGAa77bMOzgw-kiXY
scenes-app-settings-environment--settings-environment-error-tracking-configuration--dark:
hash: v1.k794b7964.610a8d8b91871b32a6b83b087df8523999636f905ebacd4d4bad4f6c2c10cdd2.N1EL1qb6-quDv9B8-LwQ5S-zyRZlCwgJJiR-ahq4p-8
hash: v1.k794b7964.033e5499811363c36dee07950ff09f33413e64b81c8522859c85748bc0443e3f.Hz66ItOfiG51KAAT2yidV4lINJmLINi-9_k81Ygdk80
scenes-app-settings-environment--settings-environment-error-tracking-configuration--light:
hash: v1.k794b7964.adb8f8b9586c3cda5749b248291df41cfc5da3f9e1764fbaef8c0c2c3b5315dc.BLb5wQ4ykREEPkol8psVfNFlk1KlbWmTZDwW8MncIPo
hash: v1.k794b7964.56f8265ff5de3733a4d00b0dbde7c0fff36ccdc886f713881134159802a13d39.9ArXuAkoxa6dyVQ_uspbjHWKM8YIgCPgCbDUnLHsxso
scenes-app-settings-environment--settings-environment-feature-flags--dark:
hash: v1.k794b7964.56670f556ffac0360ec521741db9822f4e545e25b45bd8ed4ad012da8885c30a.qj9dLuAFy8v0TwEH-UTymXnlWPe2eu-YjAOpe2zc3Q8
scenes-app-settings-environment--settings-environment-feature-flags--light:
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ export const FEATURE_FLAGS = {
ERROR_TRACKING_RATE_LIMITING_PER_ISSUE: 'error-tracking-rate-limiting-per-issue', // owner: @ablaszkiewicz #team-error-tracking
ERROR_TRACKING_RECOMMENDATIONS: 'error-tracking-recommendations', // owner: @ablaszkiewicz #team-error-tracking
ERROR_TRACKING_RELATED_ISSUES: 'error-tracking-related-issues', // owner: #team-error-tracking
ERROR_TRACKING_SEVERITY_RULES: 'error-tracking-severity-rules', // owner: #team-error-tracking
ERROR_TRACKING_WEEKLY_DIGEST: 'error-tracking-weekly-digest', // owner: #team-error-tracking
EVENT_MEDIA_PREVIEWS: 'event-media-previews', // owner: @alexlider
EXPERIMENT_BEHAVIOR_COMPARISON: 'experiment-behavior-comparison', // owner: @mp-hog #team-experiments
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/scenes/settings/SettingsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AssignmentRules } from '@posthog/products-error-tracking/frontend/scene
import { GroupingRules } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/grouping_rules/GroupingRules'
import { RateLimitSettings } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSettings'
import { Releases } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/releases/Releases'
import { SeverityRules } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/severity_rules/SeverityRules'
import { SpikeDetectionSettings } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/spike_detection/SpikeDetectionSettings'
import { SymbolSets } from '@posthog/products-error-tracking/frontend/scenes/ErrorTrackingConfigurationScene/symbol_sets/SymbolSets'
import { McpStoreSettings } from '@posthog/products-mcp-store/frontend/McpStoreSettings'
Expand Down Expand Up @@ -588,6 +589,14 @@ export const SETTINGS_MAP: SettingSection[] = [
component: <AssignmentRules />,
keywords: ['assign', 'owner', 'team', 'rule', 'routing'],
},
{
id: 'error-tracking-severity-rules',
title: 'Severity rules',
description: 'Set the initial severity of new issues based on rules you define.',
component: <SeverityRules />,
flag: 'ERROR_TRACKING_SEVERITY_RULES',
keywords: ['severity', 'priority', 'triage', 'critical', 'rule'],
},
{
id: 'error-tracking-custom-grouping',
title: 'Custom grouping rules',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/scenes/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export type SettingId =
| 'error-tracking-integrations'
| 'error-tracking-rate-limits'
| 'error-tracking-releases'
| 'error-tracking-severity-rules'
| 'error-tracking-spike-detection'
| 'error-tracking-suppression-rules'
| 'error-tracking-symbol-sets'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ function createNewRule(ruleType: ErrorTrackingRuleType, order_key: number): Erro
filters: { type: FilterLogicalOperator.Or, values: [] },
order_key,
}
case 'severity_rules':
return {
id: 'new',
disabled_data: null,
filters: { type: FilterLogicalOperator.And, values: [] },
order_key,
severity: null,
}
default:
throw new Error(`Unsupported rule type: ${ruleType}`)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ErrorTrackingIssueAssignee } from '~/queries/schema/schema-general'
import { JsonType, UniversalFiltersGroup } from '~/types'

import type {
ErrorTrackingIssueSeverityRuleEnumApi,
ErrorTrackingSeverityRuleApi,
} from '../../../generated/api.schemas'

export type ErrorTrackingBaseRule = {
id: string
filters: UniversalFiltersGroup
Expand All @@ -26,17 +31,27 @@ export type ErrorTrackingGroupingRule = ErrorTrackingBaseRule & {

export type ErrorTrackingBypassRule = ErrorTrackingBaseRule

export type ErrorTrackingSeverityRule = ErrorTrackingBaseRule & Pick<ErrorTrackingSeverityRuleApi, 'severity'>

export type ErrorTrackingSeverityRuleNew = Omit<ErrorTrackingSeverityRule, 'id' | 'severity'> & {
id: 'new'
severity: ErrorTrackingIssueSeverityRuleEnumApi | null
}

export type ErrorTrackingRule =
| ErrorTrackingSuppressionRule
| ErrorTrackingGroupingRule
| ErrorTrackingAssignmentRule
| ErrorTrackingBypassRule
| ErrorTrackingSeverityRule
| ErrorTrackingSeverityRuleNew
export type ErrorTrackingRuleNew = ErrorTrackingRule & { id: 'new' }

export enum ErrorTrackingRuleType {
Assignment = 'assignment_rules',
Bypass = 'bypass_rules',
Grouping = 'grouping_rules',
Severity = 'severity_rules',
Suppression = 'suppression_rules',
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { useActions, useValues } from 'kea'

import { LemonSelect, LemonTag } from '@posthog/lemon-ui'

import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { LemonLabel } from 'lib/lemon-ui/LemonLabel'

import {
ErrorTrackingIssueSeverityRuleEnumApi,
type ErrorTrackingIssueSeverityRuleEnumApi as Severity,
} from '../../../generated/api.schemas'
import { RuleModal } from '../rules/RuleModal'
import { severityRuleModalLogic } from './severityRuleModalLogic'

const SEVERITY_OPTIONS: { label: string; value: Severity }[] = [
{ label: 'Low', value: ErrorTrackingIssueSeverityRuleEnumApi.Low },
{ label: 'Medium', value: ErrorTrackingIssueSeverityRuleEnumApi.Medium },
{ label: 'High', value: ErrorTrackingIssueSeverityRuleEnumApi.High },
{ label: 'Critical', value: ErrorTrackingIssueSeverityRuleEnumApi.Critical },
]

export const severityTagType = (severity: Severity): 'default' | 'warning' | 'danger' => {
if (severity === ErrorTrackingIssueSeverityRuleEnumApi.Critical) {
return 'danger'
}
if (severity === ErrorTrackingIssueSeverityRuleEnumApi.High) {
return 'warning'
}
return 'default'
}

export const severityLabel = (severity: Severity): string =>
SEVERITY_OPTIONS.find((option) => option.value === severity)?.label ?? severity

export function SeverityRuleModal(): JSX.Element {
const { rule, hasFilters, hasSeverity } = useValues(severityRuleModalLogic)
const { updateSeverity } = useActions(severityRuleModalLogic)
const saveDisabledReason = !hasFilters ? 'Add at least one filter' : !hasSeverity ? 'Choose a severity' : undefined

return (
<RuleModal
logic={severityRuleModalLogic}
ruleLabel="severity"
description="Matching exceptions set the initial severity when they create a new issue. Existing issues are never changed."
pageKey="severity-rule-modal"
taxonomicGroupTypes={[TaxonomicFilterGroupType.EventProperties]}
saveDisabledReason={saveDisabledReason}
suffix={(issuesLink, dateRangeLabel) => (
<>
across {issuesLink} would have matched this severity rule in the last {dateRangeLabel}
</>
)}
extraFields={
<div>
<LemonLabel className="mb-2">Severity</LemonLabel>
<LemonSelect
fullWidth
value={rule.severity ?? undefined}
placeholder="Choose severity"
onChange={updateSeverity}
options={SEVERITY_OPTIONS.map((option) => ({
value: option.value,
label: <LemonTag type={severityTagType(option.value)}>{option.label}</LemonTag>,
}))}
/>
</div>
}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { LemonTag } from '@posthog/lemon-ui'

import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'

import { RuleList } from '../rules/RuleList'
import { ErrorTrackingRuleType, ErrorTrackingSeverityRule } from '../rules/types'
import { SeverityRuleModal, severityLabel, severityTagType } from './SeverityRuleModal'
import { severityRuleModalLogic } from './severityRuleModalLogic'

export function SeverityRules(): JSX.Element {
return (
<RuleList
ruleType={ErrorTrackingRuleType.Severity}
modalLogic={severityRuleModalLogic}
modal={<SeverityRuleModal />}
taxonomicGroupTypes={[TaxonomicFilterGroupType.EventProperties]}
pageKeyPrefix="severity-rule"
description={
<p>
Set the initial severity of newly created issues from exception properties. The first matching rule
wins. When no rule matches, built-in severity inference is preserved. Existing issues are never
changed.
</p>
}
renderCardHeaderExtra={(rule: ErrorTrackingSeverityRule) => (
<>
<span className="text-muted">·</span>
<LemonTag type={severityTagType(rule.severity)}>{severityLabel(rule.severity)}</LemonTag>
</>
)}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { expectLogic } from 'kea-test-utils'

import api from 'lib/api'

import { ProductKey } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
import { EventPropertyFilter, FilterLogicalOperator, PropertyFilterType, PropertyOperator } from '~/types'

import { ErrorTrackingIssueSeverityRuleEnumApi } from '../../../generated/api.schemas'
import { ErrorTrackingSeverityRule, ErrorTrackingRuleType } from '../rules/types'
import { severityRuleModalLogic } from './severityRuleModalLogic'

const browserFilter: EventPropertyFilter = {
key: '$browser',
value: ['Firefox'],
operator: PropertyOperator.Exact,
type: PropertyFilterType.Event,
}

const persistedRule: ErrorTrackingSeverityRule = {
id: 'rule-id',
filters: { type: FilterLogicalOperator.And, values: [browserFilter] },
severity: ErrorTrackingIssueSeverityRuleEnumApi.High,
order_key: 0,
disabled_data: null,
created_at: '2026-08-13T00:00:00Z',
updated_at: '2026-08-13T00:00:00Z',
}

describe('severityRuleModalLogic', () => {
beforeEach(() => {
initKeaTests()
jest.spyOn(api, 'query').mockResolvedValue({ results: [[3, 2]] } as any)
jest.spyOn(api.errorTracking, 'rules').mockResolvedValue({ results: [] })
jest.spyOn(api.errorTracking, 'createRule').mockResolvedValue(persistedRule)
jest.spyOn(api.errorTracking, 'updateRule').mockResolvedValue()
jest.spyOn(api.errorTracking, 'deleteRule').mockResolvedValue()
})

afterEach(() => {
jest.restoreAllMocks()
})

it('requires a supported severity and creates a rule', async () => {
const logic = severityRuleModalLogic()
logic.mount()

logic.actions.openModal()
expect(logic.values.hasSeverity).toBe(false)
logic.actions.updateSeverity(ErrorTrackingIssueSeverityRuleEnumApi.Critical)
expect(logic.values.hasSeverity).toBe(true)

await expectLogic(logic, () => logic.actions.saveRule()).toFinishAllListeners()

expect(api.errorTracking.createRule).toHaveBeenCalledWith(
ErrorTrackingRuleType.Severity,
expect.objectContaining({ severity: ErrorTrackingIssueSeverityRuleEnumApi.Critical })
)
logic.unmount()
})

it('edits and deletes a persisted rule', async () => {
const logic = severityRuleModalLogic()
logic.mount()

logic.actions.openModal(persistedRule)
logic.actions.updateSeverity(ErrorTrackingIssueSeverityRuleEnumApi.Low)
await expectLogic(logic, () => logic.actions.saveRule()).toFinishAllListeners()
expect(api.errorTracking.updateRule).toHaveBeenCalledWith(
ErrorTrackingRuleType.Severity,
expect.objectContaining({ id: persistedRule.id, severity: ErrorTrackingIssueSeverityRuleEnumApi.Low })
)

logic.actions.openModal(persistedRule)
await expectLogic(logic, () => logic.actions.deleteRule()).toFinishAllListeners()
expect(api.errorTracking.deleteRule).toHaveBeenCalledWith(ErrorTrackingRuleType.Severity, persistedRule.id)
logic.unmount()
})

it('previews matching exceptions with error tracking query tags', async () => {
const logic = severityRuleModalLogic()
logic.mount()

await expectLogic(logic, () => {
logic.actions.openModal(persistedRule)
logic.actions.loadMatchCount()
}).toFinishAllListeners()

expect(api.query).toHaveBeenCalledWith(
expect.objectContaining({
tags: { productKey: ProductKey.ERROR_TRACKING },
fixedProperties: [{ type: FilterLogicalOperator.And, values: [browserFilter] }],
})
)
expect(logic.values.matchResult).toEqual({ exceptionCount: 3, issueCount: 2 })
logic.unmount()
})
})
Loading
Loading