Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metric for emails sent #16881

Merged
merged 3 commits into from
Feb 14, 2024
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
1 change: 1 addition & 0 deletions changelog.d/16881.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A metric was added for emails sent by Synapse, broken down by type: `synapse_emails_sent_total`. Contributed by Remi Rampin.
23 changes: 23 additions & 0 deletions synapse/push/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import bleach
import jinja2
from markupsafe import Markup
from prometheus_client import Counter

from synapse.api.constants import EventTypes, Membership, RoomTypes
from synapse.api.errors import StoreError
Expand Down Expand Up @@ -56,6 +57,12 @@

T = TypeVar("T")

emails_sent_counter = Counter(
"synapse_emails_sent_total",
"Emails sent by type",
["type"],
)


CONTEXT_BEFORE = 1
CONTEXT_AFTER = 1
Expand Down Expand Up @@ -130,6 +137,8 @@ def __init__(

logger.info("Created Mailer for app_name %s" % app_name)

emails_sent_counter.labels("password_reset")

async def send_password_reset_mail(
self, email_address: str, token: str, client_secret: str, sid: str
) -> None:
Expand All @@ -153,13 +162,17 @@ async def send_password_reset_mail(

template_vars: TemplateVars = {"link": link}

emails_sent_counter.labels("password_reset").inc()

await self.send_email(
email_address,
self.email_subjects.password_reset
% {"server_name": self.hs.config.server.server_name, "app": self.app_name},
template_vars,
)

emails_sent_counter.labels("registration")

async def send_registration_mail(
self, email_address: str, token: str, client_secret: str, sid: str
) -> None:
Expand All @@ -183,13 +196,17 @@ async def send_registration_mail(

template_vars: TemplateVars = {"link": link}

emails_sent_counter.labels("registration").inc()

await self.send_email(
email_address,
self.email_subjects.email_validation
% {"server_name": self.hs.config.server.server_name, "app": self.app_name},
template_vars,
)

emails_sent_counter.labels("add_threepid")

async def send_add_threepid_mail(
self, email_address: str, token: str, client_secret: str, sid: str
) -> None:
Expand All @@ -214,13 +231,17 @@ async def send_add_threepid_mail(

template_vars: TemplateVars = {"link": link}

emails_sent_counter.labels("add_threepid").inc()

await self.send_email(
email_address,
self.email_subjects.email_validation
% {"server_name": self.hs.config.server.server_name, "app": self.app_name},
template_vars,
)

emails_sent_counter.labels("notification")

async def send_notification_mail(
self,
app_id: str,
Expand Down Expand Up @@ -315,6 +336,8 @@ async def _fetch_room_state(room_id: str) -> None:
"reason": reason,
}

emails_sent_counter.labels("notification").inc()

await self.send_email(
email_address, summary_text, template_vars, unsubscribe_link
)
Expand Down
Loading