mirror of
https://github.com/simple-login/app.git
synced 2024-09-29 13:11:29 +02:00
log "Custom/smtp_connection_time" metric in newrelic
This commit is contained in:
parent
a64968f6e5
commit
378bad6253
@ -7,6 +7,7 @@ from ast import literal_eval
|
|||||||
from typing import Callable
|
from typing import Callable
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
import newrelic.agent
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
SHA1 = subprocess.getoutput("git rev-parse HEAD")
|
SHA1 = subprocess.getoutput("git rev-parse HEAD")
|
||||||
@ -402,6 +403,12 @@ except Exception:
|
|||||||
HIBP_API_KEYS = sl_getenv("HIBP_API_KEYS", list) or []
|
HIBP_API_KEYS = sl_getenv("HIBP_API_KEYS", list) or []
|
||||||
|
|
||||||
NEWRELIC_CONFIG_PATH = os.environ.get("NEWRELIC_CONFIG_PATH")
|
NEWRELIC_CONFIG_PATH = os.environ.get("NEWRELIC_CONFIG_PATH")
|
||||||
|
newrelic_app = None
|
||||||
|
if NEWRELIC_CONFIG_PATH:
|
||||||
|
newrelic.agent.initialize(NEWRELIC_CONFIG_PATH)
|
||||||
|
|
||||||
|
newrelic_app = newrelic.agent.register_application()
|
||||||
|
|
||||||
|
|
||||||
POSTMASTER = os.environ.get("POSTMASTER")
|
POSTMASTER = os.environ.get("POSTMASTER")
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ from typing import Tuple, List, Optional, Union
|
|||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
import dkim
|
import dkim
|
||||||
|
import newrelic.agent
|
||||||
import re2 as re
|
import re2 as re
|
||||||
import spf
|
import spf
|
||||||
from cachetools import cached, TTLCache
|
from cachetools import cached, TTLCache
|
||||||
@ -53,6 +54,7 @@ from app.config import (
|
|||||||
TEMP_DIR,
|
TEMP_DIR,
|
||||||
ALIAS_AUTOMATIC_DISABLE,
|
ALIAS_AUTOMATIC_DISABLE,
|
||||||
RSPAMD_SIGN_DKIM,
|
RSPAMD_SIGN_DKIM,
|
||||||
|
newrelic_app,
|
||||||
)
|
)
|
||||||
from app.db import Session
|
from app.db import Session
|
||||||
from app.dns_utils import get_mx_domains
|
from app.dns_utils import get_mx_domains
|
||||||
@ -1307,7 +1309,11 @@ def sl_sendmail(
|
|||||||
if POSTFIX_SUBMISSION_TLS:
|
if POSTFIX_SUBMISSION_TLS:
|
||||||
smtp.starttls()
|
smtp.starttls()
|
||||||
|
|
||||||
LOG.d("getting a smtp connection takes seconds %s", time.time() - start)
|
elapsed = time.time() - start
|
||||||
|
LOG.d("getting a smtp connection takes seconds %s", elapsed)
|
||||||
|
newrelic.agent.record_custom_metric(
|
||||||
|
"Custom/smtp_connection_time", elapsed, newrelic_app
|
||||||
|
)
|
||||||
|
|
||||||
# smtp.send_message has UnicodeEncodeError
|
# smtp.send_message has UnicodeEncodeError
|
||||||
# encode message raw directly instead
|
# encode message raw directly instead
|
||||||
|
@ -78,13 +78,13 @@ from app.config import (
|
|||||||
TRANSACTIONAL_BOUNCE_SUFFIX,
|
TRANSACTIONAL_BOUNCE_SUFFIX,
|
||||||
ENABLE_SPAM_ASSASSIN,
|
ENABLE_SPAM_ASSASSIN,
|
||||||
BOUNCE_PREFIX_FOR_REPLY_PHASE,
|
BOUNCE_PREFIX_FOR_REPLY_PHASE,
|
||||||
NEWRELIC_CONFIG_PATH,
|
|
||||||
POSTMASTER,
|
POSTMASTER,
|
||||||
ALERT_HOTMAIL_COMPLAINT,
|
ALERT_HOTMAIL_COMPLAINT,
|
||||||
ALERT_YAHOO_COMPLAINT,
|
ALERT_YAHOO_COMPLAINT,
|
||||||
ALERT_HOTMAIL_COMPLAINT_TRANSACTIONAL,
|
ALERT_HOTMAIL_COMPLAINT_TRANSACTIONAL,
|
||||||
ALERT_HOTMAIL_COMPLAINT_REPLY_PHASE,
|
ALERT_HOTMAIL_COMPLAINT_REPLY_PHASE,
|
||||||
OLD_UNSUBSCRIBER,
|
OLD_UNSUBSCRIBER,
|
||||||
|
newrelic_app,
|
||||||
)
|
)
|
||||||
from app.db import Session
|
from app.db import Session
|
||||||
from app.email import status, headers
|
from app.email import status, headers
|
||||||
@ -145,12 +145,6 @@ from app.utils import sanitize_email
|
|||||||
from init_app import load_pgp_public_keys
|
from init_app import load_pgp_public_keys
|
||||||
from server import create_light_app
|
from server import create_light_app
|
||||||
|
|
||||||
newrelic_app = None
|
|
||||||
if NEWRELIC_CONFIG_PATH:
|
|
||||||
newrelic.agent.initialize(NEWRELIC_CONFIG_PATH)
|
|
||||||
|
|
||||||
newrelic_app = newrelic.agent.register_application()
|
|
||||||
|
|
||||||
|
|
||||||
def get_or_create_contact(from_header: str, mail_from: str, alias: Alias) -> Contact:
|
def get_or_create_contact(from_header: str, mail_from: str, alias: Alias) -> Contact:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user