From dc4252c4de00347b89a0877edb2dcfd15a23fa2e Mon Sep 17 00:00:00 2001 From: Tony Giorgio Date: Thu, 6 Jun 2024 12:55:13 -0500 Subject: [PATCH] Toggle diagnostic reporting --- public/i18n/en.json | 6 +- src/components/KitchenSink.tsx | 3 + src/components/ToggleReportDiagnostics.tsx | 46 +++++++++++ src/components/index.ts | 1 + src/state/megaStore.tsx | 76 +++++++++++------- src/workers/walletWorker.ts | 91 ++++++++++++---------- 6 files changed, 149 insertions(+), 74 deletions(-) create mode 100644 src/components/ToggleReportDiagnostics.tsx diff --git a/public/i18n/en.json b/public/i18n/en.json index 0c825e2a..1f2ba882 100644 --- a/public/i18n/en.json +++ b/public/i18n/en.json @@ -311,7 +311,11 @@ "enable_zaps_to_hodl": "Enable zaps to hodl invoices?", "zaps_to_hodl_desc": "Zaps to hodl invoices can result in channel force closes, which results in high on-chain fees. Use at your own risk!", "zaps_to_hodl_enable": "Enable hodl zaps", - "zaps_to_hodl_disable": "Disable hodl zaps" + "zaps_to_hodl_disable": "Disable hodl zaps", + "enable_report_diagnostics": "Enable diagnostic reporting?", + "report_diagnostics_desc": "Automatically report critical errors to the developers. All transaction data or other personal information is scrubed and anonymized.", + "report_diagnostics_enable": "Enable diagnostics", + "report_diagnostics_disable": "Disable diagnostics" } }, "backup": { diff --git a/src/components/KitchenSink.tsx b/src/components/KitchenSink.tsx index 88833d65..ade4c0ed 100644 --- a/src/components/KitchenSink.tsx +++ b/src/components/KitchenSink.tsx @@ -24,6 +24,7 @@ import { showToast, SimpleErrorDisplay, ToggleHodl, + ToggleReportDiagnostics, VStack } from "~/components"; import { useI18n } from "~/i18n/context"; @@ -572,6 +573,8 @@ export function KitchenSink() {

+ +
); } diff --git a/src/components/ToggleReportDiagnostics.tsx b/src/components/ToggleReportDiagnostics.tsx new file mode 100644 index 00000000..7d830b38 --- /dev/null +++ b/src/components/ToggleReportDiagnostics.tsx @@ -0,0 +1,46 @@ +import { Button, InnerCard, NiceP, VStack } from "~/components"; +import { useI18n } from "~/i18n/context"; +import { useMegaStore } from "~/state/megaStore"; + +export function ToggleReportDiagnostics() { + const i18n = useI18n(); + const [state, actions] = useMegaStore(); + + async function toggle() { + try { + await actions.toggleReportDiagnostics(); + window.location.href = "/"; + } catch (e) { + console.error(e); + } + } + + return ( + + + + {i18n.t( + "settings.admin.kitchen_sink.report_diagnostics_desc" + )} + + + + + + ); +} diff --git a/src/components/index.ts b/src/components/index.ts index 5706dba8..62fddc6b 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -39,6 +39,7 @@ export * from "./Toaster"; export * from "./NostrActivity"; export * from "./MutinyPlusCta"; export * from "./ToggleHodl"; +export * from "./ToggleReportDiagnostics"; export * from "./IOSbanner"; export * from "./HomePrompt"; export * from "./BigMoney"; diff --git a/src/state/megaStore.tsx b/src/state/megaStore.tsx index 21f5dbd9..76ac2296 100644 --- a/src/state/megaStore.tsx +++ b/src/state/megaStore.tsx @@ -5,8 +5,8 @@ import { useNavigate, useSearchParams } from "@solidjs/router"; import { SecureStoragePlugin } from "capacitor-secure-storage-plugin"; import { Remote } from "comlink"; import { - DEV, createContext, + DEV, onCleanup, onMount, ParentComponent, @@ -21,7 +21,6 @@ import { MutinyWalletSettingStrings, Network, setSettings - // setupMutinyWallet } from "~/logic/mutinyWalletSetup"; import { ParsedParams, toParsedParams } from "~/logic/waila"; import { MutinyFederationIdentity } from "~/routes/settings"; @@ -44,40 +43,47 @@ type LoadStage = export type WalletWorker = Remote; const RELEASE_VERSION = import.meta.env.__RELEASE_VERSION__; -const sentryenv = import.meta.env.VITE_SENTRY_ENVIRONMENT || (DEV ? "dev" : "prod"); +const sentryenv = + import.meta.env.VITE_SENTRY_ENVIRONMENT || (DEV ? "dev" : "prod"); export const makeMegaStoreContext = () => { const [searchParams] = useSearchParams(); const navigate = useNavigate(); + const reportDiagnostics = + localStorage.getItem("report_diagnostics") === "true"; // initialize both inside worker and outside - // TODO figure out when to set or not - Sentry.init({ - dsn: "https://192c556849619517322719962a057376@sen.mutinywallet.com/2", - environment: sentryenv, - release: "mutiny-web@" + RELEASE_VERSION, - integrations: [ - Sentry.browserTracingIntegration(), - Sentry.replayIntegration() - ], - - initialScope: { - tags: { component: "main" } - }, - - // Set tracesSampleRate to 1.0 to capture 100% - // of transactions for performance monitoring. - // We recommend adjusting this value in production - tracesSampleRate: 1.0, - - // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled - tracePropagationTargets: ["localhost", /^https:\/\/mutinywallet\.com/], - - // Capture Replay for 10% of all sessions, - // plus 100% of sessions with an error - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1.0 - }); + if (reportDiagnostics) { + Sentry.init({ + dsn: "https://192c556849619517322719962a057376@sen.mutinywallet.com/2", + environment: sentryenv, + release: "mutiny-web@" + RELEASE_VERSION, + integrations: [ + Sentry.browserTracingIntegration(), + Sentry.replayIntegration() + ], + + initialScope: { + tags: { component: "main" } + }, + + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for performance monitoring. + // We recommend adjusting this value in production + tracesSampleRate: 1.0, + + // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled + tracePropagationTargets: [ + "localhost", + /^https:\/\/mutinywallet\.com/ + ], + + // Capture Replay for 10% of all sessions, + // plus 100% of sessions with an error + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0 + }); + } // Not actually a shared worker, but it's the same code const sw = new ComlinkWorker( @@ -118,6 +124,7 @@ export const makeMegaStoreContext = () => { lang: localStorage.getItem("i18nexLng") || undefined, preferredInvoiceType: "unified" as "unified" | "lightning" | "onchain", should_zap_hodl: localStorage.getItem("should_zap_hodl") === "true", + report_diagnostics: reportDiagnostics, testflightPromptDismissed: localStorage.getItem("testflightPromptDismissed") === "true", federations: undefined as MutinyFederationIdentity[] | undefined, @@ -267,6 +274,7 @@ export const makeMegaStoreContext = () => { password, state.safe_mode, state.should_zap_hodl, + state.report_diagnostics, nsec ); @@ -544,6 +552,14 @@ export const makeMegaStoreContext = () => { localStorage.setItem("should_zap_hodl", should_zap_hodl.toString()); setState({ should_zap_hodl }); }, + toggleReportDiagnostics() { + const report_diagnostics = !state.report_diagnostics; + localStorage.setItem( + "report_diagnostics", + report_diagnostics.toString() + ); + setState({ report_diagnostics }); + }, async refreshFederations() { const federations = await sw.list_federations(); diff --git a/src/workers/walletWorker.ts b/src/workers/walletWorker.ts index fdd9b5b8..9bc95fa8 100644 --- a/src/workers/walletWorker.ts +++ b/src/workers/walletWorker.ts @@ -99,52 +99,57 @@ export async function setupMutinyWallet( password?: string, safeMode?: boolean, shouldZapHodl?: boolean, + reportDiagnostics?: boolean, nsec?: string ): Promise { // initialize both inside worker and outside - // TODO figure out when to set or not - Sentry.init({ - dsn: "https://192c556849619517322719962a057376@sen.mutinywallet.com/2", - environment: sentryenv, - release: "mutiny-web@" + RELEASE_VERSION, - integrations: [ - Sentry.captureConsoleIntegration(), // grab all mutiny-node console lines - Sentry.browserTracingIntegration(), - Sentry.replayIntegration() - ], - - initialScope: { - tags: { component: "worker" } - }, - - // ignore any hex larger than 20 char - ignoreErrors: [/(?:[0-9a-fA-F]{20,}\b)+/], - - // only do a new issue for errors w/ or w/o exceptions, and warnings - beforeSend(event, hint) { - const error = hint.originalException; - if (error && typeof error === "object" && "message" in error) { - return event; - } else if (event.level == "warning" || event.level == "error") { - return event; - } else { - return null; - } - }, - - // Set tracesSampleRate to 1.0 to capture 100% - // of transactions for performance monitoring. - // We recommend adjusting this value in production - tracesSampleRate: 1.0, - - // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled - tracePropagationTargets: ["localhost", /^https:\/\/mutinywallet\.com/], - - // Capture Replay for 10% of all sessions, - // plus 100% of sessions with an error - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1.0 - }); + if (reportDiagnostics) { + Sentry.init({ + dsn: "https://192c556849619517322719962a057376@sen.mutinywallet.com/2", + environment: sentryenv, + release: "mutiny-web@" + RELEASE_VERSION, + integrations: [ + Sentry.captureConsoleIntegration(), // grab all mutiny-node console lines + Sentry.browserTracingIntegration(), + Sentry.replayIntegration() + ], + + initialScope: { + tags: { component: "worker" } + }, + + // ignore any hex larger than 20 char + ignoreErrors: [/(?:[0-9a-fA-F]{20,}\b)+/], + + // only do a new issue for errors w/ or w/o exceptions, and warnings + beforeSend(event, hint) { + const error = hint.originalException; + if (error && typeof error === "object" && "message" in error) { + return event; + } else if (event.level == "warning" || event.level == "error") { + return event; + } else { + return null; + } + }, + + // Set tracesSampleRate to 1.0 to capture 100% + // of transactions for performance monitoring. + // We recommend adjusting this value in production + tracesSampleRate: 1.0, + + // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled + tracePropagationTargets: [ + "localhost", + /^https:\/\/mutinywallet\.com/ + ], + + // Capture Replay for 10% of all sessions, + // plus 100% of sessions with an error + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0 + }); + } console.log("Starting setup...");