From fd6ae6c468184eea6d36d1e794082648d64401af Mon Sep 17 00:00:00 2001 From: Noah Saso Date: Wed, 4 Oct 2023 10:31:38 -0700 Subject: [PATCH] Capture more errors with Sentry. --- .../contract/voting/daoVotingCw20Staked.ts | 2 -- src/data/transformers/index.ts | 11 ++++++++- src/data/webhooks/index.ts | 11 ++++++++- src/db/models/PendingWebhook.ts | 21 ++++++++++++++-- src/db/models/WasmStateEventTransformation.ts | 24 +++++++++++++++++-- 5 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/data/formulas/contract/voting/daoVotingCw20Staked.ts b/src/data/formulas/contract/voting/daoVotingCw20Staked.ts index db481115..9d7d33ba 100644 --- a/src/data/formulas/contract/voting/daoVotingCw20Staked.ts +++ b/src/data/formulas/contract/voting/daoVotingCw20Staked.ts @@ -84,8 +84,6 @@ export const dao: ContractFormula = { (await get(contractAddress, 'dao')), } -// TODO: isActive - export const activeThreshold: ContractFormula = { compute: async ({ contractAddress, get }) => await get(contractAddress, 'active_threshold'), diff --git a/src/data/transformers/index.ts b/src/data/transformers/index.ts index a71b3790..4c08719e 100644 --- a/src/data/transformers/index.ts +++ b/src/data/transformers/index.ts @@ -1,3 +1,5 @@ +import * as Sentry from '@sentry/node' + import { Config, ProcessedTransformer, @@ -60,10 +62,17 @@ export const getProcessedTransformers = ( try { match &&= filter.matches(event) } catch (error) { - // TODO: Store somewhere. console.error( `Error matching transformer for event ${event.blockHeight}/${event.contractAddress}/${event.key}: ${error}` ) + Sentry.captureException(error, { + tags: { + type: 'failed-transformer-match', + }, + extra: { + event, + }, + }) // On error, do not match. match = false diff --git a/src/data/webhooks/index.ts b/src/data/webhooks/index.ts index 1ef6b68b..e0d5f935 100644 --- a/src/data/webhooks/index.ts +++ b/src/data/webhooks/index.ts @@ -1,3 +1,5 @@ +import * as Sentry from '@sentry/node' + import { Config, ProcessedWebhook, Webhook, WebhookMaker } from '@/core' import { State } from '@/db' @@ -63,10 +65,17 @@ export const getProcessedWebhooks = ( try { match &&= filter.matches(event) } catch (error) { - // TODO: Store somewhere. console.error( `Error matching webhook for event ${event.blockHeight}/${event.contractAddress}/${event.key}: ${error}` ) + Sentry.captureException(error, { + tags: { + type: 'failed-webhook-match', + }, + extra: { + event, + }, + }) // On error, do not match. match = false diff --git a/src/db/models/PendingWebhook.ts b/src/db/models/PendingWebhook.ts index c98e8b1b..871db814 100644 --- a/src/db/models/PendingWebhook.ts +++ b/src/db/models/PendingWebhook.ts @@ -1,3 +1,4 @@ +import * as Sentry from '@sentry/node' import axios from 'axios' import Pusher from 'pusher' import { @@ -166,10 +167,18 @@ export class PendingWebhook extends Model { env ) } catch (error) { - // TODO: Store somewhere. console.error( `Error getting webhook value for event ${wasmEvent.blockHeight}/${wasmEvent.contractAddress}/${wasmEvent.key}: ${error}` ) + Sentry.captureException(error, { + tags: { + type: 'failed-webhook-get-value', + chainId: state.chainId, + }, + extra: { + wasmEvent, + }, + }) } // Wrap in try/catch in case a webhook errors. Don't want to prevent @@ -181,10 +190,18 @@ export class PendingWebhook extends Model { ? await webhook.endpoint(wasmEvent, env) : webhook.endpoint } catch (error) { - // TODO: Store somewhere. console.error( `Error getting webhook endpoint for event ${wasmEvent.blockHeight}/${wasmEvent.contractAddress}/${wasmEvent.key}: ${error}` ) + Sentry.captureException(error, { + tags: { + type: 'failed-webhook-get-endpoint', + chainId: state.chainId, + }, + extra: { + wasmEvent, + }, + }) } // If value or endpoint is undefined, one either errored or the diff --git a/src/db/models/WasmStateEventTransformation.ts b/src/db/models/WasmStateEventTransformation.ts index 12485e55..29a202ca 100644 --- a/src/db/models/WasmStateEventTransformation.ts +++ b/src/db/models/WasmStateEventTransformation.ts @@ -1,3 +1,4 @@ +import * as Sentry from '@sentry/node' import { Op, Sequelize, WhereOptions } from 'sequelize' import { AllowNull, @@ -20,6 +21,7 @@ import { getProcessedTransformers } from '@/data/transformers' import { DependendableEventModel, DependentKeyNamespace } from '../types' import { Contract } from './Contract' +import { State } from './State' @Table({ timestamps: true, @@ -167,6 +169,7 @@ export class WasmStateEventTransformation extends DependendableEventModel { static async transformParsedStateEvents( events: ParsedWasmStateEvent[] ): Promise { + const chainId = (await State.getSingleton())?.chainId || 'unknown' const transformers = getProcessedTransformers(loadConfig()) if (transformers.length === 0) { return [] @@ -193,10 +196,18 @@ export class WasmStateEventTransformation extends DependendableEventModel { ? transformer.name : transformer.name(event) } catch (error) { - // TODO: Store somewhere. console.error( `Error getting transformation name for event ${event.blockHeight}/${event.contractAddress}/${event.key}: ${error}` ) + Sentry.captureException(error, { + tags: { + type: 'failed-transform-get-name', + chainId, + }, + extra: { + event, + }, + }) return undefined } @@ -297,10 +308,19 @@ export class WasmStateEventTransformation extends DependendableEventModel { evaluatedTransformations.push(pendingTransformation) } } catch (error) { - // TODO: Store somewhere. console.error( `Error transforming event ${event.blockHeight}/${event.contractAddress}/${event.key}: ${error}` ) + Sentry.captureException(error, { + tags: { + type: 'failed-transform-get-value', + chainId, + }, + extra: { + event, + pendingTransformation, + }, + }) } }