: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(error-tracking): add an exception ingestion switch to settings (#120973)
Paweł Ledwoń062bd3128665
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex cce6e2c3c29d..c0c87c79b06f 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -15217,9 +15217,9 @@ snapshots:scenes-app-settings-environment--settings-environment-error-tracking--light:hash: v1.k794b7964.adb6fd411ffdc03ea8e1b9a29f01536d41a5af4b6224c37881d7ad6b06630f84.WGucFxYafyt1RqQ5e0M6MzvBxP4nGZseNtgVciGxRWcscenes-app-settings-environment--settings-environment-error-tracking-configuration--dark:- hash: v1.k794b7964.b9f9247aed6011b34d8de55a815a1076ef1264d4006e9abbe916ee28d38665f2.-DWM-Caji60kW793I3Uk4xpU9I2V4TMWOpdpUoOALXE+ hash: v1.k794b7964.ec06b32dd20c57ad9a82e1f94711678b9ccc586027958cb583102fa06bda94e5.R0Xah_fVqbKt8GSnJzj6Mb4HWqCK0VLaYPvmC-it9hQscenes-app-settings-environment--settings-environment-error-tracking-configuration--light:- hash: v1.k794b7964.8c207be636962ff664e59aa0ef01c4f036c721f77b370498a97df74558e6099d.cGjBPc2rJtnAGLrx1IjS9uYSycan4jjtoW4Mf9RLZlo+ hash: v1.k794b7964.fe0b9b2717829dbcadc4b61a3366c48a9141440fc907ed6a12d5d171f231c2df.vJ-9wkHdToz9HblFJRGAvWp8-hVVmxNp-zPPlni1vHAscenes-app-settings-environment--settings-environment-experiments--dark:hash: v1.k794b7964.97267477544077ef369227235fde9b1c9380237167be329954cf2f4ce360283e.NgTCKnQHKhLyLWyje5QLi6KyJlx3k5fnuF9ODDZ9BFYscenes-app-settings-environment--settings-environment-experiments--light:diff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsxindex 859a62cf1153..8653cd4f7e4f 100644--- a/frontend/src/scenes/settings/SettingsMap.tsx+++ b/frontend/src/scenes/settings/SettingsMap.tsx@@ -71,6 +71,7 @@ import { CalendarSyncConfig } from 'products/customer_analytics/frontend/scenes/import { CustomerAnalyticsDashboardEvents } from 'products/customer_analytics/frontend/scenes/CustomerAnalyticsConfigurationScene/events/CustomerAnalyticsDashboardEvents'import { DataQualityGateToggle } from 'products/data_quality/frontend/settings/DataQualityGateToggle'import { ExceptionAutocaptureToggle } from 'products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/exception_autocapture/ExceptionAutocaptureSettings'+import { GeneralSettings } from 'products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/general/GeneralSettings'import { SuppressionRules } from 'products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/suppression_rules/SuppressionRules'import { MAX_LOOKBACK_DAYS, MIN_LOOKBACK_DAYS } from 'products/experiments/frontend/constants'import { FeatureFlagRequestBlocklist } from 'products/feature_flags/frontend/FeatureFlagRequestBlocklist'@@ -885,14 +886,21 @@ export const SETTINGS_MAP: SettingSection[] = [},settings: [{- id: 'error-tracking-exception-autocapture',- title: 'Exception autocapture',- description:- 'Automatically capture frontend exceptions using onError and onUnhandledRejection listeners in the web JavaScript SDK.',- docsUrl: 'https://posthog.com/docs/error-tracking',- platformSupport: FEATURE_SUPPORT.errorTrackingExceptionAutocapture,- component: <ExceptionAutocaptureToggle />,- keywords: ['crash', 'bug', 'exception', 'stack trace'],+ id: 'error-tracking-general',+ title: 'General',+ component: <GeneralSettings />,+ keywords: [+ 'kill switch',+ 'disable',+ 'stop',+ 'ingestion',+ 'drop',+ 'autocapture',+ 'crash',+ 'bug',+ 'exception',+ 'stack trace',+ ],},{id: 'error-tracking-alerting',diff --git a/frontend/src/scenes/settings/stories/SettingsEnvironment.stories.tsx b/frontend/src/scenes/settings/stories/SettingsEnvironment.stories.tsxindex 339a7897663e..5f7dc36c37f2 100644--- a/frontend/src/scenes/settings/stories/SettingsEnvironment.stories.tsx+++ b/frontend/src/scenes/settings/stories/SettingsEnvironment.stories.tsx@@ -192,6 +192,19 @@ export const SettingsEnvironmentErrorTracking: Story = { args: { sectionId: 'envexport const SettingsEnvironmentErrorTrackingConfiguration: Story = {args: { sectionId: 'environment-error-tracking-configuration' },+ decorators: [+ mswDecorator({+ get: {+ '/api/projects/:id/error_tracking/settings/retrieve_settings/': {+ project_rate_limit_value: null,+ project_rate_limit_bucket_size_minutes: null,+ per_issue_rate_limit_value: null,+ per_issue_rate_limit_bucket_size_minutes: null,+ ingestion_enabled: true,+ },+ },+ }),+ ],}export const SettingsEnvironmentCSPReporting: Story = { args: { sectionId: 'environment-csp-reporting' } }diff --git a/frontend/src/scenes/settings/types.ts b/frontend/src/scenes/settings/types.tsindex f669e038ee6e..11fa1ff065be 100644--- a/frontend/src/scenes/settings/types.ts+++ b/frontend/src/scenes/settings/types.ts@@ -183,6 +183,7 @@ export type SettingId =| 'error-tracking-auto-assignment'| 'error-tracking-custom-grouping'| 'error-tracking-exception-autocapture'+ | 'error-tracking-general'| 'error-tracking-ingestion-controls'| 'error-tracking-integrations'| 'error-tracking-rate-limits'diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/general/ExceptionIngestionSettings.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/general/ExceptionIngestionSettings.tsxnew file mode 100644index 000000000000..dab462810a4b--- /dev/null+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/general/ExceptionIngestionSettings.tsx@@ -0,0 +1,58 @@+import { useActions, useValues } from 'kea'++import { LemonBanner, LemonDialog, LemonSkeleton, LemonSwitch } from '@posthog/lemon-ui'++import { errorTrackingEditAccessDisabledReason } from '../../../utils'+import { exceptionIngestionLogic } from './exceptionIngestionLogic'++export function ExceptionIngestionSettings(): JSX.Element {+ const { ingestionEnabled, settingsLoading, settingsLoadFailed } = useValues(exceptionIngestionLogic)+ const { setIngestionEnabled } = useActions(exceptionIngestionLogic)++ const onChange = (checked: boolean): void => {+ if (checked) {+ setIngestionEnabled(true)+ return+ }+ LemonDialog.open({+ title: 'Stop ingesting exceptions?',+ description:+ "PostHog will drop every exception this project sends until you turn ingestion back on. You can't recover dropped exceptions.",+ primaryButton: {+ children: 'Stop ingesting',+ status: 'danger',+ onClick: () => setIngestionEnabled(false),+ 'data-attr': 'error-tracking-ingestion-disable-confirm',+ },+ secondaryButton: { children: 'Cancel' },+ })+ }++ return (+ <div className="space-y-4">+ <div>+ <h3 className="font-semibold text-base mb-1">Exception ingestion</h3>+ <p className="text-muted-foreground">+ When this is off, PostHog drops every exception this project sends. Dropped exceptions aren't stored+ or billed, and you can't recover them. Changes take up to a minute to apply.+ </p>+ </div>+ {ingestionEnabled !== null ? (+ <LemonSwitch+ id="error-tracking-ingestion-switch"+ data-attr="error-tracking-ingestion-switch"+ label="Ingest exceptions"+ checked={ingestionEnabled}+ onChange={onChange}+ loading={settingsLoading}+ disabledReason={errorTrackingEditAccessDisabledReason()}+ bordered+ />+ ) : settingsLoadFailed ? (+ <LemonBanner type="error">Couldn't load this setting. Refresh the page to try again.</LemonBanner>+ ) : (+ <LemonSkeleton className="w-60 h-10" />+ )}+ </div>+ )+}diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/general/GeneralSettings.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/general/GeneralSettings.tsxnew file mode 100644index 000000000000..10d25a5de50d--- /dev/null+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/general/GeneralSettings.tsx@@ -0,0 +1,35 @@+import { Link } from '@posthog/lemon-ui'++import { FEATURE_SUPPORT } from 'lib/components/SupportedPlatforms/featureSupport'+import { SupportedPlatforms } from 'lib/components/SupportedPlatforms/SupportedPlatforms'++import { ExceptionAutocaptureToggle } from '../exception_autocapture/ExceptionAutocaptureSettings'+import { ExceptionIngestionSettings } from './ExceptionIngestionSettings'++export function GeneralSettings(): JSX.Element {+ return (+ <div className="space-y-8">+ <ExceptionIngestionSettings />+ <div className="space-y-4">+ <div>+ <h3 className="flex flex-wrap gap-2 items-center font-semibold text-base mb-1">+ Exception autocapture+ <SupportedPlatforms config={FEATURE_SUPPORT.errorTrackingExceptionAutocapture} />+ </h3>+ <p className="text-muted-foreground">+ Automatically capture frontend exceptions using onError and onUnhandledRejection listeners in+ the web JavaScript SDK.{' '}+ <Link+ to="https://posthog.com/docs/error-tracking"+ target="_blank"+ data-attr="settings-docs-link-error-tracking-exception-autocapture"+ >+ Docs+ </Link>+ </p>+ </div>+ <ExceptionAutocaptureToggle />+ </div>+ </div>+ )+}diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/general/exceptionIngestionLogic.ts b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/general/exceptionIngestionLogic.tsnew file mode 100644index 000000000000..c93a7f10f58e--- /dev/null+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/general/exceptionIngestionLogic.ts@@ -0,0 +1,126 @@+import { MakeLogicType, afterMount, kea, listeners, path, reducers, selectors } from 'kea'+import { loaders } from 'kea-loaders'+import posthog from 'posthog-js'++import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { getCurrentTeamId } from 'lib/utils/getAppContext'++import {+ errorTrackingSettingsRetrieveSettingsRetrieve,+ errorTrackingSettingsUpdateSettingsPartialUpdate,+} from '../../../generated/api'+import type { ErrorTrackingSettingsApi } from '../../../generated/api.schemas'++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface exceptionIngestionLogicValues {+ ingestionEnabled: boolean | null+ settings: ErrorTrackingSettingsApi | null+ settingsLoadFailed: boolean+ settingsLoading: boolean+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface exceptionIngestionLogicActions {+ loadSettings: () => any+ loadSettingsFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadSettingsSuccess: (+ settings: ErrorTrackingSettingsApi,+ payload?: any+ ) => {+ settings: ErrorTrackingSettingsApi+ payload?: any+ }+ setIngestionEnabled: (ingestionEnabled: boolean) => boolean+ setIngestionEnabledFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ setIngestionEnabledSuccess: (+ settings: ErrorTrackingSettingsApi,+ payload?: boolean+ ) => {+ settings: ErrorTrackingSettingsApi+ payload?: boolean+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface exceptionIngestionLogicMeta {+ __keaTypeGenInternalSelectorTypes: {+ ingestionEnabled: (settings: ErrorTrackingSettingsApi | null) => boolean | null+ }+}++export type exceptionIngestionLogicType = MakeLogicType<+ exceptionIngestionLogicValues,+ exceptionIngestionLogicActions,+ Record<string, any>,+ exceptionIngestionLogicMeta+>++export const exceptionIngestionLogic = kea<exceptionIngestionLogicType>([+ path([+ 'products',+ 'error_tracking',+ 'scenes',+ 'ErrorTrackingConfigurationScene',+ 'general',+ 'exceptionIngestionLogic',+ ]),++ loaders({+ settings: [+ null as ErrorTrackingSettingsApi | null,+ {+ loadSettings: async () => {+ return await errorTrackingSettingsRetrieveSettingsRetrieve(getCurrentTeamId().toString())+ },+ setIngestionEnabled: async (ingestionEnabled: boolean) => {+ return await errorTrackingSettingsUpdateSettingsPartialUpdate(getCurrentTeamId().toString(), {+ ingestion_enabled: ingestionEnabled,+ })+ },+ },+ ],+ }),++ reducers({+ settingsLoadFailed: [+ false,+ {+ loadSettings: () => false,+ loadSettingsFailure: () => true,+ },+ ],+ }),++ selectors({+ ingestionEnabled: [+ (s) => [s.settings],+ (settings: ErrorTrackingSettingsApi | null): boolean | null =>+ settings ? settings.ingestion_enabled !== false : null,+ ],+ }),++ listeners({+ setIngestionEnabledSuccess: ({ settings }) => {+ const ingestionEnabled = settings.ingestion_enabled !== false+ // pinned: analytics event name, renaming it breaks dashboards+ posthog.capture('error_tracking_ingestion_toggled', { ingestion_enabled: ingestionEnabled })+ lemonToast.success(ingestionEnabled ? 'Exception ingestion turned on' : 'Exception ingestion turned off')+ },+ }),++ afterMount(({ actions }) => {+ actions.loadSettings()+ }),+])diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingScene/errorTrackingSceneLogic.ts b/products/error_tracking/frontend/scenes/ErrorTrackingScene/errorTrackingSceneLogic.tsindex f044cce4ef94..5fc741f2d033 100644--- a/products/error_tracking/frontend/scenes/ErrorTrackingScene/errorTrackingSceneLogic.ts+++ b/products/error_tracking/frontend/scenes/ErrorTrackingScene/errorTrackingSceneLogic.ts@@ -33,6 +33,7 @@ import type {import { bulkSelectLogic } from '../../logics/bulkSelectLogic'import { pendingFingerprintIssueStateUpdateLogic } from '../../logics/pendingFingerprintIssueStateUpdateLogic'import { errorTrackingQuery } from '../../queries'+import { resolveSettingSlug } from '../../settingsRedirects'import {ERROR_TRACKING_LISTING_RESOLUTION,ERROR_TRACKING_LOGIC_KEY,@@ -277,8 +278,9 @@ export const errorTrackingSceneLogic = kea<errorTrackingSceneLogicType>([if (isActiveTab(params.activeTab) && !equal(params.activeTab, values.activeTab)) {actions.setActiveTab(params.activeTab)}- if (hashParams.selectedSetting && hashParams.selectedSetting !== values.selectedSettingId) {- actions.selectSetting(hashParams.selectedSetting)+ const selectedSettingId = resolveSettingSlug(hashParams.selectedSetting) as SettingId | undefined+ if (selectedSettingId && selectedSettingId !== values.selectedSettingId) {+ actions.selectSetting(selectedSettingId)}triggerFilterActions(params, values, actions)},diff --git a/products/error_tracking/frontend/settingsRedirects.ts b/products/error_tracking/frontend/settingsRedirects.tsindex 7cbe43387ce8..2f4d486aa365 100644--- a/products/error_tracking/frontend/settingsRedirects.ts+++ b/products/error_tracking/frontend/settingsRedirects.ts@@ -5,10 +5,12 @@ import type { Params } from 'scenes/sceneTypes'// The configuration pages (symbol sets, alerting, and so on) used to be their own routes.// They are now tabs in the configuration settings panel, so map each old path slug to its// current setting id. Both underscore and hyphen slug spellings appear in old links.+// A setting id that moved into another tab maps to that tab.const LEGACY_SETTING_SLUGS: Record<string, string> = {alerting: 'error-tracking-alerting','assignment-rules': 'error-tracking-auto-assignment',- 'exception-autocapture': 'error-tracking-exception-autocapture',+ 'exception-autocapture': 'error-tracking-general',+ 'error-tracking-exception-autocapture': 'error-tracking-general','grouping-rules': 'error-tracking-custom-grouping','rate-limit': 'error-tracking-rate-limits',releases: 'error-tracking-releases',