1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Fix issues with crash reporting & bump version to 2.2.9dev2. Ref https://github.com/GNS3/gns3-server/issues/1758

This commit is contained in:
grossmj 2020-05-21 18:19:19 +09:30
parent 1a20cbeefd
commit 5c3bd589b9
4 changed files with 32 additions and 10 deletions

View File

@ -17,7 +17,7 @@
try: try:
import sentry_sdk import sentry_sdk
from sentry_sdk.integrations.aiohttp import AioHttpIntegration from sentry_sdk.integrations.logging import LoggingIntegration
SENTRY_SDK_AVAILABLE = True SENTRY_SDK_AVAILABLE = True
except ImportError: except ImportError:
# Sentry SDK is not installed with deb package in order to simplify packaging # Sentry SDK is not installed with deb package in order to simplify packaging
@ -42,7 +42,8 @@ log = logging.getLogger(__name__)
if __version_info__[3] != 0: if __version_info__[3] != 0:
import faulthandler import faulthandler
# Display a traceback in case of segfault crash. Usefull when frozen # Display a traceback in case of segfault crash.
# Useful when this application is frozen.
# Not enabled by default for security reason # Not enabled by default for security reason
log.info("Enable catching segfault") log.info("Enable catching segfault")
try: try:
@ -78,10 +79,13 @@ class CrashReport:
else: else:
log.error("The SSL certificate bundle file '{}' could not be found".format(cacert_resource)) log.error("The SSL certificate bundle file '{}' could not be found".format(cacert_resource))
# Don't send log records as events.
sentry_logging = LoggingIntegration(level=logging.INFO, event_level=None)
sentry_sdk.init(dsn=CrashReport.DSN, sentry_sdk.init(dsn=CrashReport.DSN,
release=__version__, release=__version__,
ca_certs=cacert, ca_certs=cacert,
integrations=[AioHttpIntegration()]) integrations=[sentry_logging])
tags = { tags = {
"os:name": platform.system(), "os:name": platform.system(),
@ -128,20 +132,39 @@ class CrashReport:
for key, value in extra_context.items(): for key, value in extra_context.items():
scope.set_extra(key, value) scope.set_extra(key, value)
def capture_exception(self): def capture_exception(self, request):
if not SENTRY_SDK_AVAILABLE: if not SENTRY_SDK_AVAILABLE:
return return
if os.path.exists(".git"):
if not hasattr(sys, "frozen") and os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", ".git")):
log.warning(".git directory detected, crash reporting is turned off for developers.") log.warning(".git directory detected, crash reporting is turned off for developers.")
return return
server_config = Config.instance().get_section_config("Server") server_config = Config.instance().get_section_config("Server")
if server_config.getboolean("report_errors"): if server_config.getboolean("report_errors"):
if not SENTRY_SDK_AVAILABLE:
log.warning("Cannot capture exception: Sentry SDK is not available")
return
if os.path.exists(".git"):
log.warning(".git directory detected, crash reporting is turned off for developers.")
return
try: try:
sentry_sdk.capture_exception() if request:
# add specific extra request information
with sentry_sdk.push_scope() as scope:
scope.set_extra("method", request.method)
scope.set_extra("url", request.path)
scope.set_extra("json", request.json)
sentry_sdk.capture_exception()
else:
sentry_sdk.capture_exception()
log.info("Crash report sent with event ID: {}".format(sentry_sdk.last_event_id())) log.info("Crash report sent with event ID: {}".format(sentry_sdk.last_event_id()))
except Exception as e: except Exception as e:
log.error("Can't send crash report to Sentry: {}".format(e)) log.warning("Can't send crash report to Sentry: {}".format(e))
@classmethod @classmethod
def instance(cls): def instance(cls):

View File

@ -23,7 +23,7 @@
# or negative for a release candidate or beta (after the base version # or negative for a release candidate or beta (after the base version
# number has been incremented) # number has been incremented)
__version__ = "2.2.9dev1" __version__ = "2.2.9dev2"
__version_info__ = (2, 2, 9, 99) __version_info__ = (2, 2, 9, 99)
if "dev" in __version__: if "dev" in __version__:

View File

@ -242,7 +242,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(request=request, route=route) response = Response(request=request, route=route)
response.set_status(500) response.set_status(500)
CrashReport.instance().capture_exception() 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:

View File

@ -3,7 +3,6 @@ jsonschema==2.6.0; python_version < '3.8' # pyup: ignore
aiohttp==3.6.2 aiohttp==3.6.2
aiohttp-cors==0.7.0 aiohttp-cors==0.7.0
aiofiles==0.4.0 aiofiles==0.4.0
aiocontextvars==0.2.2; python_version < '3.7'
Jinja2>=2.7.3 Jinja2>=2.7.3
sentry-sdk>=0.14.4 sentry-sdk>=0.14.4
psutil==5.6.6 psutil==5.6.6