[ADD] runbot_merge: sentry integration

Might eventually extract / generalise, but for now it's simpler to
just do it in runbot_merge's post_load, that way there's no setup
change (just a small bit of configuration), and it's only enabled on
the instances runbot_merge is installed on.

fixes #97, closes #103
This commit is contained in:
Xavier Morel 2019-03-07 11:56:29 +01:00
parent 10b456deda
commit e0320664f9
2 changed files with 36 additions and 1 deletions

View File

@ -1 +1,35 @@
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
from . import models, controllers
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...")

View File

@ -9,5 +9,6 @@
'views/res_partner.xml',
'views/mergebot.xml',
'views/templates.xml',
]
],
'post_load': 'enable_sentry',
}