Skip to content

Commit

Permalink
Better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
motiaFB committed Jul 4, 2024
1 parent 62505b3 commit 835f4fd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/customer-server-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class CustomerClient {
logger.info(`Pulling messages status for ${JSON.stringify(requestsIds)}`);
const { statuses: serverStatuses } = await customerServerApi.messagesStatus({ requestsIds });
if (!!serverStatuses.length) {
logger.info(`Got messages status for ${JSON.stringify(serverStatuses.map((status) => { return { requestId: status.requestId, status: status.status } }))}`);
logger.info(`Got messages status from customer server for ${JSON.stringify(serverStatuses.map((status) => { return { requestId: status.requestId, status: status.status } }))}`);

await messagesService.updateStatus(serverStatuses.map((messagesStatus): ExtendedMessageStatusCache => {
const decodedMsg = messages.find((msg) => msg.messageStatus.requestId === messagesStatus.requestId);
if (!decodedMsg) {
logger.error(`Message with requestId ${messagesStatus.requestId} not found in cache`);
logger.error(`Message with requestId ${messagesStatus.requestId} not in pending cache messages`);
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/fireblocks-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class FireblocksAgentImpl implements FireblocksAgent {

_runLoopStep = async () => {
const start = Date.now();
logger.info(`Waiting for a message`);
logger.info(`Waiting for a messages from Fireblocks...`);
const messages = await fbServerApi.getMessages();
logger.info(`Got ${messages.length} messages after ${Date.now() - start}ms`);
logger.info(`Got ${messages.length} messages from Fireblocks after ${Date.now() - start}ms`);
await messageService.handleMessages(messages);
};
}
Expand Down
12 changes: 6 additions & 6 deletions src/services/messages.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MessageService implements IMessageService {
try {
const { msgId, request } = decodeAndVerifyMessage(messageEnvelope, certificates);
const { transportMetadata } = request;
logger.info(`Got message id ${msgId} with type ${transportMetadata.type} and request id ${transportMetadata.requestId}`);
logger.info(`Got from Fireblocks message id ${msgId} with type ${transportMetadata.type} and request id ${transportMetadata.requestId}`);
return { msgId, request };
} catch (e) {
logger.error(`Error decoding message ${e.message}`);
Expand All @@ -51,7 +51,7 @@ class MessageService implements IMessageService {
});

if (!!cachedMessages.length) {
cachedMessages.forEach((msg) => logger.info(`Got cached message id ${msg.msgId} request id ${msg.request.transportMetadata.requestId}`));
cachedMessages.forEach((msg) => logger.info(`Found cached message id ${msg.msgId} request id ${msg.request.transportMetadata.requestId}`));
const cachedMsgsStatus = cachedMessages.map((msg): ExtendedMessageStatusCache => {
return {
msgId: msg.msgId,
Expand All @@ -66,7 +66,7 @@ class MessageService implements IMessageService {

if (!!messagesToHandle.length) {
const msgStatuses = await customerServerApi.messagesToSign(messagesToHandle.map((msg) => msg.request));
logger.info(`Got messages status for ${JSON.stringify(msgStatuses.map((status) => { return { requestId: status.requestId, status: status.status } }))}`);
logger.info(`Got messages status from customer server for ${JSON.stringify(msgStatuses.map((status) => { return { requestId: status.requestId, status: status.status } }))}`);
await this.updateStatus(msgStatuses.map((messageStatus): ExtendedMessageStatusCache => {
const decodedMessage = messagesToHandle.find((msg) => msg.request.transportMetadata.requestId === messageStatus.requestId);
if (!decodedMessage) {
Expand All @@ -83,7 +83,7 @@ class MessageService implements IMessageService {
}

if (!!unknownMessages.length) {
unknownMessages.forEach((msg) => logger.error(`Got unknown message type ${msg.request.transportMetadata.type} and id ${msg.msgId}`));
unknownMessages.forEach((msg) => logger.error(`Got unknown message from Fireblocks type ${msg.request.transportMetadata.type} and id ${msg.msgId}`));
await this.ackMessages(unknownMessages.map((msg) => msg.msgId));
}
}
Expand All @@ -110,13 +110,13 @@ class MessageService implements IMessageService {
}

if (status === 'SIGNED' || status === 'FAILED') {
logger.info(`Got message from customer server with status: ${status}, msgId ${msgId}, cacheId: ${requestId}`);
logger.info(`Found message with final status: ${status}, msgId ${msgId}, cacheId: ${requestId}`);
await fbServerApi.broadcastResponse(messageStatus, request);
await fbServerApi.ackMessage(msgId);
this.msgCache[messageStatus.requestId].messageStatus = messageStatus;
}
} catch (e) {
throw new Error(`Error updating status to fireblocks ${e.message} for message ${msgStatus.msgId} and status ${msgStatus.messageStatus}`);
throw new Error(`Error updating status to fireblocks ${e.message} for message ${msgStatus.msgId} and status ${JSON.stringify(msgStatus.messageStatus)}`);
}
}
}
Expand Down

0 comments on commit 835f4fd

Please sign in to comment.