2019-03-07 17:56:29 +07:00
|
|
|
import logging
|
|
|
|
from os import environ
|
|
|
|
|
|
|
|
import sentry_sdk
|
|
|
|
from sentry_sdk.integrations.logging import LoggingIntegration
|
|
|
|
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
|
|
|
|
|
|
|
|
from odoo import http
|
2018-03-14 16:37:46 +07:00
|
|
|
from . import models, controllers
|
2019-03-07 17:56:29 +07:00
|
|
|
|
2020-07-30 14:49:26 +07:00
|
|
|
def delegate(self, attr):
|
|
|
|
return getattr(self.app, attr)
|
|
|
|
SentryWsgiMiddleware.__getattr__ = delegate
|
2019-03-07 17:56:29 +07:00
|
|
|
|
|
|
|
def enable_sentry():
|
|
|
|
logger = logging.getLogger('runbot_merge')
|
|
|
|
|
|
|
|
dsn = environ.get('SENTRY_DSN')
|
|
|
|
if not dsn:
|
|
|
|
logger.info("No DSN found, skipping sentry...")
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
sentry_sdk.init(
|
|
|
|
dsn,
|
|
|
|
integrations=[
|
|
|
|
# note: if the colorformatter is enabled, sentry gets lost
|
|
|
|
# and classifies everything as errors because it fails to
|
|
|
|
# properly classify levels as the colorformatter injects
|
|
|
|
# the ANSI color codes right into LogRecord.levelname
|
|
|
|
LoggingIntegration(level=logging.INFO, event_level=logging.WARNING),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
http.root = SentryWsgiMiddleware(http.root)
|
|
|
|
except Exception:
|
|
|
|
logger.exception("DSN found, failed to enable sentry...")
|
|
|
|
else:
|
|
|
|
logger.info("DSN found, sentry enabled...")
|
2020-02-11 14:46:31 +07:00
|
|
|
|
|
|
|
def _check_citext(cr):
|
|
|
|
cr.execute("select 1 from pg_extension where extname = 'citext'")
|
|
|
|
if not cr.rowcount:
|
|
|
|
try:
|
|
|
|
cr.execute('create extension citext')
|
|
|
|
except Exception:
|
|
|
|
raise AssertionError("runbot_merge needs the citext extension")
|