mirror of
https://github.com/odoo/runbot.git
synced 2025-03-22 02:45:51 +07:00

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
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
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...")
|