mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-20 20:59:48 +08:00
Prune all sensitive data before sending it to Sentry
CURA-7245
This commit is contained in:
parent
e52dc56a64
commit
62dfadecdf
@ -32,6 +32,8 @@ from UM.Resources import Resources
|
|||||||
from cura import ApplicationMetadata
|
from cura import ApplicationMetadata
|
||||||
|
|
||||||
catalog = i18nCatalog("cura")
|
catalog = i18nCatalog("cura")
|
||||||
|
home_dir = os.path.expanduser("~")
|
||||||
|
|
||||||
|
|
||||||
MYPY = False
|
MYPY = False
|
||||||
if MYPY:
|
if MYPY:
|
||||||
@ -83,6 +85,20 @@ class CrashHandler:
|
|||||||
self.dialog = QDialog()
|
self.dialog = QDialog()
|
||||||
self._createDialog()
|
self._createDialog()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def pruneSensitiveData(obj):
|
||||||
|
if type(obj) is list:
|
||||||
|
return [CrashHandler.pruneSensitiveData(item) for item in obj]
|
||||||
|
if type(obj) is dict:
|
||||||
|
return {k: CrashHandler.pruneSensitiveData(v) for k, v in obj.items()}
|
||||||
|
if type(obj) is str:
|
||||||
|
return obj.replace(home_dir, "<user_home>")
|
||||||
|
return obj
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def sentry_before_send(event, hint):
|
||||||
|
return CrashHandler.pruneSensitiveData(event)
|
||||||
|
|
||||||
def _createEarlyCrashDialog(self):
|
def _createEarlyCrashDialog(self):
|
||||||
dialog = QDialog()
|
dialog = QDialog()
|
||||||
dialog.setMinimumWidth(500)
|
dialog.setMinimumWidth(500)
|
||||||
|
@ -11,6 +11,7 @@ import sys
|
|||||||
from UM.Platform import Platform
|
from UM.Platform import Platform
|
||||||
from cura import ApplicationMetadata
|
from cura import ApplicationMetadata
|
||||||
from cura.ApplicationMetadata import CuraAppName
|
from cura.ApplicationMetadata import CuraAppName
|
||||||
|
from cura.CrashHandler import CrashHandler
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
@ -44,6 +45,7 @@ if with_sentry_sdk:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
sentry_sdk.init("https://5034bf0054fb4b889f82896326e79b13@sentry.io/1821564",
|
sentry_sdk.init("https://5034bf0054fb4b889f82896326e79b13@sentry.io/1821564",
|
||||||
|
before_send = CrashHandler.sentry_before_send,
|
||||||
environment = sentry_env,
|
environment = sentry_env,
|
||||||
release = "cura%s" % ApplicationMetadata.CuraVersion,
|
release = "cura%s" % ApplicationMetadata.CuraVersion,
|
||||||
default_integrations = False,
|
default_integrations = False,
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
from UM.Logger import LogOutput
|
from UM.Logger import LogOutput
|
||||||
from typing import Set
|
from typing import Set
|
||||||
|
|
||||||
|
from cura.CrashHandler import CrashHandler
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from sentry_sdk import add_breadcrumb
|
from sentry_sdk import add_breadcrumb
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -10,8 +13,6 @@ except ImportError:
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
import os
|
import os
|
||||||
|
|
||||||
home_dir = os.path.expanduser("~")
|
|
||||||
|
|
||||||
|
|
||||||
class SentryLogger(LogOutput):
|
class SentryLogger(LogOutput):
|
||||||
# Sentry (https://sentry.io) is the service that Cura uses for logging crashes. This logger ensures that the
|
# Sentry (https://sentry.io) is the service that Cura uses for logging crashes. This logger ensures that the
|
||||||
@ -37,7 +38,7 @@ class SentryLogger(LogOutput):
|
|||||||
# \param message String containing message to be logged
|
# \param message String containing message to be logged
|
||||||
def log(self, log_type: str, message: str) -> None:
|
def log(self, log_type: str, message: str) -> None:
|
||||||
level = self._translateLogType(log_type)
|
level = self._translateLogType(log_type)
|
||||||
message = self._pruneSensitiveData(message)
|
message = CrashHandler.pruneSensitiveData(message)
|
||||||
if level is None:
|
if level is None:
|
||||||
if message not in self._show_once:
|
if message not in self._show_once:
|
||||||
level = self._translateLogType(log_type[0])
|
level = self._translateLogType(log_type[0])
|
||||||
@ -47,12 +48,6 @@ class SentryLogger(LogOutput):
|
|||||||
else:
|
else:
|
||||||
add_breadcrumb(level = level, message = message)
|
add_breadcrumb(level = level, message = message)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _pruneSensitiveData(message):
|
|
||||||
if home_dir in message:
|
|
||||||
message = message.replace(home_dir, "<user_home>")
|
|
||||||
return message
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _translateLogType(log_type: str) -> Optional[str]:
|
def _translateLogType(log_type: str) -> Optional[str]:
|
||||||
return SentryLogger._levels.get(log_type)
|
return SentryLogger._levels.get(log_type)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user