Skip to content

Commit

Permalink
[SMTP] Log template size (#1612)
Browse files Browse the repository at this point in the history
* Log template size

* Add changeset

* format to kb

* Improve logging and add test
  • Loading branch information
poulch authored Oct 8, 2024
1 parent 12a57e2 commit 8b66ff6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-cars-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"smtp": patch
---

Processing webhook now logs the size of email and subject template
14 changes: 14 additions & 0 deletions apps/smtp/src/lib/bytes-to-kb.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
3 changes: 3 additions & 0 deletions apps/smtp/src/lib/bytes-to-kb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function bytesToKb(bytes: number): number {
return +(bytes / 1024).toFixed(2);
}
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8b66ff6

Please sign in to comment.