Skip to content

Commit

Permalink
fix: reduce logging
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Jul 15, 2022
1 parent 9b337bb commit 1e83bf0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
30 changes: 15 additions & 15 deletions backend/src/hasura/eventHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IS_DEV } from "@aca/shared/dev";
import { logger } from "@aca/shared/logger";
import { mapGetOrCreate } from "@aca/shared/map";

import { HasuraEvent, RawHasuraEvent, getUserIdFromRawHasuraEvent, normalizeHasuraEvent } from "./eventUtils";
import { HasuraEvent, RawHasuraEvent, normalizeHasuraEvent } from "./eventUtils";

type EntitiesEventsMapBase = Record<string, unknown>;

Expand Down Expand Up @@ -70,31 +70,31 @@ export function createHasuraEventsHandler<T extends EntitiesEventsMapBase>() {

async function requestHandler(req: Request, res: Response) {
const hasuraEvent = req.body as RawHasuraEvent<unknown>;
const userId = getUserIdFromRawHasuraEvent(hasuraEvent);
// const userId = getUserIdFromRawHasuraEvent(hasuraEvent);

if (IS_DEV) {
logger.info(`Handling event (${hasuraEvent.trigger.name})`);
} else {
logger.info(
{
eventId: hasuraEvent.id,
triggerName: hasuraEvent.trigger.name,
userId,
},
"Handling event"
);
// logger.info(
// {
// eventId: hasuraEvent.id,
// triggerName: hasuraEvent.trigger.name,
// userId,
// },
// "Handling event"
// );
}

await handleHasuraEvent(hasuraEvent);

if (IS_DEV) {
logger.info(`Handled event (${hasuraEvent.trigger.name})`);
} else {
logger.info("Handled event", {
eventId: hasuraEvent.id,
triggerName: hasuraEvent.trigger.name,
userId,
});
// logger.info("Handled event", {
// eventId: hasuraEvent.id,
// triggerName: hasuraEvent.trigger.name,
// userId,
// });
}

res.status(200).json({
Expand Down
16 changes: 11 additions & 5 deletions backend/src/notification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from "@aca/backend/src/gmail/capture";
import { HasuraEvent, UpdateHasuraEvent } from "@aca/backend/src/hasura";
import { Notification, db } from "@aca/db";
import { logger } from "@aca/shared/logger";

// Add newly resolved Slack message notifications to the user_slack_conversation_read debounce buffer table which
// is used to mark messages as read in the Slack API.
Expand All @@ -29,11 +30,16 @@ async function addRelatedSlackMessageToMarkAsReadQueue(notification_id: string)
},
});
} else {
await db.user_slack_conversation_read.upsert({
where: { user_slack_installation_id_slack_conversation_id: keyFields },
create: { ...keyFields, slack_last_message_ts: messageTs },
update: {},
});
// this fails quite often and pollutes sentry with too many errors
try {
await db.user_slack_conversation_read.upsert({
where: { user_slack_installation_id_slack_conversation_id: keyFields },
create: { ...keyFields, slack_last_message_ts: messageTs },
update: {},
});
} catch (e) {
logger.warn(e);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion backend/src/slack/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const sharedOptions: Options<typeof SlackBolt.ExpressReceiver> & Options<
return userSlackInstallation.data as unknown as SlackInstallation;
}

logger.warn(`No Slack installation for query ${JSON.stringify(query)}`);
//logger.warn(`No Slack installation for query ${JSON.stringify(query)}`);
// this returns a dummy SlackInstallation so the event is still acknowledged
return { teamId: "XXXX", enterpriseId: "XXXX" } as unknown as SlackInstallation;
},
Expand Down
2 changes: 1 addition & 1 deletion backend/src/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function listenForWebhooks(service: string, processFn: ProcessFunc) {
try {
lock = await acquireLock(service, message.id);
if (!(await markAsProcessed(service, message.id))) {
logger.info(`message ${message.id} from ${service} was already processed (${messageTimestamp.toISOString()})`);
//logger.info(`message ${message.id} from ${service} was already processed (${messageTimestamp.toISOString()})`);
lock.unlock().catch((err) => logger.warn("unlock error (processed)", err));
if (isAfter(addHours(new Date(), -3), messageTimestamp)) {
// message was already processed, but it still exists in the pubsub queue
Expand Down

0 comments on commit 1e83bf0

Please sign in to comment.