Toggle diagnostic reporting

This commit is contained in:
Tony Giorgio
2024-06-06 12:55:13 -05:00
committed by Tony Giorgio
parent 44ceb44fc4
commit d0ea5a5f7a
6 changed files with 139 additions and 64 deletions

View File

@@ -311,7 +311,11 @@
"enable_zaps_to_hodl": "Enable zaps to hodl invoices?", "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_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_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": { "backup": {

View File

@@ -24,6 +24,7 @@ import {
showToast, showToast,
SimpleErrorDisplay, SimpleErrorDisplay,
ToggleHodl, ToggleHodl,
ToggleReportDiagnostics,
VStack VStack
} from "~/components"; } from "~/components";
import { useI18n } from "~/i18n/context"; import { useI18n } from "~/i18n/context";
@@ -572,6 +573,8 @@ export function KitchenSink() {
<Hr /> <Hr />
<Restart /> <Restart />
<Hr /> <Hr />
<ToggleReportDiagnostics />
<Hr />
</> </>
); );
} }

View File

@@ -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 (
<InnerCard
title={i18n.t(
"settings.admin.kitchen_sink.enable_report_diagnostics"
)}
>
<VStack>
<NiceP>
{i18n.t(
"settings.admin.kitchen_sink.report_diagnostics_desc"
)}
</NiceP>
<Button
intent={state.report_diagnostics ? "green" : "red"}
onClick={toggle}
>
{state.report_diagnostics
? i18n.t(
"settings.admin.kitchen_sink.report_diagnostics_disable"
)
: i18n.t(
"settings.admin.kitchen_sink.report_diagnostics_enable"
)}
</Button>
</VStack>
</InnerCard>
);
}

View File

@@ -39,6 +39,7 @@ export * from "./Toaster";
export * from "./NostrActivity"; export * from "./NostrActivity";
export * from "./MutinyPlusCta"; export * from "./MutinyPlusCta";
export * from "./ToggleHodl"; export * from "./ToggleHodl";
export * from "./ToggleReportDiagnostics";
export * from "./IOSbanner"; export * from "./IOSbanner";
export * from "./HomePrompt"; export * from "./HomePrompt";
export * from "./BigMoney"; export * from "./BigMoney";

View File

