Skip to content

Commit

Permalink
chore: provide tags to sentry events
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Jun 21, 2024
1 parent f4e24da commit cfac7ab
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Install Playwright
run: npx playwright install --with-deps
- name: Build Storybook
run: NODE_OPTIONS="--max-old-space-size=8046" npm run build-storybook --quiet
run: NODE_OPTIONS="--max-old-space-size=8046" npm run build:storybook --quiet
- name: Serve Storybook and run tests
run: |
npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
Expand Down
16 changes: 8 additions & 8 deletions govtool/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions govtool/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "voltaire-voting-app",
"name": "govtool",
"private": true,
"version": "0.0.0",
"version": "1.0.6",
"type": "module",
"scripts": {
"build": "vite build",
"build-storybook": "storybook build",
"build:storybook": "storybook build",
"chromatic": "chromatic",
"dev": "vite",
"format": "prettier --write src",
Expand Down Expand Up @@ -34,9 +34,6 @@
"@rollup/plugin-babel": "^6.0.4",
"@rollup/pluginutils": "^5.1.0",
"@sentry/react": "^7.77.0",
"@types/jsonld": "^1.5.13",
"@types/react": "^18.2.12",
"@types/react-gtm-module": "^2.0.2",
"@usersnap/browser": "^0.0.5",
"axios": "^1.4.0",
"bech32": "^2.0.0",
Expand Down Expand Up @@ -78,7 +75,9 @@
"@testing-library/user-event": "^14.5.2",
"@types/jsonld": "^1.5.13",
"@types/node": "^20.4.8",
"@types/react": "^18.2.12",
"@types/react-dom": "^18.0.11",
"@types/react-gtm-module": "^2.0.2",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"@vitejs/plugin-react": "^4.3.0",
Expand Down Expand Up @@ -107,5 +106,5 @@
"typescript": "^5.0.2"
},
"readme": "ERROR: No README data found!",
"_id": "voltaire-voting-app@0.0.0"
"_id": "govtool@1.0.6"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useState } from "react";
import * as Sentry from "@sentry/react";

