mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-17 03:09:40 +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
|
||||
|
||||
catalog = i18nCatalog("cura")
|
||||
home_dir = os.path.expanduser("~")
|
||||
|
||||
|
||||
MYPY = False
|
||||
if MYPY:
|
||||
@ -83,6 +85,20 @@ class CrashHandler:
|
||||
self.dialog = QDialog()
|
||||
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):
|
||||
dialog = QDialog()
|
||||
dialog.setMinimumWidth(500)
|
||||
|
@ -11,6 +11,7 @@ import sys
|
||||
from UM.Platform import Platform
|
||||
from cura import ApplicationMetadata
|
||||
from cura.ApplicationMetadata import CuraAppName
|
||||
from cura.CrashHandler import CrashHandler
|
||||
|
||||
try:
|
||||
import sentry_sdk
|
||||
@ -42,8 +43,9 @@ if with_sentry_sdk:
|
||||
sentry_env = "nightly"
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
|
||||
sentry_sdk.init("https://5034bf0054fb4b889f82896326e79b13@sentry.io/1821564",
|
||||
before_send = CrashHandler.sentry_before_send,
|
||||
environment = sentry_env,
|
||||
release = "cura%s" % ApplicationMetadata.CuraVersion,
|
||||
default_integrations = False,
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
from UM.Logger import LogOutput
|
||||
from typing import Set
|
||||
|
||||
from cura.CrashHandler import CrashHandler
|
||||
|
||||
try:
|
||||
from sentry_sdk import add_breadcrumb
|
||||
except ImportError:
|
||||
@ -10,8 +13,6 @@ except ImportError:
|
||||
from typing import Optional
|
||||
import os
|
||||
|
||||
home_dir = os.path.expanduser("~")
|
||||
|
||||
|
||||
class SentryLogger(LogOutput):
|
||||
# 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
|
||||
def log(self, log_type: str, message: str) -> None:
|
||||
level = self._translateLogType(log_type)
|
||||
message = self._pruneSensitiveData(message)
|
||||
message = CrashHandler.pruneSensitiveData(message)
|
||||
if level is None:
|
||||
if message not in self._show_once:
|
||||
level = self._translateLogType(log_type[0])
|
||||
@ -47,12 +48,6 @@ class SentryLogger(LogOutput):
|
||||
else:
|
||||
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
|
||||
def _translateLogType(log_type: str) -> Optional[str]:
|
||||
return SentryLogger._levels.get(log_type)
|
||||
|
Loading…
x
Reference in New Issue
Block a user