2015-02-24 16:40:01 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014 GNS3 Technologies Inc.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import raven
|
|
|
|
import json
|
2015-02-25 10:42:02 +00:00
|
|
|
import asyncio.futures
|
2015-03-03 11:41:30 +00:00
|
|
|
import asyncio
|
2015-02-24 16:40:01 +00:00
|
|
|
|
|
|
|
from .version import __version__
|
|
|
|
from .config import Config
|
|
|
|
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class CrashReport:
|
|
|
|
|
|
|
|
"""
|
|
|
|
Report crash to a third party service
|
|
|
|
"""
|
|
|
|
|
2015-03-03 11:41:30 +00:00
|
|
|
DSN = "sync+https://50af75d8641d4ea7a4ea6b38c7df6cf9:41d54936f8f14e558066262e2ec8bbeb@app.getsentry.com/38482"
|
2015-02-24 16:40:01 +00:00
|
|
|
_instance = None
|
|
|
|
|
2015-02-24 19:22:10 +00:00
|
|
|
def __init__(self):
|
|
|
|
self._client = None
|
|
|
|
|
2015-03-02 08:05:32 +00:00
|
|
|
def capture_exception(self, request=None):
|
2015-02-24 16:40:01 +00:00
|
|
|
server_config = Config.instance().get_section_config("Server")
|
|
|
|
if server_config.getboolean("report_errors"):
|
|
|
|
if self._client is None:
|
2015-03-03 12:04:30 +00:00
|
|
|
self._client = raven.Client(CrashReport.DSN, release=__version__, raise_send_errors=True)
|
2015-03-02 08:05:32 +00:00
|
|
|
if request is not None:
|
|
|
|
self._client.http_context({
|
|
|
|
"method": request.method,
|
|
|
|
"url": request.path,
|
|
|
|
"data": request.json,
|
|
|
|
})
|
2015-03-03 12:04:30 +00:00
|
|
|
try:
|
|
|
|
self._client.captureException()
|
|
|
|
except Exception as e:
|
|
|
|
log.error("Can't send crash report to Sentry: %s", e)
|
2015-02-24 16:40:01 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def instance(cls):
|
|
|
|
if cls._instance is None:
|
|
|
|
cls._instance = CrashReport()
|
|
|
|
return cls._instance
|