From 26d780d5378bf1693b9c728c55e84e1051e40501 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Tue, 11 Jun 2024 13:18:31 -0500 Subject: [PATCH] fix sentry double init --- src/components/SetupErrorDisplay.tsx | 4 +- src/routes/settings/Encrypt.tsx | 4 -- src/state/megaStore.tsx | 65 +++++++++-------- src/workers/walletWorker.ts | 103 +++++++++++++++------------ 4 files changed, 95 insertions(+), 81 deletions(-) diff --git a/src/components/SetupErrorDisplay.tsx b/src/components/SetupErrorDisplay.tsx index f00c737f..b8f8697b 100644 --- a/src/components/SetupErrorDisplay.tsx +++ b/src/components/SetupErrorDisplay.tsx @@ -12,7 +12,8 @@ import { LargeHeader, Logs, NiceP, - SmallHeader + SmallHeader, + ToggleReportDiagnostics } from "~/components"; import { useI18n } from "~/i18n/context"; import { @@ -221,6 +222,7 @@ export function SetupErrorDisplay(props: { +
diff --git a/src/routes/settings/Encrypt.tsx b/src/routes/settings/Encrypt.tsx index e02de579..8ad1d28f 100644 --- a/src/routes/settings/Encrypt.tsx +++ b/src/routes/settings/Encrypt.tsx @@ -4,7 +4,6 @@ import { createMemo, createSignal, Show } from "solid-js"; import { BackLink, Button, - ButtonLink, DefaultMain, InfoBox, LargeHeader, @@ -162,9 +161,6 @@ export function Encrypt() { - - {i18n.t("settings.encrypt.skip")} - diff --git a/src/state/megaStore.tsx b/src/state/megaStore.tsx index 3974da4a..ec0245e0 100644 --- a/src/state/megaStore.tsx +++ b/src/state/megaStore.tsx @@ -177,36 +177,41 @@ export const makeMegaStoreContext = () => { const reportDiagnostics = localStorage.getItem("report_diagnostics") === "true"; - if (reportDiagnostics && sentryenv !== "") { - 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 - }); + try { + // If there's a password that means we've already setup sentry the first time + if (reportDiagnostics && sentryenv !== "" && !password) { + 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 + }); + } + } catch (e) { + console.error("Error initializing sentry", e); } // handle lsp settings diff --git a/src/workers/walletWorker.ts b/src/workers/walletWorker.ts index 06cddc05..6ee55ee1 100644 --- a/src/workers/walletWorker.ts +++ b/src/workers/walletWorker.ts @@ -102,52 +102,63 @@ export async function setupMutinyWallet( nsec?: string ): Promise { // initialize both inside worker and outside - if (reportDiagnostics && sentryenv !== "") { - 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 - }); + try { + if (reportDiagnostics && sentryenv !== "") { + 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 + }); + } + } catch (e) { + console.error("Error initializing sentry", e); } console.log("Starting setup...");