2015-02-24 16:40:01 +00:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
2020-05-19 06:18:53 +00:00
|
|
|
try:
|
|
|
|
import sentry_sdk
|
2020-05-21 08:49:19 +00:00
|
|
|
from sentry_sdk.integrations.logging import LoggingIntegration
|
2021-04-13 09:16:50 +00:00
|
|
|
|
2020-05-19 06:18:53 +00:00
|
|
|
SENTRY_SDK_AVAILABLE = True
|
|
|
|
except ImportError:
|
|
|
|
# Sentry SDK is not installed with deb package in order to simplify packaging
|
|
|
|
SENTRY_SDK_AVAILABLE = False
|
|
|
|
|
2015-03-05 23:11:43 +00:00
|
|
|
import os
|
2015-03-05 16:44:01 +00:00
|
|
|
import sys
|
|
|
|
import struct
|
|
|
|
import platform
|
2018-09-12 13:38:20 +00:00
|
|
|
import locale
|
2018-10-04 14:32:49 +00:00
|
|
|
import distro
|
2015-02-24 16:40:01 +00:00
|
|
|
|
2015-11-05 09:50:37 +00:00
|
|
|
from .version import __version__, __version_info__
|
2015-02-24 16:40:01 +00:00
|
|
|
from .config import Config
|
|
|
|
|
|
|
|
import logging
|
2021-04-13 09:16:50 +00:00
|
|
|
|
2015-02-24 16:40:01 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2016-05-18 09:23:45 +00:00
|
|
|
# Dev build
|
2015-11-05 09:50:37 +00:00
|
|
|
if __version_info__[3] != 0:
|
2015-05-28 10:17:56 +00:00
|
|
|
import faulthandler
|
|
|
|
|
2020-05-21 08:49:19 +00:00
|
|
|
# Display a traceback in case of segfault crash.
|
|
|
|
# Useful when this application is frozen.
|
2015-05-28 10:17:25 +00:00
|
|
|
# Not enabled by default for security reason
|
|
|
|
log.info("Enable catching segfault")
|
2017-05-16 17:28:47 +00:00
|
|
|
try:
|
|
|
|
faulthandler.enable()
|
|
|
|
except Exception:
|
|
|
|
pass # Could fail when loaded into tests
|
2015-05-28 10:17:25 +00:00
|
|
|
|
|
|
|
|
2015-02-24 16:40:01 +00:00
|
|
|
class CrashReport:
|
|
|
|
|
|
|
|
"""
|
|
|
|
Report crash to a third party service
|
|
|
|
"""
|
|
|
|
|
2023-11-15 02:07:48 +00:00
|
|
|
DSN = "https://7439f47d7914699d39d94fa76b867a65@o19455.ingest.sentry.io/38482"
|
2015-02-24 16:40:01 +00:00
|
|
|
_instance = None
|
|
|
|
|
2015-02-24 19:22:10 +00:00
|
|
|
def __init__(self):
|
|
|
|
|
2020-05-19 06:18:53 +00:00
|
|
|
# We don't want sentry making noise if an error is caught when you don't have internet
|
2021-04-13 09:16:50 +00:00
|
|
|
sentry_errors = logging.getLogger("sentry.errors")
|
2015-06-23 17:27:28 +00:00
|
|
|
sentry_errors.disabled = True
|
|
|
|
|
2021-04-13 09:16:50 +00:00
|
|
|
sentry_uncaught = logging.getLogger("sentry.errors.uncaught")
|
2015-06-23 17:27:28 +00:00
|
|
|
sentry_uncaught.disabled = True
|
|
|
|
|
2020-05-19 06:18:53 +00:00
|
|
|
if SENTRY_SDK_AVAILABLE:
|
2020-05-21 08:49:19 +00:00
|
|
|
# Don't send log records as events.
|
|
|
|
sentry_logging = LoggingIntegration(level=logging.INFO, event_level=None)
|
2023-07-06 07:16:05 +00:00
|
|
|
try:
|
|
|
|
sentry_sdk.init(dsn=CrashReport.DSN,
|
|
|
|
release=__version__,
|
|
|
|
default_integrations=False,
|
|
|
|
integrations=[sentry_logging])
|
2023-07-30 07:42:52 +00:00
|
|
|
except Exception as e:
|
2023-07-06 07:16:05 +00:00
|
|
|
log.error("Crash report could not be sent: {}".format(e))
|
|
|
|
return
|
2020-05-19 06:18:53 +00:00
|
|
|
|
|
|
|
tags = {
|
2015-03-05 16:44:01 +00:00
|
|
|
"os:name": platform.system(),
|
|
|
|
"os:release": platform.release(),
|
2015-03-05 19:12:56 +00:00
|
|
|
"os:win_32": " ".join(platform.win32_ver()),
|
|
|
|
"os:mac": "{} {}".format(platform.mac_ver()[0], platform.mac_ver()[2]),
|
2022-10-11 15:28:11 +00:00
|
|
|
"os:linux": distro.name(pretty=True),
|
2020-05-19 06:18:53 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
with sentry_sdk.configure_scope() as scope:
|
|
|
|
for key, value in tags.items():
|
|
|
|
scope.set_tag(key, value)
|
|
|
|
|
|
|
|
extra_context = {
|
2021-04-13 09:16:50 +00:00
|
|
|
"python:version": "{}.{}.{}".format(sys.version_info[0], sys.version_info[1], sys.version_info[2]),
|
2015-03-05 16:44:01 +00:00
|
|
|
"python:bit": struct.calcsize("P") * 8,
|
2015-03-05 23:11:43 +00:00
|
|
|
"python:encoding": sys.getdefaultencoding(),
|
2021-04-13 09:16:50 +00:00
|
|
|
"python:frozen": "{}".format(hasattr(sys, "frozen")),
|
2018-09-12 13:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if sys.platform.startswith("linux") and not hasattr(sys, "frozen"):
|
|
|
|
# add locale information
|
|
|
|
try:
|
|
|
|
language, encoding = locale.getlocale()
|
2020-05-19 06:18:53 +00:00
|
|
|
extra_context["locale:language"] = language
|
|
|
|
extra_context["locale:encoding"] = encoding
|
2018-09-12 13:38:20 +00:00
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# add GNS3 VM version if it exists
|
|
|
|
home = os.path.expanduser("~")
|
|
|
|
gns3vm_version = os.path.join(home, ".config", "GNS3", "gns3vm_version")
|
|
|
|
if os.path.isfile(gns3vm_version):
|
|
|
|
try:
|
|
|
|
with open(gns3vm_version) as fd:
|
2020-05-19 06:18:53 +00:00
|
|
|
extra_context["gns3vm:version"] = fd.readline().strip()
|
2018-09-12 13:38:20 +00:00
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
2020-05-19 06:18:53 +00:00
|
|
|
with sentry_sdk.configure_scope() as scope:
|
|
|
|
for key, value in extra_context.items():
|
|
|
|
scope.set_extra(key, value)
|
|
|
|
|
2020-07-09 10:43:21 +00:00
|
|
|
def capture_exception(self, request=None):
|
2020-05-21 08:49:19 +00:00
|
|
|
|
2020-05-19 06:18:53 +00:00
|
|
|
if not SENTRY_SDK_AVAILABLE:
|
|
|
|
return
|
2020-05-21 08:49:19 +00:00
|
|
|
|
2021-04-13 09:16:50 +00:00
|
|
|
if not hasattr(sys, "frozen") and os.path.exists(
|
|
|
|
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", ".git")
|
|
|
|
):
|
2020-05-19 06:18:53 +00:00
|
|
|
log.warning(".git directory detected, crash reporting is turned off for developers.")
|
|
|
|
return
|
2020-05-21 08:49:19 +00:00
|
|
|
|
2021-04-12 07:32:23 +00:00
|
|
|
if Config.instance().settings.Server.report_errors:
|
2020-05-19 06:18:53 +00:00
|
|
|
|
2020-05-21 08:49:19 +00:00
|
|
|
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
|
|
|
|
|
2015-03-03 12:04:30 +00:00
|
|
|
try:
|
2020-05-21 08:49:19 +00:00
|
|
|
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()
|
2021-04-13 09:07:58 +00:00
|
|
|
log.info(f"Crash report sent with event ID: {sentry_sdk.last_event_id()}")
|
2015-03-03 12:04:30 +00:00
|
|
|
except Exception as e:
|
2021-04-13 09:07:58 +00:00
|
|
|
log.warning(f"Can't send crash report to Sentry: {e}")
|
2015-02-24 16:40:01 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def instance(cls):
|
|
|
|
if cls._instance is None:
|
|
|
|
cls._instance = CrashReport()
|
|
|
|
return cls._instance
|