Merge branch 'CURA-7245_sentry_prune_more_user_data' of github.com:Ultimaker/Cura into 4.5

This commit is contained in:
Jaime van Kessel 2020-02-24 17:01:29 +01:00
commit 77f0ff588f
No known key found for this signature in database
GPG key ID: 3710727397403C91
3 changed files with 25 additions and 11 deletions

View file

@ -10,7 +10,7 @@ import os.path
import uuid import uuid
import json import json
import locale import locale
from typing import cast from typing import cast, Any
try: try:
from sentry_sdk.hub import Hub from sentry_sdk.hub import Hub
@ -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,21 @@ class CrashHandler:
self.dialog = QDialog() self.dialog = QDialog()
self._createDialog() self._createDialog()
@staticmethod
def pruneSensitiveData(obj: Any) -> Any:
if isinstance(obj, str):
return obj.replace(home_dir, "<user_home>")
if isinstance(obj, list):
return [CrashHandler.pruneSensitiveData(item) for item in obj]
if isinstance(obj, dict):
return {k: CrashHandler.pruneSensitiveData(v) for k, v in obj.items()}
return obj
@staticmethod
def sentryBeforeSend(event, hint):
return CrashHandler.pruneSensitiveData(event)
def _createEarlyCrashDialog(self): def _createEarlyCrashDialog(self):
dialog = QDialog() dialog = QDialog()
dialog.setMinimumWidth(500) dialog.setMinimumWidth(500)

View file

@ -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
@ -42,8 +43,9 @@ if with_sentry_sdk:
sentry_env = "nightly" sentry_env = "nightly"
except IndexError: except IndexError:
pass pass
sentry_sdk.init("https://5034bf0054fb4b889f82896326e79b13@sentry.io/1821564", sentry_sdk.init("https://5034bf0054fb4b889f82896326e79b13@sentry.io/1821564",
before_send = CrashHandler.sentryBeforeSend,
environment = sentry_env, environment = sentry_env,
release = "cura%s" % ApplicationMetadata.CuraVersion, release = "cura%s" % ApplicationMetadata.CuraVersion,
default_integrations = False, default_integrations = False,

View file

@ -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)