import { Typography } from "@atoms";
import { useCardano, useModal } from "@context";
Expand Down Expand Up @@ -65,6 +66,8 @@ export const WhatRetirementMeans = ({
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
Sentry.setTag("WhatRetirementMeans", "retireAsDrep");
Sentry.captureException(error);
openWalletErrorModal({
error,
onSumbit: onClickCancel,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useState } from "react";
import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import * as Sentry from "@sentry/react";

import { PATHS } from "@consts";
import { RegisterAsDirectVoterBoxContent } from "@organisms";
Expand Down Expand Up @@ -49,6 +50,8 @@ export const RegisterAsDirectVoterBox = () => {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
Sentry.setTag("RegisterAsDirectVoterBox", "register");
Sentry.captureException(error);
openWalletErrorModal({
error,
buttonText: t("modals.common.goToDashboard"),
Expand Down
7 changes: 4 additions & 3 deletions govtool/frontend/src/context/getUtxos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Utxos = {
}[];

export const getUtxos = async (
enabledApi: CardanoApiWallet
enabledApi: CardanoApiWallet,
): Promise<Utxos | undefined> => {
const utxos = [];

Expand All @@ -24,7 +24,7 @@ export const getUtxos = async (
// eslint-disable-next-line no-restricted-syntax
for (const rawUtxo of rawUtxos) {
const utxo = TransactionUnspentOutput.from_bytes(
Buffer.from(rawUtxo, "hex")
Buffer.from(rawUtxo, "hex"),
);
const input = utxo.input();
const txid = input.transaction_id().to_hex();
Expand Down Expand Up @@ -54,7 +54,7 @@ export const getUtxos = async (
// @ts-ignore
const assetNameHex = Buffer.from(
assetName.name(),
"utf8"
"utf8",
).toString("hex");
const multiassetAmt = multiasset.get_asset(policyId, assetName);
multiAssetStr += `+ ${multiassetAmt.to_str()} + ${policyIdHex}.${assetNameHex} (${assetNameString})`;
Expand All @@ -76,6 +76,7 @@ export const getUtxos = async (

return utxos;
} catch (err) {
Sentry.setTag("getUtxos", "error");
Sentry.captureException(err);
console.error(err);
}
Expand Down
14 changes: 14 additions & 0 deletions govtool/frontend/src/context/governanceAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import {
createContext,
useContext,
useCallback,
useEffect,
} from "react";
import { NodeObject } from "jsonld";
import { blake2bHex } from "blakejs";
import * as Sentry from "@sentry/react";

import { CIP_108, GOVERNANCE_ACTION_CONTEXT } from "@/consts";
import { canonizeJSON, generateJsonld, generateMetadataBody } from "@/utils";
Expand Down Expand Up @@ -40,6 +42,11 @@ const GovernanceActionProvider = ({ children }: PropsWithChildren) => {
* @param {GovActionMetadata} govActionMetadata - The metadata of the governance action.
* @returns The JSON-LD representation of the governance action.
*/

useEffect(() => {
Sentry.setTag("component_name", "GovernanceActionProvider");
}, []);

const createGovernanceActionJsonLD = useCallback(
async (govActionMetadata: GovActionMetadata) => {
try {
Expand All @@ -55,6 +62,11 @@ const GovernanceActionProvider = ({ children }: PropsWithChildren) => {
);
return jsonLD;
} catch (error) {
Sentry.setTag(
"GovernanceActionProvider",
"createGovernanceActionJsonLD",
);
Sentry.captureException(error);
console.error(error);
}
},
Expand All @@ -72,6 +84,8 @@ const GovernanceActionProvider = ({ children }: PropsWithChildren) => {
const canonizedJsonHash = blake2bHex(canonizedJson, undefined, 32);
return canonizedJsonHash;
} catch (error) {
Sentry.setTag("GovernanceActionProvider", "createHash");
Sentry.captureException(error);
console.error(error);
}
}, []);
Expand Down
16 changes: 16 additions & 0 deletions govtool/frontend/src/context/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useState,
} from "react";
Expand Down Expand Up @@ -197,6 +198,10 @@ const CardanoProvider = (props: Props) => {
const { isPendingTransaction, updateTransaction, pendingTransaction } =
usePendingTransaction({ isEnabled, stakeKey });

useEffect(() => {
Sentry.setTag("component_name", "CardanoProvider");
}, []);

const getChangeAddress = async (enabledApi: CardanoApiWallet) => {
try {
const raw = await enabledApi.getChangeAddress();
Expand All @@ -208,6 +213,7 @@ const CardanoProvider = (props: Props) => {
// return changeAddress for the usage of the pillars;
return changeAddress;
} catch (err) {
Sentry.setTag("wallet", "getChangeAddress");
Sentry.captureException(err);
console.error(err);
}
Expand All @@ -223,6 +229,7 @@ const CardanoProvider = (props: Props) => {
).to_bech32();
setWalletState((prev) => ({ ...prev, usedAddress }));
} catch (err) {
Sentry.setTag("wallet", "getUsedAddresses");
Sentry.captureException(err);
console.error(err);
}
Expand Down Expand Up @@ -252,6 +259,7 @@ const CardanoProvider = (props: Props) => {
extensions: [{ cip: 95 }],
})
.catch((e) => {
Sentry.setTag("wallet", "enable");
Sentry.captureException(e);
throw e.info;
});
Expand Down Expand Up @@ -352,6 +360,7 @@ const CardanoProvider = (props: Props) => {

return { status: t("ok"), stakeKey: stakeKeySet };
} catch (e) {
Sentry.setTag("wallet", "enable");
Sentry.captureException(e);
console.error(e);
setError(`${e}`);
Expand Down Expand Up @@ -562,6 +571,7 @@ const CardanoProvider = (props: Props) => {
disconnectWallet();
}

Sentry.setTag("wallet", "buildSignSubmitConwayCertTx");
Sentry.captureException(error);
console.error(error, "error");
throw error?.info ?? error;
Expand Down Expand Up @@ -608,6 +618,7 @@ const CardanoProvider = (props: Props) => {

return certBuilder;
} catch (e) {
Sentry.setTag("wallet", "buildVoteDelegationCert");
Sentry.captureException(e);
console.error(e);
throw e;
Expand Down Expand Up @@ -646,6 +657,7 @@ const CardanoProvider = (props: Props) => {
}
return Certificate.new_drep_registration(dRepRegCert);
} catch (e) {
Sentry.setTag("wallet", "buildDRepRegCert");
Sentry.captureException(e);
console.error(e);
throw e;
Expand Down Expand Up @@ -675,6 +687,7 @@ const CardanoProvider = (props: Props) => {
}
return Certificate.new_drep_update(dRepUpdateCert);
} catch (e) {
Sentry.setTag("wallet", "buildDRepUpdateCert");
Sentry.captureException(e);
console.error(e);
throw e;
Expand All @@ -697,6 +710,7 @@ const CardanoProvider = (props: Props) => {

return Certificate.new_drep_deregistration(dRepRetirementCert);
} catch (e) {
Sentry.setTag("wallet", "buildDRepRetirementCert");
Sentry.captureException(e);
console.error(e);
throw e;
Expand Down Expand Up @@ -750,6 +764,7 @@ const CardanoProvider = (props: Props) => {

return votingBuilder;
} catch (e) {
Sentry.setTag("wallet", "buildVote");
Sentry.captureException(e);
console.error(e);
throw e;
Expand Down Expand Up @@ -954,6 +969,7 @@ function useCardano() {
// TODO: type error
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
Sentry.setTag("wallet", "enable");
Sentry.captureException(e);
await context.disconnectWallet();
navigate(PATHS.home);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Dispatch, SetStateAction, useCallback, useState } from "react";
import { useNavigate } from "react-router-dom";
import { useFormContext } from "react-hook-form";
import { blake2bHex } from "blakejs";
import { captureException } from "@sentry/react";
import * as Sentry from "@sentry/react";
import { useTranslation } from "react-i18next";
import { NodeObject } from "jsonld";

Expand Down Expand Up @@ -156,7 +156,8 @@ export const useCreateGovernanceActionForm = (
throw new Error(t("errors.invalidGovernanceActionType"));
}
} catch (error) {
captureException(error);
Sentry.setTag("useCreateGovernanceActionForm", "buildTransaction");
Sentry.captureException(error);
}
},
[hash],
Expand Down Expand Up @@ -248,7 +249,8 @@ export const useCreateGovernanceActionForm = (
: undefined,
dataTestId: "create-governance-action-error-modal",
});
captureException(error);
Sentry.setTag("useCreateGovernanceActionForm", "onSubmit");
Sentry.captureException(error);
}
} finally {
setIsLoading(false);
Expand Down
3 changes: 3 additions & 0 deletions govtool/frontend/src/hooks/forms/useDelegateTodRepForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useState } from "react";
import { useNavigate } from "react-router-dom";
import { useForm, useWatch } from "react-hook-form";
import * as Sentry from "@sentry/react";

import { PATHS } from "@consts";
import { useCardano, useModal } from "@context";
Expand Down Expand Up @@ -72,6 +73,8 @@ export const useDelegateTodRepForm = () => {
});
}
} catch (error) {
Sentry.setTag("useDelegateTodRepForm", "delegate");
Sentry.captureException(error);
openModal({
type: "statusModal",
state: {
Expand Down
5 changes: 3 additions & 2 deletions govtool/frontend/src/hooks/forms/useEditDRepInfoForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { useFormContext } from "react-hook-form";
import { blake2bHex } from "blakejs";
import { captureException } from "@sentry/react";
import * as Sentry from "@sentry/react";
import { NodeObject } from "jsonld";

import {
Expand Down Expand Up @@ -177,7 +177,8 @@ export const useEditDRepInfoForm = (
},
});
} else {
captureException(error);
Sentry.setTag("useEditDRepInfoForm", "updateMetaData");
Sentry.captureException(error);

openWalletErrorModal({
error,
Expand Down
Loading

0 comments on commit cfac7ab

Please sign in to comment.