Skip to content

Commit

Permalink
refactor: Add more logs to track webhook events (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sertaç Karahoda authored Dec 21, 2021
1 parent b7beafa commit 57b3eda
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/server/queueListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ export async function initializeQueueListener(): Promise<void> {
{ correlationId: data.correlationId },
async () => {
try {
logger.info(
"Processing job",
{
meta: {
data,
id
}
}
);
await webhookEventService.processJob(data);
logger.info(
"Job processed",
Expand Down
3 changes: 3 additions & 0 deletions src/server/router/webhookEventRouter/webhookEventRouter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Router as createRouter } from "express";
import { JSONBodyParser } from "../../middlewares";
import { webhookEventService } from "../../services";
import { logger } from "../../adapters";

const webhookEventRouter = createRouter({ mergeParams: true });
webhookEventRouter.post("/",
JSONBodyParser,
async (req, res, next) => {
try {
logger.info("webhookEvent post request received.");
const webhookId = req.headers["zeplin-webhook-id"] as string;
const deliveryId = req.headers["zeplin-delivery-id"] as string;
const signature = req.headers["zeplin-signature"] as string;
Expand All @@ -20,6 +22,7 @@ webhookEventRouter.post("/",
deliveryTimestamp,
payload: req.body
});
logger.info("webhookEvent post request handled.");
res.send();
} catch (error) {
next(error);
Expand Down
31 changes: 30 additions & 1 deletion src/server/services/webhookEventService/webhookEventService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GONE, UNAUTHORIZED } from "http-status-codes";
import { WebhookEvent } from "@zeplin/sdk";

import { messageQueue, requester, Zeplin } from "../../adapters";
import { logger, messageQueue, requester, Zeplin } from "../../adapters";
import { configurationRepo, messageJobRepo, webhookEventRepo } from "../../repos";
import { getNotificationHandler } from "./notificationHandlers";
import { ServerError } from "../../errors";
Expand Down Expand Up @@ -62,7 +62,9 @@ class WebhookEventService {
const message = notificationHandler.getTeamsMessage(distinctEvents);

try {
logger.info("Sending message to teams");
await requester.post(configuration.microsoftTeams.incomingWebhookUrl, message);
logger.info("Message sent to teams");
} catch (error) {
if (error instanceof ServerError && error.statusCode === GONE) {
await configurationRepo.delete(configuration._id.toHexString());
Expand Down Expand Up @@ -125,7 +127,25 @@ class WebhookEventService {
}

await messageJobRepo.setGroupActiveJobId(groupingKey, deliveryId);
logger.info(
"Active job set",
{
meta: {
groupingKey,
deliveryId
}
}
);
await webhookEventRepo.addEventToGroup(groupingKey, event);
logger.info(
"Event added to group",
{
meta: {
groupingKey,
deliveryId
}
}
);

await messageQueue.add(
{
Expand All @@ -136,6 +156,15 @@ class WebhookEventService {
},
{ delay: notificationHandler.delay }
);
logger.info(
"Message added to queue",
{
meta: {
groupingKey,
deliveryId
}
}
);
}
}

Expand Down

0 comments on commit 57b3eda

Please sign in to comment.