Disable sentry in development and catch reporting errors (#12321)

This commit is contained in:
Justin Starry 2020-09-18 10:47:58 +08:00 committed by GitHub
parent 9b866d79fb
commit 19f412b85c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 58 additions and 56 deletions

View File

@ -1,5 +1,4 @@
import React from "react"; import React from "react";
import * as Sentry from "@sentry/react";
import { Account, useFetchAccountInfo } from "providers/accounts"; import { Account, useFetchAccountInfo } from "providers/accounts";
import { import {
TokenAccount, TokenAccount,
@ -15,6 +14,7 @@ import { TokenRegistry } from "tokenRegistry";
import { useCluster } from "providers/cluster"; import { useCluster } from "providers/cluster";
import { normalizeTokenAmount } from "utils"; import { normalizeTokenAmount } from "utils";
import { addressLabel } from "utils/tx"; import { addressLabel } from "utils/tx";
import { reportError } from "utils/sentry";
export function TokenAccountSection({ export function TokenAccountSection({
account, account,
@ -39,10 +39,8 @@ export function TokenAccountSection({
} }
} }
} catch (err) { } catch (err) {
Sentry.captureException(err, { reportError(err, {
tags: {
address: account.pubkey.toBase58(), address: account.pubkey.toBase58(),
},
}); });
} }
return <UnknownAccountCard account={account} />; return <UnknownAccountCard account={account} />;

View File

@ -1,9 +1,9 @@
import React from "react"; import React from "react";
import * as Sentry from "@sentry/react";
import { TransactionInstruction, SignatureResult } from "@solana/web3.js"; import { TransactionInstruction, SignatureResult } from "@solana/web3.js";
import { InstructionCard } from "./InstructionCard"; import { InstructionCard } from "./InstructionCard";
import { parseSerumInstructionTitle } from "utils/tx"; import { parseSerumInstructionTitle } from "utils/tx";
import { useCluster } from "providers/cluster"; import { useCluster } from "providers/cluster";
import { reportError } from "utils/sentry";
export function SerumDetailsCard({ export function SerumDetailsCard({
ix, ix,
@ -22,11 +22,9 @@ export function SerumDetailsCard({
try { try {
title = parseSerumInstructionTitle(ix); title = parseSerumInstructionTitle(ix);
} catch (error) { } catch (error) {
Sentry.captureException(error, { reportError(error, {
tags: {
url: url, url: url,
signature: signature, signature: signature,
},
}); });
} }

View File

@ -1,5 +1,4 @@
import React from "react"; import React from "react";
import * as Sentry from "@sentry/react";
import { coerce } from "superstruct"; import { coerce } from "superstruct";
import { import {
SignatureResult, SignatureResult,
@ -19,6 +18,7 @@ import {
useFetchAccountInfo, useFetchAccountInfo,
} from "providers/accounts"; } from "providers/accounts";
import { normalizeTokenAmount } from "utils"; import { normalizeTokenAmount } from "utils";
import { reportError } from "utils/sentry";
type DetailsProps = { type DetailsProps = {
tx: ParsedTransaction; tx: ParsedTransaction;
@ -36,10 +36,8 @@ export function TokenDetailsCard(props: DetailsProps) {
const coerced = coerce(info, IX_STRUCTS[type] as any); const coerced = coerce(info, IX_STRUCTS[type] as any);
return <TokenInstruction title={title} info={coerced} {...props} />; return <TokenInstruction title={title} info={coerced} {...props} />;
} catch (err) { } catch (err) {
Sentry.captureException(err, { reportError(err, {
tags: {
signature: props.tx.signatures[0], signature: props.tx.signatures[0],
},
}); });
return <UnknownDetailsCard {...props} />; return <UnknownDetailsCard {...props} />;
} }

View File

@ -12,10 +12,12 @@ import { AccountsProvider } from "./providers/accounts";
import { StatsProvider } from "providers/stats"; import { StatsProvider } from "providers/stats";
import { MintsProvider } from "providers/mints"; import { MintsProvider } from "providers/mints";
Sentry.init({ if (process.env.NODE_ENV === "production") {
Sentry.init({
dsn: dsn:
"https://5efdc15b4828434fbe949b5daed472be@o434108.ingest.sentry.io/5390542", "https://5efdc15b4828434fbe949b5daed472be@o434108.ingest.sentry.io/5390542",
}); });
}
ReactDOM.render( ReactDOM.render(
<Router> <Router>

View File

@ -1,5 +1,4 @@
import React from "react"; import React from "react";
import * as Sentry from "@sentry/react";
import { import {
PublicKey, PublicKey,
ConfirmedSignatureInfo, ConfirmedSignatureInfo,
@ -9,6 +8,7 @@ import {
import { useCluster, Cluster } from "../cluster"; import { useCluster, Cluster } from "../cluster";
import * as Cache from "providers/cache"; import * as Cache from "providers/cache";
import { ActionType, FetchStatus } from "providers/cache"; import { ActionType, FetchStatus } from "providers/cache";
import { reportError } from "utils/sentry";
type AccountHistory = { type AccountHistory = {
fetched: ConfirmedSignatureInfo[]; fetched: ConfirmedSignatureInfo[];
@ -104,7 +104,7 @@ async function fetchAccountHistory(
status = FetchStatus.Fetched; status = FetchStatus.Fetched;
} catch (error) { } catch (error) {
if (cluster !== Cluster.Custom) { if (cluster !== Cluster.Custom) {
Sentry.captureException(error, { tags: { url } }); reportError(error, { url });
} }
status = FetchStatus.FetchFailed; status = FetchStatus.FetchFailed;
} }

View File

@ -1,5 +1,4 @@
import React from "react"; import React from "react";
import * as Sentry from "@sentry/react";
import { StakeAccount as StakeAccountWasm } from "solana-sdk-wasm"; import { StakeAccount as StakeAccountWasm } from "solana-sdk-wasm";
import { PublicKey, Connection, StakeProgram } from "@solana/web3.js"; import { PublicKey, Connection, StakeProgram } from "@solana/web3.js";
import { useCluster, Cluster } from "../cluster"; import { useCluster, Cluster } from "../cluster";
@ -15,6 +14,7 @@ import {
} from "validators/accounts/token"; } from "validators/accounts/token";
import * as Cache from "providers/cache"; import * as Cache from "providers/cache";
import { ActionType, FetchStatus } from "providers/cache"; import { ActionType, FetchStatus } from "providers/cache";
import { reportError } from "utils/sentry";
export { useAccountHistory } from "./history"; export { useAccountHistory } from "./history";
export type StakeProgramData = { export type StakeProgramData = {
@ -117,9 +117,7 @@ async function fetchAccountInfo(
parsed, parsed,
}; };
} catch (err) { } catch (err) {
Sentry.captureException(err, { reportError(err, { url, address: pubkey.toBase58() });
tags: { url, address: pubkey.toBase58() },
});
// TODO store error state in Account info // TODO store error state in Account info
} }
} else if ("parsed" in result.data) { } else if ("parsed" in result.data) {
@ -133,9 +131,7 @@ async function fetchAccountInfo(
parsed, parsed,
}; };
} catch (err) { } catch (err) {
Sentry.captureException(err, { reportError(err, { url, address: pubkey.toBase58() });
tags: { url, address: pubkey.toBase58() },
});
// TODO store error state in Account info // TODO store error state in Account info
} }
} }
@ -152,7 +148,7 @@ async function fetchAccountInfo(
fetchStatus = FetchStatus.Fetched; fetchStatus = FetchStatus.Fetched;
} catch (error) { } catch (error) {
if (cluster !== Cluster.Custom) { if (cluster !== Cluster.Custom) {
Sentry.captureException(error, { tags: { url } }); reportError(error, { url });
} }
fetchStatus = FetchStatus.FetchFailed; fetchStatus = FetchStatus.FetchFailed;
} }
@ -200,9 +196,7 @@ export function useMintAccountInfo(
return coerce(data.parsed.info, MintAccountInfo); return coerce(data.parsed.info, MintAccountInfo);
} catch (err) { } catch (err) {
Sentry.captureException(err, { reportError(err, { address });
tags: { address },
});
} }
} }
@ -221,9 +215,7 @@ export function useTokenAccountInfo(
return coerce(data.parsed.info, TokenAccountInfo); return coerce(data.parsed.info, TokenAccountInfo);
} catch (err) { } catch (err) {
Sentry.captureException(err, { reportError(err, { address });
tags: { address },
});
} }
} }

View File

@ -1,11 +1,11 @@
import React from "react"; import React from "react";
import * as Sentry from "@sentry/react";
import { Connection, PublicKey } from "@solana/web3.js"; import { Connection, PublicKey } from "@solana/web3.js";
import * as Cache from "providers/cache"; import * as Cache from "providers/cache";
import { ActionType, FetchStatus } from "providers/cache"; import { ActionType, FetchStatus } from "providers/cache";
import { TokenAccountInfo } from "validators/accounts/token"; import { TokenAccountInfo } from "validators/accounts/token";
import { useCluster, Cluster } from "../cluster"; import { useCluster, Cluster } from "../cluster";
import { coerce } from "superstruct"; import { coerce } from "superstruct";
import { reportError } from "utils/sentry";
export type TokenInfoWithPubkey = { export type TokenInfoWithPubkey = {
info: TokenAccountInfo; info: TokenAccountInfo;
@ -75,7 +75,7 @@ async function fetchAccountTokens(
status = FetchStatus.Fetched; status = FetchStatus.Fetched;
} catch (error) { } catch (error) {
if (cluster !== Cluster.Custom) { if (cluster !== Cluster.Custom) {
Sentry.captureException(error, { tags: { url } }); reportError(error, { url });
} }
status = FetchStatus.FetchFailed; status = FetchStatus.FetchFailed;
} }

View File

@ -1,8 +1,8 @@
import React from "react"; import React from "react";
import * as Sentry from "@sentry/react";
import { clusterApiUrl, Connection } from "@solana/web3.js"; import { clusterApiUrl, Connection } from "@solana/web3.js";
import { useQuery } from "../utils/url"; import { useQuery } from "../utils/url";
import { useHistory, useLocation } from "react-router-dom"; import { useHistory, useLocation } from "react-router-dom";
import { reportError } from "utils/sentry";
export enum ClusterStatus { export enum ClusterStatus {
Connected, Connected,
@ -184,9 +184,7 @@ async function updateCluster(
}); });
} catch (error) { } catch (error) {
if (cluster !== Cluster.Custom) { if (cluster !== Cluster.Custom) {
Sentry.captureException(error, { reportError(error, { clusterUrl: clusterUrl(cluster, customUrl) });
tags: { clusterUrl: clusterUrl(cluster, customUrl) },
});
} }
dispatch({ status: ClusterStatus.Failure, cluster, customUrl }); dispatch({ status: ClusterStatus.Failure, cluster, customUrl });
} }

View File

@ -1,5 +1,4 @@
import React from "react"; import React from "react";
import * as Sentry from "@sentry/react";
import { useCluster, Cluster } from "providers/cluster"; import { useCluster, Cluster } from "providers/cluster";
import * as Cache from "providers/cache"; import * as Cache from "providers/cache";
import { ActionType, FetchStatus } from "providers/cache"; import { ActionType, FetchStatus } from "providers/cache";
@ -12,6 +11,7 @@ import {
import { TokenAccountInfo, TokenAccount } from "validators/accounts/token"; import { TokenAccountInfo, TokenAccount } from "validators/accounts/token";
import { ParsedInfo } from "validators"; import { ParsedInfo } from "validators";
import { coerce } from "superstruct"; import { coerce } from "superstruct";
import { reportError } from "utils/sentry";
type LargestAccounts = { type LargestAccounts = {
largest: TokenAccountBalancePairWithOwner[]; largest: TokenAccountBalancePairWithOwner[];
@ -89,7 +89,7 @@ async function fetchLargestAccounts(
} }
} catch (error) { } catch (error) {
if (cluster !== Cluster.Custom) { if (cluster !== Cluster.Custom) {
Sentry.captureException(error, { tags: { url } }); reportError(error, { url });
} }
} }
return account; return account;
@ -100,7 +100,7 @@ async function fetchLargestAccounts(
fetchStatus = FetchStatus.Fetched; fetchStatus = FetchStatus.Fetched;
} catch (error) { } catch (error) {
if (cluster !== Cluster.Custom) { if (cluster !== Cluster.Custom) {
Sentry.captureException(error, { tags: { url } }); reportError(error, { url });
} }
fetchStatus = FetchStatus.FetchFailed; fetchStatus = FetchStatus.FetchFailed;
} }

