Skip to content

Commit

Permalink
feat: sentry config and custom tags for all action exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
chambaz committed Oct 14, 2024
1 parent cde40ec commit 85d454c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 20 deletions.
10 changes: 6 additions & 4 deletions apps/marginfi-v2-ui/sentry.client.config.ts
Original file line number Diff line number Diff line change
@@ -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://[email protected]/4505861944573952",
tracesSampleRate: 1,
debug: false,
});
2 changes: 1 addition & 1 deletion apps/marginfi-v2-ui/sentry.edge.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Sentry from "@sentry/nextjs";

Sentry.init({
dsn: process.env.SENTRY_DSN,
dsn: "https://[email protected]/4505861944573952",
tracesSampleRate: 1,
debug: false,
});
2 changes: 1 addition & 1 deletion apps/marginfi-v2-ui/sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Sentry from "@sentry/nextjs";

Sentry.init({
dsn: process.env.SENTRY_DSN,
dsn: "https://[email protected]/4505861944573952",
tracesSampleRate: 1,
debug: false,
});
108 changes: 94 additions & 14 deletions packages/mrgn-utils/src/actions/individualFlows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 85d454c

Please sign in to comment.