Skip to content

Commit

Permalink
Capture more errors with Sentry.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Oct 4, 2023
1 parent 38d81ed commit fd6ae6c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/data/formulas/contract/voting/daoVotingCw20Staked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ export const dao: ContractFormula<string | undefined> = {
(await get<string>(contractAddress, 'dao')),
}

// TODO: isActive

export const activeThreshold: ContractFormula = {
compute: async ({ contractAddress, get }) =>
await get(contractAddress, 'active_threshold'),
Expand Down
11 changes: 10 additions & 1 deletion src/data/transformers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Sentry from '@sentry/node'

import {
Config,
ProcessedTransformer,
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/data/webhooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Sentry from '@sentry/node'

import { Config, ProcessedWebhook, Webhook, WebhookMaker } from '@/core'
import { State } from '@/db'

Expand Down Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions src/db/models/PendingWebhook.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/node'
import axios from 'axios'
import Pusher from 'pusher'
import {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
24 changes: 22 additions & 2 deletions src/db/models/WasmStateEventTransformation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/node'
import { Op, Sequelize, WhereOptions } from 'sequelize'
import {
AllowNull,
Expand All @@ -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,
Expand Down Expand Up @@ -167,6 +169,7 @@ export class WasmStateEventTransformation extends DependendableEventModel {
static async transformParsedStateEvents(
events: ParsedWasmStateEvent[]
): Promise<WasmStateEventTransformation[]> {
const chainId = (await State.getSingleton())?.chainId || 'unknown'
const transformers = getProcessedTransformers(loadConfig())
if (transformers.length === 0) {
return []
Expand All @@ -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
}

Expand Down Expand Up @@ -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,
},
})
}
}

Expand Down

0 comments on commit fd6ae6c

Please sign in to comment.