Skip to content

Commit

Permalink
feat: setup sentry (#618)
Browse files Browse the repository at this point in the history
* feat: setup sentry

* chore: output sourcemaps on build

* chore: send handled errors to Sentry

* chore: setup test env and add some basic test to implement

* Revert "chore: setup test env and add some basic test to implement"

This reverts commit 33f17b1.
  • Loading branch information
wa0x6e authored Jul 28, 2023
1 parent e77c7cf commit 29e6a97
Show file tree
Hide file tree
Showing 25 changed files with 224 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ DATABASE_URL=mysql://...
SEQUENCER_URL=https://testnet.seq.snapshot.org
KEYCARD_URL=https://keycard.snapshot.org
KEYCARD_SECRET=
SENTRY_DSN=
SENTRY_TRACE_SAMPLE_RATE=
22 changes: 22 additions & 0 deletions .github/workflows/sentry-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Create a Sentry release
on:
push:
branches:
- 'master'
jobs:
sentry-release:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'yarn'
- run: yarn install
- run: yarn build
- name: Sentry Release
uses: getsentry/[email protected]
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: snapshot-hub
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@ethersproject/hash": "^5.5.0",
"@ethersproject/providers": "^5.6.8",
"@ethersproject/wallet": "^5.6.2",
"@sentry/node": "^7.60.1",
"@snapshot-labs/keycard": "^0.1.0",
"@snapshot-labs/pineapple": "^0.1.0-beta.1",
"@snapshot-labs/snapshot.js": "^0.4.106",
Expand Down
4 changes: 3 additions & 1 deletion src/graphql/operations/aliases.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import db from '../../helpers/mysql';
import { buildWhereQuery, checkLimits } from '../helpers';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

export default async function (parent, args) {
const { first = 20, skip = 0, where = {} } = args;
Expand Down Expand Up @@ -34,8 +35,9 @@ export default async function (parent, args) {

try {
return await db.queryAsync(query, params);
} catch (e) {
} catch (e: any) {
log.error(`[graphql] aliases, ${JSON.stringify(e)}`);
capture(e);
return Promise.reject('request failed');
}
}
4 changes: 3 additions & 1 deletion src/graphql/operations/follows.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import db from '../../helpers/mysql';
import { buildWhereQuery, checkLimits, formatFollow } from '../helpers';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

export default async function (parent, args) {
const { first = 20, skip = 0, where = {} } = args;
Expand Down Expand Up @@ -37,8 +38,9 @@ export default async function (parent, args) {
try {
follows = await db.queryAsync(query, params);
return follows.map(follow => formatFollow(follow));
} catch (e) {
} catch (e: any) {
log.error(`[graphql] follows, ${JSON.stringify(e)}`);
capture(e);
return Promise.reject('request failed');
}
}
4 changes: 3 additions & 1 deletion src/graphql/operations/messages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import db from '../../helpers/mysql';
import { buildWhereQuery, checkLimits } from '../helpers';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

export default async function (parent, args) {
const { first = 20, skip = 0, where = {} } = args;
Expand Down Expand Up @@ -33,8 +34,9 @@ export default async function (parent, args) {
params.push(skip, first);
try {
return await db.queryAsync(query, params);
} catch (e) {
} catch (e: any) {
log.error(`[graphql] messages, ${JSON.stringify(e)}`);
capture(e);
return Promise.reject('request failed');
}
}
4 changes: 3 additions & 1 deletion src/graphql/operations/proposal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import db from '../../helpers/mysql';
import { formatProposal } from '../helpers';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

export default async function (parent, { id }) {
const query = `
Expand All @@ -12,8 +13,9 @@ export default async function (parent, { id }) {
try {
const proposals = await db.queryAsync(query, [id]);
return proposals.map(proposal => formatProposal(proposal))[0] || null;
} catch (e) {
} catch (e: any) {
log.error(`[graphql] proposal, ${JSON.stringify(e)}`);
capture(e, { context: { id } });
return Promise.reject('request failed');
}
}
4 changes: 3 additions & 1 deletion src/graphql/operations/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import db from '../../helpers/mysql';
import { buildWhereQuery, formatProposal, checkLimits } from '../helpers';
import log from '../../helpers/log';
import { verifiedSpaces } from '../../helpers/moderation';
import { capture } from '../../helpers/sentry';

export default async function (parent, args) {
const { first = 20, skip = 0, where = {} } = args;
Expand Down Expand Up @@ -81,8 +82,9 @@ export default async function (parent, args) {
try {
const proposals = await db.queryAsync(query, params);
return proposals.map(proposal => formatProposal(proposal));
} catch (e) {
} catch (e: any) {
log.error(`[graphql] proposals, ${JSON.stringify(e)}`);
capture(e);
return Promise.reject('request failed');
}
}
5 changes: 3 additions & 2 deletions src/graphql/operations/ranking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { checkLimits, formatSpace, handleRelatedSpaces, PublicError } from '../h
import log from '../../helpers/log';
import db from '../../helpers/mysql';
import { rankedSpaces } from '../../helpers/spaces';
import { capture } from '../../helpers/sentry';

export default async function (_parent, args, _context, info) {
checkLimits(args, 'ranking');
Expand Down Expand Up @@ -50,10 +51,10 @@ export default async function (_parent, args, _context, info) {
const items = await handleRelatedSpaces(info, spaces);

return { items, metrics };
} catch (e) {
console.log(e);
} catch (e: any) {
log.error(`[graphql] spaces, ${JSON.stringify(e)}`);
if (e instanceof PublicError) return e;
capture(e);
return new Error('Unexpected error');
}
}
4 changes: 3 additions & 1 deletion src/graphql/operations/space.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fetchSpaces, handleRelatedSpaces, PublicError } from '../helpers';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

export default async function (_parent, { id }, _context, info) {
if (!id) return new PublicError('Missing id');
Expand All @@ -10,9 +11,10 @@ export default async function (_parent, { id }, _context, info) {
spaces = await handleRelatedSpaces(info, spaces);

return spaces[0];
} catch (e) {
} catch (e: any) {
log.error(`[graphql] space, ${JSON.stringify(e)}`);
if (e instanceof PublicError) return e;
capture(e, { context: { id } });
return new Error('Unexpected error');
}
}
4 changes: 3 additions & 1 deletion src/graphql/operations/spaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { checkLimits, fetchSpaces, handleRelatedSpaces, PublicError } from '../helpers';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

export default async function (_parent, args, _context, info) {
checkLimits(args, 'spaces');
Expand All @@ -8,9 +9,10 @@ export default async function (_parent, args, _context, info) {
spaces = await handleRelatedSpaces(info, spaces);

return spaces;
} catch (e) {
} catch (e: any) {
log.error(`[graphql] spaces, ${JSON.stringify(e)}`);
if (e instanceof PublicError) return e;
capture(e);
return new Error('Unexpected error');
}
}
4 changes: 3 additions & 1 deletion src/graphql/operations/statement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import db from '../../helpers/mysql';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

export default async function (parent, args) {
const id = args.id;
Expand All @@ -8,8 +9,9 @@ export default async function (parent, args) {
const statements = await db.queryAsync(query, id);
if (statements.length === 1) return statements[0];
return null;
} catch (e) {
} catch (e: any) {
log.error(`[graphql] statement, ${JSON.stringify(e)}`);
capture(e, { context: { id } });
return Promise.reject('request failed');
}
}
4 changes: 3 additions & 1 deletion src/graphql/operations/statements.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import db from '../../helpers/mysql';
import { buildWhereQuery, checkLimits } from '../helpers';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

export default async function (parent, args) {
const { first = 20, skip = 0, where = {} } = args;
Expand Down Expand Up @@ -36,8 +37,9 @@ export default async function (parent, args) {
try {
statements = await db.queryAsync(query, params);
return statements;
} catch (e) {
} catch (e: any) {
log.error(`[graphql] statements, ${JSON.stringify(e)}`);
capture(e);
return Promise.reject('request failed');
}
}
4 changes: 3 additions & 1 deletion src/graphql/operations/subscriptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import db from '../../helpers/mysql';
import { buildWhereQuery, checkLimits, formatSubscription } from '../helpers';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

export default async function (parent, args) {
const { first = 20, skip = 0, where = {} } = args;
Expand Down Expand Up @@ -38,8 +39,9 @@ export default async function (parent, args) {
try {
subscriptions = await db.queryAsync(query, params);
return subscriptions.map(subscription => formatSubscription(subscription));
} catch (e) {
} catch (e: any) {
log.error(`[graphql] subscriptions, ${JSON.stringify(e)}`);
capture(e);
return Promise.reject('request failed');
}
}
4 changes: 3 additions & 1 deletion src/graphql/operations/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import db from '../../helpers/mysql';
import { formatUser } from '../helpers';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

export default async function (parent, args) {
const id = args.id;
Expand All @@ -9,8 +10,9 @@ export default async function (parent, args) {
const users = await db.queryAsync(query, id);
if (users.length === 1) return formatUser(users[0]);
return null;
} catch (e) {
} catch (e: any) {
log.error(`[graphql] user, ${JSON.stringify(e)}`);
capture(e, { context: { id } });
return Promise.reject('request failed');
}
}
4 changes: 3 additions & 1 deletion src/graphql/operations/users.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import db from '../../helpers/mysql';
import { buildWhereQuery, checkLimits, formatUser } from '../helpers';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

export default async function (parent, args) {
const { first = 20, skip = 0, where = {} } = args;
Expand Down Expand Up @@ -34,8 +35,9 @@ export default async function (parent, args) {
try {
users = await db.queryAsync(query, params);
return users.map(user => formatUser(user));
} catch (e) {
} catch (e: any) {
log.error(`[graphql] users, ${JSON.stringify(e)}`);
capture(e);
return Promise.reject('request failed');
}
}
7 changes: 5 additions & 2 deletions src/graphql/operations/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import graphqlFields from 'graphql-fields';
import db from '../../helpers/mysql';
import { formatProposal, formatVote } from '../helpers';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

export default async function (parent, { id }, context, info) {
const requestedFields = info ? graphqlFields(info) : {};
Expand All @@ -24,14 +25,16 @@ export default async function (parent, { id }, context, info) {
try {
const proposals = await db.queryAsync(query, [proposalId]);
result.proposal = formatProposal(proposals[0]);
} catch (e) {
} catch (e: any) {
log.error(`[graphql] vote, ${JSON.stringify(e)}`);
capture(e, { context: { id } });
return Promise.reject('request failed');
}
}
return result;
} catch (e) {
} catch (e: any) {
log.error(`[graphql] vote, ${JSON.stringify(e)}`);
capture(e, { context: { id } });
return Promise.reject('request failed');
}
}
10 changes: 7 additions & 3 deletions src/graphql/operations/votes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import db from '../../helpers/mysql';
import { buildWhereQuery, checkLimits, formatProposal, formatSpace, formatVote } from '../helpers';
import serve from '../../helpers/ee';
import log from '../../helpers/log';
import { capture } from '../../helpers/sentry';

async function query(parent, args, context?, info?) {
const requestedFields = info ? graphqlFields(info) : {};
Expand Down Expand Up @@ -45,7 +46,8 @@ async function query(parent, args, context?, info?) {
votes = await db.queryAsync(query, params);
// TODO: we need settings in the vote as its being passed to formatSpace inside formatVote, Maybe we dont need to do this?
votes = votes.map(vote => formatVote(vote));
} catch (e) {
} catch (e: any) {
capture(e);
log.error(`[graphql] votes, ${JSON.stringify(e)}`);
return Promise.reject('request failed');
}
Expand All @@ -66,7 +68,8 @@ async function query(parent, args, context?, info?) {
if (spaces[vote.space.id]) return { ...vote, space: spaces[vote.space.id] };
return vote;
});
} catch (e) {
} catch (e: any) {
capture(e);
log.error(`[graphql] votes, ${JSON.stringify(e)}`);
return Promise.reject('request failed');
}
Expand All @@ -88,7 +91,8 @@ async function query(parent, args, context?, info?) {
vote.proposal = proposals[vote.proposal];
return vote;
});
} catch (e) {
} catch (e: any) {
capture(e);
log.error(`[graphql] votes, ${JSON.stringify(e)}`);
return Promise.reject('request failed');
}
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/moderation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import snapshot from '@snapshot-labs/snapshot.js';
import log from './log';
import { capture } from './sentry';

const moderationURL = 'https://sh5.co/api/moderation';

Expand All @@ -19,7 +20,8 @@ async function loadModerationData() {
async function run() {
try {
await loadModerationData();
} catch (e) {
} catch (e: any) {
capture(e, { context: { url: moderationURL } });
log.error(`[moderation] failed to load ${JSON.stringify(e)}`);
}
await snapshot.utils.sleep(5e3);
Expand Down
Loading

0 comments on commit 29e6a97

Please sign in to comment.