@@ -5,8 +5,8 @@ import { useNavigate, useSearchParams } from "@solidjs/router";
import { SecureStoragePlugin } from "capacitor-secure-storage-plugin"; import { SecureStoragePlugin } from "capacitor-secure-storage-plugin";
import { Remote } from "comlink"; import { Remote } from "comlink";
import { import {
DEV,
createContext, createContext,
DEV,
onCleanup, onCleanup,
onMount, onMount,
ParentComponent, ParentComponent,
@@ -21,7 +21,6 @@ import {
MutinyWalletSettingStrings, MutinyWalletSettingStrings,
Network, Network,
setSettings setSettings
// setupMutinyWallet
} from "~/logic/mutinyWalletSetup"; } from "~/logic/mutinyWalletSetup";
import { ParsedParams, toParsedParams } from "~/logic/waila"; import { ParsedParams, toParsedParams } from "~/logic/waila";
import { MutinyFederationIdentity } from "~/routes/settings"; import { MutinyFederationIdentity } from "~/routes/settings";
@@ -44,40 +43,47 @@ type LoadStage =
export type WalletWorker = Remote<typeof import("../workers/walletWorker")>; export type WalletWorker = Remote<typeof import("../workers/walletWorker")>;
const RELEASE_VERSION = import.meta.env.__RELEASE_VERSION__; 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 = () => { export const makeMegaStoreContext = () => {
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const navigate = useNavigate(); const navigate = useNavigate();
const reportDiagnostics =
localStorage.getItem("report_diagnostics") === "true";
// initialize both inside worker and outside // initialize both inside worker and outside
// TODO figure out when to set or not if (reportDiagnostics) {
Sentry.init({ Sentry.init({
dsn: "https://192c556849619517322719962a057376@sen.mutinywallet.com/2", dsn: "https://192c556849619517322719962a057376@sen.mutinywallet.com/2",
environment: sentryenv, environment: sentryenv,
release: "mutiny-web@" + RELEASE_VERSION, release: "mutiny-web@" + RELEASE_VERSION,
integrations: [ integrations: [
Sentry.browserTracingIntegration(), Sentry.browserTracingIntegration(),
Sentry.replayIntegration() Sentry.replayIntegration()
], ],
initialScope: { initialScope: {
tags: { component: "main" } tags: { component: "main" }
}, },
// Set tracesSampleRate to 1.0 to capture 100% // Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring. // of transactions for performance monitoring.
// We recommend adjusting this value in production // We recommend adjusting this value in production
tracesSampleRate: 1.0, tracesSampleRate: 1.0,
// Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled
tracePropagationTargets: ["localhost", /^https:\/\/mutinywallet\.com/], tracePropagationTargets: [
"localhost",
/^https:\/\/mutinywallet\.com/
],
// Capture Replay for 10% of all sessions, // Capture Replay for 10% of all sessions,
// plus 100% of sessions with an error // plus 100% of sessions with an error
replaysSessionSampleRate: 0.1, replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0 replaysOnErrorSampleRate: 1.0
}); });
}
// Not actually a shared worker, but it's the same code // Not actually a shared worker, but it's the same code
const sw = new ComlinkWorker<typeof import("../workers/walletWorker")>( const sw = new ComlinkWorker<typeof import("../workers/walletWorker")>(
@@ -118,6 +124,7 @@ export const makeMegaStoreContext = () => {
lang: localStorage.getItem("i18nexLng") || undefined, lang: localStorage.getItem("i18nexLng") || undefined,
preferredInvoiceType: "unified" as "unified" | "lightning" | "onchain", preferredInvoiceType: "unified" as "unified" | "lightning" | "onchain",
should_zap_hodl: localStorage.getItem("should_zap_hodl") === "true", should_zap_hodl: localStorage.getItem("should_zap_hodl") === "true",
report_diagnostics: reportDiagnostics,
testflightPromptDismissed: testflightPromptDismissed:
localStorage.getItem("testflightPromptDismissed") === "true", localStorage.getItem("testflightPromptDismissed") === "true",
federations: undefined as MutinyFederationIdentity[] | undefined, federations: undefined as MutinyFederationIdentity[] | undefined,
@@ -267,6 +274,7 @@ export const makeMegaStoreContext = () => {
password, password,
state.safe_mode, state.safe_mode,
state.should_zap_hodl, state.should_zap_hodl,
state.report_diagnostics,
nsec nsec
); );
@@ -544,6 +552,14 @@ export const makeMegaStoreContext = () => {
localStorage.setItem("should_zap_hodl", should_zap_hodl.toString()); localStorage.setItem("should_zap_hodl", should_zap_hodl.toString());
setState({ should_zap_hodl }); setState({ should_zap_hodl });
}, },
toggleReportDiagnostics() {
const report_diagnostics = !state.report_diagnostics;
localStorage.setItem(
"report_diagnostics",
report_diagnostics.toString()
);
setState({ report_diagnostics });
},
async refreshFederations() { async refreshFederations() {
const federations = await sw.list_federations(); const federations = await sw.list_federations();

View File

@@ -99,52 +99,57 @@ export async function setupMutinyWallet(
password?: string, password?: string,
safeMode?: boolean, safeMode?: boolean,
shouldZapHodl?: boolean, shouldZapHodl?: boolean,
reportDiagnostics?: boolean,
nsec?: string nsec?: string
): Promise<boolean> { ): Promise<boolean> {
// initialize both inside worker and outside // initialize both inside worker and outside
// TODO figure out when to set or not if (reportDiagnostics) {
Sentry.init({ Sentry.init({
dsn: "https://192c556849619517322719962a057376@sen.mutinywallet.com/2", dsn: "https://192c556849619517322719962a057376@sen.mutinywallet.com/2",
environment: sentryenv, environment: sentryenv,
release: "mutiny-web@" + RELEASE_VERSION, release: "mutiny-web@" + RELEASE_VERSION,
integrations: [ integrations: [
Sentry.captureConsoleIntegration(), // grab all mutiny-node console lines Sentry.captureConsoleIntegration(), // grab all mutiny-node console lines
Sentry.browserTracingIntegration(), Sentry.browserTracingIntegration(),
Sentry.replayIntegration() Sentry.replayIntegration()
], ],
initialScope: { initialScope: {
tags: { component: "worker" } tags: { component: "worker" }
}, },
// ignore any hex larger than 20 char // ignore any hex larger than 20 char
ignoreErrors: [/(?:[0-9a-fA-F]{20,}\b)+/], ignoreErrors: [/(?:[0-9a-fA-F]{20,}\b)+/],
// only do a new issue for errors w/ or w/o exceptions, and warnings // only do a new issue for errors w/ or w/o exceptions, and warnings
beforeSend(event, hint) { beforeSend(event, hint) {
const error = hint.originalException; const error = hint.originalException;
if (error && typeof error === "object" && "message" in error) { if (error && typeof error === "object" && "message" in error) {
return event; return event;
} else if (event.level == "warning" || event.level == "error") { } else if (event.level == "warning" || event.level == "error") {
return event; return event;
} else { } else {
return null; return null;
} }
}, },
// Set tracesSampleRate to 1.0 to capture 100% // Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring. // of transactions for performance monitoring.
// We recommend adjusting this value in production // We recommend adjusting this value in production
tracesSampleRate: 1.0, tracesSampleRate: 1.0,
// Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled
tracePropagationTargets: ["localhost", /^https:\/\/mutinywallet\.com/], tracePropagationTargets: [
"localhost",
/^https:\/\/mutinywallet\.com/
],
// Capture Replay for 10% of all sessions, // Capture Replay for 10% of all sessions,
// plus 100% of sessions with an error // plus 100% of sessions with an error
replaysSessionSampleRate: 0.1, replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0 replaysOnErrorSampleRate: 1.0
}); });
}
console.log("Starting setup..."); console.log("Starting setup...");