Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/analytics/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export async function tryToFetchAllCliEvents(): Promise<PosthogEvent[]> {
retries: 10,
minTimeout: 5 * 1000,
maxTimeout: 120 * 1000,
onRetry: (e: Error) => {
onRetry: (error: Error) => {
logger.error(error);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this will log the message with the stack trace, etc...

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...",
);
},
},
Expand Down
8 changes: 7 additions & 1 deletion src/analytics/reports/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@ import moment from "../moment";
*/
export async function fetchEventsForReportGenerator(): Promise<PosthogEvent[]> {
const allEvents = await tryToFetchAllCliEvents();

logger.info("\nNumber of CLI events fetched:", allEvents.length);

const waspTeamFilters = [isNotWaspTeamEvent, isNotMihoPrivateCIServerEvent];
const nonWaspTeamEvents = waspTeamFilters.reduce(
(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);
Comment on lines +22 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we care about these in our logging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wondered how much do these filters affect the data.
Not really necessary, it's debug logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also there might be betters ways to solve some of them I hope.
With time these become more costly (computation-wise).


return sortedValidEvents;
}
Expand Down
11 changes: 11 additions & 0 deletions src/analytics/reports/periodReport/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logger from "../../../utils/logger";
import { PosthogEvent } from "../../events";
import { fetchEventsForReportGenerator } from "../events";
import { AllTimePeriodReport, PeriodReport } from "../reports";
Expand All @@ -14,6 +15,11 @@ export async function generatePeriodReport(
numPeriods: number,
periodName: PeriodName,
): Promise<PeriodReport> {
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(
Expand Down Expand Up @@ -48,6 +54,11 @@ export async function generateAllTimePeriodReport(
numPeriods: number,
periodName: PeriodName,
): Promise<AllTimePeriodReport> {
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(
Expand Down
4 changes: 4 additions & 0 deletions src/analytics/reports/totalReport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logger from "../../utils/logger";
import { PosthogEvent } from "../events";
import {
EventsByExecutionEnvironment,
Expand All @@ -16,6 +17,9 @@ import { groupEventsByProject } from "./utils";
export async function generateTotalReport(
prefetchedEvents: PosthogEvent[] | undefined = undefined,
): Promise<TotalReport> {
logger.info("Generating a total report...");
logger.debug(`Total report details: prefetchedEvents=${!!prefetchedEvents}`);

const events = prefetchedEvents ?? (await fetchEventsForReportGenerator());

const { localEvents, groupedNonLocalEvents } =
Expand Down
3 changes: 3 additions & 0 deletions src/discord/bot/analytics/commands.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -25,6 +26,8 @@ function isReportsChannel(channel: Discord.Channel): boolean {
export async function handleAnalyticsCommand(
message: GuildMessage,
): Promise<void> {
logger.info(`Handling analytics command: ${message.content}...`);

const commandArgs = extractCommandArgs(message.content);
const analyticsCommand = parseAnalyticsCommand(commandArgs);
if (!analyticsCommand) {
Expand Down
11 changes: 11 additions & 0 deletions src/discord/bot/analytics/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -19,6 +20,10 @@ export async function sendAnalyticsReportToReportsChannel(
prefetchedEvents: PosthogEvent[] | undefined = undefined,
numPeriods: number | undefined = undefined,
): Promise<void> {
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,
Expand Down Expand Up @@ -67,11 +72,13 @@ const DISCORD_MESSAGE_TOO_LONG_SUFFIX =
function convertSimpleReportToDiscordMessage(
report: Partial<TextReport & ChartReport & ImageChartsReport>,
): Discord.MessageCreateOptions {
logger.info("Converting report to a Discord message");
const options: Discord.MessageCreateOptions = {};
const embeds: Writable<Discord.MessageCreateOptions["embeds"]> = [];
const files: Writable<Discord.MessageCreateOptions["files"]> = [];

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 =
Expand All @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions src/discord/bot/daily-standup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
logger.info(`Initiating daily standup...`);
const dailyStandupChannel = await fetchTextChannelById(
discordClient,
DAILY_STANDUP_CHANNEL_ID,
Expand Down
6 changes: 6 additions & 0 deletions src/discord/bot/introduction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ async function isGuestUser(message: GuildMessage): Promise<boolean> {
export async function handleIntroductionMessage(
message: GuildMessage,
): Promise<void> {
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.",
);
return;
}

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(
Expand Down