Commit b8592a19 authored by echel0n's avatar echel0n

Updated Sentry to use latest SDK

parent cb9c5f27
......@@ -404,7 +404,14 @@ def main():
except (SystemExit, KeyboardInterrupt):
if app:
app.shutdown()
except Exception:
except Exception as e:
# attempt to send exception to sentry
try:
import sentry_sdk
sentry_sdk.capture_exception(e)
except ImportError:
pass
traceback.print_exc()
......
......@@ -20,6 +20,8 @@
# ##############################################################################
import asyncio
import datetime
import locale
import logging
import os
import platform
import re
......@@ -34,11 +36,13 @@ from urllib.parse import uses_netloc
from urllib.request import FancyURLopener
import rarfile
import sentry_sdk
from apscheduler.schedulers import SchedulerNotRunningError
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.interval import IntervalTrigger
from dateutil import tz
from fake_useragent import UserAgent
from sentry_sdk.integrations.logging import LoggingIntegration
from tornado.platform.asyncio import AnyThreadEventLoopPolicy
import sickrage
......@@ -233,6 +237,9 @@ class Core(object):
# event loop policy that allows loop creation on any thread.
asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
# init sentry
self.init_sentry()
# scheduler
self.scheduler = BackgroundScheduler({'apscheduler.timezone': 'UTC'})
......@@ -326,6 +333,12 @@ class Core(object):
# migrate config
self.config.migrate_config_file(self.config_file)
# add extra sentry tags
if sickrage.app.config.user and sickrage.app.config.user.sub_id:
sentry_sdk.set_tag('sub_id', sickrage.app.config.user.sub_id)
if sickrage.app.config.general and sickrage.app.config.general.server_id:
sentry_sdk.set_tag('server_id', sickrage.app.config.general.server_id)
# config overrides
if self.web_port:
self.config.general.web_port = self.web_port
......@@ -591,6 +604,38 @@ class Core(object):
(self.config.general.web_host, get_lan_ip())[self.config.general.web_host == '0.0.0.0'],
self.config.general.web_port, self.config.general.web_root))
def init_sentry(self):
# sentry log handler
sentry_logging = LoggingIntegration(
level=logging.INFO, # Capture info and above as breadcrumbs
event_level=logging.ERROR # Send errors as events
)
# init sentry logging
sentry_sdk.init(
dsn="https://[email protected]/2?verify_ssl=0",
integrations=[sentry_logging],
release=sickrage.version(),
environment=('master', 'develop')['dev' in sickrage.version()],
ignore_errors=[
'KeyboardInterrupt',
'PermissionError',
'FileNotFoundError',
'EpisodeNotFoundException'
]
)
# sentry tags
sentry_tags = {
'platform': platform.platform(),
'locale': repr(locale.getdefaultlocale()),
'python': platform.python_version()
}
# set sentry tags
for tag_key, tag_value in sentry_tags.items():
sentry_sdk.set_tag(tag_key, tag_value)
def load_shows(self):
threading.currentThread().setName('CORE')
......
......@@ -18,18 +18,14 @@
# You should have received a copy of the GNU General Public License
# along with SiCKRAGE. If not, see <http://www.gnu.org/licenses/>.
# ##############################################################################
import locale
import logging
import os
import pkgutil
import platform
import re
import sys
from logging import FileHandler, CRITICAL, DEBUG, ERROR, INFO, WARNING
from logging.handlers import RotatingFileHandler
import raven
from raven.handlers.logging import SentryHandler
from unidecode import unidecode
import sickrage
......@@ -148,38 +144,6 @@ class Logger(logging.getLoggerClass()):
# remove all handlers
self.handlers.clear()
sentry_ignore_exceptions = [
'KeyboardInterrupt',
'PermissionError',
'FileNotFoundError',
'EpisodeNotFoundException'
]
# sentry log handler
sentry_client = raven.Client(
'https://[email protected]/2?verify_ssl=0',
release=sickrage.version(),
repos={'sickrage': {'name': 'sickrage/sickrage'}},
ignore_exceptions=sentry_ignore_exceptions
)
sentry_tags = {
'platform': platform.platform(),
'locale': locale.getdefaultlocale(),
'python': platform.python_version()
}
if sickrage.app.config.user and sickrage.app.config.user.sub_id:
sentry_tags.update({'sub_id': sickrage.app.config.user.sub_id})
if sickrage.app.config.general and sickrage.app.config.general.server_id:
sentry_tags.update({'server_id': sickrage.app.config.general.server_id})
sentry_handler = SentryHandler(client=sentry_client, ignore_exceptions=sentry_ignore_exceptions, tags=sentry_tags)
sentry_handler.setLevel(self.logLevels['ERROR'])
sentry_handler.set_name('sentry')
self.addHandler(sentry_handler)
# console log handler
if self.consoleLogging:
console_handler = logging.StreamHandler()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment