mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-30 20:28:08 +00:00
Crash report with Sentry
This commit is contained in:
parent
67be24a412
commit
250bb38d7c
53
gns3server/crash_report.py
Normal file
53
gns3server/crash_report.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# -*- 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
|
||||||
|
|
||||||
|
from .version import __version__
|
||||||
|
from .config import Config
|
||||||
|
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class CrashReport:
|
||||||
|
|
||||||
|
"""
|
||||||
|
Report crash to a third party service
|
||||||
|
"""
|
||||||
|
|
||||||
|
DSN = "aiohttp+https://50af75d8641d4ea7a4ea6b38c7df6cf9:41d54936f8f14e558066262e2ec8bbeb@app.getsentry.com/38482"
|
||||||
|
_instance = None
|
||||||
|
|
||||||
|
def capture_exception(self, request):
|
||||||
|
server_config = Config.instance().get_section_config("Server")
|
||||||
|
if server_config.getboolean("report_errors"):
|
||||||
|
if self._client is None:
|
||||||
|
self._client = raven.Client(CrashReport.DSN, release=__version__)
|
||||||
|
self._client.http_context({
|
||||||
|
"method": request.method,
|
||||||
|
"url": request.path,
|
||||||
|
"data": request.json,
|
||||||
|
})
|
||||||
|
self._client.captureException()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def instance(cls):
|
||||||
|
if cls._instance is None:
|
||||||
|
cls._instance = CrashReport()
|
||||||
|
return cls._instance
|
@ -43,6 +43,5 @@ class VersionHandler:
|
|||||||
})
|
})
|
||||||
def check_version(request, response):
|
def check_version(request, response):
|
||||||
if request.json["version"] != __version__:
|
if request.json["version"] != __version__:
|
||||||
raise HTTPConflict(text="Client version {} differs with server version {}".format(request.json["version"],
|
raise HTTPConflict(text="Client version {} differs with server version {}".format(request.json["version"], __version__))
|
||||||
__version__))
|
|
||||||
response.json({"version": __version__})
|
response.json({"version": __version__})
|
||||||
|
@ -28,7 +28,7 @@ from gns3server.web.logger import init_logger
|
|||||||
from gns3server.version import __version__
|
from gns3server.version import __version__
|
||||||
from gns3server.config import Config
|
from gns3server.config import Config
|
||||||
from gns3server.modules.project import Project
|
from gns3server.modules.project import Project
|
||||||
|
from gns3server.crash_report import CrashReport
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -168,6 +168,7 @@ def main():
|
|||||||
|
|
||||||
Project.clean_project_directory()
|
Project.clean_project_directory()
|
||||||
|
|
||||||
|
CrashReport.instance()
|
||||||
host = server_config["host"]
|
host = server_config["host"]
|
||||||
port = int(server_config["port"])
|
port = int(server_config["port"])
|
||||||
server = Server(host, port)
|
server = Server(host, port)
|
||||||
|
@ -27,6 +27,7 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
from ..modules.vm_error import VMError
|
from ..modules.vm_error import VMError
|
||||||
from .response import Response
|
from .response import Response
|
||||||
|
from ..crash_report import CrashReport
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -39,6 +40,8 @@ def parse_request(request, input_schema):
|
|||||||
request.json = json.loads(body.decode('utf-8'))
|
request.json = json.loads(body.decode('utf-8'))
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise aiohttp.web.HTTPBadRequest(text="Invalid JSON {}".format(e))
|
raise aiohttp.web.HTTPBadRequest(text="Invalid JSON {}".format(e))
|
||||||
|
else:
|
||||||
|
request.json = {}
|
||||||
try:
|
try:
|
||||||
jsonschema.validate(request.json, input_schema)
|
jsonschema.validate(request.json, input_schema)
|
||||||
except jsonschema.ValidationError as e:
|
except jsonschema.ValidationError as e:
|
||||||
@ -135,6 +138,7 @@ class Route(object):
|
|||||||
log.error("Uncaught exception detected: {type}".format(type=type(e)), exc_info=1)
|
log.error("Uncaught exception detected: {type}".format(type=type(e)), exc_info=1)
|
||||||
response = Response(route=route)
|
response = Response(route=route)
|
||||||
response.set_status(500)
|
response.set_status(500)
|
||||||
|
CrashReport.instance().capture_exception(request)
|
||||||
exc_type, exc_value, exc_tb = sys.exc_info()
|
exc_type, exc_value, exc_tb = sys.exc_info()
|
||||||
lines = traceback.format_exception(exc_type, exc_value, exc_tb)
|
lines = traceback.format_exception(exc_type, exc_value, exc_tb)
|
||||||
if api_version is not None:
|
if api_version is not None:
|
||||||
|
@ -5,3 +5,4 @@ apache-libcloud==0.16.0
|
|||||||
requests==2.5.0
|
requests==2.5.0
|
||||||
aiohttp==0.14.4
|
aiohttp==0.14.4
|
||||||
Jinja2==2.7.3
|
Jinja2==2.7.3
|
||||||
|
raven==5.2.0
|
||||||
|
3
setup.py
3
setup.py
@ -38,7 +38,8 @@ dependencies = ["aiohttp==0.14.4",
|
|||||||
"jsonschema==2.4.0",
|
"jsonschema==2.4.0",
|
||||||
"apache-libcloud==0.16.0",
|
"apache-libcloud==0.16.0",
|
||||||
"requests==2.5.0",
|
"requests==2.5.0",
|
||||||
"Jinja2==2.7.3"]
|
"Jinja2==2.7.3",
|
||||||
|
"raven==5.2.0"]
|
||||||
|
|
||||||
if sys.version_info == (3, 3):
|
if sys.version_info == (3, 3):
|
||||||
dependencies.append("asyncio==3.4.2")
|
dependencies.append("asyncio==3.4.2")
|
||||||
|
Loading…
Reference in New Issue
Block a user