Skip to content

Commit b953c67

Browse files
authored
Merge pull request #472 from begd/feat-monitoring
Monitoring: unified error reporting with severity, enriched context, and GraphQL/streaming coverageFeat monitoring
2 parents eb3fa47 + 5285e51 commit b953c67

35 files changed

+615
-86
lines changed

indexer/config/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports = {
3737
password: process.env.DB_PASSWORD,
3838
database: process.env.DB_NAME,
3939
host: process.env.DB_HOST || 'localhost',
40+
port: Number(process.env.DB_PORT) || 5432,
4041

4142
// Database dialect to use (PostgreSQL)
4243
dialect: 'postgres',

indexer/src/config/database.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const DB_PASSWORD = getRequiredEnvString('DB_PASSWORD');
1717
const DB_NAME = getRequiredEnvString('DB_NAME');
1818
const DB_HOST = getRequiredEnvString('DB_HOST');
1919
const DB_SSL_ENABLED = getRequiredEnvString('DB_SSL_ENABLED');
20-
const DB_CONNECTION = `postgres://${DB_USERNAME}:${encodeURIComponent(DB_PASSWORD)}@${DB_HOST}/${DB_NAME}`;
20+
// Optional DB port (defaults to 5432)
21+
const DB_PORT = process.env.DB_PORT ? Number(process.env.DB_PORT) : 5432;
22+
const DB_CONNECTION = `postgres://${DB_USERNAME}:${encodeURIComponent(DB_PASSWORD)}@${DB_HOST}:${DB_PORT}/${DB_NAME}`;
2123

2224
// Determine if SSL is enabled for database connections
2325
const isSslEnabled = DB_SSL_ENABLED === 'true';
@@ -78,6 +80,7 @@ export const sequelize = new Sequelize(
7880
process.env.DB_PASSWORD as string,
7981
{
8082
host: process.env.DB_HOST || 'localhost',
83+
port: DB_PORT,
8184
dialect: 'postgres',
8285
pool: {
8386
max: 20,

indexer/src/config/migrator-wrapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async function isDatabaseAlreadyCreated() {
7373
try {
7474
await migrate();
7575
} catch (error) {
76-
console.error('Migration failed:', error);
76+
console.error('[ERROR][INFRA][INFRA_DEPLOY] Migration failed:', error);
7777
process.exit(1);
7878
} finally {
7979
await sequelize.close();

indexer/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import dotenv from 'dotenv';
1212
console.info('[INFO][INFRA][INFRA_CONFIG] Loading environment variables...');
1313
dotenv.config();
1414

15+
import { initializeErrorMonitoring } from './services/monitoring';
16+
1517
import { program } from 'commander';
1618
import { startGraphqlServer } from './kadena-server/server';
1719
import { startStreaming } from './services/streaming';
@@ -48,6 +50,7 @@ const options = program.opts();
4850
async function main() {
4951
try {
5052
console.info('Starting v1.0.2.2 with pair creation');
53+
initializeErrorMonitoring();
5154
setupAssociations();
5255
PriceUpdaterService.getInstance();
5356

indexer/src/kadena-server/domain/gas/input-checker.gas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ export function determineInputType(input: IGasLimitEstimationInput): UserInput {
101101

102102
// If none of the above formats match, throw error
103103
throw new GasLimitEstimationError(
104-
'Unknown input type. Please see the README for the accepted input format.',
104+
'[ERROR][GRAPHQL][GAS][INPUT_CHECKER] Unknown input type. Please see the README for the accepted input format.',
105105
);
106106
}

indexer/src/kadena-server/domain/gas/parser.gas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function parseInput(input: string): IGasLimitEstimationInput {
5353
return schema.parse(parsed);
5454
} catch (e) {
5555
throw new GasLimitEstimationError(
56-
'Unable to parse input as JSON. Please see the README for the accepted input format.',
56+
'[ERROR][GAS][PARSER] Unable to parse input as JSON. Please see the README for the accepted input format.',
5757
);
5858
}
5959
}

indexer/src/kadena-server/domain/gas/transaction.gas.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ export const buildTransactionPayload = (input: UserInput, networkId: string): IU
135135

136136
// Handle unexpected input types
137137
default:
138-
throw new GasLimitEstimationError('Something went wrong generating the transaction.');
138+
throw new GasLimitEstimationError(
139+
'[ERROR][GAS][TRANSACTION] Something went wrong generating the transaction.',
140+
);
139141
}
140142

141143
return transaction;

indexer/src/kadena-server/repository/infra/gateway/gas-api-gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class GasApiGateway implements GasGateway {
8181
} catch (error) {
8282
// Wrap and rethrow any errors in our custom error type
8383
throw new GasLimitEstimationError(
84-
'Chainweb Node was unable to estimate the gas limit',
84+
'[ERROR][GAS_API_GATEWAY][ESTIMATE_GAS] Chainweb Node was unable to estimate the gas limit',
8585
error,
8686
);
8787
}

indexer/src/kadena-server/repository/infra/query-builders/transaction-query-builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class TransactionQueryBuilder {
5757

5858
if (isNullOrUndefined(accountName) && minHeight && !maxHeight) {
5959
if (minHeight < 0) {
60-
throw new Error('minHeight cannot be less than 0');
60+
throw new Error('[ERROR][VALID][VALID_RANGE] minHeight cannot be less than 0');
6161
}
6262
blockParams.push(minHeight);
6363
const op = this.operator(blockParams.length);
@@ -66,7 +66,7 @@ export default class TransactionQueryBuilder {
6666

6767
if (isNullOrUndefined(accountName) && minHeight && maxHeight) {
6868
if (minHeight > maxHeight) {
69-
throw new Error('minHeight cannot be greater than maxHeight');
69+
throw new Error('[ERROR][VALID][VALID_RANGE] minHeight cannot be greater than maxHeight');
7070
}
7171

7272
blockParams.push(minHeight);

indexer/src/kadena-server/repository/infra/repository/block-db-repository.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default class BlockDbRepository implements BlockRepository {
117117
lastHeight = parseInt(heightStr, 10);
118118
lastId = parseInt(idStr, 10);
119119
if (isNaN(lastHeight) || isNaN(lastId)) {
120-
throw new Error('Invalid after cursor');
120+
throw new Error(`[ERROR][VALID][VALID_FORMAT] Invalid 'after' cursor:', ${after}`);
121121
}
122122
}
123123

@@ -126,7 +126,7 @@ export default class BlockDbRepository implements BlockRepository {
126126
lastHeight = parseInt(heightStr, 10);
127127
lastId = parseInt(idStr, 10);
128128
if (isNaN(lastHeight) || isNaN(lastId)) {
129-
throw new Error('Invalid before cursor');
129+
throw new Error(`[ERROR][VALID][VALID_FORMAT] Invalid 'before' cursor:', ${before}`);
130130
}
131131
}
132132

@@ -308,7 +308,7 @@ export default class BlockDbRepository implements BlockRepository {
308308
const beforeId = parseInt(id, 10);
309309

310310
if (isNaN(beforeHeight) || isNaN(beforeId)) {
311-
throw new Error('Invalid before cursor');
311+
throw new Error(`[ERROR][VALID][VALID_FORMAT] Invalid 'before' cursor:', ${before}`);
312312
}
313313

314314
queryParams.push(beforeHeight, beforeId);
@@ -322,7 +322,7 @@ export default class BlockDbRepository implements BlockRepository {
322322
const afterId = parseInt(id, 10);
323323

324324
if (isNaN(afterHeight) || isNaN(afterId)) {
325-
throw new Error('Invalid after cursor');
325+
throw new Error(`[ERROR][VALID][VALID_FORMAT] Invalid 'after' cursor:', ${after}`);
326326
}
327327
queryParams.push(afterHeight, afterId);
328328
conditions += `\nAND (b.height, b.id) > ($${queryParams.length - 1}, $${queryParams.length})`;
@@ -407,7 +407,9 @@ export default class BlockDbRepository implements BlockRepository {
407407
const [balanceRow] = balanceRows;
408408

409409
if (!balanceRow) {
410-
throw new Error("Miner didn't exist.");
410+
throw new Error(
411+
`[ERROR][DB][DATA_MISSING] Miner account not found for block ${hash} on chain ${chainId}.`,
412+
);
411413
}
412414

413415
const res = await handleSingleQuery({
@@ -609,7 +611,9 @@ export default class BlockDbRepository implements BlockRepository {
609611
);
610612

611613
if (blockRows.length !== eventIds.length) {
612-
throw new Error('There was an issue fetching blocks for event IDs.');
614+
throw new Error(
615+
`[ERROR][DB][DATA_CORRUPT] Fetched blocks count (${blockRows.length}) does not match event IDs count (${eventIds.length}).`,
616+
);
613617
}
614618

615619
const blockMap = blockRows.reduce(
@@ -660,7 +664,9 @@ export default class BlockDbRepository implements BlockRepository {
660664
);
661665

662666
if (blockRows.length !== transactionIds.length) {
663-
throw new Error('There was an issue fetching blocks for transaction IDs.');
667+
throw new Error(
668+
`[ERROR][DB][DATA_CORRUPT] Fetched blocks count (${blockRows.length}) does not match transaction IDs count (${transactionIds.length}).`,
669+
);
664670
}
665671

666672
const blockMap = blockRows.reduce(
@@ -709,7 +715,9 @@ export default class BlockDbRepository implements BlockRepository {
709715
);
710716

711717
if (blockRows.length !== hashes.length) {
712-
throw new Error('There was an issue fetching blocks for transaction IDs.');
718+
throw new Error(
719+
`[ERROR][DB][DATA_CORRUPT] Fetched blocks count (${blockRows.length}) does not match requested hashes count (${hashes.length}).`,
720+
);
713721
}
714722

715723
const blockMap = blockRows.reduce(

0 commit comments

Comments
 (0)