View File

@ -1,8 +1,8 @@
import React from "react"; import React from "react";
import * as Sentry from "@sentry/react";
import { AccountBalancePair, Connection } from "@solana/web3.js"; import { AccountBalancePair, Connection } from "@solana/web3.js";
import { useCluster, ClusterStatus, Cluster } from "./cluster"; import { useCluster, ClusterStatus, Cluster } from "./cluster";
import { reportError } from "utils/sentry";
export enum Status { export enum Status {
Idle, Idle,
@ -72,7 +72,7 @@ async function fetch(dispatch: Dispatch, cluster: Cluster, url: string) {
}); });
} catch (err) { } catch (err) {
if (cluster !== Cluster.Custom) { if (cluster !== Cluster.Custom) {
Sentry.captureException(err, { tags: { url } }); reportError(err, { url });
} }
dispatch("Failed to fetch top accounts"); dispatch("Failed to fetch top accounts");
} }

View File

@ -1,8 +1,8 @@
import React from "react"; import React from "react";
import * as Sentry from "@sentry/react";
import { Supply, Connection } from "@solana/web3.js"; import { Supply, Connection } from "@solana/web3.js";
import { useCluster, ClusterStatus, Cluster } from "./cluster"; import { useCluster, ClusterStatus, Cluster } from "./cluster";
import { reportError } from "utils/sentry";
export enum Status { export enum Status {
Idle, Idle,
@ -53,7 +53,7 @@ async function fetch(dispatch: Dispatch, cluster: Cluster, url: string) {
}); });
} catch (err) { } catch (err) {
if (cluster !== Cluster.Custom) { if (cluster !== Cluster.Custom) {
Sentry.captureException(err, { tags: { url } }); reportError(err, { url });
} }
dispatch("Failed to fetch supply"); dispatch("Failed to fetch supply");
} }

