diff --git a/public/locales/en.json b/public/locales/en.json index cee7495..e185dad 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -89,6 +89,7 @@ "description": "A critical error has occurred in KristWeb, so this page was terminated. See console for details.", "sentryNote": "This error was automatically reported." }, + "errorReported": "An error was automatically reported. See console for details.", "loading": "Loading...", @@ -466,6 +467,10 @@ "defaultPageSize": "Default page size for table listings", "tableHotkeys": "Enable table navigation hotkeys (left and right arrows)", + "subMenuPrivacy": "Privacy", + "errorReporting": "Enable automatic error reporting (requires refresh)", + "messageOnErrorReport": "Show a notification when an error is automatically reported (requires refresh)", + "subMenuDebug": "Debug settings", "advancedWalletFormats": "Advanced wallet formats", "menuTranslations": "Translations", diff --git a/src/pages/settings/SettingsPage.tsx b/src/pages/settings/SettingsPage.tsx index 455af6b..47e871d 100644 --- a/src/pages/settings/SettingsPage.tsx +++ b/src/pages/settings/SettingsPage.tsx @@ -4,7 +4,7 @@ import { FC } from "react"; import { Menu } from "antd"; import { - BugOutlined, GlobalOutlined, ReloadOutlined, SettingOutlined + BugOutlined, GlobalOutlined, ReloadOutlined, SettingOutlined, LockOutlined } from "@ant-design/icons"; import { useTranslation } from "react-i18next"; @@ -80,7 +80,17 @@ booleanSetting("clearTransactionForm"), integerSetting("sendTransactionDelay"), integerSetting("defaultPageSize"), - booleanSetting("tableHotkeys"), + booleanSetting("tableHotkeys") + ]} + /> + + {/* Privacy settings */} + } + settings={[ + booleanSetting("errorReporting"), + booleanSetting("messageOnErrorReport") ]} /> diff --git a/src/utils/errors.ts b/src/utils/errors.ts index 722bd48..669024d 100644 --- a/src/utils/errors.ts +++ b/src/utils/errors.ts @@ -5,14 +5,43 @@ import { CaptureContext } from "@sentry/types"; import { Integrations } from "@sentry/tracing"; +import { message } from "antd"; + declare const __GIT_VERSION__: string; const gitVersion: string = __GIT_VERSION__; +const ls = localStorage.getItem("settings.errorReporting"); +const errorReporting = process.env.DISABLE_SENTRY !== "true" && + (ls === null || ls === "true"); +const messageOnErrorReport = localStorage.getItem("settings.messageOnErrorReport") === "true"; + Sentry.init({ dsn: "https://51a018424102449b88f94c795cf62bb7@sentry.lemmmy.pw/2", release: "kristweb2-react@" + gitVersion, integrations: [new Integrations.BrowserTracing()], - tracesSampleRate: 1.0 + + // Disable Sentry error reporting if the setting is disabled: + tracesSampleRate: errorReporting ? 1 : 0, + + beforeSend(event) { + // Don't send an error event if error reporting is disabled + if (!errorReporting) return null; + + // Show a message on report if the setting is enabled + if (messageOnErrorReport) { + // TODO: Find a way to translate this, while still ensuring that this file + // is imported before everything else. + message.info("An error was automatically reported. See console for details."); + } + + return event; + }, + + beforeBreadcrumb(breadcrumb) { + // Don't send a breadcrumb event if error reporting is disabled + if (!errorReporting) return null; + return breadcrumb; + } }); export function criticalError( diff --git a/src/utils/settings.ts b/src/utils/settings.ts index 7dd362a..6b16662 100644 --- a/src/utils/settings.ts +++ b/src/utils/settings.ts @@ -66,6 +66,14 @@ readonly importOverwrite: boolean; // =========================================================================== + // PRIVACY SETTINGS + // =========================================================================== + /** Enable automatic error reporting. */ + readonly errorReporting: boolean; + /** Show a notification when an error is automatically reported. */ + readonly messageOnErrorReport: boolean; + + // =========================================================================== // DEBUG SETTINGS // =========================================================================== /** Whether or not advanced wallet formats are enabled. */ @@ -94,6 +102,9 @@ tableHotkeys: true, importOverwrite: true, + errorReporting: true, + messageOnErrorReport: false, + walletFormats: false };