mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-16 18:59:39 +08:00
SentrySDK: Turn on deep integration on demand
Only whenever the sentry_sdk module is there functions of this module will be used. The only changes, which were needed to be made, are done on cura_app.py and cura.CrashHandler. Whenever the module is not available, it's functions will be omitted. The if-clauses could happen earlier, but this at least the bare minimum, and, to be honest, on Ultimaker's distribution it won't speed up anything. I expect the if-clause to take the same amount of runtime sooner or later. The check is the same and it should be on Ultimaker's distribution always be "True". Signed-off-by: Thomas Karl Pietrowski <thopiekar@gmail.com> (github: thopiekar)
This commit is contained in:
parent
c261065d68
commit
ba5a0b0085
@ -12,9 +12,13 @@ import json
|
|||||||
import locale
|
import locale
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
from sentry_sdk.hub import Hub
|
try:
|
||||||
from sentry_sdk.utils import event_from_exception
|
from sentry_sdk.hub import Hub
|
||||||
from sentry_sdk import configure_scope
|
from sentry_sdk.utils import event_from_exception
|
||||||
|
from sentry_sdk import configure_scope
|
||||||
|
with_sentry_sdk = True
|
||||||
|
except ImportError:
|
||||||
|
with_sentry_sdk = False
|
||||||
|
|
||||||
from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR, QUrl
|
from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR, QUrl
|
||||||
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QTextEdit, QGroupBox, QCheckBox, QPushButton
|
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QTextEdit, QGroupBox, QCheckBox, QPushButton
|
||||||
@ -66,8 +70,9 @@ class CrashHandler:
|
|||||||
if has_started and exception_type in skip_exception_types:
|
if has_started and exception_type in skip_exception_types:
|
||||||
return
|
return
|
||||||
|
|
||||||
with configure_scope() as scope:
|
if with_sentry_sdk:
|
||||||
scope.set_tag("during_startup", not has_started)
|
with configure_scope() as scope:
|
||||||
|
scope.set_tag("during_startup", not has_started)
|
||||||
|
|
||||||
if not has_started:
|
if not has_started:
|
||||||
self._send_report_checkbox = None
|
self._send_report_checkbox = None
|
||||||
@ -203,16 +208,17 @@ class CrashHandler:
|
|||||||
layout.addWidget(label)
|
layout.addWidget(label)
|
||||||
group.setLayout(layout)
|
group.setLayout(layout)
|
||||||
|
|
||||||
with configure_scope() as scope:
|
if with_sentry_sdk:
|
||||||
scope.set_tag("qt_version", QT_VERSION_STR)
|
with configure_scope() as scope:
|
||||||
scope.set_tag("pyqt_version", PYQT_VERSION_STR)
|
scope.set_tag("qt_version", QT_VERSION_STR)
|
||||||
scope.set_tag("os", platform.system())
|
scope.set_tag("pyqt_version", PYQT_VERSION_STR)
|
||||||
scope.set_tag("os_version", platform.version())
|
scope.set_tag("os", platform.system())
|
||||||
scope.set_tag("locale_os", self.data["locale_os"])
|
scope.set_tag("os_version", platform.version())
|
||||||
scope.set_tag("locale_cura", self.cura_locale)
|
scope.set_tag("locale_os", self.data["locale_os"])
|
||||||
scope.set_tag("is_enterprise", ApplicationMetadata.IsEnterpriseVersion)
|
scope.set_tag("locale_cura", self.cura_locale)
|
||||||
|
scope.set_tag("is_enterprise", ApplicationMetadata.IsEnterpriseVersion)
|
||||||
scope.set_user({"id": str(uuid.getnode())})
|
|
||||||
|
scope.set_user({"id": str(uuid.getnode())})
|
||||||
|
|
||||||
return group
|
return group
|
||||||
|
|
||||||
@ -247,12 +253,13 @@ class CrashHandler:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with configure_scope() as scope:
|
if with_sentry_sdk:
|
||||||
scope.set_tag("opengl_version", opengl_instance.getOpenGLVersion())
|
with configure_scope() as scope:
|
||||||
scope.set_tag("gpu_vendor", opengl_instance.getGPUVendorName())
|
scope.set_tag("opengl_version", opengl_instance.getOpenGLVersion())
|
||||||
scope.set_tag("gpu_type", opengl_instance.getGPUType())
|
scope.set_tag("gpu_vendor", opengl_instance.getGPUVendorName())
|
||||||
scope.set_tag("active_machine", active_machine_definition_id)
|
scope.set_tag("gpu_type", opengl_instance.getGPUType())
|
||||||
scope.set_tag("active_machine_manufacturer", active_machine_manufacturer)
|
scope.set_tag("active_machine", active_machine_definition_id)
|
||||||
|
scope.set_tag("active_machine_manufacturer", active_machine_manufacturer)
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
@ -335,9 +342,10 @@ class CrashHandler:
|
|||||||
"module_name": module_name, "version": module_version, "is_plugin": isPlugin}
|
"module_name": module_name, "version": module_version, "is_plugin": isPlugin}
|
||||||
self.data["exception"] = exception_dict
|
self.data["exception"] = exception_dict
|
||||||
|
|
||||||
with configure_scope() as scope:
|
if with_sentry_sdk:
|
||||||
scope.set_tag("is_plugin", isPlugin)
|
with configure_scope() as scope:
|
||||||
scope.set_tag("module", module_name)
|
scope.set_tag("is_plugin", isPlugin)
|
||||||
|
scope.set_tag("module", module_name)
|
||||||
|
|
||||||
return group
|
return group
|
||||||
|
|
||||||
@ -396,15 +404,24 @@ class CrashHandler:
|
|||||||
# Before sending data, the user comments are stored
|
# Before sending data, the user comments are stored
|
||||||
self.data["user_info"] = self.user_description_text_area.toPlainText()
|
self.data["user_info"] = self.user_description_text_area.toPlainText()
|
||||||
|
|
||||||
try:
|
if with_sentry_sdk:
|
||||||
hub = Hub.current
|
try:
|
||||||
event, hint = event_from_exception((self.exception_type, self.value, self.traceback))
|
hub = Hub.current
|
||||||
hub.capture_event(event, hint=hint)
|
event, hint = event_from_exception((self.exception_type, self.value, self.traceback))
|
||||||
hub.flush()
|
hub.capture_event(event, hint=hint)
|
||||||
except Exception as e: # We don't want any exception to cause problems
|
hub.flush()
|
||||||
Logger.logException("e", "An exception occurred while trying to send crash report")
|
except Exception as e: # We don't want any exception to cause problems
|
||||||
|
Logger.logException("e", "An exception occurred while trying to send crash report")
|
||||||
|
if not self.has_started:
|
||||||
|
print("An exception occurred while trying to send crash report: %s" % e)
|
||||||
|
else:
|
||||||
|
msg = "SentrySDK is not available and the report could not be sent."
|
||||||
|
Logger.logException("e", msg)
|
||||||
if not self.has_started:
|
if not self.has_started:
|
||||||
print("An exception occurred while trying to send crash report: %s" % e)
|
print(msg)
|
||||||
|
print("Exception type: {}".format(self.exception_type))
|
||||||
|
print("Value: {}".format(self.value))
|
||||||
|
print("Traceback: {}".format(self.traceback))
|
||||||
|
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
|
|
||||||
|
37
cura_app.py
37
cura_app.py
@ -12,7 +12,11 @@ from UM.Platform import Platform
|
|||||||
from cura import ApplicationMetadata
|
from cura import ApplicationMetadata
|
||||||
from cura.ApplicationMetadata import CuraAppName
|
from cura.ApplicationMetadata import CuraAppName
|
||||||
|
|
||||||
import sentry_sdk
|
try:
|
||||||
|
import sentry_sdk
|
||||||
|
with_sentry_sdk = True
|
||||||
|
except ImportError:
|
||||||
|
with_sentry_sdk = False
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(prog = "cura",
|
parser = argparse.ArgumentParser(prog = "cura",
|
||||||
add_help = False)
|
add_help = False)
|
||||||
@ -24,21 +28,22 @@ parser.add_argument("--debug",
|
|||||||
|
|
||||||
known_args = vars(parser.parse_known_args()[0])
|
known_args = vars(parser.parse_known_args()[0])
|
||||||
|
|
||||||
sentry_env = "production"
|
if with_sentry_sdk:
|
||||||
if ApplicationMetadata.CuraVersion == "master":
|
sentry_env = "production"
|
||||||
sentry_env = "development"
|
if ApplicationMetadata.CuraVersion == "master":
|
||||||
try:
|
sentry_env = "development"
|
||||||
if ApplicationMetadata.CuraVersion.split(".")[2] == "99":
|
try:
|
||||||
sentry_env = "nightly"
|
if ApplicationMetadata.CuraVersion.split(".")[2] == "99":
|
||||||
except IndexError:
|
sentry_env = "nightly"
|
||||||
pass
|
except IndexError:
|
||||||
|
pass
|
||||||
sentry_sdk.init("https://5034bf0054fb4b889f82896326e79b13@sentry.io/1821564",
|
|
||||||
environment = sentry_env,
|
sentry_sdk.init("https://5034bf0054fb4b889f82896326e79b13@sentry.io/1821564",
|
||||||
release = "cura%s" % ApplicationMetadata.CuraVersion,
|
environment = sentry_env,
|
||||||
default_integrations = False,
|
release = "cura%s" % ApplicationMetadata.CuraVersion,
|
||||||
max_breadcrumbs = 300,
|
default_integrations = False,
|
||||||
server_name = "cura")
|
max_breadcrumbs = 300,
|
||||||
|
server_name = "cura")
|
||||||
|
|
||||||
if not known_args["debug"]:
|
if not known_args["debug"]:
|
||||||
def get_cura_dir_path():
|
def get_cura_dir_path():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user