diff --git a/src/analytics/events.ts b/src/analytics/events.ts index b1f536e..cccd8d3 100644 --- a/src/analytics/events.ts +++ b/src/analytics/events.ts @@ -43,10 +43,10 @@ export async function tryToFetchAllCliEvents(): Promise { retries: 10, minTimeout: 5 * 1000, maxTimeout: 120 * 1000, - onRetry: (e: Error) => { + onRetry: (error: Error) => { + logger.error(error); logger.error( - "Error happened while fetching events for report generator, trying again:", - e.message ?? e, + "Error happened while fetching events for report generator, trying again...", ); }, }, diff --git a/src/analytics/reports/events.ts b/src/analytics/reports/events.ts index c14637c..40e9b83 100644 --- a/src/analytics/reports/events.ts +++ b/src/analytics/reports/events.ts @@ -12,7 +12,6 @@ import moment from "../moment"; */ export async function fetchEventsForReportGenerator(): Promise { const allEvents = await tryToFetchAllCliEvents(); - logger.info("\nNumber of CLI events fetched:", allEvents.length); const waspTeamFilters = [isNotWaspTeamEvent, isNotMihoPrivateCIServerEvent]; @@ -20,10 +19,17 @@ export async function fetchEventsForReportGenerator(): Promise { (events, f) => events.filter(f), allEvents, ); + logger.debug( + "\nNumber of non-Wasp-team CLI events:", + nonWaspTeamEvents.length, + ); + const sortedNonWaspTeamEvents = _.sortBy(nonWaspTeamEvents, "timestamp"); + const sortedValidEvents = markAsCiEventBurstsFromDifferentUsersFromSameIp( sortedNonWaspTeamEvents, ); + logger.debug("\nNumber of valid CLI events:", sortedValidEvents.length); return sortedValidEvents; } diff --git a/src/analytics/reports/periodReport/index.ts b/src/analytics/reports/periodReport/index.ts index 34ae31c..e487a4f 100644 --- a/src/analytics/reports/periodReport/index.ts +++ b/src/analytics/reports/periodReport/index.ts @@ -1,3 +1,4 @@ +import logger from "../../../utils/logger"; import { PosthogEvent } from "../../events"; import { fetchEventsForReportGenerator } from "../events"; import { AllTimePeriodReport, PeriodReport } from "../reports"; @@ -14,6 +15,11 @@ export async function generatePeriodReport( numPeriods: number, periodName: PeriodName, ): Promise { + logger.info("Generating a period report..."); + logger.debug( + `Period report details: numPeriods=${numPeriods}, periodName=${periodName}, prefetchedEvents=${!!prefetchedEvents}`, + ); + const events = prefetchedEvents ?? (await fetchEventsForReportGenerator()); const userActivityReport = await generateUserActivityReport( @@ -48,6 +54,11 @@ export async function generateAllTimePeriodReport( numPeriods: number, periodName: PeriodName, ): Promise { + logger.info("Generating an all-time period report..."); + logger.debug( + `All-time period report details: numPeriods=${numPeriods}, periodName=${periodName}, prefetchedEvents=${!!prefetchedEvents}`, + ); + const events = prefetchedEvents ?? (await fetchEventsForReportGenerator()); const userActivityReport = await generateUserActivityReport( diff --git a/src/analytics/reports/totalReport.ts b/src/analytics/reports/totalReport.ts index ff98da5..2172323 100644 --- a/src/analytics/reports/totalReport.ts +++ b/src/analytics/reports/totalReport.ts @@ -1,3 +1,4 @@ +import logger from "../../utils/logger"; import { PosthogEvent } from "../events"; import { EventsByExecutionEnvironment, @@ -16,6 +17,9 @@ import { groupEventsByProject } from "./utils"; export async function generateTotalReport( prefetchedEvents: PosthogEvent[] | undefined = undefined, ): Promise { + logger.info("Generating a total report..."); + logger.debug(`Total report details: prefetchedEvents=${!!prefetchedEvents}`); + const events = prefetchedEvents ?? (await fetchEventsForReportGenerator()); const { localEvents, groupedNonLocalEvents } = diff --git a/src/discord/bot/analytics/commands.ts b/src/discord/bot/analytics/commands.ts index 696375c..99e8ae0 100644 --- a/src/discord/bot/analytics/commands.ts +++ b/src/discord/bot/analytics/commands.ts @@ -1,5 +1,6 @@ import Discord from "discord.js"; +import logger from "../../../utils/logger"; import { REPORTS_CHANNEL_ID } from "../../server-ids"; import { GuildMessage } from "../../types"; import { fetchTextChannelById } from "../../utils"; @@ -25,6 +26,8 @@ function isReportsChannel(channel: Discord.Channel): boolean { export async function handleAnalyticsCommand( message: GuildMessage, ): Promise { + logger.info(`Handling analytics command: ${message.content}...`); + const commandArgs = extractCommandArgs(message.content); const analyticsCommand = parseAnalyticsCommand(commandArgs); if (!analyticsCommand) { diff --git a/src/discord/bot/analytics/common.ts b/src/discord/bot/analytics/common.ts index f39f404..83bb6b2 100644 --- a/src/discord/bot/analytics/common.ts +++ b/src/discord/bot/analytics/common.ts @@ -8,6 +8,7 @@ import { TextReport, } from "../../../analytics/reports/reports"; import { Writable } from "../../../types/helpers"; +import logger from "../../../utils/logger"; import { REPORTS_CHANNEL_ID } from "../../server-ids"; import { fetchTextChannelById } from "../../utils"; @@ -19,6 +20,10 @@ export async function sendAnalyticsReportToReportsChannel( prefetchedEvents: PosthogEvent[] | undefined = undefined, numPeriods: number | undefined = undefined, ): Promise { + logger.info(`Sending analytics report to the reports channel...`); + logger.debug( + `Analytics report details: type=${reportType}, numPeriods=${numPeriods}, prefetchedEvents=${!!prefetchedEvents}`, + ); const waspReportsChannel = await fetchTextChannelById( discordClient, REPORTS_CHANNEL_ID, @@ -67,11 +72,13 @@ const DISCORD_MESSAGE_TOO_LONG_SUFFIX = function convertSimpleReportToDiscordMessage( report: Partial, ): Discord.MessageCreateOptions { + logger.info("Converting report to a Discord message"); const options: Discord.MessageCreateOptions = {}; const embeds: Writable = []; const files: Writable = []; if (report.text) { + logger.debug("Report has a `text` field"); let content: string = report.text.join("\n"); if (content.length >= DISCORD_MAX_MSG_SIZE) { content = @@ -84,12 +91,16 @@ function convertSimpleReportToDiscordMessage( } if (report.imageChartsChart) { + logger.debug( + `Report has a \`imageChartsChart\` field (URL=${report.imageChartsChart.toURL()})`, + ); embeds.push( new Discord.EmbedBuilder().setImage(report.imageChartsChart.toURL()), ); } if (report.bufferChart) { + logger.debug("Report has a `bufferChart` field"); files.push(report.bufferChart); } diff --git a/src/discord/bot/daily-standup.ts b/src/discord/bot/daily-standup.ts index bed0b0d..e931758 100644 --- a/src/discord/bot/daily-standup.ts +++ b/src/discord/bot/daily-standup.ts @@ -2,12 +2,14 @@ import Discord from "discord.js"; import InspirationalQuotes from "inspirational-quotes"; import _ from "lodash"; +import logger from "../../utils/logger"; import { DAILY_STANDUP_CHANNEL_ID } from "../server-ids"; import { fetchTextChannelById } from "../utils"; export async function initiateDailyStandup( discordClient: Discord.Client, ): Promise { + logger.info(`Initiating daily standup...`); const dailyStandupChannel = await fetchTextChannelById( discordClient, DAILY_STANDUP_CHANNEL_ID, diff --git a/src/discord/bot/introduction.ts b/src/discord/bot/introduction.ts index 497472d..675902a 100644 --- a/src/discord/bot/introduction.ts +++ b/src/discord/bot/introduction.ts @@ -24,8 +24,11 @@ async function isGuestUser(message: GuildMessage): Promise { export async function handleIntroductionMessage( message: GuildMessage, ): Promise { + logger.info(`Handling introduction message [${message.id}]...`); + const trimmedMessageLength = message.content.trim().length; if (trimmedMessageLength < 20) { + logger.debug(`Introduction message [${message.id}] is too short`); await message.reply( "👋 Great to have you here! Please introduce yourself with a message that's at least 2️⃣0️⃣ characters long and I will give you full access to the server.", ); @@ -33,6 +36,9 @@ export async function handleIntroductionMessage( } try { + logger.debug( + `Introduction message [${message.id}] is valid. Removing the guest role...`, + ); const member = await message.guild.members.fetch(message.author.id); await member.roles.remove(GUEST_ROLE_ID); await message.reply(