mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Add metric for emails sent (#16881)
This adds a counter `synapse_emails_sent_total` for emails sent. They are broken down by `type`, which are `password_reset`, `registration`, `add_threepid`, `notification` (matching the methods of `Mailer`).
This commit is contained in:
parent
bc1db16086
commit
0621e8eb0e
1
changelog.d/16881.feature
Normal file
1
changelog.d/16881.feature
Normal file
@ -0,0 +1 @@
|
||||
A metric was added for emails sent by Synapse, broken down by type: `synapse_emails_sent_total`. Contributed by Remi Rampin.
|
@ -26,6 +26,7 @@ from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, TypeVar
|
||||
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
|
||||
@ -56,6 +57,12 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
emails_sent_counter = Counter(
|
||||
"synapse_emails_sent_total",
|
||||
"Emails sent by type",
|
||||
["type"],
|
||||
)
|
||||
|
||||
|
||||
CONTEXT_BEFORE = 1
|
||||
CONTEXT_AFTER = 1
|
||||
@ -130,6 +137,8 @@ class Mailer:
|
||||
|
||||
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:
|
||||
@ -153,6 +162,8 @@ class Mailer:
|
||||
|
||||
template_vars: TemplateVars = {"link": link}
|
||||
|
||||
emails_sent_counter.labels("password_reset").inc()
|
||||
|
||||
await self.send_email(
|
||||
email_address,
|
||||
self.email_subjects.password_reset
|
||||
@ -160,6 +171,8 @@ class Mailer:
|
||||
template_vars,
|
||||
)
|
||||
|
||||
emails_sent_counter.labels("registration")
|
||||
|
||||
async def send_registration_mail(
|
||||
self, email_address: str, token: str, client_secret: str, sid: str
|
||||
) -> None:
|
||||
@ -183,6 +196,8 @@ class Mailer:
|
||||
|
||||
template_vars: TemplateVars = {"link": link}
|
||||
|
||||
emails_sent_counter.labels("registration").inc()
|
||||
|
||||
await self.send_email(
|
||||
email_address,
|
||||
self.email_subjects.email_validation
|
||||
@ -190,6 +205,8 @@ class Mailer:
|
||||
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:
|
||||
@ -214,6 +231,8 @@ class Mailer:
|
||||
|
||||
template_vars: TemplateVars = {"link": link}
|
||||
|
||||
emails_sent_counter.labels("add_threepid").inc()
|
||||
|
||||
await self.send_email(
|
||||
email_address,
|
||||
self.email_subjects.email_validation
|
||||
@ -221,6 +240,8 @@ class Mailer:
|
||||
template_vars,
|
||||
)
|
||||
|
||||
emails_sent_counter.labels("notification")
|
||||
|
||||
async def send_notification_mail(
|
||||
self,
|
||||
app_id: str,
|
||||
@ -315,6 +336,8 @@ class Mailer:
|
||||
"reason": reason,
|
||||
}
|
||||
|
||||
emails_sent_counter.labels("notification").inc()
|
||||
|
||||
await self.send_email(
|
||||
email_address, summary_text, template_vars, unsubscribe_link
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user