Skip to content

Commit

Permalink
add error tracking to minting backend (#1848)
Browse files Browse the repository at this point in the history
  • Loading branch information
shineli1984 authored Jun 2, 2024
1 parent b9fa369 commit f521fc8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
23 changes: 23 additions & 0 deletions packages/minting-backend/sdk/src/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,26 @@ export const trackRecordMint = () => {
// ignore
}
};

export const trackError = (error: Error) => {
try {
track(moduleName, 'error', {
name: error.name,
message: error.message
});
} catch {
// ignore
}
};

export const trackUncaughtException = (error: Error, origin: string) => {
try {
track(moduleName, 'error', {
name: error.name,
message: error.message,
origin,
});
} catch {
// ignore
}
};
3 changes: 3 additions & 0 deletions packages/minting-backend/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ImmutableConfiguration, ModuleConfiguration } from '@imtbl/config';
import { BlockchainData } from '@imtbl/blockchain-data';
import { init } from '@imtbl/webhook';
import { setEnvironment, setPublishableApiKey } from '@imtbl/metrics';
import { trackUncaughtException } from 'analytics';
import { mintingPersistence as mintingPersistencePg } from './persistence/pg/postgres';
import { mintingPersistence as mintingPersistencePrismaSqlite } from './persistence/prismaSqlite/sqlite';
import {
Expand Down Expand Up @@ -79,3 +80,5 @@ export class MintingBackendModule {
});
}
}

process.on('uncaughtExceptionMonitor', trackUncaughtException);
6 changes: 5 additions & 1 deletion packages/minting-backend/sdk/src/minting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { BlockchainData as Types } from '@imtbl/generated-clients';
import { BlockchainData } from '@imtbl/blockchain-data';
import { CreateMintRequest, MintRequest, MintingPersistence } from './persistence/type';
import { Logger } from './logger/type';
import { trackProcessMint, trackRecordMint, trackSubmitMintingRequests } from './analytics';
import {
trackError, trackProcessMint, trackRecordMint, trackSubmitMintingRequests
} from './analytics';

// TODO: expose metrics
// - submitting status count, conflicting status count
Expand Down Expand Up @@ -124,6 +126,7 @@ export const submitMintingRequests = async (
return response;
} catch (e: any) {
logger.error(e);
trackError(e);

if (
e.code === 'CONFLICT_ERROR'
Expand All @@ -144,6 +147,7 @@ export const submitMintingRequests = async (
);
} catch (e2) {
logger.error(e2);
trackError(e);
}
} else {
// separate assets into "need to be retied" and "exceeded max number of tries."
Expand Down
2 changes: 1 addition & 1 deletion samples/minting-backend-with-postgres/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Fastify, { FastifyReply, FastifyRequest } from 'fastify'
import { mintingBackend, config } from '@imtbl/sdk';
import { Pool } from 'pg';
import { v4 as uuidv4, stringify, parse } from 'uuid';
import { v4 as uuidv4, parse } from 'uuid';

const fastify = Fastify({
logger: true
Expand Down

0 comments on commit f521fc8

Please sign in to comment.