feat: add Sentry metrics for extract job tracking#348
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
murderteeth
left a comment
There was a problem hiding this comment.
Review: Sentry metrics for extract job tracking
The pivot from CSV logging to Sentry metrics is clean — no leftover CSV code. PR description accurately matches the final implementation. Sentry.metrics.count() is confirmed supported in SDK v10.25.0+ (currently in open beta).
Three changes requested below.
murderteeth
left a comment
There was a problem hiding this comment.
Line comments with suggested changes attached.
packages/lib/mq.ts
Outdated
| if (MQ_INVENTORY && SENTRY_DSN && queue === 'extract-1') { | ||
| Sentry.metrics.count('mq.extract_job_added', 1, { | ||
| attributes: { | ||
| jobName: job.name, | ||
| address: String(data.address ?? data.source?.address ?? ''), | ||
| chainId: String(data.chainId ?? data.source?.chainId ?? ''), | ||
| fromBlock: String(data.from ?? data.fromBlock ?? ''), | ||
| toBlock: String(data.to ?? data.toBlock ?? ''), | ||
| abiPath: String(data.abiPath ?? data.abi?.abiPath ?? '') | ||
| } | ||
| }) | ||
| } |
There was a problem hiding this comment.
Since we're using Sentry, track all queues instead of just extract-1. Remove the queue === 'extract-1' filter and add queue as an attribute — you can still filter to any specific queue in Sentry dashboards.
| if (MQ_INVENTORY && SENTRY_DSN && queue === 'extract-1') { | |
| Sentry.metrics.count('mq.extract_job_added', 1, { | |
| attributes: { | |
| jobName: job.name, | |
| address: String(data.address ?? data.source?.address ?? ''), | |
| chainId: String(data.chainId ?? data.source?.chainId ?? ''), | |
| fromBlock: String(data.from ?? data.fromBlock ?? ''), | |
| toBlock: String(data.to ?? data.toBlock ?? ''), | |
| abiPath: String(data.abiPath ?? data.abi?.abiPath ?? '') | |
| } | |
| }) | |
| } | |
| if (MQ_INVENTORY && SENTRY_DSN) { | |
| Sentry.metrics.count('mq.job_added', 1, { | |
| attributes: { | |
| queue, | |
| jobName: job.name, | |
| address: String(data.address ?? data.source?.address ?? ''), | |
| chainId: String(data.chainId ?? data.source?.chainId ?? ''), | |
| fromBlock: String(data.from ?? data.fromBlock ?? ''), | |
| toBlock: String(data.to ?? data.toBlock ?? ''), | |
| abiPath: String(data.abiPath ?? data.abi?.abiPath ?? '') | |
| } | |
| }) | |
| } |
Duplicate detection still works — group by queue + jobName + address + chainId + fromBlock + toBlock in Sentry.
packages/lib/mq.ts
Outdated
| @@ -1,6 +1,14 @@ | |||
| import { Queue, Worker } from 'bullmq' | |||
| import { Job } from './types' | |||
| import * as Sentry from '@sentry/node' | |||
There was a problem hiding this comment.
@sentry/node loads the full Sentry + OpenTelemetry instrumentation stack on import. Since this only runs when MQ_INVENTORY and SENTRY_DSN are set, consider a dynamic import to avoid the overhead in all other processes that touch mq.ts.
Something like:
let Sentry: typeof import('@sentry/node') | null = null
if (MQ_INVENTORY && SENTRY_DSN) {
import('@sentry/node').then(s => {
Sentry = s
Sentry.init({ dsn: SENTRY_DSN })
})
}Then guard usage with if (Sentry) { ... }.
packages/lib/mq.ts
Outdated
| if (MQ_INVENTORY && SENTRY_DSN) { | ||
| process.on('beforeExit', async () => { | ||
| await Sentry.flush(5000) | ||
| }) | ||
| } |
There was a problem hiding this comment.
Node.js beforeExit does not await promises from async handlers — Sentry.flush(5000) may not complete before the process exits. Also, beforeExit doesn't fire on SIGTERM/SIGINT (the common shutdown signals).
Consider:
for (const signal of ['SIGTERM', 'SIGINT'] as const) {
process.on(signal, async () => {
await Sentry.flush(5000)
process.exit(0)
})
}Or call Sentry.flush() explicitly in the existing down() function since that's already the shutdown path.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
murderteeth
left a comment
There was a problem hiding this comment.
lgtm. i should have been more clear on when to flush sentry so i went ahead and added a commit for it
Fair! |
Summary
@sentry/nodetopackages/liband initializes Sentry inmq.tswhenMQ_INVENTORY=trueandSENTRY_DSNis setmq.extract_job_addedcounter metric on every job added to theextract-1queue, with attributes:jobName,address,chainId,fromBlock,toBlock,abiPathbeforeExitto ensure all metrics are deliveredjobName + address + chainId + fromBlock + toBlockand alert where count > 1Files changed
packages/lib/package.json— added@sentry/nodepackages/lib/mq.ts— Sentry init + metrics counter inadd()+ flush onbeforeExitTest plan
packages/ingest/.envconfig/abis.local.yaml(or use the existing one)Wait for the fanout to dispatch extract jobs (watch the ingest logs)
Go to Sentry > Metrics, filter by the Kong project, search for
mq.extract_job_addedaddress + chainId + fromBlock + toBlockand check for any combination where the count > 1 — these are duplicate dispatches