log "Custom/smtp_connection_time" metric in newrelic

This commit is contained in:
Son 2021-12-30 11:46:01 +01:00
parent a64968f6e5
commit 378bad6253
3 changed files with 15 additions and 8 deletions

View File

@ -7,6 +7,7 @@ from ast import literal_eval
from typing import Callable
from urllib.parse import urlparse
import newrelic.agent
from dotenv import load_dotenv
SHA1 = subprocess.getoutput("git rev-parse HEAD")
@ -402,6 +403,12 @@ except Exception:
HIBP_API_KEYS = sl_getenv("HIBP_API_KEYS", list) or []
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")

View File

@ -17,6 +17,7 @@ from typing import Tuple, List, Optional, Union
import arrow
import dkim
import newrelic.agent
import re2 as re
import spf
from cachetools import cached, TTLCache
@ -53,6 +54,7 @@ from app.config import (
TEMP_DIR,
ALIAS_AUTOMATIC_DISABLE,
RSPAMD_SIGN_DKIM,
newrelic_app,
)
from app.db import Session
from app.dns_utils import get_mx_domains
@ -1307,7 +1309,11 @@ def sl_sendmail(
if POSTFIX_SUBMISSION_TLS:
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
# encode message raw directly instead

View File

@ -78,13 +78,13 @@ from app.config import (
TRANSACTIONAL_BOUNCE_SUFFIX,
ENABLE_SPAM_ASSASSIN,
BOUNCE_PREFIX_FOR_REPLY_PHASE,
NEWRELIC_CONFIG_PATH,
POSTMASTER,
ALERT_HOTMAIL_COMPLAINT,
ALERT_YAHOO_COMPLAINT,
ALERT_HOTMAIL_COMPLAINT_TRANSACTIONAL,
ALERT_HOTMAIL_COMPLAINT_REPLY_PHASE,
OLD_UNSUBSCRIBER,
newrelic_app,
)
from app.db import Session
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 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:
"""