diff --git a/.changeset/popular-cars-hunt.md b/.changeset/popular-cars-hunt.md new file mode 100644 index 000000000..93dfdd9b9 --- /dev/null +++ b/.changeset/popular-cars-hunt.md @@ -0,0 +1,5 @@ +--- +"smtp": patch +--- + +Processing webhook now logs the size of email and subject template diff --git a/apps/smtp/src/lib/bytes-to-kb.test.ts b/apps/smtp/src/lib/bytes-to-kb.test.ts new file mode 100644 index 000000000..91099397c --- /dev/null +++ b/apps/smtp/src/lib/bytes-to-kb.test.ts @@ -0,0 +1,14 @@ +import { describe, expect, it } from "vitest"; + +import { bytesToKb } from "./bytes-to-kb"; + +describe("bytesToKb", () => { + it("should convert bytes to kb", () => { + expect(bytesToKb(1024)).toBe(1); + expect(bytesToKb(2048)).toBe(2); + expect(bytesToKb(3072)).toBe(3); + expect(bytesToKb(34344443)).toBe(33539.5); + expect(bytesToKb(43433434343)).toBe(42415463.23); + expect(bytesToKb(3434334)).toBe(3353.84); + }); +}); diff --git a/apps/smtp/src/lib/bytes-to-kb.ts b/apps/smtp/src/lib/bytes-to-kb.ts new file mode 100644 index 000000000..161c7048a --- /dev/null +++ b/apps/smtp/src/lib/bytes-to-kb.ts @@ -0,0 +1,3 @@ +export function bytesToKb(bytes: number): number { + return +(bytes / 1024).toFixed(2); +} diff --git a/apps/smtp/src/modules/event-handlers/use-case/send-event-messages.use-case.ts b/apps/smtp/src/modules/event-handlers/use-case/send-event-messages.use-case.ts index b58054f79..683695d18 100644 --- a/apps/smtp/src/modules/event-handlers/use-case/send-event-messages.use-case.ts +++ b/apps/smtp/src/modules/event-handlers/use-case/send-event-messages.use-case.ts @@ -1,11 +1,13 @@ +import { err, errAsync, Result, ResultAsync } from "neverthrow"; + +import { BaseError } from "../../../errors"; +import { bytesToKb } from "../../../lib/bytes-to-kb"; +import { createLogger } from "../../../logger"; +import { SmtpConfiguration } from "../../smtp/configuration/smtp-config-schema"; import { IGetSmtpConfiguration } from "../../smtp/configuration/smtp-configuration.service"; import { IEmailCompiler } from "../../smtp/services/email-compiler"; -import { MessageEventTypes } from "../message-event-types"; -import { createLogger } from "../../../logger"; import { ISMTPEmailSender, SendMailArgs } from "../../smtp/services/smtp-email-sender"; -import { BaseError } from "../../../errors"; -import { err, errAsync, Result, ResultAsync } from "neverthrow"; -import { SmtpConfiguration } from "../../smtp/configuration/smtp-config-schema"; +import { MessageEventTypes } from "../message-event-types"; export class SendEventMessagesUseCase { static BaseError = BaseError.subclass("SendEventMessagesUseCaseError"); @@ -134,7 +136,10 @@ export class SendEventMessagesUseCase { ); } - this.logger.info("Successfully compiled email template"); + this.logger.info("Successfully compiled email template", { + bodyTemplateSizeKb: bytesToKb(new Blob([eventSettings.template]).size), + subjectTemplateSizeKb: bytesToKb(new Blob([eventSettings.subject]).size), + }); const smtpSettings: SendMailArgs["smtpSettings"] = { host: config.smtpHost,