Skip to content

Commit

Permalink
chore: instrument wallet connect provider (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e authored Jan 18, 2024
1 parent a5df93f commit 74ed462
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/helpers/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import init, { client } from '@snapshot-labs/snapshot-metrics';
import type { Express } from 'express';
import { capture } from '@snapshot-labs/snapshot-sentry';
import db from './mysql';
import { getSubscribersFromWalletConnect } from '../providers/walletconnectNotify';

export default function initMetrics(app: Express) {
init(app, {
Expand Down Expand Up @@ -48,6 +49,10 @@ new client.Gauge({
)
)[0].count as any
);
this.set(
{ type: 'walletconnect' },
(await getSubscribersFromWalletConnect()).length
);
}
});

Expand Down
8 changes: 7 additions & 1 deletion src/providers/walletconnectNotify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fetch from 'node-fetch';
import { capture } from '@snapshot-labs/snapshot-sentry';
import { timeOutgoingRequest } from '../helpers/metrics';

const WALLETCONNECT_NOTIFY_SERVER_URL =
process.env.WALLETCONNECT_NOTIFY_SERVER_URL;
Expand Down Expand Up @@ -95,6 +96,9 @@ export async function sendNotification(notification, accounts) {
notification
};

const end = timeOutgoingRequest.startTimer({ provider: 'walletconnect' });
let success = false;

try {
const notifyRs = await fetch(notifyUrl, {
method: 'POST',
Expand All @@ -106,10 +110,12 @@ export async function sendNotification(notification, accounts) {
});

const notifySuccess = await notifyRs.json();

success = true;
return notifySuccess;
} catch (e) {
capture('[WalletConnect] failed to notify subscribers', e);
} finally {
end({ status: success ? 200 : 500 });
}
}

Expand Down

0 comments on commit 74ed462

Please sign in to comment.