From 85d454c5e47d932974bba58104bdb196ef1e8cac Mon Sep 17 00:00:00 2001 From: chambaz Date: Mon, 14 Oct 2024 15:54:11 -0400 Subject: [PATCH] feat: sentry config and custom tags for all action exceptions --- apps/marginfi-v2-ui/sentry.client.config.ts | 10 +- apps/marginfi-v2-ui/sentry.edge.config.ts | 2 +- apps/marginfi-v2-ui/sentry.server.config.ts | 2 +- .../mrgn-utils/src/actions/individualFlows.ts | 108 +++++++++++++++--- 4 files changed, 102 insertions(+), 20 deletions(-) diff --git a/apps/marginfi-v2-ui/sentry.client.config.ts b/apps/marginfi-v2-ui/sentry.client.config.ts index 2767473ec9..12349db6ae 100644 --- a/apps/marginfi-v2-ui/sentry.client.config.ts +++ b/apps/marginfi-v2-ui/sentry.client.config.ts @@ -1,5 +1,7 @@ -// This file configures the initialization of Sentry on the client. -// The config you add here will be used whenever a users loads a page in their browser. -// https://docs.sentry.io/platforms/javascript/guides/nextjs/ - import * as Sentry from "@sentry/nextjs"; + +Sentry.init({ + dsn: "https://5dd81f7047c001781ac8a520d8355f11@o1279738.ingest.us.sentry.io/4505861944573952", + tracesSampleRate: 1, + debug: false, +}); diff --git a/apps/marginfi-v2-ui/sentry.edge.config.ts b/apps/marginfi-v2-ui/sentry.edge.config.ts index 6eb66d1e61..12349db6ae 100644 --- a/apps/marginfi-v2-ui/sentry.edge.config.ts +++ b/apps/marginfi-v2-ui/sentry.edge.config.ts @@ -1,7 +1,7 @@ import * as Sentry from "@sentry/nextjs"; Sentry.init({ - dsn: process.env.SENTRY_DSN, + dsn: "https://5dd81f7047c001781ac8a520d8355f11@o1279738.ingest.us.sentry.io/4505861944573952", tracesSampleRate: 1, debug: false, }); diff --git a/apps/marginfi-v2-ui/sentry.server.config.ts b/apps/marginfi-v2-ui/sentry.server.config.ts index 6eb66d1e61..12349db6ae 100644 --- a/apps/marginfi-v2-ui/sentry.server.config.ts +++ b/apps/marginfi-v2-ui/sentry.server.config.ts @@ -1,7 +1,7 @@ import * as Sentry from "@sentry/nextjs"; Sentry.init({ - dsn: process.env.SENTRY_DSN, + dsn: "https://5dd81f7047c001781ac8a520d8355f11@o1279738.ingest.us.sentry.io/4505861944573952", tracesSampleRate: 1, debug: false, }); diff --git a/packages/mrgn-utils/src/actions/individualFlows.ts b/packages/mrgn-utils/src/actions/individualFlows.ts index f9f0678c1d..74db3ff554 100644 --- a/packages/mrgn-utils/src/actions/individualFlows.ts +++ b/packages/mrgn-utils/src/actions/individualFlows.ts @@ -54,7 +54,12 @@ export async function createAccount({ multiStepToast.setSuccessAndNext(); } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "createAccount", + wallet: walletContextState?.publicKey?.toBase58(), + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while depositing: ${msg}`); console.log(error); @@ -92,7 +97,12 @@ export async function createAccountAndDeposit({ multiStepToast.setSuccessAndNext(); } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "createAccount", + wallet: walletContextState?.publicKey?.toBase58(), + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while depositing: ${msg}`); console.log(error); @@ -105,7 +115,13 @@ export async function createAccountAndDeposit({ return txnSig; } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "deposit", + wallet: walletContextState?.publicKey?.toBase58(), + bank: bank.meta.tokenSymbol, + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while depositing: ${msg}`); console.log(error); @@ -143,7 +159,13 @@ export async function deposit({ return txnSig; } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "deposit", + wallet: marginfiAccount?.authority?.toBase58(), + bank: bank.meta.tokenSymbol, + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while depositing: ${msg}`); console.log(error); @@ -181,7 +203,13 @@ export async function borrow({ return sigs; } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "borrow", + wallet: marginfiAccount?.authority?.toBase58(), + bank: bank.meta.tokenSymbol, + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while borrowing: ${msg}`); console.log(error); @@ -221,7 +249,13 @@ export async function withdraw({ return sigs; } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "withdraw", + wallet: marginfiAccount?.authority?.toBase58(), + bank: bank.meta.tokenSymbol, + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while withdrawing: ${msg}`); console.log(error); @@ -260,7 +294,13 @@ export async function repay({ return txnSig; } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "repay", + wallet: marginfiAccount?.authority?.toBase58(), + bank: bank.meta.tokenSymbol, + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while repaying: ${msg}`); console.log(error); @@ -329,7 +369,14 @@ export async function looping({ return sigs; } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "looping", + wallet: marginfiAccount?.authority?.toBase58(), + bank: bank.meta.tokenSymbol, + loopingBank: loopingOptions?.loopingBank.meta.tokenSymbol, + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while looping: ${msg}`); console.log(error); @@ -392,7 +439,14 @@ export async function repayWithCollat({ return sigs; } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "repayWithCollat", + wallet: marginfiAccount?.authority?.toBase58(), + bank: bank.meta.tokenSymbol, + repayWithCollatBank: repayWithCollatOptions?.depositBank.meta.tokenSymbol, + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while repaying: ${msg}`); console.log(error); @@ -415,7 +469,12 @@ export async function collectRewardsBatch( return txnSig; } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "collectRewardsBatch", + wallet: marginfiAccount?.authority?.toBase58(), + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while collecting rewards: ${msg}`); console.log(error); @@ -461,7 +520,13 @@ export const closeBalance = async ({ return txnSig; } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "closeBalance", + wallet: marginfiAccount?.authority?.toBase58(), + bank: bank.meta.tokenSymbol, + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while closing balance`); console.log(error); @@ -521,7 +586,12 @@ export async function mintLstStakeToStake({ return txnSig; } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "mintLstStakeToStake", + wallet: wallet.publicKey.toBase58(), + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while minting lst: ${msg}`); console.log(error); @@ -587,7 +657,12 @@ export async function mintLstNative({ return txnSig; } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "mintLstNative", + wallet: wallet.publicKey.toBase58(), + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while minting lst: ${msg}`); console.log(error); @@ -663,7 +738,12 @@ export async function mintLstToken({ return swapSig; } catch (error: any) { const msg = extractErrorString(error); - Sentry.captureException({ message: error }); + Sentry.setTags({ + action: "mintLstToken", + wallet: wallet.publicKey.toBase58(), + customMessage: msg, + }); + Sentry.captureException(error); multiStepToast.setFailed(msg); console.log(`Error while minting lst: ${msg}`); console.log(error);