Skip to content

Commit

Permalink
clean up logging and slack
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennerSpear committed Jan 24, 2022
1 parent a93d7d1 commit c3772e8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions dev/mint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ async function main() {

const promises = [];

for (let i = 21; i < 40; i++) {
console.log(`submitting tx ${i} for ${contractAddress}`);
for (let i = 0; i < 10; i++) {
console.log(`submitting tx ${i} for ${contractAddress} from ${getSigner(i).address}`);
const tokenGardenContractWritable = tokenGardenContract.connect(getSigner(i));
const value = 0;
const promise = tokenGardenContractWritable.mint({ value });
Expand Down
4 changes: 2 additions & 2 deletions server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
fetcher,
fetchBaseOptions,
SLACK_API_TOKEN,
conversationId,
channelId,
openseaForceUpdateURL,
FetcherError,
networkStrings,
Expand Down Expand Up @@ -36,7 +36,7 @@ const slackClient = new WebClient(SLACK_API_TOKEN);

async function slack(text) {
return await slackClient.chat.postMessage({
channel: conversationId,
channel: channelId,
text,
});
}
Expand Down
20 changes: 15 additions & 5 deletions utils/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createHmac } from 'crypto';
import fetch from 'node-fetch-retry';

import { logError, logWarning } from './logging.mjs';
export const BIRTHBLOCK_WEBHOOK_URL = process.env.BIRTHBLOCK_WEBHOOK_URL;
export const BIRTHBLOCK_CONTRACT_ADDRESS = process.env.BIRTHBLOCK_CONTRACT_ADDRESS;

Expand All @@ -20,8 +21,6 @@ export const ALCHEMY_NOTIFY_WEBHOOK_ID = process.env.ALCHEMY_NOTIFY_WEBHOOK_ID;
export const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
export const OPENSEA_API_KEY = process.env.OPENSEA_API_KEY;

export const DATADOG_API_KEY = process.env.DATADOG_API_KEY;

export const INFURA_ID = process.env.INFURA_ID;
export const NETWORK = process.env.NETWORK.toLowerCase();
export const SLACK_API_TOKEN = process.env.SLACK_API_TOKEN;
Expand All @@ -30,7 +29,10 @@ export const blackholeAddress = '0x0000000000000000000000000000000000000000';
export const alchemyUpdateWebhookAddressesURL =
'https://dashboard.alchemyapi.io/api/update-webhook-addresses';

export const conversationId = 'C02M123F48N'; // The-Metagame #mints channel
export const mintsChannelId = 'C02M123F48N'; // The-Metagame #mints channel
export const testnetMintsChannelId = 'C02V8TR888L';

export const channelId = NETWORK === 'ethereum' ? mintsChannelId : testnetMintsChannelId;

export const signMessage = (body) => {
const hmac = createHmac('sha256', EVENT_FORWARDER_AUTH_TOKEN); // Create a HMAC SHA256 hash using the auth token
Expand Down Expand Up @@ -127,6 +129,13 @@ export class FetcherError extends Error {
export function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

const fetcherLogData = {
level: 'error',
function_name: 'fetcher',
message: 'null??',
};

export async function fetcher(url, options, maxRetries = 3) {
let retries = 0;
while (maxRetries > retries) {
Expand All @@ -142,9 +151,10 @@ export async function fetcher(url, options, maxRetries = 3) {
message: await response.text(),
};
retries++;
console.log(`retrying, ${maxRetries - retries} retries left`);
fetcherLogData.thrown_error = error;
logWarning(fetcherLogData, 'fetcher retry warning');
if (maxRetries === retries) {
console.log(error); // TODO logflare and slack?
logError(fetcherLogData, error);
throw new FetcherError(error);
}
await sleep(1000 * 2 ** retries);
Expand Down
4 changes: 1 addition & 3 deletions utils/logging.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import DatadogWinston from 'datadog-winston';
import winston, { format } from 'winston';

import { DATADOG_API_KEY } from './index.mjs';

const { combine, printf, colorize } = format;

const colors = {
Expand All @@ -29,7 +27,7 @@ const service =
: 'event-forwarder-dev-logger';

const datadogTransport = new DatadogWinston({
apiKey: DATADOG_API_KEY,
apiKey: process.env.DATADOG_API_KEY,
hostname: 'railway',
service,
ddsource: 'nodejs',
Expand Down

0 comments on commit c3772e8

Please sign in to comment.