View File

@ -1,5 +1,4 @@
import React from "react"; import React from "react";
import * as Sentry from "@sentry/react";
import { import {
Connection, Connection,
TransactionSignature, TransactionSignature,
@ -8,6 +7,7 @@ import {
import { useCluster, Cluster } from "../cluster"; import { useCluster, Cluster } from "../cluster";
import * as Cache from "providers/cache"; import * as Cache from "providers/cache";
import { ActionType, FetchStatus } from "providers/cache"; import { ActionType, FetchStatus } from "providers/cache";
import { reportError } from "utils/sentry";
export interface Details { export interface Details {
transaction?: ParsedConfirmedTransaction | null; transaction?: ParsedConfirmedTransaction | null;
@ -61,7 +61,7 @@ async function fetchDetails(
fetchStatus = FetchStatus.Fetched; fetchStatus = FetchStatus.Fetched;
} catch (error) { } catch (error) {
if (cluster !== Cluster.Custom) { if (cluster !== Cluster.Custom) {
Sentry.captureException(error, { tags: { url } }); reportError(error, { url });
} }
fetchStatus = FetchStatus.FetchFailed; fetchStatus = FetchStatus.FetchFailed;
} }

View File

@ -1,5 +1,4 @@
import React from "react"; import React from "react";
import * as Sentry from "@sentry/react";
import { import {
TransactionSignature, TransactionSignature,
Connection, Connection,
@ -9,6 +8,7 @@ import { useCluster, Cluster } from "../cluster";
import { DetailsProvider } from "./details"; import { DetailsProvider } from "./details";
import * as Cache from "providers/cache"; import * as Cache from "providers/cache";
import { ActionType, FetchStatus } from "providers/cache"; import { ActionType, FetchStatus } from "providers/cache";
import { reportError } from "utils/sentry";
export { useTransactionDetails } from "./details"; export { useTransactionDetails } from "./details";
export type Confirmations = number | "max"; export type Confirmations = number | "max";
@ -80,9 +80,7 @@ export async function fetchTransactionStatus(
blockTime = await connection.getBlockTime(value.slot); blockTime = await connection.getBlockTime(value.slot);
} catch (error) { } catch (error) {
if (cluster === Cluster.MainnetBeta) { if (cluster === Cluster.MainnetBeta) {
Sentry.captureException(error, { reportError(error, { slot: `${value.slot}` });
tags: { slot: `${value.slot}` },
});
} }
} }
let timestamp: Timestamp = blockTime !== null ? blockTime : "unavailable"; let timestamp: Timestamp = blockTime !== null ? blockTime : "unavailable";
@ -105,7 +103,7 @@ export async function fetchTransactionStatus(
fetchStatus = FetchStatus.Fetched; fetchStatus = FetchStatus.Fetched;
} catch (error) { } catch (error) {
if (cluster !== Cluster.Custom) { if (cluster !== Cluster.Custom) {
Sentry.captureException(error, { tags: { url } }); reportError(error, { url });
} }
fetchStatus = FetchStatus.FetchFailed; fetchStatus = FetchStatus.FetchFailed;
} }

View File

@ -0,0 +1,18 @@
import * as Sentry from "@sentry/react";
type Tags =
| {
[key: string]: string;
}
| undefined;
export function reportError(err: Error, tags: Tags) {
console.error(err);
try {
Sentry.captureException(err, {
tags,
});
} catch (err) {
// Sentry can fail if error rate limit is reached
}
}